Ejemplo n.º 1
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)
Ejemplo n.º 2
0
 def get_all(self):
     """Return all assemblies, based on the query provided."""
     request.check_request_for_https()
     handler = assembly_handler.AssemblyHandler(
         pecan.request.security_context)
     return [assembly.Assembly.from_db_model(assm, pecan.request.host_url)
             for assm in handler.get_all()]
Ejemplo n.º 3
0
    def post(self, data):
        """Create a new assembly."""
        policy.check('create_assembly', pecan.request.security_context)
        host_url = pecan.request.application_url.rstrip('/')
        js_data = data.as_dict(objects.registry.Assembly)
        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 = assembly_handler.AssemblyHandler(
            pecan.request.security_context)
        return assembly.Assembly.from_db_model(handler.create(js_data),
                                               host_url)
Ejemplo n.º 4
0
 def get(self):
     """Return this assembly."""
     request.check_request_for_https()
     handler = assembly_handler.AssemblyHandler(
         pecan.request.security_context)
     return assembly.Assembly.from_db_model(handler.get(self._id),
                                            pecan.request.host_url)
Ejemplo n.º 5
0
 def test_assembly_get(self, mock_registry):
     mock_registry.Assembly.get_by_uuid.return_value = {}
     handler = assembly_handler.AssemblyHandler()
     res = handler.get('test_id')
     self.assertIsNotNone(res)
     mock_registry.Assembly.get_by_uuid.\
         assert_called_once_with(None, 'test_id')
Ejemplo n.º 6
0
 def put(self, data):
     """Modify this assembly."""
     handler = assembly_handler.AssemblyHandler(
         pecan.request.security_context)
     res = handler.update(self._id,
                          data.as_dict(objects.registry.Assembly))
     return assembly.Assembly.from_db_model(res, pecan.request.host_url)
Ejemplo n.º 7
0
 def test_update(self, mock_registry):
     data = {'user_id': 'new_user_id',
             'plan_uuid': 'input_plan_uuid'}
     handler = assembly_handler.AssemblyHandler(self.ctx)
     handler.update('test_id', data)
     mock_registry.Assembly.update_and_save.assert_called_once_with(
         self.ctx, 'test_id', data)
Ejemplo n.º 8
0
 def test_delete(self, mock_registry):
     db_obj = fakes.FakeAssembly()
     mock_registry.Assembly.get_by_uuid.return_value = db_obj
     handler = assembly_handler.AssemblyHandler()
     handler.delete('test_id')
     db_obj.destroy.assert_called_once_with(None)
     mock_registry.Assembly.get_by_uuid.assert_called_once_with(
         None, 'test_id')
Ejemplo n.º 9
0
 def put(self, data):
     """Modify this assembly."""
     policy.check('update_assembly', pecan.request.security_context)
     handler = assembly_handler.AssemblyHandler(
         pecan.request.security_context)
     res = handler.update(self._id, data.as_dict(objects.registry.Assembly))
     host_url = pecan.request.application_url.rstrip('/')
     return assembly.Assembly.from_db_model(res, host_url)
Ejemplo n.º 10
0
 def get(self):
     """Return this assembly."""
     policy.check('show_assembly', pecan.request.security_context)
     request.check_request_for_https()
     handler = assembly_handler.AssemblyHandler(
         pecan.request.security_context)
     host_url = pecan.request.application_url.rstrip('/')
     return assembly.Assembly.from_db_model(handler.get(self._id), host_url)
Ejemplo n.º 11
0
 def test_delete(self, mock_cond, mock_deploy, mock_kc, mock_registry):
     db_obj = fakes.FakeAssembly()
     mock_registry.Assembly.get_by_uuid.return_value = db_obj
     handler = assembly_handler.AssemblyHandler(self.ctx)
     handler.delete('test_id')
     mock_registry.Assembly.get_by_uuid.assert_called_once_with(self.ctx,
                                                                'test_id')
     mock_cond.assert_called_once_with(db_obj.id, {'status': 'DELETING'})
     mock_deploy.assert_called_once_with(assem_id=db_obj.id)
Ejemplo n.º 12
0
 def test_assembly_get(self, mock_registry):
     mock_registry.return_value.Assembly.get_by_uuid.return_value = {
         'plan_id': '1234'
     }
     handler = assembly_handler.AssemblyHandler(self.ctx)
     res = handler.get('test_id')
     self.assertIsNotNone(res)
     get_by_uuid = mock_registry.Assembly.get_by_uuid
     get_by_uuid.assert_called_once_with(self.ctx, 'test_id')
Ejemplo n.º 13
0
 def test_update(self, mock_registry):
     data = {'user_id': 'new_user_id'}
     db_obj = fakes.FakeAssembly()
     mock_registry.Assembly.get_by_uuid.return_value = db_obj
     handler = assembly_handler.AssemblyHandler()
     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.Assembly.get_by_uuid.assert_called_once_with(
         None, 'test_id')
Ejemplo n.º 14
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
Ejemplo n.º 15
0
 def get_all(self):
     """Return all assemblies, based on the query provided."""
     policy.check('get_assemblies', pecan.request.security_context)
     request.check_request_for_https()
     handler = assembly_handler.AssemblyHandler(
         pecan.request.security_context)
     host_url = pecan.request.application_url.rstrip('/')
     return [
         assembly.Assembly.from_db_model(assm, host_url)
         for assm in handler.get_all()
     ]
Ejemplo n.º 16
0
 def test_delete(self, mock_deploy, mock_kc, mock_registry):
     db_obj = fakes.FakeAssembly()
     mock_registry.Assembly.get_by_uuid.return_value = db_obj
     handler = assembly_handler.AssemblyHandler(self.ctx)
     handler.delete('test_id')
     db_obj.save.assert_called_once_with(self.ctx)
     mock_registry.Assembly.get_by_uuid.assert_called_once_with(
         self.ctx, 'test_id')
     mock_kc.return_value.delete_trust.assert_called_once_with(
         'trust_worthy')
     mock_deploy.assert_called_once_with(assem_id=db_obj.id)
     self.assertEqual(STATES.DELETING, db_obj.status)
Ejemplo n.º 17
0
    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)
Ejemplo n.º 18
0
    def test_create_with_username_in_ctx(self, mock_kc, mock_registry):
        data = {'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'}

        handler = assembly_handler.AssemblyHandler(self.ctx)
        res = handler.create(data)

        self.assertEqual(res.username, self.ctx.user_name)
Ejemplo n.º 19
0
    def _build_artifact(self, plan, artifact, verb='build', commit_sha='',
                        status_url=None, workflow=None):

        if workflow is None:
            workflow = ['unittest', 'build', 'deploy']
        ahand = assembly_handler.AssemblyHandler(self.context)
        plandata = {
            'plan_id': plan.id,
            'name': "%s-%s" % (plan.name, artifact['name']),
            'description': '',
            'workflow': workflow,
            }
        ahand.create(plandata, commit_sha=commit_sha, status_url=status_url)
Ejemplo n.º 20
0
    def test_create(self, mock_kc, mock_build, 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': {
                    'href': 'https://example.com/ex.git'
                },
                'language_pack': 'auto'
            }]
        }
        mock_registry.Image.return_value = fakes.FakeImage()
        trust_ctx = utils.dummy_context()
        trust_ctx.trust_id = '12345'
        mock_kc.return_value.create_trust_context.return_value = trust_ctx

        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)
        mock_build.assert_called_once_with(
            build_id=8,
            name='nodeus',
            assembly_id=8,
            source_uri='https://example.com/ex.git',
            test_cmd=None,
            base_image_id='auto',
            source_format='heroku',
            image_format='qcow2')
        mock_kc.return_value.create_trust_context.assert_called_once_with()
Ejemplo n.º 21
0
 def test_create(self, mock_registry):
     data = {'user_id': 'new_user_id'}
     handler = assembly_handler.AssemblyHandler()
     res = handler.create(data)
     self.assertEqual('new_user_id', res.user_id)
Ejemplo n.º 22
0
 def test_assembly_get_all(self, mock_registry):
     mock_registry.AssemblyList.get_all.return_value = {}
     handler = assembly_handler.AssemblyHandler(self.ctx)
     res = handler.get_all()
     self.assertIsNotNone(res)
     mock_registry.AssemblyList.get_all.assert_called_once_with(self.ctx)
Ejemplo n.º 23
0
 def get_all(self):
     """Return all assemblies, based on the query provided."""
     handler = assembly_handler.AssemblyHandler()
     return handler.get_all()
Ejemplo n.º 24
0
 def test_assembly_get_all(self):
     handler = assembly.AssemblyHandler()
     res = handler.get_all()
     self.assertIsNotNone(res)
Ejemplo n.º 25
0
 def delete(self):
     """Delete this assembly."""
     policy.check('delete_assembly', pecan.request.security_context)
     handler = assembly_handler.AssemblyHandler(
         pecan.request.security_context)
     return handler.delete(self._id)
Ejemplo n.º 26
0
 def __init__(self, assembly_id):
     super(AssemblyController, self).__init__()
     self._id = assembly_id
     self._handler = assembly_handler.AssemblyHandler()
Ejemplo n.º 27
0
 def post(self, data):
     """Create a new assembly."""
     handler = assembly_handler.AssemblyHandler()
     return handler.create(data)
Ejemplo n.º 28
0
 def __init__(self):
     super(AssembliesController, self).__init__()
     self._handler = assembly_handler.AssemblyHandler()
Ejemplo n.º 29
0
 def delete(self):
     """Delete this assembly."""
     handler = assembly_handler.AssemblyHandler(
         pecan.request.security_context)
     return handler.delete(self._id)
Ejemplo n.º 30
0
 def delete(self):
     """Delete this assembly."""
     handler = assembly_handler.AssemblyHandler()
     return handler.delete(self._id)