Пример #1
0
    def test_dynamic_service_manager_start_stop(self):
        """
        This test exercises the ServiceManager functions, but doesn't really
        verify functionality beyond the tests above
        """
        # Skip for integration tests, otherwise will fail on systems without
        # runit
        if self.is_integration_test:
            return

        mgr = ServiceManager(
            ['dummy1', 'dummy2'], 'runit', MagicMock(), ['redirectd'], []
        )

        self.subprocess_mock.return_value = (
            'down: e2e_controller: 268195s; run: log: (pid 2275) 268195s\n'
        )
        self.assertEqual(mgr._service_control['redirectd'].status(),
                         ServiceState.Inactive)

        mgr.update_dynamic_services(['redirectd'])
        self.subprocess_mock.return_value = (
            'run: e2e_controller: 268195s; run: log: (pid 2275) 268195s\n'
        )
        self.assertEqual(mgr._service_control['redirectd'].status(),
                         ServiceState.Active)

        mgr.update_dynamic_services([])
        self.subprocess_mock.return_value = (
            'down: e2e_controller: 268195s; run: log: (pid 2275) 268195s\n'
        )
        self.assertEqual(mgr._service_control['redirectd'].status(),
                         ServiceState.Inactive)
Пример #2
0
    def test_dynamic_service_manager_start_stop(self):
        """
        This test exercises the ServiceManager functions, but doesn't really
        verify functionality beyond the tests above
        """
        mgr = ServiceManager(
            ['dummy1', 'dummy2'],
            'systemd',
            MagicMock(),
            ['redirectd'],
            [],
        )

        self.subprocess_mock.return_value = b'inactive\n'
        self.assertEqual(
            mgr._service_control['redirectd'].status(),
            ServiceState.Inactive,
        )

        self._loop.run_until_complete(
            mgr.update_dynamic_services(['redirectd']), )
        self.subprocess_mock.return_value = b'active\n'
        self.assertEqual(
            mgr._service_control['redirectd'].status(),
            ServiceState.Active,
        )

        self._loop.run_until_complete(mgr.update_dynamic_services([]))
        self.subprocess_mock.return_value = b'inactive\n'
        self.assertEqual(
            mgr._service_control['redirectd'].status(),
            ServiceState.Inactive,
        )