mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Code cleanup and make sure the beacons config file is deleted after testing
Conflicts: - tests/integration/modules/beacons.py
This commit is contained in:
parent
c7fc09f97d
commit
4627c4ea6d
@ -11,38 +11,32 @@ import os
|
||||
from salt.modules import beacons
|
||||
from salt.exceptions import CommandExecutionError
|
||||
import integration
|
||||
import salt.utils
|
||||
|
||||
# Salttesting libs
|
||||
from salttesting import skipIf
|
||||
from salttesting.helpers import destructiveTest, ensure_in_syspath
|
||||
|
||||
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
beacons.__opts__ = {}
|
||||
|
||||
BEACON_CONF_DIR = os.path.join(integration.TMP, 'minion.d')
|
||||
if not os.path.exists(BEACON_CONF_DIR):
|
||||
os.makedirs(BEACON_CONF_DIR)
|
||||
|
||||
IS_ADMIN = False
|
||||
if salt.utils.is_windows():
|
||||
import salt.utils.win_functions
|
||||
current_user = salt.utils.win_functions.get_current_user()
|
||||
if current_user == 'SYSTEM':
|
||||
IS_ADMIN = True
|
||||
else:
|
||||
IS_ADMIN = salt.utils.win_functions.is_admin(current_user)
|
||||
else:
|
||||
IS_ADMIN = os.geteuid() == 0
|
||||
|
||||
|
||||
@skipIf(not IS_ADMIN, 'You must be root to run these tests')
|
||||
@destructiveTest
|
||||
class BeaconsAddDeleteTest(integration.ModuleCase):
|
||||
'''
|
||||
Tests the add and delete functions
|
||||
'''
|
||||
def setUp(self):
|
||||
self.minion_conf_d_dir = os.path.join(
|
||||
self.minion_opts['config_dir'],
|
||||
os.path.dirname(self.minion_opts['default_include']))
|
||||
if not os.path.isdir(self.minion_conf_d_dir):
|
||||
os.makedirs(self.minion_conf_d_dir)
|
||||
self.beacons_config_file_path = os.path.join(self.minion_conf_d_dir, 'beacons.conf')
|
||||
|
||||
def tearDown(self):
|
||||
if os.path.isfile(self.beacons_config_file_path):
|
||||
os.unlink(self.beacons_config_file_path)
|
||||
|
||||
def test_add_and_delete(self):
|
||||
'''
|
||||
Test adding and deleting a beacon
|
||||
@ -62,13 +56,26 @@ class BeaconsAddDeleteTest(integration.ModuleCase):
|
||||
self.run_function('beacons.save')
|
||||
|
||||
|
||||
@skipIf(not IS_ADMIN, 'You must be root to run these tests')
|
||||
@destructiveTest
|
||||
class BeaconsTest(integration.ModuleCase):
|
||||
'''
|
||||
Tests the beacons execution module
|
||||
'''
|
||||
beacons_config_file_path = minion_conf_d_dir = None
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
if os.path.isfile(cls.beacons_config_file_path):
|
||||
os.unlink(cls.beacons_config_file_path)
|
||||
|
||||
def setUp(self):
|
||||
if self.minion_conf_d_dir is None:
|
||||
self.minion_conf_d_dir = os.path.join(
|
||||
self.minion_opts['config_dir'],
|
||||
os.path.dirname(self.minion_opts['default_include']))
|
||||
if not os.path.isdir(self.minion_conf_d_dir):
|
||||
os.makedirs(self.minion_conf_d_dir)
|
||||
self.__class__.beacons_config_file_path = os.path.join(self.minion_conf_d_dir, 'beacons.conf')
|
||||
try:
|
||||
# Add beacon to disable
|
||||
self.run_function('beacons.add', ['ps', [{'apache2': 'stopped'}]])
|
||||
|
Loading…
Reference in New Issue
Block a user