Ejemplo n.º 1
0
 def test_delete(self, mock_registry):
     db_obj = fakes.FakeWorkflow()
     mock_registry.Workflow.get_by_uuid.return_value = db_obj
     handler = workflow_handler.WorkflowHandler(self.ctx)
     handler.delete('test_id')
     mock_registry.Workflow.get_by_uuid.assert_called_once_with(
         self.ctx, 'test_id')
Ejemplo n.º 2
0
    def test_create(self, mock_wf_insert, mock_pa, mock_registry):

        app_obj = fakes.FakeApp()
        app_id = app_obj.id
        test_cmd = app_obj.workflow_config['test_cmd']
        run_cmd = app_obj.workflow_config['run_cmd']
        mock_registry.App.get_by_id.return_value = app_obj

        workflow_data = {
            "actions": ["unittest", "build", "deploy"],
            "app_id": app_id,
            "source": app_obj.source,
            "config": app_obj.workflow_config,
            "actions": app_obj.trigger_actions
        }

        fp = fakes.FakePlan()
        mock_registry.Plan.return_value = fp

        fa = fakes.FakeAssembly()
        fa.plan_uuid = fp.uuid
        mock_registry.Assembly.return_value = fa

        wf_obj = fakes.FakeWorkflow()
        wf_obj.app_id = app_obj.id
        wf_obj.assembly = fa.id
        mock_registry.Workflow.return_value = wf_obj

        fi = fakes.FakeImage()
        mock_registry.Image.return_value = fi

        handler = workflow_handler.WorkflowHandler(self.ctx)

        res = handler.create(workflow_data,
                             commit_sha='master',
                             status_url='',
                             du_id='')
        self.assertEqual(wf_obj, res)
        git_info = {
            'source_url': app_obj.source['repository'],
            'commit_sha': app_obj.source['revision'],
            'repo_token': app_obj.source['repo_token'],
            'private': app_obj.source['private'],
            'private_ssh_key': app_obj.source['private_ssh_key'],
            'status_url': '',
        }
        mock_pa.assert_called_once_with(
            verb='launch_workflow',
            workflow=['unittest', 'build', 'deploy'],
            build_id=fa.id,
            name=fi.name,
            assembly_id=fa.id,
            git_info=git_info,
            test_cmd=test_cmd,
            ports=app_obj.ports,
            base_image_id=fi.base_image_id,
            source_format=fi.source_format,
            image_format=fi.image_format,
            run_cmd=run_cmd,
            du_id='')
Ejemplo n.º 3
0
    def test_destroy_absent_wf_present(self, mock_client, mock_registry,
                                       mock_tlogger, mock_log_handler,
                                       mock_swift_delete):

        cfg.CONF.worker.image_storage = "swift"
        fake_assem = fakes.FakeAssembly()
        mock_registry.Assembly.get_by_id.return_value = fake_assem
        fake_image = fakes.FakeImage()
        mock_registry.Image.get_by_id.return_value = fake_image

        fake_wf = fakes.FakeWorkflow()
        mock_registry.Workflow.get_by_assembly_id.side_effect = fake_wf

        mock_log = mock_tlogger.TenantLogger.return_value.log
        mock_upload = mock_tlogger.TenantLogger.return_value.upload
        mock_log_del = mock_log_handler.return_value.delete
        mock_heat = mock_client.return_value.heat
        mock_del = mock_heat.return_value.stacks.delete

        hh = heat_handler.Handler()
        with mock.patch.object(hh,
                               "_find_id_if_stack_exists",
                               return_value=None):

            hh.destroy_assembly(self.ctx, fake_assem.id)

        self.assertFalse(mock_del.called)
        self.assertFalse(fake_assem.destroy.called)
        mock_registry.Image.get_by_id.assert_called_once_with(
            mock.ANY, fake_assem.image_id)
        docker_image_name = fake_image.docker_image_name
        img_filename = docker_image_name.split('-', 1)[1]
        mock_swift_delete.assert_called_once_with('solum_du', img_filename)
        self.assertTrue(mock_log.called)
        self.assertTrue(mock_upload.called)
        self.assertEqual(1, mock_log_del.call_count)
        self.assertEqual(mock.call(fake_assem.uuid), mock_log_del.call_args)