diff --git a/adagios/bi/tests.py b/adagios/bi/tests.py index bb760601d..2e64dfb76 100644 --- a/adagios/bi/tests.py +++ b/adagios/bi/tests.py @@ -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() @@ -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): diff --git a/adagios/misc/tests.py b/adagios/misc/tests.py index fbdc28526..2a294826f 100644 --- a/adagios/misc/tests.py +++ b/adagios/misc/tests.py @@ -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 diff --git a/adagios/settings.py b/adagios/settings.py index ecba1e347..e7853c57c 100644 --- a/adagios/settings.py +++ b/adagios/settings.py @@ -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 +# 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 diff --git a/adagios/status/tests.py b/adagios/status/tests.py index 9feb31efc..efe12dda4 100644 --- a/adagios/status/tests.py +++ b/adagios/status/tests.py @@ -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') diff --git a/adagios/utils.py b/adagios/utils.py index 8bcad3847..3784be69b 100644 --- a/adagios/utils.py +++ b/adagios/utils.py @@ -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): @@ -153,10 +155,10 @@ 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') @@ -164,9 +166,9 @@ def create_minimal_environment(self): 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)