def test_load_environment(self): local_root = tempfile.mkdtemp() config = Configuration("agent", "1.2.3") config.system_root = local_root self.add_cleanup_path(local_root) split = config.split_version() filename = config.name + config.file_extension paths = [ join(config.system_root, config.child_dir, split[2], filename), join(config.system_root, config.child_dir + os.sep, filename), ] for i, path in enumerate(paths): try: os.makedirs(dirname(path)) except OSError: pass data = dedent( """ env: key%s: %s key: %s """ % (i, i, i) ) with open(path, "w") as stream: stream.write(data) self.add_cleanup_path(stream.name) environment = {} config.load(environment=environment) self.assertEqual(environment, {"key0": 0, "key1": 1, "key": 1})
def test_load_empty_file(self): local_root = tempfile.mkdtemp() config = Configuration("agent", "1.2.3") config.system_root = local_root self.add_cleanup_path(local_root) split = config.split_version() filename = config.name + config.file_extension paths = [ join(config.system_root, config.child_dir + os.sep, filename), join(config.system_root, config.child_dir, split[2], filename), ] for i, path in enumerate(paths): try: os.makedirs(dirname(path)) except OSError: pass with open(path, "w") as stream: stream.write("") self.add_cleanup_path(stream.name) config.load()
def __init__(self, data=None, environment=None, load=True): super(LoggingConfiguration, self).__init__("pyfarm.agent") assert data is None or isinstance(data, dict) assert environment is None or isinstance(environment, dict) if environment is None: environment = os.environ if load: self.load(environment=environment) self.update( # A mapping of UUIDs to job type instances. jobtypes={}, # A mapping of tasks to job type instances. current_assignments={}, # The last time we were in touch with the master, # or the last time it was in touch with us. last_master_contact=None, # The last time we announced ourselves to the master. This # may be longer than --master-reannounce if # `last_master_contact` caused us to skip an announcement. last_announce=None) if data is not None: self.update(data) # Load configuration file(s) for jobtypes and then # update the local instance if load: jobtypes_config = Configuration( "pyfarm.jobtypes", version=self.version) jobtypes_config.load(environment=environment) self.update(jobtypes_config)