hacking.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. .. _installing-for-development:
  2. Installing Salt for development
  3. ===============================
  4. Clone the repository using:
  5. .. code-block:: bash
  6. git clone https://github.com/saltstack/salt
  7. .. note:: tags
  8. Just cloning the repository is enough to work with Salt and make
  9. contributions. However, fetching additional tags from git is required to
  10. have Salt report the correct version for itself. To do this, first
  11. add the git repository as an upstream source:
  12. .. code-block:: bash
  13. git remote add upstream https://github.com/saltstack/salt
  14. Fetching tags is done with the git 'fetch' utility:
  15. .. code-block:: bash
  16. git fetch --tags upstream
  17. Create a new `virtualenv`_:
  18. .. code-block:: bash
  19. virtualenv /path/to/your/virtualenv
  20. .. _`virtualenv`: https://pypi.org/project/virtualenv/
  21. Avoid making your :ref:`virtualenv path too long <too_long_socket_path>`.
  22. On Arch Linux, where Python 3 is the default installation of Python, use
  23. the ``virtualenv2`` command instead of ``virtualenv``.
  24. On Gentoo you must use ``--system-site-packages`` to enable pkg and portage_config
  25. functionality
  26. .. note:: Using system Python modules in the virtualenv
  27. To use already-installed python modules in virtualenv (instead of having pip
  28. download and compile new ones), run ``virtualenv --system-site-packages``
  29. Using this method eliminates the requirement to install the salt dependencies
  30. again, although it does assume that the listed modules are all installed in the
  31. system PYTHONPATH at the time of virtualenv creation.
  32. .. note:: Python development package
  33. Be sure to install python devel package in order to install required Python
  34. modules. In Debian/Ubuntu run ``sudo apt-get install -y python-dev``. In RedHat
  35. based system install ``python-devel``
  36. Activate the virtualenv:
  37. .. code-block:: bash
  38. source /path/to/your/virtualenv/bin/activate
  39. Install Salt (and dependencies) into the virtualenv:
  40. .. code-block:: bash
  41. pip install pyzmq PyYAML pycrypto msgpack-python jinja2 psutil futures tornado
  42. pip install -e ./salt # the path to the salt git clone from above
  43. .. note:: Installing psutil
  44. Python header files are required to build this module, otherwise the pip
  45. install will fail. If your distribution separates binaries and headers into
  46. separate packages, make sure that you have the headers installed. In most
  47. Linux distributions which split the headers into their own package, this
  48. can be done by installing the ``python-dev`` or ``python-devel`` package.
  49. For other platforms, the package will likely be similarly named.
  50. .. _`RHEL`: https://www.redhat.com/products/enterprise-linux/
  51. .. _`CentOS`: http://centos.org/
  52. .. _`Fedora Linux`: http://fedoraproject.org/
  53. .. _`Amazon Linux`: https://aws.amazon.com/amazon-linux-ami/
  54. .. note:: Installing dependencies on macOS.
  55. You can install needed dependencies on macOS using homebrew or macports.
  56. See :ref:`macOS Installation <macos-installation>`
  57. .. warning:: Installing on RedHat-based Distros
  58. If installing from pip (or from source using ``setup.py install``), be
  59. advised that the ``yum-utils`` package is needed for Salt to manage
  60. packages on RedHat-based systems.
  61. Running a self-contained development version
  62. --------------------------------------------
  63. During development it is easiest to be able to run the Salt master and minion
  64. that are installed in the virtualenv you created above, and also to have all
  65. the configuration, log, and cache files contained in the virtualenv as well.
  66. The ``/path/to/your/virtualenv`` referenced multiple times below is also
  67. available in the variable ``$VIRTUAL_ENV`` once the virtual environment is
  68. activated.
  69. Copy the master and minion config files into your virtualenv:
  70. .. code-block:: bash
  71. mkdir -p /path/to/your/virtualenv/etc/salt/pki/{master,minion}
  72. cp ./salt/conf/master ./salt/conf/minion /path/to/your/virtualenv/etc/salt/
  73. Edit the master config file:
  74. 1. Uncomment and change the ``user: root`` value to your own user.
  75. 2. Uncomment and change the ``root_dir: /`` value to point to
  76. ``/path/to/your/virtualenv``.
  77. 3. Uncomment and change the ``pki_dir: /etc/salt/pki/master`` value to point to
  78. ``/path/to/your/virtualenv/etc/salt/pki/master``
  79. 4. If you are running version 0.11.1 or older, uncomment, and change the
  80. ``pidfile: /var/run/salt-master.pid`` value to point to
  81. ``/path/to/your/virtualenv/salt-master.pid``.
  82. 5. If you are also running a non-development version of Salt you will have to
  83. change the ``publish_port`` and ``ret_port`` values as well.
  84. Edit the minion config file:
  85. 1. Repeat the edits you made in the master config for the ``user`` and
  86. ``root_dir`` values as well as any port changes.
  87. 2. Uncomment and change the ``pki_dir: /etc/salt/pki/minion`` value to point to
  88. ``/path/to/your/virtualenv/etc/salt/pki/minion``
  89. 3. If you are running version 0.11.1 or older, uncomment, and change the
  90. ``pidfile: /var/run/salt-minion.pid`` value to point to
  91. ``/path/to/your/virtualenv/salt-minion.pid``.
  92. 4. Uncomment and change the ``master: salt`` value to point at ``localhost``.
  93. 5. Uncomment and change the ``id:`` value to something descriptive like
  94. "saltdev". This isn't strictly necessary but it will serve as a reminder of
  95. which Salt installation you are working with.
  96. 6. If you changed the ``ret_port`` value in the master config because you are
  97. also running a non-development version of Salt, then you will have to
  98. change the ``master_port`` value in the minion config to match.
  99. .. note:: Using `salt-call` with a :ref:`Standalone Minion <tutorial-standalone-minion>`
  100. If you plan to run `salt-call` with this self-contained development
  101. environment in a masterless setup, you should invoke `salt-call` with
  102. ``-c /path/to/your/virtualenv/etc/salt`` so that salt can find the minion
  103. config file. Without the ``-c`` option, Salt finds its config files in
  104. `/etc/salt`.
  105. Start the master and minion, accept the minion's key, and verify your local Salt
  106. installation is working:
  107. .. code-block:: bash
  108. cd /path/to/your/virtualenv
  109. salt-master -c ./etc/salt -d
  110. salt-minion -c ./etc/salt -d
  111. salt-key -c ./etc/salt -L
  112. salt-key -c ./etc/salt -A
  113. salt -c ./etc/salt '*' test.version
  114. Running the master and minion in debug mode can be helpful when developing. To
  115. do this, add ``-l debug`` to the calls to ``salt-master`` and ``salt-minion``.
  116. If you would like to log to the console instead of to the log file, remove the
  117. ``-d``.
  118. .. _too_long_socket_path:
  119. .. note:: Too long socket path?
  120. Once the minion starts, you may see an error like the following:
  121. .. code-block:: bash
  122. zmq.core.error.ZMQError: ipc path "/path/to/your/virtualenv/
  123. var/run/salt/minion/minion_event_7824dcbcfd7a8f6755939af70b96249f_pub.ipc"
  124. is longer than 107 characters (sizeof(sockaddr_un.sun_path)).
  125. This means that the path to the socket the minion is using is too long. This is
  126. a system limitation, so the only workaround is to reduce the length of this
  127. path. This can be done in a couple different ways:
  128. 1. Create your virtualenv in a path that is short enough.
  129. 2. Edit the :conf_minion:`sock_dir` minion config variable and reduce its
  130. length. Remember that this path is relative to the value you set in
  131. :conf_minion:`root_dir`.
  132. ``NOTE:`` The socket path is limited to 107 characters on Solaris and Linux,
  133. and 103 characters on BSD-based systems.
  134. .. note:: File descriptor limits
  135. Ensure that the system open file limit is raised to at least 2047:
  136. .. code-block:: bash
  137. # check your current limit
  138. ulimit -n
  139. # raise the limit. persists only until reboot
  140. # use 'limit descriptors 2047' for c-shell
  141. ulimit -n 2047
  142. To set file descriptors on macOS, refer to the :ref:`macOS Installation
  143. <macos-installation>` instructions.
  144. Changing Default Paths
  145. ~~~~~~~~~~~~~~~~~~~~~~
  146. Instead of updating your configuration files to point to the new root directory
  147. and having to pass the new configuration directory path to all of Salt's CLI
  148. tools, you can explicitly tweak the default system paths that Salt expects:
  149. .. code-block:: bash
  150. GENERATE_SALT_SYSPATHS=1 pip install --global-option='--salt-root-dir=/path/to/your/virtualenv/' \
  151. -e ./salt # the path to the salt git clone from above
  152. You can now call all of Salt's CLI tools without explicitly passing the configuration directory.
  153. Additional Options
  154. ..................
  155. If you want to distribute your virtualenv, you probably don't want to include
  156. Salt's clone ``.git/`` directory, and, without it, Salt won't report the
  157. accurate version. You can tell ``setup.py`` to generate the hardcoded version
  158. information which is distributable:
  159. .. code-block:: bash
  160. GENERATE_SALT_SYSPATHS=1 WRITE_SALT_VERSION=1 pip install --global-option='--salt-root-dir=/path/to/your/virtualenv/' \
  161. -e ./salt # the path to the salt git clone from above
  162. Instead of passing those two environmental variables, you can just pass a
  163. single one which will trigger the other two:
  164. .. code-block:: bash
  165. MIMIC_SALT_INSTALL=1 pip install --global-option='--salt-root-dir=/path/to/your/virtualenv/' \
  166. -e ./salt # the path to the salt git clone from above
  167. This last one will grant you an editable salt installation with hardcoded
  168. system paths and version information.
  169. Installing Salt from the Python Package Index
  170. ---------------------------------------------
  171. If you are installing using ``easy_install``, you will need to define a
  172. :strong:`USE_SETUPTOOLS` environment variable, otherwise dependencies will not
  173. be installed:
  174. .. code-block:: bash
  175. USE_SETUPTOOLS=1 easy_install salt
  176. Editing and previewing the documentation
  177. ----------------------------------------
  178. You need ``sphinx-build`` command to build the docs. In Debian/Ubuntu this is
  179. provided in the ``python-sphinx`` package. Sphinx can also be installed
  180. to a virtualenv using pip:
  181. .. code-block:: bash
  182. pip install Sphinx==1.3.1
  183. Change to salt documentation directory, then:
  184. .. code-block:: bash
  185. cd doc; make html
  186. - This will build the HTML docs. Run ``make`` without any arguments to see the
  187. available make targets, which include :strong:`html`, :strong:`man`, and
  188. :strong:`text`.
  189. - The docs then are built within the :strong:`docs/_build/` folder. To update
  190. the docs after making changes, run ``make`` again.
  191. - The docs use `reStructuredText
  192. <https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html>`_
  193. for markup.
  194. See a live demo at http://rst.ninjs.org/.
  195. - The help information on each module or state is culled from the python code
  196. that runs for that piece. Find them in ``salt/modules/`` or ``salt/states/``.
  197. - To build the docs on Arch Linux, the :strong:`python2-sphinx` package is
  198. required. Additionally, it is necessary to tell :strong:`make` where to find
  199. the proper :strong:`sphinx-build` binary, like so:
  200. .. code-block:: bash
  201. make SPHINXBUILD=sphinx-build2 html
  202. - To build the docs on RHEL/CentOS 6, the :strong:`python-sphinx10` package
  203. must be installed from EPEL, and the following make command must be used:
  204. .. code-block:: bash
  205. make SPHINXBUILD=sphinx-build html
  206. Once you've updated the documentation, you can run the following command to
  207. launch a simple Python HTTP server to see your changes:
  208. .. code-block:: bash
  209. cd _build/html; python -m SimpleHTTPServer
  210. Running unit and integration tests
  211. ----------------------------------
  212. Run the test suite with following command:
  213. .. code-block:: bash
  214. ./setup.py test
  215. See :ref:`here <salt-test-suite>` for more information regarding the test suite.
  216. Issue and Pull Request Labeling System
  217. --------------------------------------
  218. SaltStack uses several labeling schemes to help facilitate code contributions
  219. and bug resolution. See the :ref:`Labels and Milestones
  220. <labels-and-milestones>` documentation for more information.