1
0

HACKING.rst 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. Developing Salt
  2. ===============
  3. If you want to help develop Salt there is a great need and your patches are
  4. welcome!
  5. To assist in Salt development, you can help in a number of ways.
  6. Setting a GitHub pull request
  7. -----------------------------
  8. This is the preferred method for contributions, simply create a GitHub
  9. fork, commit your changes to the fork, and then open up a pull request.
  10. Please review the following questions when creating a pull request:
  11. `<https://docs.saltstack.com/en/develop/topics/development/pull_requests.html>`_
  12. Contributions Welcome!
  13. ----------------------
  14. The goal here is to make contributions clear, make sure there is a trail for
  15. where the code has come from, but most importantly, to give credit where credit
  16. is due!
  17. The `Open Comparison Contributing Docs`__ explains the workflow for forking,
  18. cloning, branching, committing, and sending a pull request for the git
  19. repository.
  20. ``git pull upstream develop`` is a shorter way to update your local repository
  21. to the latest version.
  22. .. __: http://opencomparison.readthedocs.org/en/latest/contributing.html
  23. Editing and Previewing the Docs
  24. -------------------------------
  25. You need ``sphinx-build`` to build the docs. In Debian/Ubuntu this is provided
  26. in the ``python-sphinx`` package.
  27. Then::
  28. cd doc; make html
  29. - The docs then are built in the ``docs/_build/html/`` folder. If you make
  30. changes and want to see the results, ``make html`` again.
  31. - The docs use ``reStructuredText`` for markup. See a live demo at
  32. http://rst.ninjs.org/
  33. - The help information on each module or state is culled from the python code
  34. that runs for that piece. Find them in ``salt/modules/`` or ``salt/states/``.
  35. - If you are developing using Arch Linux (or any other distribution for which
  36. Python 3 is the default Python installation), then ``sphinx-build`` may be
  37. named ``sphinx-build2`` instead. If this is the case, then you will need to
  38. run the following ``make`` command::
  39. make SPHINXBUILD=sphinx-build2 html
  40. Installing Salt for development
  41. -------------------------------
  42. Clone the repository using::
  43. git clone https://github.com/saltstack/salt
  44. cd salt
  45. .. note:: tags
  46. Just cloning the repository is enough to work with Salt and make
  47. contributions. However, you must fetch additional tags into your clone to
  48. have Salt report the correct version for itself. To do this, fetch the tags
  49. with the command::
  50. git fetch --tags
  51. Preparing your system
  52. ~~~~~~~~~~~~~~~~~~~~~
  53. In order to install Salt's requirements, you'll need a system with a compiler
  54. and Python's development libraries.
  55. Debian-based systems
  56. ````````````````````
  57. On Debian and derivative systems such as Ubuntu, system requirements can be
  58. installed by running::
  59. apt-get install -y build-essential libssl-dev python-dev python-m2crypto \
  60. python-pip python-virtualenv virtualenvwrapper
  61. RedHat-based systems
  62. ````````````````````
  63. If you are developing using one of these releases, you will want to create your
  64. virtualenv using the ``--system-site-packages`` option so that these modules
  65. are available in the virtualenv.
  66. Installing dependencies on macOS
  67. ````````````````````````````````
  68. One simple way to get all needed dependencies on macOS is to use homebrew,
  69. and install the following packages::
  70. brew install zmq
  71. Afterward the pip commands should run without a hitch. Also be sure to set
  72. max_open_files to 2048 (see below).
  73. Create a virtual environment
  74. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  75. Create a new `virtualenv`_::
  76. virtualenv /path/to/your/virtualenv
  77. .. _`virtualenv`: http://pypi.python.org/pypi/virtualenv
  78. On Arch Linux, where Python 3 is the default installation of Python, use the
  79. ``virtualenv2`` command instead of ``virtualenv``.
  80. Debian, Ubuntu, and the RedHat systems mentioned above, you should use
  81. ``--system-site-packages`` when creating the virtualenv, to pull in the
  82. M2Crypto installed using apt::
  83. virtualenv --system-site-packages /path/to/your/virtualenv
  84. On Gentoo systems you should use ``--system-site-packages`` when creating
  85. the virtualenv to enable pkg and portage_config functionality as the
  86. portage package is not available via pip
  87. .. note:: Using your system Python modules in the virtualenv
  88. If you have the required python modules installed on your system already
  89. and would like to use them in the virtualenv rather than having pip
  90. download and compile new ones into this environment, run ``virtualenv``
  91. with the ``--system-site-packages`` option. If you do this, you can skip
  92. the pip command below that installs the dependencies (pyzmq, M2Crypto,
  93. etc.), assuming that the listed modules are all installed in your system
  94. PYTHONPATH at the time you create your virtualenv.
  95. Configure your virtual environment
  96. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  97. Activate the virtualenv::
  98. source /path/to/your/virtualenv/bin/activate
  99. Install Salt (and dependencies) into the virtualenv.
  100. ZeroMQ Transport:
  101. .. code-block:: bash
  102. pip install -r requirements/zeromq.txt
  103. pip install psutil
  104. pip install -e .
  105. Running a self-contained development version
  106. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  107. During development it is easiest to be able to run the Salt master and minion
  108. that are installed in the virtualenv you created above, and also to have all
  109. the configuration, log, and cache files contained in the virtualenv as well.
  110. Copy the master and minion config files into your virtualenv::
  111. mkdir -p /path/to/your/virtualenv/etc/salt
  112. cp ./salt/conf/master /path/to/your/virtualenv/etc/salt/master
  113. cp ./salt/conf/minion /path/to/your/virtualenv/etc/salt/minion
  114. Edit the master config file:
  115. 1. Uncomment and change the ``user: root`` value to your own user.
  116. 2. Uncomment and change the ``root_dir: /`` value to point to
  117. ``/path/to/your/virtualenv``.
  118. 3. If you are running version 0.11.1 or older, uncomment and change the
  119. ``pidfile: /var/run/salt-master.pid`` value to point to
  120. ``/path/to/your/virtualenv/salt-master.pid``.
  121. 4. If you are also running a non-development version of Salt you will have to
  122. change the ``publish_port`` and ``ret_port`` values as well.
  123. 5. On xxxOS X also set max_open_files to 2048.
  124. Edit the minion config file:
  125. 1. Repeat the edits you made in the master config for the ``user`` and
  126. ``root_dir`` values as well as any port changes.
  127. 2. If you are running version 0.11.1 or older, uncomment and change the
  128. ``pidfile: /var/run/salt-minion.pid`` value to point to
  129. ``/path/to/your/virtualenv/salt-minion.pid``.
  130. 3. Uncomment and change the ``master: salt`` value to point at ``localhost``.
  131. 4. Uncomment and change the ``id:`` value to something descriptive like
  132. "saltdev". This isn't strictly necessary but it will serve as a reminder of
  133. which Salt installation you are working with.
  134. 5. If you changed the ``ret_port`` value in the master config because you are
  135. also running a non-development version of Salt, then you will have to
  136. change the ``master_port`` value in the minion config to match.
  137. .. note:: Using `salt-call` with a :ref:`Standalone Minion <tutorial-standalone-minion>`
  138. If you plan to run `salt-call` with this self-contained development
  139. environment in a masterless setup, you should invoke `salt-call` with
  140. ``-c /path/to/your/virtualenv/etc/salt`` so that salt can find the minion
  141. config file. Without the ``-c`` option, Salt finds its config files in
  142. `/etc/salt`.
  143. Start the master and minion, accept the minion's key, and verify your local Salt
  144. installation is working::
  145. cd /path/to/your/virtualenv
  146. salt-master -c ./etc/salt -d
  147. salt-minion -c ./etc/salt -d
  148. salt-key -c ./etc/salt -L
  149. salt-key -c ./etc/salt -A
  150. salt -c ./etc/salt '*' test.ping
  151. Running the master and minion in debug mode can be helpful when developing. To
  152. do this, add ``-l debug`` to the calls to ``salt-master`` and ``salt-minion``.
  153. If you would like to log to the console instead of to the log file, remove the
  154. ``-d``.
  155. Once the minion starts, you may see an error like the following::
  156. zmq.core.error.ZMQError: ipc path "/path/to/your/virtualenv/var/run/salt/minion/minion_event_7824dcbcfd7a8f6755939af70b96249f_pub.ipc" is longer than 107 characters (sizeof(sockaddr_un.sun_path)).
  157. This means that the path to the socket the minion is using is too long. This is
  158. a system limitation, so the only workaround is to reduce the length of this
  159. path. This can be done in a couple different ways:
  160. 1. Create your virtualenv in a path that is short enough.
  161. 2. Edit the :conf_minion:`sock_dir` minion config variable and reduce its
  162. length. Remember that this path is relative to the value you set in
  163. :conf_minion:`root_dir`.
  164. ``NOTE:`` The socket path is limited to 107 characters on Solaris and Linux,
  165. and 103 characters on BSD-based systems.
  166. File descriptor limit
  167. ~~~~~~~~~~~~~~~~~~~~~
  168. Check your file descriptor limit with::
  169. ulimit -n
  170. If it is less than 2047, you should increase it with::
  171. ulimit -n 2047
  172. (or "limit descriptors 2047" for c-shell)
  173. Running the tests
  174. ~~~~~~~~~~~~~~~~~
  175. For running tests, you'll also need to install ``requirements/dev_python27.txt``::
  176. pip install -r requirements/dev_python27.txt
  177. Finally you use setup.py to run the tests with the following command::
  178. ./setup.py test
  179. For greater control while running the tests, please try::
  180. ./tests/runtests.py -h