def test_is_attr_set(self): data = attributes.ATTR_NOT_SPECIFIED self.assertFalse(attributes.is_attr_set(data)) data = None self.assertFalse(attributes.is_attr_set(data)) data = "I'm set" self.assertTrue(attributes.is_attr_set(data))
def create_mead(self, context, mead): mead_data = mead['mead'] template = mead_data['attributes'].get('mead') if isinstance(template, dict): # TODO(sripriya) remove this yaml dump once db supports storing # json format of yaml files in a separate column instead of # key value string pairs in mea attributes table mead_data['attributes']['mead'] = yaml.safe_dump(template) elif isinstance(template, str): self._report_deprecated_yaml_str() if "tosca_definitions_version" not in template: raise exceptions.Invalid('Not a valid template: ' 'tosca_definitions_version is missing.') LOG.debug('mead %s', mead_data) service_types = mead_data.get('service_types') if not attributes.is_attr_set(service_types): LOG.debug('service type must be specified') raise mem.ServiceTypesNotSpecified() for service_type in service_types: # TODO(yamahata): # framework doesn't know what services are valid for now. # so doesn't check it here yet. pass if 'template_source' in mead_data: template_source = mead_data.get('template_source') else: template_source = 'onboarded' mead['mead']['template_source'] = template_source self._parse_template_input(mead) return super(MEMPlugin, self).create_mead(context, mead)
def create_mead(self, context, mead): mead = mead['mead'] LOG.debug('mead %s', mead) tenant_id = self._get_tenant_id_for_create(context, mead) service_types = mead.get('service_types') mgmt_driver = mead.get('mgmt_driver') template_source = mead.get("template_source") if (not attributes.is_attr_set(service_types)): LOG.debug('service types unspecified') raise mem.ServiceTypesNotSpecified() try: with context.session.begin(subtransactions=True): mead_id = uuidutils.generate_uuid() mead_db = MEAD(id=mead_id, tenant_id=tenant_id, name=mead.get('name'), description=mead.get('description'), mgmt_driver=mgmt_driver, template_source=template_source, deleted_at=datetime.min) context.session.add(mead_db) for (key, value) in mead.get('attributes', {}).items(): attribute_db = MEADAttribute(id=uuidutils.generate_uuid(), mead_id=mead_id, key=key, value=value) context.session.add(attribute_db) for service_type in (item['service_type'] for item in mead['service_types']): service_type_db = ServiceType(id=uuidutils.generate_uuid(), tenant_id=tenant_id, mead_id=mead_id, service_type=service_type) context.session.add(service_type_db) except DBDuplicateEntry as e: raise exceptions.DuplicateEntity(_type="mead", entry=e.columns) LOG.debug('mead_db %(mead_db)s %(attributes)s ', { 'mead_db': mead_db, 'attributes': mead_db.attributes }) mead_dict = self._make_mead_dict(mead_db) LOG.debug('mead_dict %s', mead_dict) self._cos_db_plg.create_event( context, res_id=mead_dict['id'], res_type=constants.RES_TYPE_MEAD, res_state=constants.RES_EVT_ONBOARDED, evt_type=constants.RES_EVT_CREATE, tstamp=mead_dict[constants.RES_EVT_CREATED_FLD]) return mead_dict