Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PyTest #24] Beacons module related fixes #55532

Merged
merged 2 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions salt/modules/beacons.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,14 @@ def add(name, beacon_data, **kwargs):
if name in beacons and beacons[name] == beacon_data:
ret['result'] = True
ret['comment'] = 'Added beacon: {0}.'.format(name)
else:
elif event_ret:
ret['result'] = False
ret['comment'] = event_ret['comment']
else:
ret['result'] = False
ret['comment'] = 'Did not receive the beacon add complete event before the timeout of {}s'.format(
kwargs.get('timeout', default_event_wait)
)
return ret
except KeyError:
# Effectively a no-op, since we can't really return without an event system
Expand Down Expand Up @@ -295,9 +300,14 @@ def modify(name, beacon_data, **kwargs):
if name in beacons and beacons[name] == beacon_data:
ret['result'] = True
ret['comment'] = 'Modified beacon: {0}.'.format(name)
else:
elif event_ret:
ret['result'] = False
ret['comment'] = event_ret['comment']
else:
ret['result'] = False
ret['comment'] = 'Did not receive the beacon modify complete event before the timeout of {}s'.format(
kwargs.get('timeout', default_event_wait)
)
return ret
except KeyError:
# Effectively a no-op, since we can't really return without an event system
Expand Down Expand Up @@ -342,9 +352,14 @@ def delete(name, **kwargs):
ret['result'] = True
ret['comment'] = 'Deleted beacon: {0}.'.format(name)
return ret
else:
elif event_ret:
ret['result'] = False
ret['comment'] = event_ret['comment']
else:
ret['result'] = False
ret['comment'] = 'Did not receive the beacon delete complete event before the timeout of {}s'.format(
kwargs.get('timeout', default_event_wait)
)
except KeyError:
# Effectively a no-op, since we can't really return without an event system
ret['comment'] = 'Event module not available. Beacon add failed.'
Expand Down Expand Up @@ -422,9 +437,14 @@ def enable(**kwargs):
if 'enabled' in beacons and beacons['enabled']:
ret['result'] = True
ret['comment'] = 'Enabled beacons on minion.'
else:
elif event_ret:
ret['result'] = False
ret['comment'] = 'Failed to enable beacons on minion.'
else:
ret['result'] = False
ret['comment'] = 'Did not receive the beacon enabled complete event before the timeout of {}s'.format(
kwargs.get('timeout', default_event_wait)
)
return ret
except KeyError:
# Effectively a no-op, since we can't really return without an event system
Expand Down Expand Up @@ -464,9 +484,14 @@ def disable(**kwargs):
if 'enabled' in beacons and not beacons['enabled']:
ret['result'] = True
ret['comment'] = 'Disabled beacons on minion.'
else:
elif event_ret:
ret['result'] = False
ret['comment'] = 'Failed to disable beacons on minion.'
else:
ret['result'] = False
ret['comment'] = 'Did not receive the beacon disabled complete event before the timeout of {}s'.format(
kwargs.get('timeout', default_event_wait)
)
return ret
except KeyError:
# Effectively a no-op, since we can't really return without an event system
Expand Down Expand Up @@ -532,12 +557,14 @@ def enable_beacon(name, **kwargs):
else:
ret['result'] = False
ret['comment'] = 'Failed to enable beacon {0} on minion.'.format(name)
elif event_ret:
ret['result'] = False
ret['comment'] = event_ret['comment']
else:
ret['result'] = False
if event_ret is not None:
ret['comment'] = event_ret['comment']
else:
ret['comment'] = 'Beacon enabled event never received'
ret['comment'] = 'Did not receive the beacon enabled complete event before the timeout of {}s'.format(
kwargs.get('timeout', default_event_wait)
)
return ret
except KeyError:
# Effectively a no-op, since we can't really return without an event system
Expand Down Expand Up @@ -593,12 +620,14 @@ def disable_beacon(name, **kwargs):
else:
ret['result'] = False
ret['comment'] = 'Failed to disable beacon on minion.'
elif event_ret:
ret['result'] = False
ret['comment'] = event_ret['comment']
else:
ret['result'] = False
if event_ret is not None:
ret['comment'] = event_ret['comment']
else:
ret['comment'] = 'Beacon disabled event never received'
ret['comment'] = 'Did not receive the beacon disabled complete event before the timeout of {}s'.format(
kwargs.get('timeout', default_event_wait)
)
return ret
except KeyError:
# Effectively a no-op, since we can't really return without an event system
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/modules/test_gpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
# Import Salt Testing libs
from tests.support.helpers import destructiveTest
from tests.support.unit import TestCase, skipIf
from tests.support.paths import TMP
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.mock import (
NO_MOCK,
NO_MOCK_REASON,
MagicMock,
patch
)
from tests.support.runtests import RUNTIME_VARS

# Import Salt libs
import salt.utils.platform
Expand Down Expand Up @@ -179,14 +179,14 @@ def setup_loader_modules(self):
@skipIf(not HAS_GPG, 'GPG Module Unavailable')
def setUp(self):
super(GpgTestCase, self).setUp()
self.gpghome = os.path.join(TMP, 'gpghome')
self.gpghome = os.path.join(RUNTIME_VARS.TMP, 'gpghome')
if not os.path.isdir(self.gpghome):
# left behind... Don't fail because of this!
os.makedirs(self.gpghome)
self.gpgfile_pub = os.path.join(TMP, 'gpgfile.pub')
self.gpgfile_pub = os.path.join(RUNTIME_VARS.TMP, 'gpgfile.pub')
with salt.utils.files.fopen(self.gpgfile_pub, 'wb') as fp:
fp.write(salt.utils.stringutils.to_bytes(GPG_TEST_PUB_KEY))
self.gpgfile_priv = os.path.join(TMP, 'gpgfile.priv')
self.gpgfile_priv = os.path.join(RUNTIME_VARS.TMP, 'gpgfile.priv')
with salt.utils.files.fopen(self.gpgfile_priv, 'wb') as fp:
fp.write(salt.utils.stringutils.to_bytes(GPG_TEST_PRIV_KEY))
self.user = 'salt'
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/states/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
call,
mock_open,
patch)
from tests.support.paths import TMP
from tests.support.runtests import RUNTIME_VARS

# Import salt libs
import salt.utils.files
Expand Down Expand Up @@ -2358,7 +2358,7 @@ def test__check_directory(self):
# Run _check_directory function
# Verify that it returns correctly
# Delete tmp directory structure
root_tmp_dir = os.path.join(TMP, 'test__check_dir')
root_tmp_dir = os.path.join(RUNTIME_VARS.TMP, 'test__check_dir')
expected_dir_mode = 0o777
depth = 3
try:
Expand Down