Beispiel #1
0
 def delete(self):
     """Delete this pipeline."""
     policy.check('delete_pipeline',
                  pecan.request.security_context)
     handler = pipeline_handler.PipelineHandler(
         pecan.request.security_context)
     return handler.delete(self._id)
Beispiel #2
0
    def test_build_execution_context_first_run(self, mock_ks, mock_net,
                                               mock_registry):
        fpipe = fakes.FakePipeline()
        fplan = fakes.FakePlan()
        mock_net.return_value = {'public_net': 'fake-net-id'}
        mock_registry.Plan.get_by_id.return_value = fplan
        fplan.raw_content = {
            'name':
            'theplan',
            'artifacts': [{
                'name': 'nodeus',
                'artifact_type': 'heroku',
                'content': {
                    'href': 'https://example.com/ex.git'
                },
                'language_pack': '1-2-3-4'
            }]
        }

        handler = pipeline_handler.PipelineHandler(self.ctx)

        handler._get_context_from_last_execution = mock.MagicMock(
            return_value=None)

        handler._create_empty_stack = mock.MagicMock(return_value='foo')
        url_for = mock_ks.return_value.client.service_catalog.url_for
        url_for.return_value = 'url-for'
        ex_ctx = handler._build_execution_context(fpipe)
        self.assertEqual('foo', ex_ctx['stack_id'])
        self.assertEqual('url-for', ex_ctx['build_service_url'])
        self.assertEqual('1-2-3-4', ex_ctx['base_image_id'])
        self.assertEqual('heroku', ex_ctx['source_format'])
        self.assertEqual('faker', ex_ctx['parameters']['app_name'])
        self.assertEqual('fake-net-id', ex_ctx['parameters']['public_net'])
Beispiel #3
0
    def test_delete(self, mock_clients, mock_registry):
        db_obj = fakes.FakePipeline()
        mock_exec = mock.MagicMock()
        mock_exec.context = json.dumps({'stack_id': 'foo'})
        mock_mistral = mock_clients.return_value.mistral.return_value
        mock_mistral.executions.get.return_value = mock_exec
        wb = yamlutils.dump({
            'Workflow': {
                'tasks': {
                    'start': {
                        'parameters': {
                            'stack_id': ''
                        }
                    }
                }
            }
        })
        mock_mistral.workbooks.get_definition.return_value = wb

        mock_registry.Pipeline.get_by_uuid.return_value = db_obj
        handler = pipeline_handler.PipelineHandler(self.ctx)
        handler.delete('test_id')
        db_obj.destroy.assert_called_once_with(self.ctx)
        mock_registry.Pipeline.get_by_uuid.assert_called_once_with(
            self.ctx, 'test_id')

        mock_heat = mock_clients.return_value.heat.return_value
        mock_heat.stacks.delete.assert_called_once_with(stack_id='foo')

        mock_kc = mock_clients.return_value.keystone.return_value
        mock_kc.delete_trust.assert_called_once_with('trust_worthy')
Beispiel #4
0
    def post(self, data):
        """Create a new pipeline."""
        policy.check('create_pipeline', pecan.request)
        js_data = data.as_dict(objects.registry.Pipeline)
        host_url = pecan.request.application_url.rstrip('/')
        if data.plan_uri is not wsme.Unset:
            plan_uri = data.plan_uri
            if plan_uri.startswith(host_url):
                pl_uuid = plan_uri.split('/')[-1]
                pl = objects.registry.Plan.get_by_uuid(
                    pecan.request.security_context, pl_uuid)
                js_data['plan_id'] = pl.id
            else:
                # TODO(asalkeld) we are not hosting the plan so
                # download the plan and insert it into our db.
                raise exception.BadRequest(reason=_(
                    'The plan was not hosted in solum'))

        if js_data.get('plan_id') is None:
            raise exception.BadRequest(reason=_(
                'The plan was not given or could not be found'))

        handler = pipeline_handler.PipelineHandler(
            pecan.request.security_context)
        return pipeline.Pipeline.from_db_model(
            handler.create(js_data), host_url)
Beispiel #5
0
    def test_empty_create_stack(self, mock_get, mock_clients, mock_registry):
        db_obj = fakes.FakePipeline()
        test_name = str(uuid.uuid4())
        test_id = str(uuid.uuid4())
        db_obj.name = test_name
        mock_registry.Pipeline.return_value = db_obj

        fake_template = json.dumps({})
        mock_get.return_value = fake_template

        mock_create = mock_clients.return_value.heat.return_value.stacks.create
        mock_create.return_value = {
            "stack": {
                "id": test_id,
                "links": [{
                    "href": "http://fake.ref",
                    "rel": "self"
                }]
            }
        }
        handler = pipeline_handler.PipelineHandler(self.ctx)
        res = handler._create_empty_stack(db_obj)
        mock_create.assert_called_once_with(stack_name=test_name,
                                            template=fake_template)
        self.assertEqual(test_id, res)
Beispiel #6
0
 def get_all(self, pipeline_id):
     """Return all executions, based on the provided pipeline_id."""
     handler = pipeline_handler.PipelineHandler(
         pecan.request.security_context)
     return [execution.Execution.from_db_model(obj,
                                               pecan.request.host_url)
             for obj in handler.get(pipeline_id).executions]
Beispiel #7
0
 def put(self, data):
     """Modify this pipeline."""
     handler = pipeline_handler.PipelineHandler(
         pecan.request.security_context)
     res = handler.update(self._id,
                          data.as_dict(objects.registry.Pipeline))
     return pipeline.Pipeline.from_db_model(res, pecan.request.host_url)
Beispiel #8
0
 def get(self):
     """Return this pipeline."""
     policy.check('show_pipeline',
                  pecan.request.security_context)
     handler = pipeline_handler.PipelineHandler(
         pecan.request.security_context)
     host_url = pecan.request.application_url.rstrip('/')
     return pipeline.Pipeline.from_db_model(handler.get(self._id), host_url)
Beispiel #9
0
 def get_all(self):
     """Return all pipelines."""
     handler = pipeline_handler.PipelineHandler(
         pecan.request.security_context)
     return [
         pipeline.Pipeline.from_db_model(obj, pecan.request.host_url)
         for obj in handler.get_all()
     ]
Beispiel #10
0
 def test_pipeline_get(self, mock_registry):
     mock_registry.return_value.Pipeline.get_by_uuid.return_value = {
         'plan_id': '1234'
     }
     handler = pipeline_handler.PipelineHandler(self.ctx)
     res = handler.get('test_id')
     self.assertIsNotNone(res)
     mock_registry.Pipeline.get_by_uuid.assert_called_once_with(
         self.ctx, 'test_id')
Beispiel #11
0
 def get_all(self):
     """Return all pipelines."""
     policy.check('get_pipelines',
                  pecan.request.security_context)
     handler = pipeline_handler.PipelineHandler(
         pecan.request.security_context)
     host_url = pecan.request.application_url.rstrip('/')
     return [pipeline.Pipeline.from_db_model(obj, host_url)
             for obj in handler.get_all()]
Beispiel #12
0
    def post(self, trigger_id):
        """Trigger a new event on Solum."""
        try:
            handler = assembly_handler.AssemblyHandler(None)
            handler.trigger_workflow(trigger_id)
        except exception.ResourceNotFound:
            handler = pipeline_handler.PipelineHandler(None)
            handler.trigger_workflow(trigger_id)

        pecan.response.status = 202
Beispiel #13
0
 def get_all(self, pipeline_id):
     """Return all executions, based on the provided pipeline_id."""
     policy.check('get_pipeline_executions', pecan.request.security_context)
     handler = pipeline_handler.PipelineHandler(
         pecan.request.security_context)
     host_url = pecan.request.application_url.rstrip('/')
     return [
         execution.Execution.from_db_model(obj, host_url)
         for obj in handler.get(pipeline_id).executions
     ]
Beispiel #14
0
 def put(self, data):
     """Modify this pipeline."""
     policy.check('update_pipeline',
                  pecan.request.security_context)
     handler = pipeline_handler.PipelineHandler(
         pecan.request.security_context)
     res = handler.update(self._id,
                          data.as_dict(objects.registry.Pipeline))
     host_url = pecan.request.application_url.rstrip('/')
     return pipeline.Pipeline.from_db_model(res, host_url)
Beispiel #15
0
 def test_ensure_workbook_exists(self, mock_clients, mock_registry):
     fpipe = fakes.FakePipeline()
     fpipe.workbook_name = 'build'
     mock_mistral = mock_clients.return_value.mistral.return_value
     wbook = mock.MagicMock()
     wbook.workbook_name = 'build'
     mock_mistral.workbooks.get.return_value = wbook
     handler = pipeline_handler.PipelineHandler(self.ctx)
     handler._ensure_workbook(fpipe)
     mock_mistral.workbooks.create.assert_has_calls([])
Beispiel #16
0
 def test_update(self, mock_registry):
     data = {'user_id': 'new_user_id', 'plan_uuid': 'input_plan_uuid'}
     db_obj = fakes.FakePipeline()
     mock_registry.Pipeline.get_by_uuid.return_value = db_obj
     handler = pipeline_handler.PipelineHandler(self.ctx)
     res = handler.update('test_id', data)
     self.assertEqual(db_obj.user_id, res.user_id)
     db_obj.save.assert_called_once_with(self.ctx)
     db_obj.update.assert_called_once_with(data)
     mock_registry.Pipeline.get_by_uuid.assert_called_once_with(
         self.ctx, 'test_id')
Beispiel #17
0
 def test_ensure_workbook_unknown(self, mock_get, mock_clients,
                                  mock_registry):
     fpipe = fakes.FakePipeline()
     fpipe.workbook_name = 'we-dont-have-this'
     mock_mistral = mock_clients.return_value.mistral.return_value
     mock_mistral.workbooks.get.side_effect = ValueError(
         'Workbook not found')
     mock_get.side_effect = exception.ObjectNotFound(name='workbook',
                                                     id='we-dont-have-this')
     handler = pipeline_handler.PipelineHandler(self.ctx)
     self.assertRaises(exception.ObjectNotFound, handler._ensure_workbook,
                       fpipe)
Beispiel #18
0
 def test_trigger_workflow(self, mock_registry):
     trigger_id = 1
     db_obj = fakes.FakePipeline()
     mock_registry.Pipeline.get_by_trigger_id.return_value = db_obj
     plan_obj = fakes.FakePlan()
     mock_registry.Plan.get_by_id.return_value = plan_obj
     handler = pipeline_handler.PipelineHandler(self.ctx)
     handler._execute_workbook = mock.MagicMock()
     handler._context_from_trust_id = mock.MagicMock(return_value=self.ctx)
     handler.trigger_workflow(trigger_id)
     handler._execute_workbook.assert_called_once_with(db_obj)
     handler._context_from_trust_id.assert_called_once_with('trust_worthy')
     mock_registry.Pipeline.get_by_trigger_id.assert_called_once_with(
         None, trigger_id)
Beispiel #19
0
    def test_ensure_workbook_not_exists(self, mock_clients, mock_registry):
        fpipe = fakes.FakePipeline()
        fpipe.workbook_name = 'build'
        mock_mistral = mock_clients.return_value.mistral.return_value
        mock_mistral.workbooks.get.side_effect = ValueError(
            'Workbook not found')
        handler = pipeline_handler.PipelineHandler(self.ctx)
        handler._ensure_workbook(fpipe)

        mock_mistral.workbooks.create.assert_called_once_with(
            'build', 'solum generated workbook', ['solum', 'builtin'])
        wbook = catalog.get('workbooks', 'build')
        mock_mistral.workbooks.upload_definition.assert_called_once_with(
            'build', wbook)
Beispiel #20
0
    def test_build_execution_context_next_run(self, mock_clients,
                                              mock_registry):
        fpipe = fakes.FakePipeline()
        fplan = fakes.FakePlan()
        mock_registry.Plan.get_by_id.return_value = fplan
        fplan.raw_content = {
            'name':
            'theplan',
            'artifacts': [{
                'name': 'nodeus',
                'artifact_type': 'heroku',
                'content': {
                    'href': 'https://example.com/ex.git'
                },
                'language_pack': '1-2-3-4'
            }]
        }

        mock_exec = mock.MagicMock()
        mock_exec.context = json.dumps({
            'stack_id': 'foo',
            'build_service_url': 'url-for',
            'base_image_id': '1-2-3-4',
            'source_format': 'heroku',
            'parameters': {
                'app_name': 'fruit',
                'public_net': 'nsa-2-0'
            }
        })
        mock_mistral = mock_clients.return_value.mistral.return_value
        mock_mistral.executions.get.return_value = mock_exec
        wbook = catalog.get('workbooks', 'build_deploy')
        mock_mistral.workbooks.get_definition.return_value = wbook

        handler = pipeline_handler.PipelineHandler(self.ctx)

        ex_ctx = handler._build_execution_context(fpipe)
        self.assertEqual('foo', ex_ctx['stack_id'])
        self.assertEqual('url-for', ex_ctx['build_service_url'])
        self.assertEqual('1-2-3-4', ex_ctx['base_image_id'])
        self.assertEqual('heroku', ex_ctx['source_format'])
        self.assertEqual('fruit', ex_ctx['parameters']['app_name'])
        self.assertEqual('nsa-2-0', ex_ctx['parameters']['public_net'])
Beispiel #21
0
    def test_get_context_from_last_execution(self, mock_clients,
                                             mock_registry):
        fpipe = fakes.FakePipeline()
        mock_exec = mock.MagicMock()
        mock_exec.context = json.dumps({
            'stack_id': 'foo',
            'build_service_url': 'url-for',
            'base_image_id': '1-2-3-4',
            'source_format': 'heroku'
        })
        mock_mistral = mock_clients.return_value.mistral.return_value
        mock_mistral.executions.get.return_value = mock_exec
        wbook = catalog.get('workbooks', 'build_deploy')
        mock_mistral.workbooks.get_definition.return_value = wbook

        handler = pipeline_handler.PipelineHandler(self.ctx)

        ex_ctx = handler._get_context_from_last_execution(fpipe)
        self.assertEqual('foo', ex_ctx['stack_id'])
        self.assertEqual('url-for', ex_ctx['build_service_url'])
        self.assertEqual('1-2-3-4', ex_ctx['base_image_id'])
        self.assertEqual('heroku', ex_ctx['source_format'])
Beispiel #22
0
    def test_create(self, mock_kc, mock_registry):
        data = {
            'user_id': 'new_user_id',
            'uuid': 'input_uuid',
            'plan_uuid': 'input_plan_uuid'
        }

        db_obj = fakes.FakePipeline()
        mock_registry.Pipeline.return_value = db_obj
        fp = fakes.FakePlan()
        mock_registry.Plan.get_by_id.return_value = fp
        fp.raw_content = {
            'name':
            'theplan',
            'artifacts': [{
                'name': 'nodeus',
                'artifact_type': 'application.heroku',
                'content': {
                    'href': 'https://example.com/ex.git'
                },
                'language_pack': 'auto'
            }]
        }
        trust_ctx = utils.dummy_context()
        trust_ctx.trust_id = '12345'
        mock_kc.return_value.create_trust_context.return_value = trust_ctx

        handler = pipeline_handler.PipelineHandler(self.ctx)
        handler._execute_workbook = mock.MagicMock()
        handler._ensure_workbook = mock.MagicMock()
        res = handler.create(data)
        db_obj.update.assert_called_once_with(data)
        handler._execute_workbook.assert_called_once_with(db_obj)
        handler._ensure_workbook.assert_called_once_with(db_obj)
        db_obj.create.assert_called_once_with(self.ctx)
        self.assertEqual(db_obj, res)
        mock_kc.return_value.create_trust_context.assert_called_once_with()
Beispiel #23
0
 def delete(self):
     """Delete this pipeline."""
     handler = pipeline_handler.PipelineHandler(
         pecan.request.security_context)
     return handler.delete(self._id)
Beispiel #24
0
 def get(self):
     """Return this pipeline."""
     handler = pipeline_handler.PipelineHandler(
         pecan.request.security_context)
     return pipeline.Pipeline.from_db_model(handler.get(self._id),
                                            pecan.request.host_url)
Beispiel #25
0
 def test_pipeline_get_all(self, mock_registry):
     mock_registry.PipelineList.get_all.return_value = {}
     handler = pipeline_handler.PipelineHandler(self.ctx)
     res = handler.get_all()
     self.assertIsNotNone(res)
     mock_registry.PipelineList.get_all.assert_called_once_with(self.ctx)
Beispiel #26
0
 def test_update(self, mock_registry):
     data = {'user_id': 'new_user_id', 'plan_uuid': 'input_plan_uuid'}
     handler = pipeline_handler.PipelineHandler(self.ctx)
     handler.update('test_id', data)
     mock_registry.Pipeline.update_and_save.assert_called_once_with(
         self.ctx, 'test_id', data)