Example #1
0
    def test_kill_container_remove(self):
        """``container_shell`` 'kill_container' removes containers it's killed"""
        container_shell.kill_container(self.container, self.the_signal,
                                       self.persist, self.persist_egrep,
                                       self.ps_path, self.logger)

        self.assertTrue(self.container.remove.called)
Example #2
0
    def test_kill_container_remove_error(self):
        """``container_shell`` 'kill_container' logs unexpected failures to remove containers"""
        self.container.remove.side_effect = Exception("testing")
        container_shell.kill_container(self.container, self.the_signal,
                                       self.persist, self.persist_egrep,
                                       self.ps_path, self.logger)

        self.assertTrue(self.logger.exception.called)
Example #3
0
    def test_kill_container_remove_gone(self):
        """``container_shell`` 'kill_container' ignores failures to remove containers that no longer exist"""
        self.container.remove.side_effect = docker.errors.NotFound("testing")
        container_shell.kill_container(self.container, self.the_signal,
                                       self.persist, self.persist_egrep,
                                       self.ps_path, self.logger)

        self.assertFalse(self.logger.exception.called)
Example #4
0
    def test_kill_container_should_not(self):
        """``container_shell`` 'kill_container' bails early if it should_not_kill"""
        self.container.attrs['ExecIDs'] = [MagicMock()]
        container_shell.kill_container(self.container, self.the_signal,
                                       self.persist, self.persist_egrep,
                                       self.ps_path, self.logger)

        self.assertEqual(self.logger.debug.call_count, 0)
Example #5
0
    def test_kill_container(self):
        """``container_shell`` 'kill_container' sends the supplied signal to PID 1"""
        container_shell.kill_container(self.container, self.the_signal,
                                       self.persist, self.persist_egrep,
                                       self.ps_path, self.logger)

        the_args, _ = self.container.exec_run.call_args
        kill_cmd = the_args[0]
        expected = 'kill -SIGTERM 1'

        self.assertEqual(kill_cmd, expected)
Example #6
0
    def test_kill_logs_unexpected(self, fake_should_not_kill):
        """``container_shell`` 'kill_container' logs unexpected erros when trying to kill a container"""
        fake_should_not_kill.return_value = False
        fake_resp = MagicMock()
        fake_resp.status_code = 500
        error = docker.errors.APIError("SERVER ERROR", response=fake_resp)
        self.container.exec_run.side_effect = error

        container_shell.kill_container(self.container, self.the_signal,
                                       self.persist, self.persist_egrep,
                                       self.ps_path, self.logger)

        self.assertTrue(self.logger.exception.called)
Example #7
0
    def test_kill_ignores_409(self, fake_should_not_kill):
        """``container_shell`` 'kill_container' ignores failures to kill a container that's not running"""
        fake_should_not_kill.return_value = False
        fake_resp = MagicMock()
        fake_resp.status_code = 409
        error = docker.errors.APIError("CONFLICT", response=fake_resp)
        self.container.exec_run.side_effect = error

        container_shell.kill_container(self.container, self.the_signal,
                                       self.persist, self.persist_egrep,
                                       self.ps_path, self.logger)

        self.assertFalse(self.logger.exception.called)