salt/tests/integration/netapi/test_client.py
rallytime f08ee6c6ae
Update netapi client tests
This change does 2 things:
- Skip 2 tests: they are not actually _testing_ anything, just running functions
  Let's skip these for now until we can dedicate some time to investigate what
  should be tested here. This will also help the tests breath a little bit.
- Add a small sleep to the async test. This test needs a little breathing room so
  the procs don't get stepped on. I think this is what is causing the master to
  shut down sometimes during test runs:

```
08:41:47          test_wheel_async (integration.netapi.test_client.NetapiClientTest)
08:41:47        [CPU:0.0%|MEM:13.2%]  ... 12:41:47,280 [salt.utils.process                         :670 ][ERROR   ] An un-handled exception from the multiprocessing process 'SignalHandlingMultiprocessingProcess-24' was caught:
08:41:47        Traceback (most recent call last):
08:41:47          File "/tmp/kitchen/testing/salt/utils/process.py", line 663, in _run
08:41:47            return self._original_run()
08:41:47          File "/usr/lib/python3.5/multiprocessing/process.py", line 93, in run
08:41:47            self._target(*self._args, **self._kwargs)
08:41:47          File "/tmp/kitchen/testing/salt/client/mixins.py", line 457, in _proc_function
08:41:47            salt.utils.daemonize()
08:41:47          File "/tmp/kitchen/testing/salt/utils/__init__.py", line 514, in daemonize
08:41:47            os.dup2(dev_null.fileno(), sys.stdout.fileno())
08:41:47        io.UnsupportedOperation: fileno
08:41:47        Process SignalHandlingMultiprocessingProcess-24:
08:41:47        Traceback (most recent call last):
08:41:47          File "/usr/lib/python3.5/multiprocessing/process.py", line 249, in _bootstrap
08:41:47            self.run()
08:41:47          File "/tmp/kitchen/testing/salt/utils/process.py", line 663, in _run
08:41:47            return self._original_run()
08:41:47          File "/usr/lib/python3.5/multiprocessing/process.py", line 93, in run
08:41:47            self._target(*self._args, **self._kwargs)
08:41:47          File "/tmp/kitchen/testing/salt/client/mixins.py", line 457, in _proc_function
08:41:47            salt.utils.daemonize()
08:41:47          File "/tmp/kitchen/testing/salt/utils/__init__.py", line 514, in daemonize
08:41:47            os.dup2(dev_null.fileno(), sys.stdout.fileno())
08:41:47        io.UnsupportedOperation: fileno
```
2018-08-09 10:11:20 -04:00

104 lines
3.0 KiB
Python

# encoding: utf-8
# Import Python libs
from __future__ import absolute_import
import os
import time
# Import Salt Testing libs
from tests.support.paths import TMP_CONF_DIR
from tests.support.unit import TestCase, skipIf
# Import Salt libs
import salt.config
import salt.netapi
class NetapiClientTest(TestCase):
eauth_creds = {
'username': 'saltdev_auto',
'password': 'saltdev',
'eauth': 'auto',
}
def setUp(self):
'''
Set up a NetapiClient instance
'''
opts = salt.config.client_config(os.path.join(TMP_CONF_DIR, 'master'))
self.netapi = salt.netapi.NetapiClient(opts)
def tearDown(self):
del self.netapi
def test_local(self):
low = {'client': 'local', 'tgt': '*', 'fun': 'test.ping'}
low.update(self.eauth_creds)
ret = self.netapi.run(low)
self.assertEqual(ret, {'minion': True, 'sub_minion': True})
def test_local_async(self):
low = {'client': 'local_async', 'tgt': '*', 'fun': 'test.ping'}
low.update(self.eauth_creds)
ret = self.netapi.run(low)
# Remove all the volatile values before doing the compare.
self.assertIn('jid', ret)
ret.pop('jid', None)
ret['minions'] = sorted(ret['minions'])
self.assertEqual(ret, {'minions': sorted(['minion', 'sub_minion'])})
def test_wheel(self):
low = {'client': 'wheel', 'fun': 'key.list_all'}
low.update(self.eauth_creds)
ret = self.netapi.run(low)
# Remove all the volatile values before doing the compare.
self.assertIn('tag', ret)
ret.pop('tag')
data = ret.get('data', {})
self.assertIn('jid', data)
data.pop('jid', None)
self.assertIn('tag', data)
data.pop('tag', None)
ret.pop('_stamp', None)
data.pop('_stamp', None)
self.maxDiff = None
self.assertTrue(set(['master.pem', 'master.pub']).issubset(set(ret['data']['return']['local'])))
def test_wheel_async(self):
# Give this test a little breathing room
time.sleep(3)
low = {'client': 'wheel_async', 'fun': 'key.list_all'}
low.update(self.eauth_creds)
ret = self.netapi.run(low)
self.assertIn('jid', ret)
self.assertIn('tag', ret)
@skipIf(True, 'This is not testing anything. Skipping for now.')
def test_runner(self):
# TODO: fix race condition in init of event-- right now the event class
# will finish init even if the underlying zmq socket hasn't connected yet
# this is problematic for the runnerclient's master_call method if the
# runner is quick
#low = {'client': 'runner', 'fun': 'cache.grains'}
low = {'client': 'runner', 'fun': 'test.sleep', 'arg': [2]}
low.update(self.eauth_creds)
ret = self.netapi.run(low)
@skipIf(True, 'This is not testing anything. Skipping for now.')
def test_runner_async(self):
low = {'client': 'runner', 'fun': 'cache.grains'}
low.update(self.eauth_creds)
ret = self.netapi.run(low)