2016-02-23 22:46:21 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-02-24 16:56:11 +00:00
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Justin Anderson <janderson@saltstack.com>`
|
|
|
|
'''
|
2016-02-22 15:53:02 +00:00
|
|
|
|
|
|
|
# Python Libs
|
|
|
|
from __future__ import absolute_import
|
2016-02-23 22:46:21 +00:00
|
|
|
import os
|
2016-02-22 15:53:02 +00:00
|
|
|
|
|
|
|
# Salt Libs
|
2016-02-23 22:46:21 +00:00
|
|
|
from salt.exceptions import CommandExecutionError
|
|
|
|
|
|
|
|
# Salttesting libs
|
2017-03-09 15:42:33 +00:00
|
|
|
import tests.integration as integration
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf
|
2016-02-22 15:53:02 +00:00
|
|
|
|
|
|
|
|
2016-02-23 23:19:07 +00:00
|
|
|
class BeaconsAddDeleteTest(integration.ModuleCase):
|
2016-02-22 15:53:02 +00:00
|
|
|
'''
|
2016-02-23 23:19:07 +00:00
|
|
|
Tests the add and delete functions
|
2016-02-22 15:53:02 +00:00
|
|
|
'''
|
2017-03-09 15:42:33 +00:00
|
|
|
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)
|
|
|
|
|
2016-02-23 23:19:07 +00:00
|
|
|
def test_add_and_delete(self):
|
2016-02-23 22:46:21 +00:00
|
|
|
'''
|
2016-02-23 23:19:07 +00:00
|
|
|
Test adding and deleting a beacon
|
2016-02-23 22:46:21 +00:00
|
|
|
'''
|
|
|
|
_add = self.run_function('beacons.add', ['ps', {'apache2': 'stopped'}])
|
|
|
|
self.assertTrue(_add['result'])
|
2016-02-22 15:53:02 +00:00
|
|
|
|
2016-02-23 22:46:21 +00:00
|
|
|
# save added beacon
|
|
|
|
_save = self.run_function('beacons.save')
|
|
|
|
self.assertTrue(_save['result'])
|
2016-02-22 15:53:02 +00:00
|
|
|
|
2016-02-23 23:19:07 +00:00
|
|
|
# delete the beacon
|
2016-02-23 22:46:21 +00:00
|
|
|
_delete = self.run_function('beacons.delete', ['ps'])
|
|
|
|
self.assertTrue(_delete['result'])
|
2016-02-22 18:22:34 +00:00
|
|
|
|
2016-02-23 22:46:21 +00:00
|
|
|
# save the results
|
|
|
|
self.run_function('beacons.save')
|
2016-02-22 18:22:34 +00:00
|
|
|
|
2016-02-23 23:19:07 +00:00
|
|
|
|
|
|
|
class BeaconsTest(integration.ModuleCase):
|
|
|
|
'''
|
|
|
|
Tests the beacons execution module
|
|
|
|
'''
|
2017-03-09 15:42:33 +00:00
|
|
|
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)
|
|
|
|
|
2016-02-23 23:19:07 +00:00
|
|
|
def setUp(self):
|
2017-03-09 15:42:33 +00:00
|
|
|
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')
|
2016-02-23 22:46:21 +00:00
|
|
|
try:
|
|
|
|
# Add beacon to disable
|
|
|
|
self.run_function('beacons.add', ['ps', {'apache2': 'stopped'}])
|
|
|
|
self.run_function('beacons.save')
|
|
|
|
except CommandExecutionError:
|
|
|
|
self.skipTest('Unable to add beacon')
|
|
|
|
|
2016-02-23 23:19:07 +00:00
|
|
|
def tearDown(self):
|
|
|
|
# delete added beacon
|
|
|
|
self.run_function('beacons.delete', ['ps'])
|
|
|
|
self.run_function('beacons.save')
|
|
|
|
|
|
|
|
def test_disable(self):
|
|
|
|
'''
|
|
|
|
Test disabling beacons
|
|
|
|
'''
|
2016-02-24 17:38:23 +00:00
|
|
|
# assert beacon exists
|
|
|
|
_list = self.run_function('beacons.list', return_yaml=False)
|
|
|
|
self.assertIn('ps', _list)
|
|
|
|
|
2016-02-23 22:46:21 +00:00
|
|
|
ret = self.run_function('beacons.disable')
|
|
|
|
self.assertTrue(ret['result'])
|
2016-02-24 17:38:23 +00:00
|
|
|
|
|
|
|
# assert beacons are disabled
|
|
|
|
_list = self.run_function('beacons.list', return_yaml=False)
|
|
|
|
self.assertFalse(_list['enabled'])
|
|
|
|
|
2016-02-23 22:46:21 +00:00
|
|
|
# disable added beacon
|
2016-02-22 18:22:34 +00:00
|
|
|
ret = self.run_function('beacons.disable_beacon', ['ps'])
|
2016-02-23 22:46:21 +00:00
|
|
|
self.assertTrue(ret['result'])
|
|
|
|
|
2016-02-24 17:38:23 +00:00
|
|
|
# assert beacon ps is disabled
|
|
|
|
_list = self.run_function('beacons.list', return_yaml=False)
|
|
|
|
self.assertFalse(_list['ps']['enabled'])
|
|
|
|
|
2016-02-22 18:22:34 +00:00
|
|
|
def test_enable(self):
|
2016-02-23 22:46:21 +00:00
|
|
|
'''
|
|
|
|
Test enabling beacons
|
|
|
|
'''
|
2016-02-24 17:38:23 +00:00
|
|
|
# assert beacon exists
|
|
|
|
_list = self.run_function('beacons.list', return_yaml=False)
|
|
|
|
self.assertIn('ps', _list)
|
|
|
|
|
2016-02-23 22:46:21 +00:00
|
|
|
# enable beacons on minion
|
2016-02-22 18:22:34 +00:00
|
|
|
ret = self.run_function('beacons.enable')
|
2016-02-23 22:46:21 +00:00
|
|
|
self.assertTrue(ret['result'])
|
2016-02-24 17:38:23 +00:00
|
|
|
|
|
|
|
# assert beacons are enabled
|
|
|
|
_list = self.run_function('beacons.list', return_yaml=False)
|
|
|
|
self.assertTrue(_list['enabled'])
|
|
|
|
|
2016-02-29 21:21:19 +00:00
|
|
|
@skipIf(True, 'Skip until https://github.com/saltstack/salt/issues/31516 problems are resolved.')
|
|
|
|
def test_enabled_beacons(self):
|
|
|
|
'''
|
|
|
|
Test enabled specific beacon
|
|
|
|
'''
|
2016-02-23 22:46:21 +00:00
|
|
|
# enable added beacon
|
2016-02-22 18:22:34 +00:00
|
|
|
ret = self.run_function('beacons.enable_beacon', ['ps'])
|
2016-02-23 22:46:21 +00:00
|
|
|
self.assertTrue(ret['result'])
|
2016-02-22 18:22:34 +00:00
|
|
|
|
2016-02-24 17:38:23 +00:00
|
|
|
# assert beacon ps is enabled
|
|
|
|
_list = self.run_function('beacons.list', return_yaml=False)
|
|
|
|
self.assertTrue(_list['ps']['enabled'])
|
|
|
|
|
2016-02-23 22:46:21 +00:00
|
|
|
def test_list(self):
|
|
|
|
'''
|
|
|
|
Test lising the beacons
|
|
|
|
'''
|
|
|
|
# list beacons
|
|
|
|
ret = self.run_function('beacons.list', return_yaml=False)
|
|
|
|
if 'enabled' in ret:
|
|
|
|
self.assertEqual(ret, {'ps': {'apache2': 'stopped'}, 'enabled': True})
|
|
|
|
else:
|
|
|
|
self.assertEqual(ret, {'ps': {'apache': 'stopped'}})
|