def test_read_yaml_file(): fd, path = tempfile.mkstemp() os.close(fd) with open(path, "w") as output: output.write("value: 42\n") result = pdosq.read_yaml_file(path) assert result['value'] == 42 pdosq.safe_remove(path) assert pdosq.read_yaml_file(path, default=None) is None assert pdosq.read_yaml_file(path, default={}) == {}
def read_provisioning_conf(): """ Read provisioning information from the configuration file. This file will exist on startup if the node is to be self-provisioned. """ path = os.path.join(settings.CONFIG_HOME_DIR, "provision.yaml") return pdosq.read_yaml_file(path, default={})
def load(path=None): """ Load host configuration. Tries to load host configuration from persistent file. If that does not work, it will try to automatically generate a working configuration. Returns a host config object on success or None on failure. """ if path is None: path = settings.HOST_CONFIG_FILE return pdosq.read_yaml_file(path, default=None)
def extract_tarred_chute(data): tar = tarfile.TarFile(fileobj=data) if not tarfile_is_safe(tar): raise Exception("Tarfile contains unsafe paths") tempdir = tempfile.mkdtemp() tar.extractall(tempdir) configfile = os.path.join(tempdir, "paradrop.yaml") if not os.path.isfile(configfile): raise Exception("No paradrop.yaml file found in chute source") paradrop_yaml = pdosq.read_yaml_file(configfile, default={}) return (tempdir, paradrop_yaml)
def resolveInfo(nexus, path): ''' Given a path to the config file, load its contents and assign it to the config file as appropriate. ''' # Check to make sure we have a default settings file if not os.path.isfile(path): createDefaultInfo(path) contents = pdosq.read_yaml_file(path) # Sanity check contents of info and throw it out if bad if not validateInfo(contents): output.out.err('Saved configuration data invalid, destroying it.') os.remove(path) createDefaultInfo(path) contents = pdosq.read_yaml_file(path, default={}) writeYaml(contents, path) nexus.info.pdid = contents['pdid'] nexus.info.version = contents['version'] nexus.info.pdserver = contents['pdserver'] nexus.info.wampRouter = contents['wampRouter']
def load_chute_configuration(update): """ Load and interpret paradrop.yaml file. """ if not update.has_chute_build(): return config = {} workdir = getattr(update, "workdir", None) if workdir is not None: conf_path = os.path.join(workdir, settings.CHUTE_CONFIG_FILE) config = pdosq.read_yaml_file(conf_path, default={}) # Look for additional build information from the update object # and merge with the configuration file. if hasattr(update, "build"): config.update(update.build) # Try to set the owner of the chute. if hasattr(update, "user"): config['owner'] = update.user update.new = build_chute(config)
def read_provisioning_result(): """ Read provisioning result from the filesystem. """ path = os.path.join(settings.CONFIG_HOME_DIR, "provisioned.yaml") return pdosq.read_yaml_file(path, default={})
def testSaveUpdatesYaml(): nex = TestingNexus() nex.info.a = 1 dic = pdosq.read_yaml_file(settings.CONFIG_FILE) assert dic['a'] == 1