def test_wait_service(self):
        """Tests waiting on a service.
        """
        # Disable W0212(protected-access)
        # pylint: disable=W0212
        supervisor.wait_service(self.root, supervisor.ServiceWaitAction.down)
        treadmill.subproc.check_call.assert_called_with(
            [supervisor._get_cmd('svwait'), '-d', self.root])

        treadmill.subproc.check_call.reset_mock()
        supervisor.wait_service(
            (os.path.join(self.root, 'a'), os.path.join(self.root, 'b')),
            supervisor.ServiceWaitAction.up,
            all_services=False,
            timeout=100,
        )

        treadmill.subproc.check_call.assert_called_with([
            supervisor._get_cmd('svwait'), '-t100', '-o', '-u',
            os.path.join(self.root, 'a'),
            os.path.join(self.root, 'b')
        ])

        treadmill.subproc.check_call.reset_mock()
        treadmill.subproc.check_call.side_effect = \
            subproc.CalledProcessError(99, supervisor._get_cmd('svwait'))
        with self.assertRaises(subproc.CalledProcessError):
            supervisor.wait_service(self.root,
                                    supervisor.ServiceWaitAction.really_down)
        treadmill.subproc.check_call.assert_called_with(
            [supervisor._get_cmd('svwait'), '-D', self.root])
Exemple #2
0
    def test_control_service_wait(self):
        """Tests controlling a service and wait"""
        # Disable W0212(protected-access)
        # pylint: disable=W0212

        # shutdown supervised service
        res = supervisor.control_service(
            self.root, supervisor.ServiceControlAction.down,
            wait=supervisor.ServiceWaitAction.down,
            timeout=100,
        )

        treadmill.subproc.check_call.assert_called_with(
            [supervisor._get_cmd('svc'), '-d', self.root]
        )
        treadmill.supervisor.wait_service.assert_called_with(
            self.root,
            treadmill.supervisor.ServiceWaitAction.down,
            timeout=100
        )
        self.assertTrue(res)

        # shutdown service timeouts
        treadmill.subproc.check_call.reset_mock()
        supervisor.wait_service.side_effect = \
            subproc.CalledProcessError(99, supervisor._get_cmd('svwait'))

        res = supervisor.control_service(
            self.root, supervisor.ServiceControlAction.down,
            wait=supervisor.ServiceWaitAction.down,
            timeout=100,
        )
        treadmill.subproc.check_call.assert_called_with(
            [supervisor._get_cmd('svc'), '-d', self.root]
        )
        treadmill.supervisor.wait_service.assert_called_with(
            self.root,
            treadmill.supervisor.ServiceWaitAction.down,
            timeout=100
        )
        self.assertFalse(res)

        # shutdown unsupervised service
        treadmill.subproc.check_call.reset_mock()
        treadmill.subproc.check_call.side_effect = \
            subproc.CalledProcessError(100, supervisor._get_cmd('svc'))

        with self.assertRaises(subproc.CalledProcessError):
            supervisor.control_service(
                self.root, supervisor.ServiceControlAction.down,
                wait=supervisor.ServiceWaitAction.down,
                timeout=100,
            )
    def test_is_supervised(self):
        """Tests that checking if a service directory is supervised.
        """
        # Disable W0212(protected-access)
        # pylint: disable=W0212
        self.assertTrue(supervisor.is_supervised(self.root))
        treadmill.subproc.check_call.assert_called_with(
            [supervisor._get_cmd('svok'), self.root])

        treadmill.subproc.check_call.side_effect = \
            subproc.CalledProcessError(1, supervisor._get_cmd('svok'))
        self.assertFalse(supervisor.is_supervised(self.root))
        treadmill.subproc.check_call.assert_called_with(
            [supervisor._get_cmd('svok'), self.root])
 def test_control_svscan(self):
     """Tests controlling an svscan instance.
     """
     # Disable W0212(protected-access)
     # pylint: disable=W0212
     supervisor.control_svscan(self.root,
                               (supervisor.SvscanControlAction.alarm,
                                supervisor.SvscanControlAction.nuke))
     treadmill.subproc.check_call.assert_called_with(
         [supervisor._get_cmd('svscanctl'), '-an', self.root])
Exemple #5
0
    def test_control_service(self):
        """Tests controlling a service.
        """
        # Disable W0212(protected-access)
        # pylint: disable=W0212
        self.assertTrue(supervisor.control_service(
            self.root, supervisor.ServiceControlAction.down
        ))
        treadmill.subproc.check_call.assert_called_with(
            [supervisor._get_cmd('svc'), '-d', self.root]
        )

        self.assertTrue(supervisor.control_service(
            self.root, (
                supervisor.ServiceControlAction.up,
                supervisor.ServiceControlAction.once_at_most,
            ),
            timeout=100,  # Should not be used
        ))
        treadmill.subproc.check_call.assert_called_with(
            [supervisor._get_cmd('svc'), '-uO', self.root]
        )

        self.assertTrue(supervisor.control_service(
            self.root, supervisor.ServiceControlAction.up,
            wait=supervisor.ServiceWaitAction.up,
            timeout=100,
        ))
        treadmill.subproc.check_call.assert_called_with(
            [supervisor._get_cmd('svwait'), '-t100', '-u', self.root]
        )

        treadmill.subproc.check_call.side_effect = \
            subproc.CalledProcessError(1, supervisor._get_cmd('svc'))
        self.assertRaises(
            subproc.CalledProcessError,
            supervisor.control_service,
            self.root,
            supervisor.ServiceControlAction.down
        )
        treadmill.subproc.check_call.assert_called_with(
            [supervisor._get_cmd('svc'), '-d', self.root]
        )