Exemplo n.º 1
0
 def test_container_run_create_raises_docker_error(
         self, mock_create, mock_pull, mock_attach_volume,
         mock_detach_volume, mock_list_by_container, mock_save,
         mock_spawn_n):
     container = Container(self.context, **utils.get_test_container())
     image = {'image': 'repo', 'path': 'out_path', 'driver': 'glance',
              'repo': 'test', 'tag': 'testtag'}
     mock_pull.return_value = image, True
     mock_create.side_effect = exception.DockerError(
         message="Docker Error occurred")
     mock_spawn_n.side_effect = lambda f, *x, **y: f(*x, **y)
     self.compute_manager._resource_tracker = FakeResourceTracker()
     networks = []
     volumes = [FakeVolumeMapping()]
     self.compute_manager.container_create(
         self.context,
         requested_networks=networks,
         requested_volumes=volumes,
         container=container,
         limits=None, run=True)
     mock_save.assert_called_with(self.context)
     self.assertEqual('Error', container.status)
     self.assertEqual('Docker Error occurred', container.status_reason)
     mock_pull.assert_any_call(self.context, container.image, 'latest',
                               'always', 'glance')
     mock_create.assert_called_once_with(
         self.context, container, image, networks, volumes)
     mock_attach_volume.assert_called_once()
     mock_detach_volume.assert_called_once()
     self.assertEqual(0, len(FakeVolumeMapping.volumes))
Exemplo n.º 2
0
 def test_container_run_image_pull_docker_error(
         self, mock_pull, mock_attach_volume, mock_detach_volume,
         mock_list_by_container, mock_save, mock_spawn_n):
     container_dict = utils.get_test_container(
         image='test:latest', image_driver='docker',
         image_pull_policy='ifnotpresent')
     container = Container(self.context, **container_dict)
     mock_pull.side_effect = exception.DockerError(
         message="Docker Error occurred")
     mock_spawn_n.side_effect = lambda f, *x, **y: f(*x, **y)
     networks = []
     volumes = [FakeVolumeMapping()]
     self.compute_manager.container_create(
         self.context,
         requested_networks=networks,
         requested_volumes=volumes,
         container=container,
         limits=None, run=True)
     mock_save.assert_called_with(self.context)
     self.assertEqual('Error', container.status)
     self.assertEqual('Docker Error occurred', container.status_reason)
     mock_pull.assert_called_once_with(self.context, 'test', 'latest',
                                       'ifnotpresent', 'docker')
     mock_attach_volume.assert_called_once()
     mock_detach_volume.assert_called_once()
     self.assertEqual(0, len(FakeVolumeMapping.volumes))
Exemplo n.º 3
0
 def test_container_create_pull_image_failed_docker_error(
         self, mock_fail, mock_pull, mock_create_sandbox, mock_save):
     container = Container(self.context, **utils.get_test_container())
     mock_pull.side_effect = exception.DockerError("Pull Failed")
     mock_create_sandbox.return_value = mock.MagicMock()
     self.compute_manager._do_container_create(self.context, container)
     mock_fail.assert_called_once_with(self.context, container,
                                       "Pull Failed")
 def test_container_create_pull_image_failed_docker_error(
         self, mock_fail, mock_pull, mock_save):
     container = Container(self.context, **utils.get_test_container())
     mock_pull.side_effect = exception.DockerError("Pull Failed")
     networks = []
     self.compute_manager._do_container_create(self.context, container,
                                               networks)
     mock_fail.assert_called_once_with(self.context,
                                       container, "Pull Failed")
 def test_container_kill_failed(self, mock_kill, mock_fail):
     container = Container(self.context, **utils.get_test_container())
     mock_kill.side_effect = exception.DockerError(
         message="Docker Error occurred")
     self.assertRaises(exception.DockerError,
                       self.compute_manager._do_container_kill,
                       self.context, container, None, reraise=True)
     mock_fail.assert_called_with(self.context,
                                  container, 'Docker Error occurred')
Exemplo n.º 6
0
 def _pull_image(self, repo, tag):
     with docker_utils.docker_client() as docker:
         for line in docker.pull(repo, tag=tag, stream=True):
             error = json.loads(line).get('errorDetail')
             if error:
                 if "not found" in error['message']:
                     raise exception.ImageNotFound(error['message'])
                 else:
                     raise exception.DockerError(error['message'])
Exemplo n.º 7
0
 def test_container_delete_failed(self, mock_delete, mock_save, mock_fail):
     container = Container(self.context, **utils.get_test_container())
     mock_delete.side_effect = exception.DockerError(
         message="Docker Error occurred")
     self.assertRaises(exception.DockerError,
                       self.compute_manager.container_delete, self.context,
                       container, False)
     mock_save.assert_called_with(self.context)
     mock_fail.assert_called_with(self.context, container,
                                  'Docker Error occurred')
Exemplo n.º 8
0
 def test_container_run_image_pull_docker_error(self, mock_fail, mock_pull,
                                                mock_save):
     container = Container(self.context, **utils.get_test_container())
     mock_pull.side_effect = exception.DockerError(
         message="Docker Error occurred")
     self.compute_manager._do_container_run(self.context, container)
     mock_save.assert_called_with(self.context)
     mock_fail.assert_called_with(self.context, container,
                                  'Docker Error occurred')
     mock_pull.assert_called_once_with(self.context, 'kubernetes/pause',
                                       'latest', 'ifnotpresent')
Exemplo n.º 9
0
 def test_container_create_docker_create_failed(self, mock_fail,
                                                mock_create, mock_pull,
                                                mock_save):
     container = Container(self.context, **utils.get_test_container())
     image = {'image': 'repo', 'path': 'out_path', 'driver': 'glance'}
     mock_pull.return_value = image, False
     mock_create.side_effect = exception.DockerError("Creation Failed")
     self.compute_manager._resource_tracker = FakeResourceTracker()
     networks = []
     self.compute_manager._do_container_create(self.context, container,
                                               networks)
     mock_fail.assert_called_once_with(
         self.context, container, "Creation Failed", unset_host=True)
Exemplo n.º 10
0
def docker_client():
    client_kwargs = dict()
    if not CONF.docker.api_insecure:
        client_kwargs['ca_cert'] = CONF.docker.ca_file
        client_kwargs['client_key'] = CONF.docker.key_file
        client_kwargs['client_cert'] = CONF.docker.key_file

    try:
        yield DockerHTTPClient(CONF.docker.api_url,
                               CONF.docker.docker_remote_api_version,
                               CONF.docker.default_timeout, **client_kwargs)
    except errors.APIError as e:
        raise exception.DockerError(error_msg=six.text_type(e))
Exemplo n.º 11
0
    def test_pull_image_raises_docker_error(self, mock_should_pull_image,
                                            mock_search, mock_parse_image):
        mock_should_pull_image.return_value = True
        mock_search.return_value = {'image': 'nginx', 'path': 'xyz'}
        mock_parse_image.return_value = ('repo', 'tag')

        with mock.patch.object(
                self.mock_docker,
                'pull',
                side_effect=exception.DockerError('Error')) as mock_pull:
            self.assertRaises(exception.DockerError, self.driver.pull_image,
                              None, 'repo', 'tag', 'always')
            self.mock_docker.pull.assert_called_once_with('repo', tag='tag')
            self.assertEqual(1, mock_pull.call_count)
Exemplo n.º 12
0
def docker_client():
    client_kwargs = dict()
    if not CONF.docker.api_insecure:
        client_kwargs['ca_cert'] = CONF.docker.ca_file
        client_kwargs['client_key'] = CONF.docker.key_file
        client_kwargs['client_cert'] = CONF.docker.cert_file

    try:
        yield DockerHTTPClient(CONF.docker.api_url,
                               CONF.docker.docker_remote_api_version,
                               CONF.docker.default_timeout, **client_kwargs)
    except errors.APIError as e:
        desired_exc = exception.DockerError(error_msg=str(e))
        utils.reraise(type(desired_exc), desired_exc, sys.exc_info()[2])
 def test_container_run_image_pull_docker_error(self, mock_fail,
                                                mock_pull, mock_save):
     container_dict = utils.get_test_container(
         image='test:latest', image_driver='docker',
         image_pull_policy='ifnotpresent')
     container = Container(self.context, **container_dict)
     mock_pull.side_effect = exception.DockerError(
         message="Docker Error occurred")
     networks = []
     self.compute_manager._do_container_run(self.context,
                                            container,
                                            networks)
     mock_save.assert_called_with(self.context)
     mock_fail.assert_called_with(self.context,
                                  container, 'Docker Error occurred')
     mock_pull.assert_called_once_with(self.context, 'test', 'latest',
                                       'ifnotpresent', 'docker')
Exemplo n.º 14
0
 def test_container_run_create_raises_docker_error(self, mock_create,
                                                   mock_fail, mock_pull,
                                                   mock_save):
     container = Container(self.context, **utils.get_test_container())
     mock_pull.return_value = {'name': 'nginx', 'path': None}
     mock_create.side_effect = exception.DockerError(
         message="Docker Error occurred")
     self.compute_manager._do_container_run(self.context, container)
     mock_save.assert_called_with(self.context)
     mock_fail.assert_called_with(self.context, container,
                                  'Docker Error occurred')
     mock_pull.assert_any_call(self.context, container.image, 'latest',
                               'always')
     mock_create.assert_called_once_with(self.context, container, None, {
         'name': 'nginx',
         'path': None
     })
Exemplo n.º 15
0
 def test_container_delete_failed_force(self, mock_delete,
                                        mock_list_by_container,
                                        mock_save,
                                        mock_fail, mock_destroy,
                                        mock_remove_usage):
     mock_list_by_container.return_value = []
     container = Container(self.context, **utils.get_test_container())
     mock_delete.side_effect = exception.DockerError(
         message="Docker Error occurred")
     self.compute_manager._do_container_delete(self.context, container,
                                               True)
     mock_save.assert_called_with(self.context)
     mock_fail.assert_called_with(self.context,
                                  container, 'Docker Error occurred')
     mock_destroy.assert_called_once_with(self.context)
     mock_remove_usage.assert_called_once_with(self.context, container,
                                               True)
Exemplo n.º 16
0
 def test_container_run_create_raises_docker_error(self, mock_create,
                                                   mock_fail,
                                                   mock_pull, mock_save):
     container = Container(self.context, **utils.get_test_container())
     mock_pull.return_value = {'name': 'nginx', 'path': None}, True
     mock_create.side_effect = exception.DockerError(
         message="Docker Error occurred")
     self.compute_manager._resource_tracker = FakeResourceTracker()
     networks = []
     self.compute_manager._do_container_run(self.context,
                                            container,
                                            networks)
     mock_save.assert_called_with(self.context)
     mock_fail.assert_called_with(
         self.context, container, 'Docker Error occurred', unset_host=True)
     mock_pull.assert_any_call(self.context, container.image, 'latest',
                               'always', 'glance')
     mock_create.assert_called_once_with(
         self.context, container, {'name': 'nginx', 'path': None})