def test_init_copy_flow_as_non_owner(self, mock_import): img_repo = mock.MagicMock() admin_repo = mock.MagicMock() fake_req = {"method": {"name": "copy-image"}, "backend": ['cheap']} fake_img = mock.MagicMock() fake_img.id = IMAGE_ID1 fake_img.status = 'active' fake_img.extra_properties = {'os_glance_import_task': TASK_ID1} admin_repo.get.return_value = fake_img import_flow.get_flow(task_id=TASK_ID1, task_type=TASK_TYPE, task_repo=mock.MagicMock(), image_repo=img_repo, admin_repo=admin_repo, image_id=IMAGE_ID1, import_req=fake_req, backend=['cheap']) # Assert that we saved the image with the admin repo instead of the # user-context one at the end of get_flow() when we initialize the # parameters. admin_repo.save.assert_called_once_with(fake_img, 'active') img_repo.save.assert_not_called()
def test_get_flow_pops_stage_host(self): import_flow.get_flow(task_id=TASK_ID1, task_type=TASK_TYPE, task_repo=self.mock_task_repo, image_repo=self.mock_image_repo, image_id=IMAGE_ID1, import_req=self.gd_task_input['import_req']) self.assertNotIn('os_glance_stage_host', self.mock_image.extra_properties) self.assertIn('os_glance_import_task', self.mock_image.extra_properties)
def _pass_uri(self, mock_lf_init, mock_flow_add, mock_VS_init, uri, file_uri, import_req): flow_kwargs = {"task_id": TASK_ID1, "task_type": TASK_TYPE, "task_repo": self.mock_task_repo, "image_repo": self.mock_image_repo, "image_id": IMAGE_ID1, "import_req": import_req} mock_lf_init.return_value = None mock_VS_init.return_value = None self.config(node_staging_uri=uri) import_flow.get_flow(**flow_kwargs) mock_VS_init.assert_called_with(TASK_ID1, TASK_TYPE, self.mock_task_repo, file_uri)
def _get_flow(self, import_req=None): inputs = { 'task_id': mock.MagicMock(), 'task_type': mock.MagicMock(), 'task_repo': mock.MagicMock(), 'image_repo': mock.MagicMock(), 'image_id': mock.MagicMock(), 'import_req': import_req or mock.MagicMock() } flow = api_image_import.get_flow(**inputs) return flow
def _get_flow(self, import_req=None): inputs = { 'task_id': mock.sentinel.task_id, 'task_type': mock.MagicMock(), 'task_repo': mock.MagicMock(), 'image_repo': mock.MagicMock(), 'image_id': mock.MagicMock(), 'import_req': import_req or mock.MagicMock() } inputs['image_repo'].get.return_value = mock.MagicMock( extra_properties={'os_glance_import_task': mock.sentinel.task_id}) flow = api_image_import.get_flow(**inputs) return flow