def test_copy_image_to_staging_store_data_exists(self, mock_store_api, mock_exists, mock_getsize, mock_unlink): mock_store_api.return_value = self.staging_store mock_exists.return_value = True mock_getsize.return_value = 4 copy_image_task = copy_image._CopyImage(self.task.task_id, self.task_type, self.image_repo, self.image_id) with mock.patch.object(self.image_repo, 'get') as get_mock: get_mock.return_value = mock.MagicMock( image_id=self.images[0]['id'], locations=self.images[0]['locations'], status=self.images[0]['status'], size=4) copy_image_task.execute() mock_exists.assert_called_once() mock_store_api.assert_called_once_with("os_glance_staging_store") mock_getsize.assert_called_once() # As valid image data already exists in staging area # it does not remove it and also does not download # it again to staging area mock_unlink.assert_not_called() self.staging_store.add.assert_not_called()
def test_copy_image_to_staging_store_partial_data_exists( self, mock_store_api, mock_exists, mock_getsize, mock_unlink): mock_store_api.return_value = self.staging_store mock_exists.return_value = True mock_getsize.return_value = 3 copy_image_task = copy_image._CopyImage(self.task.task_id, self.task_type, self.image_repo, self.action_wrapper) with mock.patch.object(self.image_repo, 'get') as get_mock: get_mock.return_value = mock.MagicMock( image_id=self.images[0]['id'], locations=self.images[0]['locations'], status=self.images[0]['status'], extra_properties={'os_glance_import_task': self.task.task_id}, size=4) with mock.patch.object(store_api, 'get') as get_data: get_data.return_value = (b"dddd", 4) copy_image_task.execute() mock_exists.assert_called_once() mock_getsize.assert_called_once() mock_unlink.assert_called_once() self.staging_store.add.assert_called_once() mock_store_api.assert_called_once_with( "os_glance_staging_store")
def test_copy_non_existing_image_to_staging_store_(self, mock_store_api): mock_store_api.return_value = self.staging_store copy_image_task = copy_image._CopyImage(self.task.task_id, self.task_type, self.image_repo, self.image_id) with mock.patch.object(self.image_repo, 'get') as get_mock: get_mock.side_effect = exception.NotFound() self.assertRaises(exception.NotFound, copy_image_task.execute) mock_store_api.assert_called_once_with("os_glance_staging_store")
def test_copy_image_to_staging_store(self, mock_store_api): mock_store_api.return_value = self.staging_store copy_image_task = copy_image._CopyImage(self.task.task_id, self.task_type, self.image_repo, self.image_id) with mock.patch.object(self.image_repo, 'get') as get_mock: get_mock.return_value = mock.MagicMock( image_id=self.images[0]['id'], locations=self.images[0]['locations'], status=self.images[0]['status']) with mock.patch.object(store_api, 'get') as get_data: get_data.return_value = (b"dddd", 4) copy_image_task.execute() self.staging_store.add.assert_called_once() mock_store_api.assert_called_once_with( "os_glance_staging_store")