def test_validate_container_state(self): container = Container(self.context, **utils.get_test_container()) container.status = 'Stopped' self.assertRaises(exception.InvalidStateException, self.compute_manager._validate_container_state, container, 'stop') self.assertRaises(exception.InvalidStateException, self.compute_manager._validate_container_state, container, 'pause') container.status = 'Running' self.assertRaises(exception.InvalidStateException, self.compute_manager._validate_container_state, container, 'start') self.assertRaises(exception.InvalidStateException, self.compute_manager._validate_container_state, container, 'unpause')
def test_container_delete_invalid_state(self, mock_validate): container = Container(self.context, **utils.get_test_container()) mock_validate.side_effect = exception.InvalidStateException self.assertRaises(exception.InvalidStateException, self.compute_manager.container_delete, self.context, container, False)
def test_container_delete(self, mock_delete, mock_validate): container = Container(self.context, **utils.get_test_container()) self.compute_manager.container_delete(self.context, container, False) mock_delete.assert_called_once_with(container, False)
def test_container_create_docker_create_failed(self, mock_fail, mock_create, mock_save): container = Container(self.context, **utils.get_test_container()) mock_create.side_effect = exception.DockerError self.compute_manager._do_container_create(self.context, container) mock_fail.assert_called_once_with(container)
def test_container_create(self, mock_create, mock_pull, mock_save): container = Container(self.context, **utils.get_test_container()) self.compute_manager._do_container_create(self.context, container) mock_save.assert_called_with() mock_pull.assert_called_once_with(container.image) mock_create.assert_called_once_with(container)
def test_fail_container(self, mock_save): container = Container(self.context, **utils.get_test_container()) self.compute_manager._fail_container(container) self.assertEqual(fields.ContainerStatus.ERROR, container.status) self.assertIsNone(container.task_state)
def test_container_kill(self, mock_kill): container = Container(self.context, **utils.get_test_container()) self.compute_manager.container_kill(self.context, container, None) mock_kill.assert_called_once_with(container, None)
def test_container_kill_failed(self, mock_kill, mock_validate): container = Container(self.context, **utils.get_test_container()) mock_kill.side_effect = exception.DockerError self.assertRaises(exception.DockerError, self.compute_manager.container_kill, self.context, container, None)
def test_container_execute_failed(self, mock_execute): container = Container(self.context, **utils.get_test_container()) mock_execute.side_effect = exception.DockerError self.assertRaises(exception.DockerError, self.compute_manager.container_exec, self.context, container, 'fake_cmd')
def test_container_execute(self, mock_execute): container = Container(self.context, **utils.get_test_container()) self.compute_manager.container_exec(self.context, container, 'fake_cmd') mock_execute.assert_called_once_with(container, 'fake_cmd')
def test_container_logs_failed(self, mock_logs): container = Container(self.context, **utils.get_test_container()) mock_logs.side_effect = exception.DockerError self.assertRaises(exception.DockerError, self.compute_manager.container_logs, self.context, container)
def test_container_logs(self, mock_logs): container = Container(self.context, **utils.get_test_container()) self.compute_manager.container_logs(self.context, container) mock_logs.assert_called_once_with(container)
def test_container_unpause(self, mock_unpause, mock_validate): container = Container(self.context, **utils.get_test_container()) self.compute_manager.container_unpause(self.context, container) mock_unpause.assert_called_once_with(container)