コード例 #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_lp_handler.py プロジェクト: paperandsoap/solum
    def test_languagepack_delete_with_plan_not_using_lp(self,
                                                        mock_app,
                                                        mock_planlist,
                                                        mock_log_handler,
                                                        mock_swift_delete,
                                                        mock_img):
        cfg.CONF.worker.image_storage = "swift"
        fi = fakes.FakeImage()
        mock_img.get_lp_by_name_or_uuid.return_value = fi
        mock_img.destroy.return_value = {}
        mock_planlist.get_all.return_value = [fakes.FakePlan()]

        mock_app.get_all_by_lp.return_value = {}
        handler = language_pack_handler.LanguagePackHandler(self.ctx)
        handler.delete('lp_name')

        mock_img.get_lp_by_name_or_uuid.assert_called_once_with(
            self.ctx, 'lp_name')
        docker_image_name = fi.docker_image_name
        img_filename = docker_image_name.split('-', 1)[1]
        mock_swift_delete.assert_called_once_with('solum_lp', img_filename)
        self.assertTrue(mock_planlist.get_all.called)
        log_handler = mock_log_handler.return_value
        log_handler.delete.assert_called_once_with(fi.uuid)
        fi.destroy.assert_called_once_with(self.ctx)
コード例 #3
0
ファイル: test_workflow.py プロジェクト: maniacs-ops/solum
    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='')
コード例 #4
0
ファイル: test_plan.py プロジェクト: prayalankar2/solum
 def test_plans_post_nodata(self, handler_mock, resp_mock, request_mock):
     request_mock.body = ''
     request_mock.content_type = 'application/json'
     handler_create = handler_mock.return_value.create
     handler_create.return_value = fakes.FakePlan()
     plan.PlansController().post()
     self.assertEqual(400, resp_mock.status)
コード例 #5
0
ファイル: test_plan.py プロジェクト: prayalankar2/solum
 def test_trigger_workflow_stage_select(self, mock_kc, mock_registry):
     trigger_id = 1
     plan_obj = fakes.FakePlan()
     artifacts = [{
         "name": "Test",
         "artifact_type": "heroku",
         "content": {
             "href": "https://github.com/some/project"
         },
         "language_pack": "auto"
     }]
     plan_obj.raw_content = {"artifacts": artifacts}
     mock_registry.Plan.get_by_trigger_id.return_value = plan_obj
     handler = plan_handler.PlanHandler(self.ctx)
     handler._build_artifact = mock.MagicMock()
     handler.trigger_workflow(trigger_id, workflow=['unittest'])
     handler._build_artifact.assert_called_once_with(
         plan_obj,
         artifact=artifacts[0],
         commit_sha='',
         status_url=None,
         workflow=['unittest'],
     )
     mock_registry.Plan.get_by_trigger_id.assert_called_once_with(
         None, trigger_id)
コード例 #6
0
 def test_trigger_workflow(self, mock_registry):
     trigger_id = 1
     artifacts = [{
         "name": "Test",
         "artifact_type": "heroku",
         "content": {
             "href": "https://github.com/some/project"
         },
         "language_pack": "auto"
     }]
     db_obj = fakes.FakeAssembly()
     mock_registry.Assembly.get_by_trigger_id.return_value = db_obj
     plan_obj = fakes.FakePlan()
     mock_registry.Plan.get_by_id.return_value = plan_obj
     plan_obj.raw_content = {"artifacts": artifacts}
     handler = assembly_handler.AssemblyHandler(self.ctx)
     handler._build_artifact = mock.MagicMock()
     handler._context_from_trust_id = mock.MagicMock(return_value=self.ctx)
     handler.trigger_workflow(trigger_id)
     handler._build_artifact.assert_called_once_with(db_obj, artifacts[0])
     handler._context_from_trust_id.assert_called_once_with('trust_worthy')
     mock_registry.Assembly.get_by_trigger_id.assert_called_once_with(
         None, trigger_id)
     mock_registry.Plan.get_by_id.assert_called_once_with(
         self.ctx, db_obj.plan_id)
コード例 #7
0
ファイル: test_plan.py プロジェクト: prayalankar2/solum
 def test_plan_put_empty_yaml(self, PlanHandler, resp_mock, request_mock):
     request_mock.content_type = 'application/x-yaml'
     request_mock.body = '{}'
     hand_update = PlanHandler.return_value.update
     hand_update.return_value = fakes.FakePlan()
     plan.PlanController('test_id').put()
     self.assertEqual(400, resp_mock.status)
コード例 #8
0
ファイル: test_plan.py プロジェクト: prayalankar2/solum
 def test_plans_post_invalid_yaml(self, handler_mock, resp_mock,
                                  request_mock):
     request_mock.body = 'invalid yaml file'
     request_mock.content_type = 'application/x-yaml'
     handler_create = handler_mock.return_value.create
     handler_create.return_value = fakes.FakePlan()
     plan.PlansController().post()
     self.assertEqual(400, resp_mock.status)
コード例 #9
0
ファイル: test_plan.py プロジェクト: prayalankar2/solum
 def test_plan_delete(self, mock_kc, mock_destroy, mock_registry):
     db_obj = fakes.FakePlan()
     mock_registry.Plan.get_by_uuid.return_value = db_obj
     handler = plan_handler.PlanHandler(self.ctx)
     handler.delete('test_id')
     mock_destroy.assert_called_once_with(app_id=db_obj.id)
     mock_registry.Plan.get_by_uuid.assert_called_once_with(
         self.ctx, 'test_id')
コード例 #10
0
ファイル: test_plan.py プロジェクト: prayalankar2/solum
 def test_plans_post_version_not_found_yaml(self, PlanHandler, resp_mock,
                                            request_mock):
     request_mock.body = 'name: ex_plan1\ndescription: dsc1.'
     request_mock.content_type = 'application/x-yaml'
     hand_create = PlanHandler.return_value.create
     hand_create.return_value = fakes.FakePlan()
     plan.PlansController().post()
     self.assertEqual(400, resp_mock.status)
コード例 #11
0
ファイル: test_plan.py プロジェクト: julienvey/solum
 def test_plan_delete(self, mock_registry):
     db_obj = fakes.FakePlan()
     mock_registry.Plan.get_by_uuid.return_value = db_obj
     handler = plan_handler.PlanHandler()
     handler.delete('test_id')
     db_obj.destroy.assert_called_once_with(None)
     mock_registry.Plan.get_by_uuid.assert_called_once_with(None,
                                                            'test_id')
コード例 #12
0
ファイル: test_plan.py プロジェクト: prayalankar2/solum
 def test_plan_create(self, mock_kc, mock_registry):
     data = {'name': 'new_name', 'uuid': 'input_uuid'}
     db_obj = fakes.FakePlan()
     mock_registry.Plan.return_value = db_obj
     handler = plan_handler.PlanHandler(self.ctx)
     res = handler.create(data)
     db_obj.create.assert_called_once_with(self.ctx)
     self.assertEqual(db_obj, res)
コード例 #13
0
    def test_assemblies_post_ref_rel_uris(self, PlanHandler, AssemblyHandler,
                                          resp_mock, request_mock):
        hand_get = PlanHandler.return_value.get
        hand_get.return_value = fakes.FakePlan()

        hand_create_from_plan = AssemblyHandler.return_value.create_from_plan
        fake_assembly = fakes.FakeAssembly()
        hand_create_from_plan.return_value = fake_assembly

        cntrl = assemblies.AssembliesController()

        # test reference to CAMP plan relative to assemblies
        ref_object = {'plan_uri':
                      '../plans/24e3974c-195d-4a6a-96b0-7924ed3c742a'}
        request_mock.content_type = 'application/json'
        request_mock.body = json.dumps(ref_object)

        resp = cntrl.post()
        self.assertIsNotNone(resp)
        self.assertEqual(201, resp_mock.status)
        self.assertIsNotNone(resp_mock.location)
        self.assertEqual(fake_assembly.name, resp['name'])

        # test reference to Solum plan relative to assemblies
        ref_object = {'plan_uri':
                      '../../../v1/plans/24e3974c-195d-4a6a-96b0-7924ed3c742a'}
        request_mock.content_type = 'application/json'
        request_mock.body = json.dumps(ref_object)

        resp = cntrl.post()
        self.assertIsNotNone(resp)
        self.assertEqual(201, resp_mock.status)
        self.assertIsNotNone(resp_mock.location)
        self.assertEqual(fake_assembly.name, resp['name'])

        # test reference to CAMP plan relative to root
        ref_object = {'plan_uri':
                      '/camp/v1_1/plans/24e3974c-195d-4a6a-96b0-7924ed3c742a'}
        request_mock.content_type = 'application/json'
        request_mock.body = json.dumps(ref_object)

        resp = cntrl.post()
        self.assertIsNotNone(resp)
        self.assertEqual(201, resp_mock.status)
        self.assertIsNotNone(resp_mock.location)
        self.assertEqual(fake_assembly.name, resp['name'])

        # test reference to Solum plan relative to root
        ref_object = {'plan_uri':
                      '/v1/plans/24e3974c-195d-4a6a-96b0-7924ed3c742a'}
        request_mock.content_type = 'application/json'
        request_mock.body = json.dumps(ref_object)

        resp = cntrl.post()
        self.assertIsNotNone(resp)
        self.assertEqual(201, resp_mock.status)
        self.assertIsNotNone(resp_mock.location)
        self.assertEqual(fake_assembly.name, resp['name'])
コード例 #14
0
ファイル: test_plan.py プロジェクト: prayalankar2/solum
 def test_plan_put_version_not_found_json(self, PlanHandler, resp_mock,
                                          request_mock):
     data = {'name': 'foo'}
     request_mock.body = json.dumps(data)
     request_mock.content_type = 'application/json'
     hand_update = PlanHandler.return_value.update
     hand_update.return_value = fakes.FakePlan()
     plan.PlanController('test_id').put()
     self.assertEqual(400, resp_mock.status)
コード例 #15
0
 def test_plans_post_yaml(self, PlanHandler, resp_mock, request_mock):
     request_mock.body = 'version: 1\nname: ex_plan1\ndescription: dsc1.'
     request_mock.content_type = 'application/x-yaml'
     hand_create = PlanHandler.return_value.create
     hand_create.return_value = fakes.FakePlan()
     plan.PlansController().post()
     hand_create.assert_called_with({'name': 'ex_plan1',
                                     'description': 'dsc1.'})
     self.assertEqual(201, resp_mock.status)
コード例 #16
0
 def test_plan_put_invalid_yaml(self, PlanHandler, resp_mock, request_mock,
                                mock_policy):
     mock_policy.return_value = True
     request_mock.content_type = 'application/x-yaml'
     request_mock.body = 'invalid yaml file'
     hand_update = PlanHandler.return_value.update
     hand_update.return_value = fakes.FakePlan()
     plan.PlanController('test_id').put()
     self.assertEqual(400, resp_mock.status)
コード例 #17
0
ファイル: test_plan.py プロジェクト: prayalankar2/solum
 def test_plans_post_version_not_found_json(self, PlanHandler, resp_mock,
                                            request_mock):
     json_update = {'name': 'foo'}
     request_mock.body = json.dumps(json_update)
     request_mock.content_type = 'application/json'
     hand_create = PlanHandler.return_value.create
     hand_create.return_value = fakes.FakePlan()
     plan.PlansController().post()
     self.assertEqual(400, resp_mock.status)
コード例 #18
0
ファイル: test_plan.py プロジェクト: prayalankar2/solum
 def test_plan_put_version_not_found_yaml(self, PlanHandler, resp_mock,
                                          request_mock):
     data = 'name: ex_plan1\ndescription: yaml plan1.'
     request_mock.body = data
     request_mock.content_type = 'application/x-yaml'
     hand_update = PlanHandler.return_value.update
     hand_update.return_value = fakes.FakePlan()
     plan.PlanController('test_id').put()
     self.assertEqual(400, resp_mock.status)
コード例 #19
0
 def test_plans_post_empty_yaml(self, handler_mock, resp_mock, request_mock,
                                mock_policy):
     mock_policy.return_value = True
     request_mock.body = '{}'
     request_mock.content_type = 'application/x-yaml'
     handler_create = handler_mock.return_value.create
     handler_create.return_value = fakes.FakePlan()
     plan.PlansController().post()
     self.assertEqual(400, resp_mock.status)
コード例 #20
0
 def test_plan_put_ok_yaml(self, PlanHandler, resp_mock, request_mock):
     data = 'version: 1\nname: ex_plan1\ndescription: dsc1.'
     request_mock.body = data
     request_mock.content_type = 'application/x-yaml'
     hand_update = PlanHandler.return_value.update
     hand_update.return_value = fakes.FakePlan()
     plan.PlanController('test_id').put()
     hand_update.assert_called_with('test_id', {'name': 'ex_plan1',
                                                'description': u'dsc1.'})
     self.assertEqual(200, resp_mock.status)
コード例 #21
0
ファイル: test_plan.py プロジェクト: julienvey/solum
 def test_plan_update(self, mock_registry):
     data = {'user_id': 'new_user_id'}
     db_obj = fakes.FakePlan()
     mock_registry.Plan.get_by_uuid.return_value = db_obj
     handler = plan_handler.PlanHandler()
     res = handler.update('test_id', data)
     self.assertEqual(db_obj.user_id, res.user_id)
     db_obj.save.assert_called_once_with(None)
     mock_registry.Plan.get_by_uuid.assert_called_once_with(None,
                                                            'test_id')
コード例 #22
0
ファイル: test_plan.py プロジェクト: prayalankar2/solum
 def test_plans_get_all_json(self, PlanHandler, resp_mock, request_mock):
     hand_get = PlanHandler.return_value.get_all
     fake_plan = fakes.FakePlan()
     hand_get.return_value = [fake_plan]
     resp = plan.PlansController().get_all()
     self.assertIsNotNone(resp)
     resp_json = json.loads(resp)
     self.assertEqual(fake_plan.raw_content['name'], resp_json[0]['name'])
     self.assertEqual(200, resp_mock.status)
     hand_get.assert_called_with()
コード例 #23
0
 def test_plan_get(self, PlanHandler, resp_mock, request_mock):
     hand_get = PlanHandler.return_value.get
     fake_plan = fakes.FakePlan()
     hand_get.return_value = fake_plan
     cont = plan.PlanController('test_id')
     resp = cont.get()
     self.assertIsNotNone(resp)
     resp_yml = yaml.load(resp)
     self.assertEqual(fake_plan.raw_content['name'], resp_yml['name'])
     hand_get.assert_called_with('test_id')
     self.assertEqual(200, resp_mock.status)
コード例 #24
0
 def test_plan_put_ok_json(self, PlanHandler, resp_mock, request_mock,
                           mock_policy):
     mock_policy.return_value = True
     data = {'name': 'foo', 'version': '1'}
     request_mock.body = json.dumps(data)
     request_mock.content_type = 'application/json'
     hand_update = PlanHandler.return_value.update
     hand_update.return_value = fakes.FakePlan()
     plan.PlanController('test_id').put()
     hand_update.assert_called_with('test_id', {'name': 'foo'})
     self.assertEqual(200, resp_mock.status)
コード例 #25
0
 def test_plans_post_json(self, PlanHandler, resp_mock, request_mock,
                          mock_policy):
     mock_policy.return_value = True
     json_update = {'name': 'foo', 'version': '1'}
     request_mock.body = json.dumps(json_update)
     request_mock.content_type = 'application/json'
     hand_create = PlanHandler.return_value.create
     hand_create.return_value = fakes.FakePlan()
     plan.PlansController().post()
     hand_create.assert_called_with({'name': 'foo'})
     self.assertEqual(201, resp_mock.status)
コード例 #26
0
ファイル: test_plan.py プロジェクト: prayalankar2/solum
 def test_plans_get_all_yaml(self, PlanHandler, resp_mock, request_mock):
     hand_get = PlanHandler.return_value.get_all
     request_mock.accept = 'application/x-yaml'
     fake_plan = fakes.FakePlan()
     hand_get.return_value = [fake_plan]
     resp = plan.PlansController().get_all()
     self.assertIsNotNone(resp)
     resp_yml = yaml.load(resp)
     self.assertEqual(fake_plan.raw_content['name'], resp_yml[0]['name'])
     self.assertEqual(200, resp_mock.status)
     hand_get.assert_called_with()
コード例 #27
0
ファイル: test_plan.py プロジェクト: prayalankar2/solum
    def test_plan_delete_dberror(self, PlanHandler, resp_mock, request_mock):
        hand_get = PlanHandler.return_value.get
        fake_plan = fakes.FakePlan()
        hand_get.return_value = fake_plan

        hand_delete = PlanHandler.return_value.delete
        hand_delete.side_effect = db_exc.DBError()
        obj = plan.PlanController('test_id')
        obj.delete()
        hand_delete.assert_called_with('test_id')
        self.assertEqual(409, resp_mock.status)
コード例 #28
0
ファイル: test_assembly.py プロジェクト: gokulchandrap/solum
    def test_create_with_private_github_repo(self, mock_kc, mock_pa,
                                             mock_registry):
        data = {
            'user_id': 'new_user_id',
            'uuid': 'input_uuid',
            'plan_uuid': 'input_plan_uuid'
        }

        db_obj = fakes.FakeAssembly()
        mock_registry.Assembly.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': 'heroku',
                'content': {
                    'private': True,
                    'href': 'https://example.com/ex.git',
                    'public_key': 'ssh-rsa abc'
                },
                'language_pack': 'auto'
            }]
        }
        fp.deploy_keys_uri = 'secret_ref_uri'
        mock_registry.Image.return_value = fakes.FakeImage()

        handler = assembly_handler.AssemblyHandler(self.ctx)
        res = handler.create(data)
        db_obj.update.assert_called_once_with(data)
        db_obj.create.assert_called_once_with(self.ctx)
        self.assertEqual(db_obj, res)
        git_info = {
            'source_url': "https://example.com/ex.git",
            'commit_sha': '',
            'repo_token': None,
            'status_url': None,
        }
        mock_pa.assert_called_once_with(
            verb='launch_workflow',
            workflow=['unittest', 'build', 'deploy'],
            build_id=8,
            name='nodeus',
            assembly_id=8,
            git_info=git_info,
            ports=[80],
            test_cmd=None,
            base_image_id='auto',
            source_format='heroku',
            image_format='qcow2',
            run_cmd=None)
コード例 #29
0
ファイル: test_plans.py プロジェクト: gokulchandrap/solum
    def test_plans_get(self, PlanHandler, resp_mock, request_mock):
        hand_get_all = PlanHandler.return_value.get_all
        fake_plan = fakes.FakePlan()
        hand_get_all.return_value = [fake_plan]

        resp = plans.PlansController().get()
        self.assertIsNotNone(resp)
        self.assertEqual(200, resp_mock.status)
        self.assertIsNotNone(resp['result'].plan_links)
        plan_links = resp['result'].plan_links
        self.assertEqual(1, len(plan_links))
        self.assertEqual(fake_plan.name, plan_links[0].target_name)
コード例 #30
0
ファイル: test_plan.py プロジェクト: prayalankar2/solum
    def test_plan_put_bad_names(self, PlanHandler, resp_mock, request_mock):
        request_mock.content_type = 'application/x-yaml'
        hand_update = PlanHandler.return_value.update
        hand_update.return_value = fakes.FakePlan()
        pc = plan.PlanController('test_id')
        request_mock.body = 'version: 1\nname: %s' % ('a' * 101)
        pc.put()
        self.assertEqual(400, resp_mock.status)

        request_mock.body = 'version: 1\nname: %s' % ('name with spaces')
        pc.put()
        self.assertEqual(400, resp_mock.status)