salt/tests/integration/modules/test_beacons.py

146 lines
4.7 KiB
Python
Raw Normal View History

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>`
'''
# Python Libs
from __future__ import absolute_import
2016-02-23 22:46:21 +00:00
import os
# Salt Libs
2016-02-23 22:46:21 +00:00
from salt.exceptions import CommandExecutionError
# Salttesting libs
import tests.integration as integration
from tests.support.unit import skipIf
2016-02-23 23:19:07 +00:00
class BeaconsAddDeleteTest(integration.ModuleCase):
'''
2016-02-23 23:19:07 +00:00
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)
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-23 22:46:21 +00:00
# save added beacon
_save = self.run_function('beacons.save')
self.assertTrue(_save['result'])
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-23 22:46:21 +00:00
# save the results
self.run_function('beacons.save')
2016-02-23 23:19:07 +00:00
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)
2016-02-23 23:19:07 +00:00
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')
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
'''
# 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'])
# 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
ret = self.run_function('beacons.disable_beacon', ['ps'])
2016-02-23 22:46:21 +00:00
self.assertTrue(ret['result'])
# assert beacon ps is disabled
_list = self.run_function('beacons.list', return_yaml=False)
self.assertFalse(_list['ps']['enabled'])
def test_enable(self):
2016-02-23 22:46:21 +00:00
'''
Test enabling beacons
'''
# 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
ret = self.run_function('beacons.enable')
2016-02-23 22:46:21 +00:00
self.assertTrue(ret['result'])
# 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
ret = self.run_function('beacons.enable_beacon', ['ps'])
2016-02-23 22:46:21 +00:00
self.assertTrue(ret['result'])
# 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'}})