mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge branch '2018.3' into fix_38310_pygit2_checkout_ext_pillar_remote_using_tag
This commit is contained in:
commit
c20977e3bc
9 changed files with 102 additions and 28 deletions
|
@ -448,7 +448,7 @@ def _osx_memdata():
|
|||
sysctl = salt.utils.path.which('sysctl')
|
||||
if sysctl:
|
||||
mem = __salt__['cmd.run']('{0} -n hw.memsize'.format(sysctl))
|
||||
swap_total = __salt__['cmd.run']('{0} -n vm.swapusage'.format(sysctl)).split()[2]
|
||||
swap_total = __salt__['cmd.run']('{0} -n vm.swapusage'.format(sysctl)).split()[2].replace(',', '.')
|
||||
if swap_total.endswith('K'):
|
||||
_power = 2**10
|
||||
elif swap_total.endswith('M'):
|
||||
|
@ -947,7 +947,7 @@ def _virtual(osdata):
|
|||
if os.path.isfile('/sys/devices/virtual/dmi/id/product_name'):
|
||||
try:
|
||||
with salt.utils.files.fopen('/sys/devices/virtual/dmi/id/product_name', 'r') as fhr:
|
||||
output = salt.utils.stringutils.to_unicode(fhr.read())
|
||||
output = salt.utils.stringutils.to_unicode(fhr.read(), errors='replace')
|
||||
if 'VirtualBox' in output:
|
||||
grains['virtual'] = 'VirtualBox'
|
||||
elif 'RHEV Hypervisor' in output:
|
||||
|
@ -2288,7 +2288,7 @@ def _hw_data(osdata):
|
|||
if os.path.exists(contents_file):
|
||||
try:
|
||||
with salt.utils.files.fopen(contents_file, 'r') as ifile:
|
||||
grains[key] = ifile.read().strip()
|
||||
grains[key] = salt.utils.stringutils.to_unicode(ifile.read().strip(), errors='replace')
|
||||
if key == 'uuid':
|
||||
grains['uuid'] = grains['uuid'].lower()
|
||||
except (IOError, OSError) as err:
|
||||
|
|
|
@ -58,22 +58,22 @@ def __virtual__():
|
|||
'influxdb library not available.'))
|
||||
|
||||
|
||||
def _client(user=None, password=None, host=None, port=None, **client_args):
|
||||
if not user:
|
||||
user = __salt__['config.option']('influxdb.user', 'root')
|
||||
if not password:
|
||||
password = __salt__['config.option']('influxdb.password', 'root')
|
||||
if not host:
|
||||
host = __salt__['config.option']('influxdb.host', 'localhost')
|
||||
if not port:
|
||||
port = __salt__['config.option']('influxdb.port', 8086)
|
||||
def _client(influxdb_user=None, influxdb_password=None, influxdb_host=None, influxdb_port=None, **client_args):
|
||||
if not influxdb_user:
|
||||
influxdb_user = __salt__['config.option']('influxdb.user', 'root')
|
||||
if not influxdb_password:
|
||||
influxdb_password = __salt__['config.option']('influxdb.password', 'root')
|
||||
if not influxdb_host:
|
||||
influxdb_host = __salt__['config.option']('influxdb.host', 'localhost')
|
||||
if not influxdb_port:
|
||||
influxdb_port = __salt__['config.option']('influxdb.port', 8086)
|
||||
for ignore in _STATE_INTERNAL_KEYWORDS:
|
||||
if ignore in client_args:
|
||||
del client_args[ignore]
|
||||
return influxdb.InfluxDBClient(host=host,
|
||||
port=port,
|
||||
username=user,
|
||||
password=password,
|
||||
return influxdb.InfluxDBClient(host=influxdb_host,
|
||||
port=influxdb_port,
|
||||
username=influxdb_user,
|
||||
password=influxdb_password,
|
||||
**client_args)
|
||||
|
||||
|
||||
|
|
|
@ -433,7 +433,6 @@ def disabled(name, runas=None, domain='system'):
|
|||
disabled = launchctl('print-disabled',
|
||||
domain,
|
||||
return_stdout=True,
|
||||
output_loglevel='trace',
|
||||
runas=runas)
|
||||
for service in disabled.split("\n"):
|
||||
if name in service:
|
||||
|
|
|
@ -128,7 +128,7 @@ def present(name,
|
|||
if isinstance(profile, string_types):
|
||||
profile = __salt__['config.option'](profile)
|
||||
|
||||
ret = {'name': name, 'result': None, 'comment': None, 'changes': None}
|
||||
ret = {'name': name, 'result': None, 'comment': None, 'changes': {}}
|
||||
datasource = __salt__['grafana4.get_datasource'](name, orgname, profile)
|
||||
data = _get_json_data(
|
||||
name=name,
|
||||
|
@ -149,6 +149,9 @@ def present(name,
|
|||
defaults=datasource)
|
||||
|
||||
if not datasource:
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'Datasource {0} will be created'.format(name)
|
||||
return ret
|
||||
__salt__['grafana4.create_datasource'](profile=profile, **data)
|
||||
datasource = __salt__['grafana4.get_datasource'](name, profile=profile)
|
||||
ret['result'] = True
|
||||
|
@ -163,14 +166,16 @@ def present(name,
|
|||
datasource[key] = None
|
||||
|
||||
if data == datasource:
|
||||
ret['changes'] = {}
|
||||
ret['comment'] = 'Data source {0} already up-to-date'.format(name)
|
||||
return ret
|
||||
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'Datasource {0} will be updated'.format(name)
|
||||
return ret
|
||||
__salt__['grafana4.update_datasource'](
|
||||
datasource['id'], profile=profile, **data)
|
||||
ret['result'] = True
|
||||
ret['changes'] = deep_diff(datasource, data, ignore=['id', 'orgId'])
|
||||
ret['changes'] = deep_diff(datasource, data, ignore=['id', 'orgId', 'readOnly'])
|
||||
ret['comment'] = 'Data source {0} updated'.format(name)
|
||||
return ret
|
||||
|
||||
|
@ -200,6 +205,9 @@ def absent(name, orgname=None, profile='grafana'):
|
|||
ret['comment'] = 'Data source {0} already absent'.format(name)
|
||||
return ret
|
||||
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'Datasource {0} will be deleted'.format(name)
|
||||
return ret
|
||||
__salt__['grafana4.delete_datasource'](datasource['id'], profile=profile)
|
||||
|
||||
ret['result'] = True
|
||||
|
|
|
@ -129,6 +129,9 @@ def present(name,
|
|||
raise
|
||||
|
||||
if create:
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'Org {0} will be created'.format(name)
|
||||
return ret
|
||||
__salt__['grafana4.create_org'](profile=profile, name=name)
|
||||
org = __salt__['grafana4.get_org'](name, profile)
|
||||
ret['changes'] = org
|
||||
|
@ -138,6 +141,9 @@ def present(name,
|
|||
city=city, zipCode=zip_code, state=address_state, country=country,
|
||||
defaults=org['address'])
|
||||
if data != org['address']:
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'Org {0} address will be updated'.format(name)
|
||||
return ret
|
||||
__salt__['grafana4.update_org_address'](name, profile=profile, **data)
|
||||
if create:
|
||||
dictupdate.update(ret['changes']['address'], data)
|
||||
|
@ -148,6 +154,9 @@ def present(name,
|
|||
data = _get_json_data(theme=theme, homeDashboardId=home_dashboard_id,
|
||||
timezone=timezone, defaults=prefs)
|
||||
if data != prefs:
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'Org {0} prefs will be updated'.format(name)
|
||||
return ret
|
||||
__salt__['grafana4.update_org_prefs'](name, profile=profile, **data)
|
||||
if create:
|
||||
dictupdate.update(ret['changes'], data)
|
||||
|
@ -164,13 +173,25 @@ def present(name,
|
|||
for username, role in users.items():
|
||||
if username in db_users:
|
||||
if role is False:
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'Org {0} user {1} will be ' \
|
||||
'deleted'.format(name, username)
|
||||
return ret
|
||||
__salt__['grafana4.delete_org_user'](
|
||||
db_users[username]['userId'], profile=profile)
|
||||
elif role != db_users[username]['role']:
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'Org {0} user {1} role will be ' \
|
||||
'updated'.format(name, username)
|
||||
return ret
|
||||
__salt__['grafana4.update_org_user'](
|
||||
db_users[username]['userId'], loginOrEmail=username,
|
||||
role=role, profile=profile)
|
||||
elif role:
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'Org {0} user {1} will be created'.format(
|
||||
name, username)
|
||||
return ret
|
||||
__salt__['grafana4.create_org_user'](
|
||||
loginOrEmail=username, role=role, profile=profile)
|
||||
|
||||
|
@ -218,6 +239,9 @@ def absent(name, profile='grafana'):
|
|||
ret['comment'] = 'Org {0} already absent'.format(name)
|
||||
return ret
|
||||
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'Org {0} will be deleted'.format(name)
|
||||
return ret
|
||||
__salt__['grafana4.delete_org'](org['id'], profile=profile)
|
||||
|
||||
ret['result'] = True
|
||||
|
|
|
@ -91,6 +91,9 @@ def present(name,
|
|||
create = not user
|
||||
|
||||
if create:
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'User {0} will be created'.format(name)
|
||||
return ret
|
||||
__salt__['grafana4.create_user'](
|
||||
login=name,
|
||||
password=password,
|
||||
|
@ -100,17 +103,24 @@ def present(name,
|
|||
user = __salt__['grafana4.get_user'](name, profile)
|
||||
ret['changes']['new'] = user
|
||||
|
||||
user_data = __salt__['grafana4.get_user_data'](user['id'])
|
||||
user_data = __salt__['grafana4.get_user_data'](user['id'], profile=profile)
|
||||
data = _get_json_data(login=name, email=email, name=fullname, theme=theme,
|
||||
defaults=user_data)
|
||||
if data != _get_json_data(login=None, email=None, name=None, theme=None,
|
||||
defaults=user_data):
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'User {0} will be updated'.format(name)
|
||||
return ret
|
||||
__salt__['grafana4.update_user'](user['id'], profile=profile, **data)
|
||||
dictupdate.update(
|
||||
ret['changes'], deep_diff(
|
||||
user_data, __salt__['grafana4.get_user_data'](user['id'])))
|
||||
|
||||
if user['isAdmin'] != is_admin:
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'User {0} isAdmin status will be updated'.format(
|
||||
name)
|
||||
return ret
|
||||
__salt__['grafana4.update_user_permissions'](
|
||||
user['id'], isGrafanaAdmin=is_admin, profile=profile)
|
||||
dictupdate.update(ret['changes'], deep_diff(
|
||||
|
@ -148,6 +158,9 @@ def absent(name, profile='grafana'):
|
|||
user = __salt__['grafana4.get_user'](name, profile)
|
||||
|
||||
if user:
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'User {0} will be deleted'.format(name)
|
||||
return ret
|
||||
orgs = __salt__['grafana4.get_user_orgs'](user['id'], profile=profile)
|
||||
__salt__['grafana4.delete_user'](user['id'], profile=profile)
|
||||
for org in orgs:
|
||||
|
|
|
@ -335,7 +335,7 @@ def state(name,
|
|||
if top:
|
||||
cmd_kw['topfn'] = ''.join(cmd_kw.pop('arg'))
|
||||
elif sls:
|
||||
cmd_kw['mods'] = cmd_kw.pop('arg')
|
||||
cmd_kw['mods'] = ''.join(cmd_kw.pop('arg'))
|
||||
cmd_kw.update(cmd_kw.pop('kwarg'))
|
||||
tmp_ret = __salt__[fun](**cmd_kw)
|
||||
cmd_ret = {__opts__['id']: {
|
||||
|
|
|
@ -117,21 +117,21 @@ class ServiceModuleTest(ModuleCase):
|
|||
systemd = salt.utils.systemd.booted()
|
||||
|
||||
# check service was not enabled
|
||||
if systemd or salt.utils.platform.is_windows():
|
||||
self.assertIn('ERROR', enable)
|
||||
else:
|
||||
try:
|
||||
self.assertFalse(enable)
|
||||
except AssertionError:
|
||||
self.assertIn('ERROR', enable)
|
||||
|
||||
# check service was not disabled
|
||||
if tuple(self.run_function('grains.item', ['osrelease_info'])['osrelease_info']) == (14, 0o4) and not systemd:
|
||||
# currently upstart does not have a mechanism to report if disabling a service fails if does not exist
|
||||
self.assertTrue(self.run_function('service.disable', [srv_name]))
|
||||
else:
|
||||
if salt.utils.platform.is_windows():
|
||||
try:
|
||||
disable = self.run_function('service.disable', [srv_name])
|
||||
self.assertFalse(disable)
|
||||
except AssertionError:
|
||||
self.assertTrue('error' in disable.lower())
|
||||
else:
|
||||
self.assertFalse(self.run_function('service.disable', [srv_name]))
|
||||
|
||||
if salt.utils.platform.is_darwin():
|
||||
self.assertFalse(self.run_function('service.disabled', [srv_name]))
|
||||
|
|
|
@ -908,3 +908,33 @@ class CoreGrainsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
osdata = {'kernel': 'Linux', }
|
||||
ret = core._virtual(osdata)
|
||||
self.assertEqual(ret['virtual'], virt)
|
||||
|
||||
@patch('salt.utils.path.which', MagicMock(return_value='/usr/sbin/sysctl'))
|
||||
def test_osx_memdata_with_comma(self):
|
||||
'''
|
||||
test osx memdata method when comma returns
|
||||
'''
|
||||
def _cmd_side_effect(cmd):
|
||||
if 'hw.memsize' in cmd:
|
||||
return '4294967296'
|
||||
elif 'vm.swapusage' in cmd:
|
||||
return 'total = 1024,00M used = 160,75M free = 863,25M (encrypted)'
|
||||
with patch.dict(core.__salt__, {'cmd.run': MagicMock(side_effect=_cmd_side_effect)}):
|
||||
ret = core._osx_memdata()
|
||||
assert ret['swap_total'] == 1024
|
||||
assert ret['mem_total'] == 4096
|
||||
|
||||
@patch('salt.utils.path.which', MagicMock(return_value='/usr/sbin/sysctl'))
|
||||
def test_osx_memdata(self):
|
||||
'''
|
||||
test osx memdata
|
||||
'''
|
||||
def _cmd_side_effect(cmd):
|
||||
if 'hw.memsize' in cmd:
|
||||
return '4294967296'
|
||||
elif 'vm.swapusage' in cmd:
|
||||
return 'total = 0.00M used = 0.00M free = 0.00M (encrypted)'
|
||||
with patch.dict(core.__salt__, {'cmd.run': MagicMock(side_effect=_cmd_side_effect)}):
|
||||
ret = core._osx_memdata()
|
||||
assert ret['swap_total'] == 0
|
||||
assert ret['mem_total'] == 4096
|
||||
|
|
Loading…
Add table
Reference in a new issue