def test_me(self): me = romeo.whoami() self.assertIsInstance(me, romeo.foundation.RomeoKeyValue) env = romeo.getEnvironment(MY_SWEET_ENVIRONMENT) self.assertIsInstance(env, romeo.foundation.RomeoKeyValue) # this next one may be confusing so i'll spell it out # server is related to env and env is related to server self.assertEqual(env.isRelated(me), True) self.assertEqual(me.isRelated(env), True) # server is a child of env and server has ancestor env self.assertEqual(env.isChild(me), True) self.assertEqual(me.isAncestor(env), True) x = list(me.search("NAME"))[0].VALUE self.assertIs(romeo.getEnvironment(x), env) self.assertEqual(x, MY_SWEET_ENVIRONMENT) self.assertListEqual(sorted(me.keys()), ["ARTIFACTS", "HOSTNAME", "SERVER"])
def test_me(self): me = romeo.whoami() self.assertIsInstance(me, romeo.foundation.RomeoKeyValue) env = romeo.getEnvironment(MY_SWEET_ENVIRONMENT) self.assertIsInstance(env, romeo.foundation.RomeoKeyValue) # this next one may be confusing so i'll spell it out # server is related to env and env is related to server self.assertEqual(env.isRelated(me), True) self.assertEqual(me.isRelated(env), True) # server is a child of env and server has ancestor env self.assertEqual(env.isChild(me), True) self.assertEqual(me.isAncestor(env), True) x = list(me.search('NAME'))[0].VALUE self.assertIs(romeo.getEnvironment(x), env) self.assertEqual(x, MY_SWEET_ENVIRONMENT) self.assertListEqual(sorted(me.keys()), ['ARTIFACTS', 'HOSTNAME', 'SERVER'])
def test_hostdb(self): env = romeo.getEnvironment(MY_SWEET_ENVIRONMENT) hostdb = romeo.hostdb.node_constructor(env) self.assertListEqual(sorted(hostdb.keys()), ["ARTIFACTS", "FILENAME", "HOSTNAME", "NAME", "SERVER"]) self.assertEqual(hostdb.get("FILENAME"), self.mysweetconfig) self.assertEqual(hostdb.get("NAME"), MY_SWEET_ENVIRONMENT) envDict = hostdb.copy() self.assertIsInstance(envDict, dict) self.assertIs(romeo.hostdb.whoami(romeo.MYHOSTNAME).entity, romeo.whoami())
def test_hostdb(self): env = romeo.getEnvironment(MY_SWEET_ENVIRONMENT) hostdb = romeo.hostdb.node_constructor(env) self.assertListEqual( sorted(hostdb.keys()), ['ARTIFACTS', 'FILENAME', 'HOSTNAME', 'NAME', 'SERVER']) self.assertEqual(hostdb.get('FILENAME'), self.mysweetconfig) self.assertEqual(hostdb.get('NAME'), MY_SWEET_ENVIRONMENT) envDict = hostdb.copy() self.assertIsInstance(envDict, dict) self.assertIs( romeo.hostdb.whoami(romeo.MYHOSTNAME).entity, romeo.whoami())
def configure(self): """load configuration for the rest of us.""" #FIXME, we need to fix romeo to load configuration for a directy specified at startup #and allow SIGHUP to reload configuration try: drone.log('Processing ROMEO Configuration') romeo.reload(datadir=drone.HOSTDB) me = romeo.whoami() except romeo.IdentityCrisis: drone.log('ROMEO Configuration is missing SERVER entry for %s' % \ (romeo.MYHOSTNAME,)) drone.log('DroneD is Exiting') exit(1) #Config FAIL!!!! ENV_NAME = [ i for i in romeo.listEnvironments() \ if i.isChild(me) ][0].get('NAME').VALUE ENV_OBJECT = romeo.getEnvironment(ENV_NAME) #figure out if we are supposed to run new services SERVICES = {} for service in me.VALUE.get('SERVICES', []): if 'SERVICENAME' not in service: continue SERVICES[service['SERVICENAME']] = copy.deepcopy(service) #figure out if we are supposed to manage application artifacts APPLICATIONS = {} for i in romeo.grammars.search('my SHORTNAME'): search = str('select ARTIFACT') for x in romeo.grammars.search(search): if x.get('SHORTNAME') != i: continue if not ENV_OBJECT.isChild(x): continue #right artifact/wrong env check APPLICATIONS[i.VALUE] = copy.deepcopy(x.VALUE) #journal and drone are builtins and should always run AUTOSTART_SERVICES = ('journal','drone') for service_object in SERVICES.values(): if 'AUTOSTART' in service_object and service_object['AUTOSTART']: if service_object['SERVICENAME'] in AUTOSTART_SERVICES: continue AUTOSTART_SERVICES += (service_object['SERVICENAME'],) #make sure the application service is available if APPLICATIONS and 'application' not in AUTOSTART_SERVICES: AUTOSTART_SERVICES += ('application',) #primary data storage self.data = { 'AUTOSTART_SERVICES': AUTOSTART_SERVICES, 'EXCESSIVE_LOGGING': drone.DEBUG, 'ROMEO_API': romeo, 'ROMEO_HOST_OBJECT': me, 'ROMEO_ENV_NAME': ENV_NAME, 'ROMEO_ENV_OBJECT': ENV_OBJECT, 'HOSTNAME': me.get('HOSTNAME').VALUE, 'SERVICES': SERVICES, 'APPLICATIONS': APPLICATIONS, 'DRONED_PORT': drone.PORT, 'DRONED_USER': drone.UID, 'DRONED_GROUP': drone.GID, 'DRONED_HOMEDIR': drone.DRONED_HOMEDIR, #FIXME move webroot to drone service 'DRONED_WEBROOT': drone.DRONED_WEBROOT, #FIXME move journaldir to journal service 'JOURNAL_DIR': drone.JOURNAL_DIR, 'LOG_DIR': drone.LOG_DIR, 'DEBUG_EVENTS': drone.DEBUG, #FIXME cli, config file override these ... some of it needs to go into services 'DRONED_PRIMES': '/usr/share/droned/primes', 'DRONED_KEY_DIR': '/etc/pki/droned', 'DRONED_MASTER_KEY_FILE': '/etc/pki/droned/local.private', 'DRONED_MASTER_KEY': rsa.PrivateKey('/etc/pki/droned/local.private'), 'DRONED_POLL_INTERVAL': 30, 'SERVER_POLL_OFFSET': 0.333, 'INSTANCE_POLL_INTERVAL': 1.0, 'ACTION_EXPIRATION_TIME': 600, 'DO_NOTHING_MODE': False, 'MAX_CONCURRENT_COMMANDS': 5, 'SERVER_MANAGEMENT_INTERVAL': 10, }
def getChild(self, name, request): if name in self.environments: return RomeoResource(name, romeo.getEnvironment(name)) return _ConfigResource.getChild(self, name, request)
def getEnvironment(name): import romeo return node_constructor(romeo.getEnvironment(name))
def configure(self): """load configuration for the rest of us.""" #FIXME, we need to fix romeo to load configuration for a directy specified at startup #and allow SIGHUP to reload configuration try: drone.log('Processing ROMEO Configuration') romeo.reload(datadir=drone.HOSTDB) me = romeo.whoami() except romeo.IdentityCrisis: drone.log('ROMEO Configuration is missing SERVER entry for %s' % \ (romeo.MYHOSTNAME,)) drone.log('DroneD is Exiting') exit(1) #Config FAIL!!!! ENV_NAME = [ i for i in romeo.listEnvironments() \ if i.isChild(me) ][0].get('NAME').VALUE ENV_OBJECT = romeo.getEnvironment(ENV_NAME) #figure out if we are supposed to run new services SERVICES = {} for service in me.VALUE.get('SERVICES', []): if 'SERVICENAME' not in service: continue SERVICES[service['SERVICENAME']] = copy.deepcopy(service) #figure out if we are supposed to manage application artifacts APPLICATIONS = {} for i in romeo.grammars.search('my SHORTNAME'): search = str('select ARTIFACT') for x in romeo.grammars.search(search): if x.get('SHORTNAME') != i: continue if isinstance(x.VALUE.get('CLASS', False), type(None)): continue if not ENV_OBJECT.isChild(x): continue #right artifact/wrong env check APPLICATIONS[i.VALUE] = copy.deepcopy(x.VALUE) #journal and drone are builtins and should always run AUTOSTART_SERVICES = ('journal', 'drone') for service_object in SERVICES.values(): if 'AUTOSTART' in service_object and service_object['AUTOSTART']: if service_object['SERVICENAME'] in AUTOSTART_SERVICES: continue AUTOSTART_SERVICES += (service_object['SERVICENAME'], ) #make sure the application service is available if APPLICATIONS and 'application' not in AUTOSTART_SERVICES: AUTOSTART_SERVICES += ('application', ) #primary data storage self.data = { 'reactor': drone.reactor, 'AUTOSTART_SERVICES': AUTOSTART_SERVICES, 'EXCESSIVE_LOGGING': drone.DEBUG, 'RETAINED_LOGS': drone.RETAINED_LOG_COUNT, 'ROMEO_API': romeo, 'ROMEO_HOST_OBJECT': me, 'ROMEO_ENV_NAME': ENV_NAME, 'ROMEO_ENV_OBJECT': ENV_OBJECT, 'HOSTNAME': me.get('HOSTNAME').VALUE, 'SERVICES': SERVICES, 'APPLICATIONS': APPLICATIONS, 'DRONED_PORT': drone.PORT, 'DRONED_USER': drone.UID, 'DRONED_GROUP': drone.GID, 'DRONED_HOMEDIR': drone.DRONED_HOMEDIR, #FIXME move webroot to drone service 'DRONED_WEBROOT': drone.DRONED_WEBROOT, #FIXME move journaldir to journal service 'JOURNAL_DIR': drone.JOURNAL_DIR, 'LOG_DIR': drone.LOG_DIR, 'DEBUG_EVENTS': drone.DEBUG, #FIXME cli, config file override these ... some of it needs to go into services 'DRONED_PRIMES': drone.PRIMES_FILE, 'DRONED_KEY_DIR': drone.RSA_DIR, 'DRONED_MASTER_KEY_FILE': drone.RSA_MASTER_KEY_FILE, 'DRONED_MASTER_KEY': rsa.PrivateKey(drone.RSA_MASTER_KEY_FILE), 'DRONED_POLL_INTERVAL': 30, 'SERVER_POLL_OFFSET': 0.333, 'INSTANCE_POLL_INTERVAL': 1.0, 'ACTION_EXPIRATION_TIME': 600, 'DO_NOTHING_MODE': False, 'MAX_CONCURRENT_COMMANDS': drone.MAX_CONCURRENCY, 'SERVER_MANAGEMENT_INTERVAL': 10, }