2012-07-01 00:26:47 +00:00
Developing Salt
===============
If you want to help develop Salt there is a great need and your patches are
welcome!
To assist in Salt development, you can help in a number of ways.
2015-02-15 14:03:58 +00:00
Setting a GitHub pull request
2012-07-01 00:26:47 +00:00
-----------------------------
2015-02-15 14:03:58 +00:00
This is the preferred method for contributions, simply create a GitHub
2012-07-01 00:26:47 +00:00
fork, commit your changes to the fork, and then open up a pull request.
2016-10-21 21:34:18 +00:00
Please review the following questions when creating a pull request:
2016-10-21 21:38:15 +00:00
`<https://docs.saltstack.com/en/develop/topics/development/pull_requests.html>`_
2016-10-21 21:34:18 +00:00
2012-07-01 00:26:47 +00:00
Contributions Welcome!
----------------------
2012-07-16 14:15:49 +00:00
The goal here is to make contributions clear, make sure there is a trail for
2012-07-01 00:26:47 +00:00
where the code has come from, but most importantly, to give credit where credit
is due!
2012-07-04 19:00:51 +00:00
The `Open Comparison Contributing Docs`__ explains the workflow for forking,
cloning, branching, committing, and sending a pull request for the git
repository.
2012-07-03 22:52:44 +00:00
2012-07-04 19:00:51 +00:00
`` git pull upstream develop `` is a shorter way to update your local repository
to the latest version.
2012-07-01 00:26:47 +00:00
.. __: http://opencomparison.readthedocs.org/en/latest/contributing.html
2012-07-03 22:40:10 +00:00
Editing and Previewing the Docs
-------------------------------
2012-07-01 02:45:58 +00:00
You need `` sphinx-build `` to build the docs. In Debian/Ubuntu this is provided
2012-07-04 19:00:51 +00:00
in the `` python-sphinx `` package.
2012-07-03 22:40:10 +00:00
Then::
cd doc; make html
2012-07-04 19:00:51 +00:00
- The docs then are built in the `` docs/_build/html/ `` folder. If you make
changes and want to see the results, `` make html `` again.
- The docs use `` reStructuredText `` for markup. See a live demo at
http://rst.ninjs.org/
- The help information on each module or state is culled from the python code
2013-01-17 00:42:32 +00:00
that runs for that piece. Find them in `` salt/modules/ `` or `` salt/states/ `` .
- If you are developing using Arch Linux (or any other distribution for which
Python 3 is the default Python installation), then `` sphinx-build `` may be
named `` sphinx-build2 `` instead. If this is the case, then you will need to
run the following `` make `` command::
make SPHINXBUILD=sphinx-build2 html
2012-07-03 23:06:57 +00:00
2012-07-01 02:45:58 +00:00
Installing Salt for development
-------------------------------
2012-07-01 00:26:47 +00:00
Clone the repository using::
git clone https://github.com/saltstack/salt
2013-03-11 21:02:51 +00:00
cd salt
2012-07-01 00:26:47 +00:00
2013-01-17 00:06:24 +00:00
.. note :: tags
Just cloning the repository is enough to work with Salt and make
contributions. However, you must fetch additional tags into your clone to
2013-03-11 21:02:51 +00:00
have Salt report the correct version for itself. To do this, fetch the tags
with the command::
2013-01-17 00:06:24 +00:00
2013-03-11 21:02:51 +00:00
git fetch --tags
2013-01-17 00:06:24 +00:00
2013-03-11 21:04:16 +00:00
Preparing your system
~~~~~~~~~~~~~~~~~~~~~
2013-01-17 00:06:24 +00:00
2013-03-11 21:04:16 +00:00
In order to install Salt's requirements, you'll need a system with a compiler
and Python's development libraries.
Debian-based systems
`` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ``
On Debian and derivative systems such as Ubuntu, system requirements can be
installed by running::
2013-03-28 20:53:11 +00:00
apt-get install -y build-essential libssl-dev python-dev python-m2crypto \
2016-11-03 21:47:59 +00:00
python-pip python-virtualenv virtualenvwrapper
2013-03-11 21:04:16 +00:00
RedHat-based systems
`` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ``
If you are developing using one of these releases, you will want to create your
virtualenv using the `` --system-site-packages `` option so that these modules
are available in the virtualenv.
2016-12-28 21:49:46 +00:00
Installing dependencies on macOS
`` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ``
2013-03-11 21:04:16 +00:00
2016-12-28 21:49:46 +00:00
One simple way to get all needed dependencies on macOS is to use homebrew,
2013-03-11 21:04:16 +00:00
and install the following packages::
brew install zmq
Afterward the pip commands should run without a hitch. Also be sure to set
max_open_files to 2048 (see below).
2013-01-17 00:06:24 +00:00
2013-03-11 21:12:24 +00:00
Create a virtual environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2012-07-01 02:45:58 +00:00
Create a new `virtualenv`_ ::
virtualenv /path/to/your/virtualenv
2013-01-17 00:42:32 +00:00
.. _`virtualenv`: http://pypi.python.org/pypi/virtualenv
2012-08-20 19:00:35 +00:00
2013-01-17 00:42:32 +00:00
On Arch Linux, where Python 3 is the default installation of Python, use the
`` virtualenv2 `` command instead of `` virtualenv `` .
2012-08-20 19:00:35 +00:00
2013-03-11 21:04:16 +00:00
Debian, Ubuntu, and the RedHat systems mentioned above, you should use
`` --system-site-packages `` when creating the virtualenv, to pull in the
M2Crypto installed using apt::
virtualenv --system-site-packages /path/to/your/virtualenv
2015-07-15 03:35:53 +00:00
On Gentoo systems you should use `` --system-site-packages `` when creating
the virtualenv to enable pkg and portage_config functionality as the
portage package is not available via pip
2013-01-17 00:42:32 +00:00
.. note :: Using your system Python modules in the virtualenv
If you have the required python modules installed on your system already
and would like to use them in the virtualenv rather than having pip
download and compile new ones into this environment, run `` virtualenv ``
with the `` --system-site-packages `` option. If you do this, you can skip
the pip command below that installs the dependencies (pyzmq, M2Crypto,
etc.), assuming that the listed modules are all installed in your system
PYTHONPATH at the time you create your virtualenv.
2012-07-01 02:45:58 +00:00
2013-03-11 21:12:24 +00:00
Configure your virtual environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2012-07-01 02:45:58 +00:00
Activate the virtualenv::
source /path/to/your/virtualenv/bin/activate
2014-06-26 23:37:00 +00:00
Install Salt (and dependencies) into the virtualenv.
2012-07-01 02:45:58 +00:00
2014-06-26 23:37:00 +00:00
ZeroMQ Transport:
.. code-block :: bash
2014-12-28 00:29:03 +00:00
pip install -r requirements/zeromq.txt
2013-03-11 21:04:16 +00:00
pip install psutil
pip install -e .
2012-07-01 02:45:58 +00:00
2013-02-02 08:06:40 +00:00
2012-07-01 02:45:58 +00:00
Running a self-contained development version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
During development it is easiest to be able to run the Salt master and minion
that are installed in the virtualenv you created above, and also to have all
the configuration, log, and cache files contained in the virtualenv as well.
Copy the master and minion config files into your virtualenv::
mkdir -p /path/to/your/virtualenv/etc/salt
2013-01-17 00:42:32 +00:00
cp ./salt/conf/master /path/to/your/virtualenv/etc/salt/master
cp ./salt/conf/minion /path/to/your/virtualenv/etc/salt/minion
2012-07-01 02:45:58 +00:00
Edit the master config file:
1. Uncomment and change the `` user: root `` value to your own user.
2. Uncomment and change the `` root_dir: / `` value to point to
`` /path/to/your/virtualenv `` .
2013-01-17 00:42:32 +00:00
3. If you are running version 0.11.1 or older, uncomment and change the
`` pidfile: /var/run/salt-master.pid `` value to point to
`` /path/to/your/virtualenv/salt-master.pid `` .
4. If you are also running a non-development version of Salt you will have to
2012-07-01 02:45:58 +00:00
change the `` publish_port `` and `` ret_port `` values as well.
2016-12-28 21:49:46 +00:00
5. On xxxOS X also set max_open_files to 2048.
2012-07-01 02:45:58 +00:00
Edit the minion config file:
1. Repeat the edits you made in the master config for the `` user `` and
`` root_dir `` values as well as any port changes.
2013-01-17 00:42:32 +00:00
2. If you are running version 0.11.1 or older, uncomment and change the
`` pidfile: /var/run/salt-minion.pid `` value to point to
`` /path/to/your/virtualenv/salt-minion.pid `` .
3. Uncomment and change the `` master: salt `` value to point at `` localhost `` .
4. Uncomment and change the `` id: `` value to something descriptive like
2012-07-01 02:45:58 +00:00
"saltdev". This isn't strictly necessary but it will serve as a reminder of
which Salt installation you are working with.
2014-02-11 05:09:24 +00:00
5. If you changed the `` ret_port `` value in the master config because you are
also running a non-development version of Salt, then you will have to
change the `` master_port `` value in the minion config to match.
2012-07-01 02:45:58 +00:00
2016-12-15 23:09:27 +00:00
.. note :: Using `salt-call` with a :ref: `Standalone Minion <tutorial-standalone-minion>`
2012-09-12 20:51:22 +00:00
If you plan to run `salt-call` with this self-contained development
environment in a masterless setup, you should invoke `salt-call` with
`` -c /path/to/your/virtualenv/etc/salt `` so that salt can find the minion
2013-01-17 00:42:32 +00:00
config file. Without the `` -c `` option, Salt finds its config files in
`/etc/salt` .
2012-09-12 20:51:22 +00:00
2013-05-01 23:06:17 +00:00
Start the master and minion, accept the minion's key, and verify your local Salt
2012-07-01 02:45:58 +00:00
installation is working::
2013-01-17 00:42:32 +00:00
cd /path/to/your/virtualenv
2012-08-13 23:47:28 +00:00
salt-master -c ./etc/salt -d
salt-minion -c ./etc/salt -d
2012-08-21 22:03:48 +00:00
salt-key -c ./etc/salt -L
salt-key -c ./etc/salt -A
2012-08-13 23:47:28 +00:00
salt -c ./etc/salt '*' test.ping
2012-07-01 02:45:58 +00:00
2013-01-17 00:42:32 +00:00
Running the master and minion in debug mode can be helpful when developing. To
do this, add `` -l debug `` to the calls to `` salt-master `` and `` salt-minion `` .
If you would like to log to the console instead of to the log file, remove the
`` -d `` .
Once the minion starts, you may see an error like the following::
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)).
2014-08-11 14:04:27 +00:00
This means that the path to the socket the minion is using is too long. This is
2013-01-17 00:42:32 +00:00
a system limitation, so the only workaround is to reduce the length of this
path. This can be done in a couple different ways:
1. Create your virtualenv in a path that is short enough.
2. Edit the :conf_minion:`sock_dir` minion config variable and reduce its
length. Remember that this path is relative to the value you set in
:conf_minion:`root_dir` .
`` NOTE: `` The socket path is limited to 107 characters on Solaris and Linux,
and 103 characters on BSD-based systems.
2016-11-03 21:47:59 +00:00
2012-07-01 00:26:47 +00:00
File descriptor limit
~~~~~~~~~~~~~~~~~~~~~
Check your file descriptor limit with::
ulimit -n
2012-09-02 21:00:28 +00:00
If it is less than 2047, you should increase it with::
ulimit -n 2047
(or "limit descriptors 2047" for c-shell)
2012-07-01 00:26:47 +00:00
2012-07-01 02:45:58 +00:00
Running the tests
~~~~~~~~~~~~~~~~~
2012-07-01 00:26:47 +00:00
2014-12-28 00:29:03 +00:00
For running tests, you'll also need to install `` requirements/dev_python2x.txt `` ::
2012-07-01 00:26:47 +00:00
2014-12-28 00:29:03 +00:00
pip install -r requirements/dev_python2x.txt
2012-07-01 00:26:47 +00:00
Finally you use setup.py to run the tests with the following command::
./setup.py test
2012-08-13 23:47:28 +00:00
For greater control while running the tests, please try::
./tests/runtests.py -h