def set_job_matrix_settings(repo_path, specification): """Function for setting job matrix settings :param str path_to_repo: path to repository :param dict specification: dictionary containging section, name and setting value :return: 200 OK if successfull, 404 NOT FOUND otherwise """ try: if (specification['section'] == 'collectionSpecification'): output = formatter.format_job_matrix_collection_specification(specification) name = specification['name'] else: output = specification['value'] if (specification['name'] == 'commands'): name = 'cmds' elif (specification['name'] == 'arguments'): name = 'args' elif (specification['name'] == 'workload'): name = 'workloads' original_path = os.getcwd() os.chdir(repo_path) commands.config_set('local', name, output) os.chdir(original_path) return create_response('Job matrix settings set successfully', 200) except Exception as e: os.chdir(original_path) eprint(e) return create_response(e, 404)
def set_global_settings(section, name, value): """Function for setting shared (global) Perun settings :param str section: section of settings which contains the specified command (eg. general) :param str name: name of the item which is to be set (eg. paging) :param str value: new value :return: 200 OK if successfull, 404 NOT FOUND otherwise """ try: commands.config_set('shared', section + '.' + name, value) return create_response('Global settings set successfully', 200) except Exception as e: eprint(e) return create_response(e, 404)
def test_edit(pcs_full, capsys): """Test 'editing' the configuration file Expecting no errors or exceptions """ # First try to get the exception by calling bogus editor commands.config_set('local', 'general.editor', 'bogus') with pytest.raises(ExternalEditorErrorException): commands.config_edit('local') capsys.readouterr() # Use cat as a valid editor commands.config_set('local', 'general.editor', 'cat') commands.config_edit('local') capsys.readouterr() _, err = capsys.readouterr() assert err == ''
def set_local_settings(path_to_repo, section, name, value): """Function for setting local Perun settings :param str path_to_repo: path to repository :param str section: section of settings which contains the specified command (eg. general) :param str name: name of the item which is to be set (eg. paging) :param str value: new value :return: 200 OK if successfull, 404 NOT FOUND otherwise """ original_path = os.getcwd() os.chdir(path_to_repo) try: commands.config_set('local', section + '.' + name, value) os.chdir(original_path) return create_response('Local settings set successfully', 200) except Exception as e: os.chdir(original_path) eprint(e) return create_response(e, 404)
def test_set_exists(pcs_full, capsys): """Test calling 'perun --set KEY', such that the key was in config and is reset""" # Set valid thing in local commands.config_set('local', 'bogus.key', 'true') capsys.readouterr() commands.config_get('local', 'bogus.key') out, err = capsys.readouterr() assert 'bogus.key' in out and 'true' in out assert err == '' # Set valid thing in global random_value = str(random.randint(0, 10**6)) commands.config_set('shared', 'testkey', random_value) capsys.readouterr() commands.config_get('shared', 'testkey') out, err = capsys.readouterr() assert 'testkey' in out and random_value in out assert err == '' # Set valid thing in nearest with pytest.raises(MissingConfigSectionException): commands.config_get('local', 'test2key') commands.config_set('recursive', 'test2key', 'testvalue') capsys.readouterr() commands.config_get('recursive', 'test2key') out, err = capsys.readouterr() assert 'test2key' in out and 'testvalue' in out assert err == ''