コード例 #1
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'])
コード例 #2
0
ファイル: test_pipeline.py プロジェクト: gokulchandrap/solum
 def test_pipeline_put_none(self, PipelineHandler, resp_mock, request_mock):
     request_mock.body = None
     request_mock.content_type = 'application/json'
     hand_put = PipelineHandler.return_value.put
     hand_put.return_value = fakes.FakePipeline()
     pipeline.PipelineController('test_id').put()
     self.assertEqual(400, resp_mock.status)
コード例 #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')
コード例 #4
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)
コード例 #5
0
ファイル: test_pipeline.py プロジェクト: gokulchandrap/solum
 def test_pipeline_put_ok(self, PipelineHandler, resp_mock, request_mock):
     json_update = {'name': 'foo'}
     request_mock.body = json.dumps(json_update)
     request_mock.content_type = 'application/json'
     hand_update = PipelineHandler.return_value.update
     hand_update.return_value = fakes.FakePipeline()
     pipeline.PipelineController('test_id').put()
     hand_update.assert_called_with('test_id', json_update)
     self.assertEqual(200, resp_mock.status)
コード例 #6
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([])
コード例 #7
0
ファイル: test_pipeline.py プロジェクト: gokulchandrap/solum
 def test_pipelines_post_nodata(self, PipelineHandler, resp_mock,
                                request_mock):
     request_mock.body = ''
     request_mock.content_type = 'application/json'
     hand_create = PipelineHandler.return_value.create
     hand_create.return_value = fakes.FakePipeline()
     ret_val = pipeline.PipelinesController().post()
     faultstring = str(ret_val['faultstring'])
     self.assertEqual("Missing argument: \"data\"", faultstring)
     self.assertEqual(400, resp_mock.status)
コード例 #8
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')
コード例 #9
0
ファイル: test_pipeline.py プロジェクト: gokulchandrap/solum
 def test_pipelines_post_not_hosted(self, PipelineHandler, resp_mock,
                                    request_mock):
     json_create = {'name': 'foo', 'plan_uri': 'http://example.com/a.git'}
     request_mock.body = json.dumps(json_create)
     request_mock.content_type = 'application/json'
     hand_create = PipelineHandler.return_value.create
     hand_create.return_value = fakes.FakePipeline()
     ret_val = pipeline.PipelinesController().post()
     faultstring = str(ret_val['faultstring'])
     self.assertIn('The plan was not hosted in solum', faultstring)
     self.assertEqual(400, resp_mock.status)
コード例 #10
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)
コード例 #11
0
ファイル: test_pipeline.py プロジェクト: gokulchandrap/solum
 def test_pipeline_get(self, PipelineHandler, resp_mock, request_mock):
     hand_get = PipelineHandler.return_value.get
     fake_pipeline = fakes.FakePipeline()
     hand_get.return_value = fake_pipeline
     resp = pipeline.PipelineController('test_id').get()
     self.assertIsNotNone(fake_pipeline)
     self.assertEqual(fake_pipeline.name, resp['result'].name)
     self.assertEqual(fake_pipeline.project_id, resp['result'].project_id)
     self.assertEqual(fake_pipeline.uuid, resp['result'].uuid)
     self.assertEqual(fake_pipeline.user_id, resp['result'].user_id)
     hand_get.assert_called_with('test_id')
     self.assertEqual(200, resp_mock.status)
コード例 #12
0
ファイル: test_pipeline.py プロジェクト: gokulchandrap/solum
 def test_pipelines_post_no_plan(self, PipelineHandler, resp_mock,
                                 request_mock):
     json_create = {'name': 'foo'}
     request_mock.body = json.dumps(json_create)
     request_mock.content_type = 'application/json'
     hand_create = PipelineHandler.return_value.create
     hand_create.return_value = fakes.FakePipeline()
     pipeline.PipelinesController().post()
     ret_val = pipeline.PipelinesController().post()
     faultstring = str(ret_val['faultstring'])
     self.assertIn('The plan was not given or could not be found',
                   faultstring)
     self.assertEqual(400, resp_mock.status)
コード例 #13
0
ファイル: test_pipeline.py プロジェクト: gokulchandrap/solum
 def test_pipelines_get_all(self, PipelineHandler, resp_mock, request_mock):
     hand_get = PipelineHandler.return_value.get_all
     fake_pipeline = fakes.FakePipeline()
     hand_get.return_value = [fake_pipeline]
     resp = pipeline.PipelinesController().get_all()
     self.assertEqual(fake_pipeline.name, resp['result'][0].name)
     self.assertEqual(fake_pipeline.project_id,
                      resp['result'][0].project_id)
     self.assertEqual(fake_pipeline.uuid, resp['result'][0].uuid)
     self.assertEqual(fake_pipeline.user_id, resp['result'][0].user_id)
     hand_get.assert_called_with()
     self.assertEqual(200, resp_mock.status)
     self.assertIsNotNone(resp)
コード例 #14
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)
コード例 #15
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)
コード例 #16
0
ファイル: test_pipeline.py プロジェクト: paulczar/solum
    def test_pipelines_post(self, mock_Plan, PipelineHandler,
                            resp_mock, request_mock):
        json_create = {'name': 'foo',
                       'plan_uri': 'http://test_url:8080/test/911'}
        request_mock.body = json.dumps(json_create)
        request_mock.content_type = 'application/json'
        request_mock.security_context = None
        mock_Plan.get_by_uuid.return_value = fakes.FakePlan()

        hand_create = PipelineHandler.return_value.create
        hand_create.return_value = fakes.FakePipeline()
        pipeline.PipelinesController().post()
        hand_create.assert_called_with({'name': 'foo',
                                        'plan_id': 8})
        mock_Plan.get_by_uuid.assert_called_with(None, '911')
        self.assertEqual(201, resp_mock.status)
コード例 #17
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'])
コード例 #18
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'])
コード例 #19
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()