예제 #1
0
    def test_destroy(self, mock_destroy):
        template = objects.DeployTemplate(context=self.context,
                                          id=self.fake_template['id'])

        template.destroy()

        mock_destroy.assert_called_once_with(self.fake_template['id'])
예제 #2
0
    def test_create(self, mock_create):
        template = objects.DeployTemplate(context=self.context,
                                          **self.fake_template)

        mock_create.return_value = db_utils.get_test_deploy_template()

        template.create()

        args, _kwargs = mock_create.call_args
        self.assertEqual(1, mock_create.call_count)

        self.assertEqual(self.fake_template['name'], template.name)
        self.assertEqual(self.fake_template['steps'], template.steps)
        self.assertEqual(self.fake_template['extra'], template.extra)
예제 #3
0
    def test_save(self, mock_update):
        template = objects.DeployTemplate(context=self.context,
                                          **self.fake_template)
        template.obj_reset_changes()

        mock_update.return_value = db_utils.get_test_deploy_template(
            name='CUSTOM_DT2')

        template.name = 'CUSTOM_DT2'
        template.save()

        mock_update.assert_called_once_with(
            self.fake_template['uuid'],
            {'name': 'CUSTOM_DT2', 'version': objects.DeployTemplate.VERSION})

        self.assertEqual('CUSTOM_DT2', template.name)
예제 #4
0
def get_test_deploy_template(ctxt, **kw):
    """Return a DeployTemplate object with appropriate attributes.

    NOTE: The object leaves the attributes marked as changed, such
    that a create() could be used to commit it to the DB.
    """
    db_template = db_utils.get_test_deploy_template(**kw)
    # Let DB generate ID if it isn't specified explicitly
    if 'id' not in kw:
        del db_template['id']
    if 'steps' not in kw:
        for step in db_template['steps']:
            del step['id']
            del step['deploy_template_id']
    else:
        for kw_step, template_step in zip(kw['steps'], db_template['steps']):
            if 'id' not in kw_step and 'id' in template_step:
                del template_step['id']
    template = objects.DeployTemplate(ctxt)
    for key in db_template:
        setattr(template, key, db_template[key])
    return template
예제 #5
0
    def post(self, template):
        """Create a new deploy template.

        :param template: a deploy template within the request body.
        """
        api_utils.check_policy('baremetal:deploy_template:create')

        context = api.request.context
        tdict = template.as_dict()
        # NOTE(mgoddard): UUID is mandatory for notifications payload
        if not tdict.get('uuid'):
            tdict['uuid'] = uuidutils.generate_uuid()

        new_template = objects.DeployTemplate(context, **tdict)

        notify.emit_start_notification(context, new_template, 'create')
        with notify.handle_error_notification(context, new_template, 'create'):
            new_template.create()
        # Set the HTTP Location Header
        api.response.location = link.build_url('deploy_templates',
                                               new_template.uuid)
        api_template = DeployTemplate.convert_with_links(new_template)
        notify.emit_end_notification(context, new_template, 'create')
        return api_template