Exemplo n.º 1
0
    def reset(self):
        """ Performs reset. Raises exception on error """

        # Check service status
        service_obj = Service('elasticsearch.service')
        service_state = service_obj.get_state()
        if service_state._state == 'active':
            Log.warn("Elasticsearch service in active state. \n"
                     "Stopping Elasticsearch service now...")
            service_obj.stop()

        # Clear log files.
        Elasticsearch.truncate_log_files(self.log_path)
        Log.info("Reset done.")
        return 0
class TestSystemHandler(unittest.TestCase):
    _service_name = 'rsyslog.service'

    def setUp(self):
        self.service_obj = Service(TestSystemHandler._service_name)

    def test_start(self):
        self.service_obj.start()
        service_state = self.test_get_state()
        self.assertEqual(service_state.state, 'active')
        self.assertEqual(service_state.substate, 'running')

    def test_stop(self):
        self.service_obj.stop()
        service_state = self.test_get_state()
        self.assertEqual(service_state.state, 'inactive')
        self.assertEqual(service_state.substate, 'dead')

    def test_restart(self):
        self.service_obj.restart()
        service_state = self.test_get_state()
        self.assertEqual(service_state.state, 'active')
        self.assertEqual(service_state.substate, 'running')

    def test_enable(self):
        self.service_obj.enable()
        is_enable = self.test_is_enabled()
        self.assertTrue(is_enable)

    def test_disable(self):
        self.service_obj.disable()
        is_enable = self.test_is_enabled()
        self.assertFalse(is_enable)

    def test_get_state(self):
        return self.service_obj.get_state()

    def test_is_enabled(self):
        return self.service_obj.is_enabled()