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

add: possibility to have other backends in FakeAdagiosEnvironment #399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions adagios/bi/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ class TestBusinessProcessLogic(TestCase):
""" This class responsible for testing business classes logic """
def setUp(self):
self.environment = adagios.utils.FakeAdagiosEnvironment()
self.environment.create_minimal_environment()
self.environment.create_minimal_environment(backend=adagios.settings.BACKEND)
self.environment.configure_livestatus()
self.environment.update_adagios_global_variables()
self.environment.start()
self.environment.start(start_command=adagios.settings.ENGINE_START_COMMAND)

self.livestatus = self.environment.get_livestatus()
self.livestatus.test()
Expand All @@ -177,7 +177,7 @@ def setUp(self):
BusinessProcess._default_filename = filename

def tearDown(self):
self.environment.terminate()
self.environment.terminate(stop_command=adagios.settings.ENGINE_STOP_COMMAND)
os.remove(BusinessProcess._default_filename)

def testBestAndWorstState(self):
Expand Down
2 changes: 1 addition & 1 deletion adagios/misc/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def testFakeAdagiosEnvironment(self):
fake_adagios = self.fake_adagios

# Make sure temporary environment gets created
fake_adagios.create_minimal_environment()
fake_adagios.create_minimal_environment(backend=adagios.settings.BACKEND)
self.assertTrue(os.path.exists(fake_adagios.adagios_config_file))

# Make sure adagios.settings is updated
Expand Down
17 changes: 17 additions & 0 deletions adagios/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,23 @@

]

# Backend
# Used notably for tests, to create adapted fake environments
BACKEND = 'nagios'
# BACKEND = 'shinken'

# Engine start command
# None works fine for Nagios, because Pynag will guess it
ENGINE_START_COMMAND = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENGINE_START_COMMAND and ENGINE_STOP_COMMAND both look like they should belong inside FakeShinkenEnvironment as per my comments on the pynag pull request.

# Shinken hack, as it's not trivial to specify another configuration than
# /etc/shinken/shinken.cfg
# ENGINE_START_COMMAND = 'ln -s /var/run/shinken/arbiterd.pid {tmp_dir}/nagios.pid && service shinken-broker start && service shinken-poller start && service shinken-reactionner start && service shinken-receiver start && service shinken-scheduler start && /usr/bin/shinken-arbiter -c {tmp_conf} -d && sleep 10'

# Engine stop command
# None works fine for Nagios, because Pynag will guess it
ENGINE_STOP_COMMAND = None
# ENGINE_STOP_COMMAND = 'service shinken stop'

# Graphite #

# the url where to fetch data and images
Expand Down
8 changes: 4 additions & 4 deletions adagios/status/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ class LiveStatusTestCase(unittest.TestCase):
def setUpClass(cls):
cls.nagios_config = adagios.settings.nagios_config
cls.environment = adagios.utils.FakeAdagiosEnvironment()
cls.environment.create_minimal_environment()
cls.environment.create_minimal_environment(backend=adagios.settings.BACKEND)
cls.environment.configure_livestatus()
cls.environment.update_adagios_global_variables()
cls.environment.start()
cls.livestatus = cls.environment.get_livestatus()
cls.environment.start(start_command=adagios.settings.ENGINE_START_COMMAND)

cls.livestatus = cls.environment.get_livestatus()
cls.factory = RequestFactory()

@classmethod
def tearDownClass(cls):
cls.environment.terminate()
cls.environment.terminate(stop_command=adagios.settings.ENGINE_STOP_COMMAND)

def testLivestatusConnectivity(self):
requests = self.livestatus.query('GET status', 'Columns: requests')
Expand Down
12 changes: 7 additions & 5 deletions adagios/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ def update_adagios_global_variables(self):
adagios.settings.adagios_configfile = self.adagios_config_file
adagios.settings.USER_PREFS_PATH = self.adagios_config_dir + "/userdata"
adagios.settings.nagios_config = self.cfg_file
adagios.settings.livestatus_path = self.livestatus_socket_path
# we update livestatus_path only if the socket mode is used
if ':' not in adagios.settings.livestatus_path and '/' in adagios.settings.livestatus_path:
adagios.settings.livestatus_path = self.livestatus_socket_path
reload_config_file(self.adagios_config_file)

def restore_adagios_global_variables(self):
Expand All @@ -153,20 +155,20 @@ def restore_adagios_global_variables(self):
adagios.settings.__dict__.clear()
adagios.settings.__dict__.update(self._adagios_settings_copy)

def create_minimal_environment(self):
def create_minimal_environment(self, backend='nagios'):
""" Behaves like FakeNagiosEnvironment except also creates adagios config directory """

super(FakeAdagiosEnvironment, self).create_minimal_environment()
super(FakeAdagiosEnvironment, self).create_minimal_environment(backend=backend)
self.adagios_config_dir = os.path.join(self.tempdir, 'adagios')
self.adagios_config_file = os.path.join(self.adagios_config_dir, 'adagios.conf')

os.makedirs(self.adagios_config_dir)
with open(self.adagios_config_file, 'w') as f:
f.write('')

def terminate(self):
def terminate(self, stop_command=None):
""" Behaves like FakeNagiosEnvironment except also restores adagios.settings module """
if self._adagios_settings_copy:
self.restore_adagios_global_variables()
super(FakeAdagiosEnvironment, self).terminate()
super(FakeAdagiosEnvironment, self).terminate(stop_command=stop_command)