def test_ok1(self): dir = FileFixtures('dtrs').path('ok1') registry = DeployableTypeRegistry(dir) registry.load() self.assertEqual(2, len(registry.dt)) dt = registry.get('common_doc') self.assertOneDt(dt, doc_content='common document') dt = registry.get('implicit_doc') self.assertOneDt(dt, doc_content='implicit document')
class DeployableTypeRegistryService(ServiceProcess): """Deployable Type Registry service interface """ declare = ServiceProcess.service_declare(name='dtrs', version='0.1.0', dependencies=[]) def slc_init(self): registry = self.spawn_args.get('registry') registry_dir = self.spawn_args.get('registry_dir') if registry is None and registry_dir is None: raise ValueError("DTRS needs either 'registry' or 'registry_dir' in spawnargs") if registry is not None: self.registry = registry else: log.info('DTRS configured to use directory %s' % registry_dir) self.registry = DeployableTypeRegistry(registry_dir) self.registry.load() def op_lookup(self, content, headers, msg): """Resolve a deployable type """ # hide the password so it doesn't get logged hide_password = deepcopy(content) if hide_password.get('vars') and 'cassandra_password' in hide_password['vars']: hide_password['vars']['cassandra_password'] = '******' if hide_password.get('vars') and 'broker_password' in hide_password['vars']: hide_password['vars']['broker_password'] = '******' log.debug('Received DTRS lookup. content: %s', hide_password) # just using a file for this right now, to keep it simple dt_id = content['deployable_type'] nodes = content.get('nodes') vars = content.get('vars') dt = self.registry.get(dt_id) if not dt: return self._dtrs_error(msg, 'Unknown deployable type name: '+ dt_id) doc_tpl = dt['document'] defaults = dt.get('vars') all_vars = {} if defaults: all_vars.update(defaults) if vars: try: process_vars(vars, dt_id) except DeployableTypeValidationError, e: return self._dtrs_error(msg, str(e)) all_vars.update(vars) template = string.Template(doc_tpl) try: document = template.substitute(all_vars) except KeyError,e: return self._dtrs_error(msg, 'DT doc has variable not present in request or defaults: %s' % str(e))