mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #9553 from s0undt3ch/develop
Use testing config files
This commit is contained in:
commit
ca79876787
2 changed files with 29 additions and 13 deletions
|
@ -54,9 +54,11 @@ def usage(args=None):
|
|||
'''
|
||||
flags = _clean_flags(args, 'disk.usage')
|
||||
if not os.path.isfile('/etc/mtab'):
|
||||
log.warn("df cannot run without /etc/mtab ")
|
||||
log.warn('df cannot run without /etc/mtab')
|
||||
if __grains__.get('virtual_subtype') == 'LXC':
|
||||
log.warn('df command failed and LXC detected. If you are running a Docker container, consider linking /proc/mounts to /etc/mtab or running with consider running Docker with -privileged')
|
||||
log.warn('df command failed and LXC detected. If you are running '
|
||||
'a Docker container, consider linking /proc/mounts to '
|
||||
'/etc/mtab or consider running Docker with -privileged')
|
||||
return {}
|
||||
if __grains__['kernel'] == 'Linux':
|
||||
cmd = 'df -P'
|
||||
|
@ -98,7 +100,7 @@ def usage(args=None):
|
|||
'capacity': comps[4],
|
||||
}
|
||||
except IndexError:
|
||||
log.warn("Problem parsing disk usage information")
|
||||
log.warn('Problem parsing disk usage information')
|
||||
ret = {}
|
||||
return ret
|
||||
|
||||
|
@ -145,7 +147,7 @@ def inodeusage(args=None):
|
|||
'filesystem': comps[0],
|
||||
}
|
||||
except (IndexError, ValueError):
|
||||
log.warn("Problem parsing inode usage information")
|
||||
log.warn('Problem parsing inode usage information')
|
||||
ret = {}
|
||||
return ret
|
||||
|
||||
|
@ -181,7 +183,7 @@ def percent(args=None):
|
|||
else:
|
||||
ret[comps[5]] = comps[4]
|
||||
except IndexError:
|
||||
log.warn("Problem parsing disk usage information")
|
||||
log.warn('Problem parsing disk usage information')
|
||||
ret = {}
|
||||
if args:
|
||||
return ret[args]
|
||||
|
|
|
@ -3,24 +3,38 @@
|
|||
:codauthor: :email:`Mike Place <mp@saltstack.com>`
|
||||
'''
|
||||
|
||||
# Import Python libs
|
||||
import os
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting import TestCase, skipIf
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
from salttesting.mock import patch, call, NO_MOCK, NO_MOCK_REASON, DEFAULT, MagicMock
|
||||
ensure_in_syspath('../')
|
||||
|
||||
# Import Salt libs
|
||||
import integration
|
||||
from salt import client
|
||||
from salt.exceptions import EauthAuthenticationError, SaltInvocationError
|
||||
|
||||
ensure_in_syspath('../')
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class LocalClientTestCase(TestCase):
|
||||
class LocalClientTestCase(TestCase,
|
||||
integration.AdaptedConfigurationTestCaseMixIn):
|
||||
def setUp(self):
|
||||
self.local_client = client.LocalClient()
|
||||
if not os.path.exists('/tmp/salttest'):
|
||||
# This path is hardcoded in the configuration file
|
||||
os.makedirs('/tmp/salttest/cache')
|
||||
if not os.path.exists(integration.TMP_CONF_DIR):
|
||||
os.makedirs(integration.TMP_CONF_DIR)
|
||||
|
||||
self.local_client = client.LocalClient(
|
||||
self.get_config_file_path('master')
|
||||
)
|
||||
|
||||
def test_create_local_client(self):
|
||||
local_client = client.LocalClient()
|
||||
self.assertIsInstance(local_client, client.LocalClient, "LocalClient did not create a LocalClient instance")
|
||||
local_client = client.LocalClient(self.get_config_file_path('master'))
|
||||
self.assertIsInstance(local_client, client.LocalClient, 'LocalClient did not create a LocalClient instance')
|
||||
|
||||
def test_check_pub_data(self):
|
||||
just_minions = {'minions': ['m1', 'm2']}
|
||||
|
@ -30,12 +44,12 @@ class LocalClientTestCase(TestCase):
|
|||
self.assertRaises(EauthAuthenticationError, self.local_client._check_pub_data, None)
|
||||
self.assertDictEqual({},
|
||||
self.local_client._check_pub_data(just_minions),
|
||||
"Did not handle lack of jid correctly")
|
||||
'Did not handle lack of jid correctly')
|
||||
|
||||
self.assertDictEqual(
|
||||
{},
|
||||
self.local_client._check_pub_data({'jid': '0'}),
|
||||
"Passing JID of zero is not handled gracefully")
|
||||
'Passing JID of zero is not handled gracefully')
|
||||
|
||||
with patch.dict(self.local_client.opts, {}):
|
||||
self.local_client._check_pub_data(jid_no_minions)
|
||||
|
|
Loading…
Add table
Reference in a new issue