def test_create_invalid_step_no_interface(self): uuid = uuidutils.generate_uuid() template = db_utils.get_test_deploy_template(uuid=uuid, name='CUSTOM_DT2') del template['steps'][0]['interface'] self.assertRaises(db_exc.DBError, self.dbapi.create_deploy_template, template)
def test_create_invalid_step_no_interface(self): uuid = uuidutils.generate_uuid() template = db_utils.get_test_deploy_template(uuid=uuid, name='CUSTOM_DT2') del template['steps'][0]['interface'] self.assertRaises(db_exc.DBError, self.dbapi.create_deploy_template, template)
def deploy_template_post_data(**kw): """Return a DeployTemplate object without internal attributes.""" template = db_utils.get_test_deploy_template(**kw) # These values are not part of the API object template.pop('version') # Remove internal attributes from each step. step_internal = api_utils.DEPLOY_STEP_SCHEMA['properties'] template['steps'] = [ remove_other_fields(step, step_internal) for step in template['steps'] ] # Remove internal attributes from the template. return remove_other_fields(template, dt_controller.TEMPLATE_SCHEMA['properties'])
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)
def deploy_template_post_data(**kw): """Return a DeployTemplate object without internal attributes.""" template = db_utils.get_test_deploy_template(**kw) # These values are not part of the API object template.pop('version') # Remove internal attributes from each step. step_internal = types.JsonPatchType.internal_attrs() step_internal.append('deploy_template_id') template['steps'] = [remove_internal(step, step_internal) for step in template['steps']] # Remove internal attributes from the template. dt_patch = dt_controller.DeployTemplatePatchType internal = dt_patch.internal_attrs() return remove_internal(template, internal)
def deploy_template_post_data(**kw): """Return a DeployTemplate object without internal attributes.""" template = db_utils.get_test_deploy_template(**kw) # These values are not part of the API object template.pop('version') # Remove internal attributes from each step. step_internal = types.JsonPatchType.internal_attrs() step_internal.append('deploy_template_id') template['steps'] = [remove_internal(step, step_internal) for step in template['steps']] # Remove internal attributes from the template. dt_patch = dt_controller.DeployTemplatePatchType internal = dt_patch.internal_attrs() return remove_internal(template, internal)
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)
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
def setUp(self): super(TestDeployTemplateObject, self).setUp() self.ctxt = context.get_admin_context() self.fake_template = db_utils.get_test_deploy_template()