salt/tests/integration/client/test_standard.py

150 lines
4.0 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# Import python libs
from __future__ import absolute_import
import os
# Import Salt Testing libs
from tests.support.case import ModuleCase
2012-04-04 03:57:41 +00:00
# Import salt libs
import salt.utils
2012-04-04 03:57:41 +00:00
class StdTest(ModuleCase):
2012-04-04 03:57:41 +00:00
'''
Test standard client calls
'''
2012-04-04 03:57:41 +00:00
def test_cli(self):
'''
Test cli function
'''
cmd_iter = self.client.cmd_cli(
'minion',
'test.ping',
)
for ret in cmd_iter:
self.assertTrue(ret['minion'])
2014-09-29 23:37:53 +00:00
# make sure that the iter waits for long running jobs too
cmd_iter = self.client.cmd_cli(
'minion',
'test.sleep',
[6]
)
num_ret = 0
for ret in cmd_iter:
num_ret += 1
self.assertTrue(ret['minion'])
assert num_ret > 0
2014-10-28 15:12:10 +00:00
# ping a minion that doesn't exist, to make sure that it doesn't hang forever
# create fake minion
key_file = os.path.join(self.master_opts['pki_dir'], 'minions', 'footest')
# touch the file
Clean up open filehandles (#35359) * salt/crypt.py: clean up open filehandles * salt/fileclient.py: clean up open filehandles * salt/grains/core.py: clean up open filehandles * salt/modules/cp.py: clean up open filehandles * salt/modules/data.py: clean up open filehandles * salt/modules/dnsutil.py: clean up open filehandles * salt/modules/dockerng.py: clean up open filehandles * salt/modules/inspectlib/collector.py: clean up open filehandles * salt/modules/file.py: clean up open filehandles * salt/modules/hosts.py: clean up open filehandles * salt/modules/incron.py: clean up open filehandles * salt/modules/dpkg.py: clean up open filehandles * salt/modules/linux_sysctl.py: clean up open filehandles * salt/modules/netbsd_sysctl.py: clean up open filehandles * salt/modules/network.py: clean up open filehandles * salt/modules/nftables.py: clean up open filehandles * salt/modules/openbsd_sysctl.py: clean up open filehandles * salt/modules/rh_ip.py: clean up open filehandles * salt/modules/portage_config.py: clean up open filehandles * salt/modules/status.py: clean up open filehandles * salt/modules/tls.py: clean up open filehandles * salt/modules/xapi.py: clean up open filehandles * salt/modules/x509.py: clean up open filehandles * salt/modules/virt.py: clean up open filehandles * salt/modules/zcbuildout.py: clean up open filehandles * salt/returners/local_cache.py: clean up open filehandles * salt/utils/cloud.py: clean up open filehandles * salt/states/pkgrepo.py: clean up open filehandles * salt/states/x509.py: clean up open filehandles * salt/transport/mixins/auth.py: clean up open filehandles * salt/utils/__init__.py: clean up open filehandles * salt/states/pkg.py: clean up open filehandles * salt/utils/minion.py: clean up open filehandles * salt/utils/openstack/nova.py: clean up open filehandles * salt/utils/openstack/swift.py: clean up open filehandles * salt/utils/process.py: clean up open filehandles * salt/utils/templates.py: clean up open filehandles * salt/utils/virt.py: clean up open filehandles * tests/integration/__init__.py: clean up open filehandles * tests/integration/cli/grains.py: clean up open filehandles * tests/integration/client/standard.py: clean up open filehandles * tests/integration/modules/hosts.py: clean up open filehandles * tests/unit/utils/vt_test.py: clean up open filehandles * tests/integration/shell/enabled.py: clean up open filehandles * tests/integration/states/cmd.py: clean up open filehandles * tests/integration/states/file.py: clean up open filehandles * tests/integration/states/match.py: clean up open filehandles * tests/unit/config_test.py: clean up open filehandles * tests/unit/templates/jinja_test.py: clean up open filehandles * tests/unit/utils/find_test.py: clean up open filehandles * tests/integration/modules/state.py: clean up open filehandles * Update dnsutil_test to reflect changes in fopen usage
2016-08-11 16:45:24 +00:00
with salt.utils.fopen(key_file, 'a'):
pass
# ping that minion and ensure it times out
try:
cmd_iter = self.client.cmd_cli(
'footest',
'test.ping',
)
num_ret = 0
for ret in cmd_iter:
num_ret += 1
self.assertTrue(ret['minion'])
assert num_ret == 0
finally:
os.unlink(key_file)
2012-04-04 03:57:41 +00:00
def test_iter(self):
'''
test cmd_iter
'''
cmd_iter = self.client.cmd_iter(
'minion',
'test.ping',
)
for ret in cmd_iter:
self.assertTrue(ret['minion'])
def test_iter_no_block(self):
'''
test cmd_iter_no_block
'''
cmd_iter = self.client.cmd_iter_no_block(
'minion',
'test.ping',
)
for ret in cmd_iter:
if ret is None:
continue
self.assertTrue(ret['minion'])
def test_batch(self):
'''
test cmd_batch
'''
cmd_batch = self.client.cmd_batch(
'minion',
'test.ping',
)
for ret in cmd_batch:
self.assertTrue(ret['minion'])
def test_batch_raw(self):
'''
test cmd_batch with raw option
'''
cmd_batch = self.client.cmd_batch(
'minion',
'test.ping',
raw=True,
)
for ret in cmd_batch:
self.assertTrue(ret['data']['success'])
2012-04-04 03:57:41 +00:00
def test_full_returns(self):
'''
test cmd_iter
'''
ret = self.client.cmd_full_return(
'minion',
'test.ping',
)
self.assertIn('minion', ret)
self.assertEqual({'ret': True, 'success': True}, ret['minion'])
def test_disconnected_return(self):
'''
Test return/messaging on a disconnected minion
'''
test_ret = {'ret': 'Minion did not return. [No response]', 'out': 'no_return'}
# Create a minion key, but do not start the "fake" minion. This mimics
# a disconnected minion.
key_file = os.path.join(self.master_opts['pki_dir'], 'minions', 'disconnected')
Clean up open filehandles (#35359) * salt/crypt.py: clean up open filehandles * salt/fileclient.py: clean up open filehandles * salt/grains/core.py: clean up open filehandles * salt/modules/cp.py: clean up open filehandles * salt/modules/data.py: clean up open filehandles * salt/modules/dnsutil.py: clean up open filehandles * salt/modules/dockerng.py: clean up open filehandles * salt/modules/inspectlib/collector.py: clean up open filehandles * salt/modules/file.py: clean up open filehandles * salt/modules/hosts.py: clean up open filehandles * salt/modules/incron.py: clean up open filehandles * salt/modules/dpkg.py: clean up open filehandles * salt/modules/linux_sysctl.py: clean up open filehandles * salt/modules/netbsd_sysctl.py: clean up open filehandles * salt/modules/network.py: clean up open filehandles * salt/modules/nftables.py: clean up open filehandles * salt/modules/openbsd_sysctl.py: clean up open filehandles * salt/modules/rh_ip.py: clean up open filehandles * salt/modules/portage_config.py: clean up open filehandles * salt/modules/status.py: clean up open filehandles * salt/modules/tls.py: clean up open filehandles * salt/modules/xapi.py: clean up open filehandles * salt/modules/x509.py: clean up open filehandles * salt/modules/virt.py: clean up open filehandles * salt/modules/zcbuildout.py: clean up open filehandles * salt/returners/local_cache.py: clean up open filehandles * salt/utils/cloud.py: clean up open filehandles * salt/states/pkgrepo.py: clean up open filehandles * salt/states/x509.py: clean up open filehandles * salt/transport/mixins/auth.py: clean up open filehandles * salt/utils/__init__.py: clean up open filehandles * salt/states/pkg.py: clean up open filehandles * salt/utils/minion.py: clean up open filehandles * salt/utils/openstack/nova.py: clean up open filehandles * salt/utils/openstack/swift.py: clean up open filehandles * salt/utils/process.py: clean up open filehandles * salt/utils/templates.py: clean up open filehandles * salt/utils/virt.py: clean up open filehandles * tests/integration/__init__.py: clean up open filehandles * tests/integration/cli/grains.py: clean up open filehandles * tests/integration/client/standard.py: clean up open filehandles * tests/integration/modules/hosts.py: clean up open filehandles * tests/unit/utils/vt_test.py: clean up open filehandles * tests/integration/shell/enabled.py: clean up open filehandles * tests/integration/states/cmd.py: clean up open filehandles * tests/integration/states/file.py: clean up open filehandles * tests/integration/states/match.py: clean up open filehandles * tests/unit/config_test.py: clean up open filehandles * tests/unit/templates/jinja_test.py: clean up open filehandles * tests/unit/utils/find_test.py: clean up open filehandles * tests/integration/modules/state.py: clean up open filehandles * Update dnsutil_test to reflect changes in fopen usage
2016-08-11 16:45:24 +00:00
with salt.utils.fopen(key_file, 'a'):
pass
# ping disconnected minion and ensure it times out and returns with correct message
try:
cmd_iter = self.client.cmd_cli(
'disconnected',
'test.ping',
show_timeout=True
)
num_ret = 0
for ret in cmd_iter:
num_ret += 1
self.assertEqual(ret['disconnected']['ret'], test_ret['ret'])
self.assertEqual(ret['disconnected']['out'], test_ret['out'])
# Ensure that we entered the loop above
self.assertEqual(num_ret, 1)
finally:
os.unlink(key_file)