This one is pretty silly; hopefully the regex match is still specific
enough to be a good test.
% bash -c '/tmp/someenv/bin/pip install something'
bash: /tmp/someenv/bin/pip: No such file or directory
% zsh -c '/tmp/someenv/bin/pip install something'
zsh:1: no such file or directory: /tmp/someenv/bin/pip
While running the tests within a VirtualBox(vagrant) machine, if the salt source is mounted using shared folders, any tests involving hard links WILL fail. Any tests involving symlinks, can be made to work by setting some properties on the VirtualBox shared folder. By moving the tests `tmp` directory to `tempfile.gettempdir()` we avoid this false test case errors.
* All logging messages are now logged on a log file. If verbose is enabled, the log messages are also logged to the console.
* The tests report now also let's us know if there were no glitches.
* Some tests might be considered destructive, such as adding or removing users from the system. This change allows those tests to be skipped unless stated otherwise.
```python
from saltunittest import destructiveTest
class ATestCase(TestCase):
@destructiveTest
def test_some_destructive_code(self):
"""Some destructive code."""
```
On the console we get something like:
```
test_destructive (unit.config_test.ConfigTestCase) ... skipped 'Destructive tests are disabled'
```
Previously we have to go through the scroll history to see which tests failed, which were skipped, etc. Now, besides test failures, errors and skips being reported like they always were, we also provide a nice overall report and the end.
Previously using `state.template` or `state.template_str` would not be checked/rendered into proper formatting resulting in some templates not being correctly executed. For example, the following template worked:
```
/tmp/issue-2068-template-str:
virtualenv:
- managed
- no_site_packages: True
- distribute: True
pep8-pip:
pip:
- installed
- name: pep8
- bin_env: /tmp/issue-2068-template-str
- mirrors: http://testpypi.python.org/pypi
- require:
- virtualenv: /tmp/issue-2068-template-str
```
as opposed to the following which did not work:
```
/tmp/issue-2068-template-str:
virtualenv.managed:
- no_site_packages: True
- distribute: True
pep8-pip:
pip.installed:
- name: pep8
- bin_env: /tmp/issue-2068-template-str
- mirrors: http://testpypi.python.org/pypi
- require:
- virtualenv: /tmp/issue-2068-template-str
```
The dotted names should be converted into lists for example, which was the problems with the two examples above.
* In order to check if something went wrong while running the various pip commands using the command module, we need to know, at least, the return code, this way we can report the failure.
* `salt.modules.pip.uninstall()` now returns the `cmd.run_all` `dict` instead of a list of strings. **This breaks previous behaviour**.
* Added a test case for `salt.modules.pip.uninstall()` changes.
Some packages, carbon and graphite-web for example, install their packages to a specific root, using a `virtualenv` or not. `pip freeze` won't show those packages as installed.
* Moved the state `pip.installed` tests to it's own module, the correct one.
* Added a test which checks for the presence of errors while running `pip.installed` introduced while fixing #2028
* `salt.states.pip.installed()` now keeps a reference to the output of the `__salt__['pip.install']()` call. The reason for this is that we need to know and pass along any information about an eventual error when running that call. This is now done in addition to the old behaviour.
* Add some tests which triggered the issue.
* Even when the tests logging handler stream is directed to `/dev/null` we still need a low logging level so that our custom logging handler, used to see if certain log messages are emitted or not, catches messages.
* Even when the tests logging handler stream is directed to `/dev/null` we still need a low logging level so that our custom logging handler, used to see if certain log messages are emitted or not, catches messages.
We defined that the amount of accepted keys should be lower than 1/4 of the system's max open file setting. Inform the user about the current situation, the logging level is "attached" to the gravity of the current status.
This is just a simple logging handler which will keep all emitted log messages in a list. This can be used to test if a certain log messages is emitted in a certain scenario. Usage example:
```python
with TestsLoggingHandler() as handler:
# (...) Do what ever you wish here
handler.messages # here are the emitted log messages
```
The `pki` and all minion's configuration directories are now all created under the same temporary directory.
The minion's ID's are now something more meaningful and less random to ease the interpretation of what's going on while running.
Minor pep-8 corrections.
The generation of keys does not involve all the checks required to accept/deny/list keys. This code change allows:
* regular users to generate keys
* `/etc/salt` and `/var/log/salt` not to exist or not to be readable by the current user
It also does not check for a running master. We have now lowered the requirements to run this script just for generating keys.
* Allow the `minionswarm` to run under user space
* Provide some additional configuration to the minions to use the temporary directories created for the swarm.
* Try to properly shutdown the running minions.
* As a last resort, `kill -KILL` all minions still running.
* Test both master and minion events firing
* Allow targeting the minions in `tests.integration.ModuleCase.run_function()`
* The above item allows to also test events firing using `tcp` as `ipc_mode` which is being used by the tests `sub_minion`
* `salt.modules.file.contains()`, `salt.modules.file.contains_regex()`, `salt.modules.file.contains_glob()` and `salt.utils.find` now do the searching/matching against chunks of data; using defaults, 32KB chunks of data in files; instead of searching/matching line by line.
* Based on the above changes `salt.states.file.append()`, when checking if the text to append is already present, now uses `salt.modules.file.contains_regex()` in order to match spanning multiple lines ignoring the addition/deletion of white-space or new lines, except inside commas.
* The regex used on the above item is built at runtime using `salt.utils.build_whitepace_splited_regex()`, just feed the text to it and you'll get back the proper regex to the matching/searching on, for example `salt.modules.file.contains_regex()`.
* Added tests for all this code.
Corey Quinn reported a issue where __grains__['os_family'] returned a
KeyError. This commits adds a check to the grains module test to ensure
os_family is present.
* `salt-call` default outputter returned from `salt.output.get_printout()` was `None` and `None` isn't callable neither outputs anything useful. In this case, the fault Outputter should be used.
* `get_printout()` also tested for `txt_out` which now is, in the cleaned up parsers, `text_out`. Fixed.
This commit kind of reverts the previous "no more os.sep.join ..." commit by solving the issue which led to switching that code to `os.path.join`. Tested both on linux and windows.
On the parsers cleanup branch, I though about making the available options as equal as possible. Since the log_file setting for the master and the minion could be separately set, I made the logfile option for the key also log_file. Yet, since there's no key specific config file, it shares master, one could only specify the log_file settings from the cli, it could not be hardcoded on the config file, unless, we made a separate config file just for key.
So, in order to reduce required changes, and keep it all as backwards compatible as possible, the key log file options is now, once again, `--key-logfile` which will allow us to hardcode it in the masters config file as `key_logfile`.
This will also, hopefully make travis behave better too.
When using `--no-clean` while running tests, some files/dirs still need to be removed, if not, test will fail. This commit tries to addresses those issues.
Reused the output options and logging setup mix-ins.
Fixed a bug introduced in previous commit on `salt.utils.parsers.SaltCPOptionParser._mixin_after_parsed()`, function does not accept any arguments.
For this, the timeout mix-in and both the target and output parser group mix-ins were re-used. Way less code and logic to keep track of.
Added a simple test for this binary too.
* Created 2 mix-ins as option groups, the output options and the target options. This will allow adding some explanatory text besides separating these options from the parser's main options.
* All options on the parser, including the grouped options are now merged to the loaded configuration which will latter get passed on.
* Also created the timeout mix-in which will be used in other binaries.
While performing integration tests, the "mockbin" directory is
inserted in the beginning of the $PATH environment variable.
This effectively means that every file placed in this directory will be
executed instead of real one from the system, which opens up the
opportunity to write more complex integration tests.
At the time the only wrapper for "su" command (used in "cmdmod") is
placed there.
Defined "integration.run_tests()" function which can be used to execute
a particular integration test case. Existing bolerplate code in modules
and states tests is replaced with following lines:
if __name__ == '__main__':
from integration import run_tests
run_tests(TestCaseName)
Typical usecase could look like this:
python integration/modules/pip.py --no-clean -vv
--no-clean option speeds up repeating test execution by skipping the cleanup
process before and after testing.
Typical use case command could look like
./runtests.py -vv --no-clean --name integration.modules.ssh
I don't really like doing this, but `/tmp/subsalttest dir` is already
hardcoded in other places for running tests.
Without this, when running tests under a mounted Vagrant drive,
`ssh-keygen` doesn't have permission to create the symlink for
known_hosts to known_hosts.old, causing a test to fail.
```
======================================================================
FAIL: test_rm_known_host (integration.modules.ssh.SSHModuleTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/vagrant/tests/integration/modules/ssh.py", line 143, in
test_rm_known_host
self.assertEqual(ret, 'add')
AssertionError: 'exists' != 'add'
```
`link /vagrant/tests/integration/tmp/known_hosts to
/vagrant/tests/integration/tmp/known_hosts.old: Operation not permitted`