Commit Graph

40 Commits

Author SHA1 Message Date
Ch3LL
3734b1ec89
Catch socket.error exception in testprogram 2018-08-01 16:35:16 -04:00
William Giokas
d4ca0e3a97
test: except for OSError only 2018-07-26 17:27:02 -04:00
Ch3LL
87dd85a220
Use different pub and ret ports for testprogram integration tests 2018-07-19 13:07:27 -04:00
Daniel A. Wozniak
70c603451b
Fix py2 thin dir issues 2018-06-20 17:16:30 -07:00
Daniel A Wozniak
c6697b9f16
Move kill process tree and re-use it 2018-05-06 09:44:55 -07:00
Erik Johnson
d31939574b Avoid race condition when iterating through processes
If a process has already exited between when psutil.process_iter() was
invoked, and when we invoke the cmdline() func, it will raise an
exception. This commit catches this exception and skips these processes.
2017-06-29 15:08:17 -05:00
Erik Johnson
a29b458416 Update orphan finding code to handle differences in psutil on PY3
This should fix the remainder of the test flakiness for
integration.shell.test_proxy.ProxyTest.test_exit_status_correct_usage
2017-06-09 15:20:23 -05:00
Erik Johnson
cb91437b08 Add wait_for_orphans to testprogram classes
This allows for the shutdown function to also terminate any orphaned
processes which were spawned during the time between when
terminate_process is invoked, and when the processes are actually
killed.
2017-06-08 00:25:53 -05:00
Erik Johnson
8e380679cc Kill child PIDs when shutting down a testprogram daemon
This fixes the test failures recently observed in
integration.shell.test_master.MasterTest.test_exit_status_correct_usage.
The test failures were not a regression, but rather a symptom of a
greater problem with the TestProgram class' shutdown() func. When
terminating the process using the terminate_process helper from
pytest-salt, it does not pass kill_children, which defaults to False.
This makes the helper only kill the main PID, leaving all the other PIDs
running.

This means that every time the integration suite was being run, each
time the TestProgram class was used to spawn a temporary daemon, it
would leave all the child PIDs running when the shutdown() is invoked.

By passing kill_children=True, we ensure that the child PIDs are also
killed. This should provide a significant perfomance improvement in the
test suite.
2017-06-05 16:38:23 -05:00
rallytime
9ff2694155 Merge branch '2016.11' into 'nitrogen'
Conflicts:
  - pkg/salt-minion.service
  - salt/modules/junos.py
  - salt/modules/localemod.py
  - salt/modules/win_system.py
  - salt/states/junos.py
  - tests/unit/modules/test_localemod.py
  - tests/unit/modules/test_win_powercfg.py
  - tests/unit/states/dockerng_test.py
2017-05-24 16:32:59 -06:00
Benjamin Drung
33a7f8b2ec Fix typos
lintian found several spelling errors.

Signed-off-by: Benjamin Drung <benjamin.drung@profitbricks.com>
2017-05-24 12:50:29 +02:00
Pedro Algarvio
61003bca0a
Take care of resource leakage on tests 2017-04-04 18:58:20 +01:00
Pedro Algarvio
f9b58aa2e2
This is not an integration test. Skip test.
Skipping tests since I have no clue what is supposed to be tested here
with that `raise Exception(ret)` at the end.
2017-04-01 14:22:53 +01:00
Pedro Algarvio
40a64191a1
Absolute imports and A LOT of code cleanup. 2017-03-01 01:33:07 +00:00
Pedro Algarvio
3beb3fb801
Move whatever we need from salttesting to salt.
Let's drop the salttesting dependency cycle.
2017-02-28 22:52:49 +00:00
plastikos
dde85e1144 Various fixes for MacOS X (#36085)
* Change "unknown" user to "some_unknown_user_xyz" since "unknown"
  *is* a valid user

* Add timeout to proxy test_exit_status_no_proxyid() since a known
  failure case is to infinitely loop with an error.

* Always force the source code tree under test to be the first entry
  in PYTHONPATH (excluding verbatim_env)
2016-09-06 16:30:08 -06:00
plastikos
1101e30389 Various fixes for MacOS X (#36080)
* Change "unknown" user to "some_unknown_user_xyz" since "unknown"
  *is* a valid user

* Add timeout to proxy test_exit_status_no_proxyid() since a known
  failure case is to infinitely loop with an error.

* Always force the source code tree under test to be the first entry
  in PYTHONPATH (excluding verbatim_env)
2016-09-06 16:29:26 -06:00
Pedro Algarvio
85fe1b31d5
Use the terminate_process_pid helper function 2016-08-23 18:36:27 +01:00
Pedro Algarvio
f7693f306c
Apply child processes cleanup counter measure on testprogram too.
Additionally, avoid timeout exceptions with registered atexit calls for testprogram(s)
2016-08-22 00:36:53 +01:00
Mike Place
15d088c15f Avoid str to bytes join in test util (#35295)
Fixes some shell.call tests.
2016-08-09 08:47:34 -06:00
Thayne Harbaugh
5fb3f025e4 Joining sys.path is redundant and causes the string result to be split and re-joined. 2016-08-08 11:31:17 -06:00
rallytime
fbe87fbb4a PY3: Fix byte string encoding issues when running shell.proxy int tests 2016-08-01 18:03:48 -06:00
Thayne Harbaugh
c6d08bf31b Minor tweaks to testing exit codes
* shared config settings go in `config_base` rather than *each* config
* Ensure that `name` attribute is a string
* Ensure that `dirtree` gets used from kwargs
* Adding 'XXXX' to the mkdtemp template is unnecessary
* Only template values if they are strings - otherwise just use them directly
2016-08-01 11:20:15 -06:00
Thayne Harbaugh
8a700b54f8 Appease the pylint gods: lambdas 2016-07-28 15:20:25 -06:00
Thayne Harbaugh
c37bafaca1 Appease the pylint gods. 2016-07-28 14:50:53 -06:00
Thayne Harbaugh
7082d91379 Test exit status of salt-call
* Only install packages when user is 'root'
* Only remove packages when user is 'root'
* Only remove packages that were installed
2016-06-28 15:10:11 -06:00
Thayne Harbaugh
5a8c2fcd2c Test exit status of salt-syndic 2016-06-28 15:10:09 -06:00
Thayne Harbaugh
8a5f1aa1cf Test exit status of "salt" CLI 2016-06-28 15:10:09 -06:00
Thayne Harbaugh
f790075a51 Test exit status of salt-run 2016-06-28 15:10:08 -06:00
Thayne Harbaugh
c79fe3d83a Programs may require multiple config files.
* Change the .config attribute to .config_base and .configs as a dictionary of configs
* A config has multiple parts

  :name: the key in the .configs dictionary
  :path: the path where the config is written (when absent defaults to .config_dir and config name)
  :map:  the contents of the config (for salt programs this is a dictionary)

* Values can be substituted into the config contents using standard python string formatting labels
* Add a .config_attrs which maps object attributes into config space
* Directories for make_dirtree() can reference object attributes using leading '&'
2016-06-28 15:10:07 -06:00
Thayne Harbaugh
5e170d8ae9 Configuration files may be needed for simple test programs - move all
config handling to TestProgram so that it can be used there.
2016-06-28 15:10:06 -06:00
Erik Johnson
20ed2c6bcf Remove repr formatting flag in places where it is used solely for quoting (#34183)
* salt/cloud/__init__.py: remove repr formatting

* salt/cloud/clouds/azurearm.py: remove repr formatting

* salt/cloud/clouds/ec2.py: remove repr formatting

* salt/cloud/clouds/profitbricks.py: remove repr formatting

* salt/loader.py: remove repr formatting

* salt/modules/win_file.py: remove repr formatting

* salt/modules/zypper.py: remove repr formatting

* salt/pillar/consul_pillar.py: remove repr formatting

* salt/renderers/pyobjects.py: remove repr formatting

* salt/returners/sentry_return.py: remove repr formatting

* salt/states/bower.py: remove repr formatting

* salt/states/cabal.py: remove repr formatting

* salt/states/cmd.py: remove repr formatting

* salt/states/composer.py: remove repr formatting

* salt/states/win_network.py: remove repr formatting

* salt/states/eselect.py: remove repr formatting

* salt/states/file.py: remove repr formatting

* salt/states/htpasswd.py: remove repr formatting

* salt/states/memcached.py: remove repr formatting

* salt/states/npm.py: remove repr formatting

* salt/states/pip_state.py: remove repr formatting

* salt/states/pkg.py: remove repr formatting

* salt/states/pkgrepo.py: remove repr formatting

* salt/states/supervisord.py: remove repr formatting

* salt/states/timezone.py: remove repr formatting

* salt/states/virtualenv_mod.py: remove repr formatting

* salt/states/dockerio.py: remove repr formatting

* salt/states/win_system.py: remove repr formatting

* salt/utils/nb_popen.py: remove repr formatting

* salt/utils/cloud.py: remove repr formatting

* Add pylint disable due to legit usage of repr flag

See https://github.com/saltstack/salt-pylint/pull/6

* Fix composer tests

These tests needed to be updated because quoting was changed in the
state module in 9dc9146. There was an unnecessary !r used for the
exception class there, which means that instead of the exception class
being passed through the formatter and coming out with the equivalent
value of err.__str__(), we get a repr'ed instance of the exception class
(i.e.  SaltException('',)) in the state output.

The unit test was asserting that we have that repr'ed instance of
SaltException in the output, a case of writing the test to confirm the
badly-conceived output in the state. This has also been corrected.

* salt/cloud/clouds/azurearm.py: lint fixes

* salt/modules/boto_s3_bucket.py: lint fixes

* salt/modules/minion.py: lint fixes

* salt/modules/reg.py: lint fixes

* salt/modules/testinframod.py: lint fixes

* salt/modules/win_iis.py: lint fixes

* salt/pillar/csvpillar.py: lint fixes

* salt/utils/win_functions.py: lint fixes

* salt/states/nxos.py: lint fixes

* salt/returners/mongo_future_return.py: lint fixes

* tests/integration/__init__.py: lint fixes

* tests/unit/context_test.py: lint fixes

* tests/integration/states/file.py: lint fixes

* tests/integration/utils/test_reactor.py: lint fixes

* tests/integration/utils/testprogram.py: lint fixes

* tests/unit/__init__.py: lint fixes

* tests/integration/shell/minion.py: lint fixes

* tests/unit/modules/boto_apigateway_test.py: lint fixes

* tests/unit/modules/boto_cognitoidentity_test.py: lint fixes

* tests/unit/modules/boto_elasticsearch_domain_test.py: lint fixes

* tests/unit/modules/k8s_test.py: lint fixes

* tests/unit/modules/reg_win_test.py: lint fixes

* tests/unit/states/boto_apigateway_test.py: lint fixes

* tests/unit/states/boto_cognitoidentity_test.py: lint fixes

* tests/unit/states/boto_elasticsearch_domain_test.py: lint fixes
2016-06-29 16:30:18 -04:00
Thayne Harbaugh
0fff44644e Handle case where PYTHONPATH environment var is not set. 2016-06-08 14:02:57 -06:00
Thayne Harbaugh
88ce32ae80 Improvements and bugfixes to testprogram utilities
* Automatically add --proxyid to salt-proxy arguments

* Add parameters to disable automatic adding of arguments and environment
  settings: .run() now takes verbatim_args and verbatim_env

* salt-proxy uses salt-minion.pid file

* Simplify .shutdown()

  + pass timeout to .wait_for_daemon_pid()

  + attempt kill before checking timeout value

  + Testing for "no such pid" (case that process was already dead) was
    previously incorrect, but was masked due to (what should have been) a
    superfluous call to salt.utils.process.os_is_running()
2016-06-03 14:47:23 -06:00
Thayne Harbaugh
68a9912d3a Refactor `testprogram` framework to minimize explicit setup and improve reuse.
* Add a ``testprogram.TestProgramCase()`` to simplify test classes

  + Has ``setUp()`` and ``tearDown()`` to create ephemeral test directory
    (really should be moved to salttesting.TestCase)

  + Common ``assert_exit_status()`` for validating and reporting failures in
    exit status.

* Add missing ``testprogram.TestDaemonSaltProxy`` class

* Remove specific setting of ``program`` parameter in initialization of
  ``TestDaemonSaltMinion`` since ``testprogram.TestSaltProgramMeta`` already
  handles that unless a specific override is required.

* Automatically set ``user`` in config for master, minion and proxy test
  classes if a specific user is not specified.

* Automatically set ``PYTHONPATH`` as ``sys.path`` unless it is specified.
2016-06-02 16:51:54 -06:00
Thayne Harbaugh
11a9e1e839 Various improvements to the TestProgram classes:
* Add debug logging when a program is started
  * Set a flag once a TestDaemon has been shutdown(); check flag in is_running()
  * Add .config_path property
  * salt.utils.process.clean_proc() only works with multiprocessing - replace it
  * Automatically add --config-dir for TestSaltDaemon if it isn't already specified
2016-06-01 18:21:49 -06:00
plastikos
0efbbcd17f * Improve init script: specifically manage salt configurations rather than arbitrary salt processes (#32666)
* * Improve init script: specifically manage salt configurations rather than arbitrary salt processes

Unfortunately SysV init scripts tend to rummage through PIDs filtering for
appropriate processes to manage.  Unfortunately the filters are usually weak
and don't account for similar processes run by other users, PIDs of dead
processes being re-used for completely different executables, etc..  These
weaknesses can result in killing unrelated processes with potentially serious
results.

These improvements to the SysV init script is a complete rewrite with the
following improvements:

  * Specifically manage individual salt configurations rather than looking for
    salt minion-like processes.
  * Obtain salt minion information from the salt configuration - use the
    information to manage the specifically configured process.
  * Drop all of the platform-specific helper functions that allow the
    previously-mentioned weaknesses.

    + Unfortunately this means that the output information may not match the
      specific platform (this could easily be corrected).

  * Now can manage multiple salt processes started by different users

    + Unfortunately starts/stops/restarts as a group and is unable to manage
      them both as a group or as individual processes (this could easily be
      corrected)

The new initscript also allows various control variables to be overridden by
environment variables or through settings put in ``/etc/sysconf/salt`` or
``/etc/default/salt``.

:SALTMINION_DEBUG: Dump each line expansion before execution, output system
                   information on failure.  Default: unset

:SALTMINION_BINDIR: Location of ``salt-minion``, ``salt-call`` and other
                    executables.  Default: ``/usr/bin``

:SALTMINION_SYSCONFDIR: The parent directory for the ``salt`` configuration
                        directory and the ``sysconfig`` or ``default``
                        directory.

* Add lines that went missing in the rebase+squash
2016-05-09 10:57:13 -07:00
Thomas Jackson
e35c7ac313 cleanup "Caste jid as str (its an int all over), and change runner tag to correct prefix"
This reverts most of commit 745f2d84835ae23800358cd4dcc9c8525b502714.

apparently I picked up some other changes I didn't mean to

Conflicts:
	salt/utils/event.py
	tests/integration/utils/test_reactor.py
2015-01-10 16:32:24 -08:00
Thomas Jackson
d352057f11 Pylint fix 2015-01-10 16:31:59 -08:00
Thomas Jackson
c17462d062 Caste jid as str (its an int all over), and change runner tag to correct prefix 2015-01-10 16:30:00 -08:00