Convert fstrings to .format to facilitate porting

Fstrings are a python 3.6 feature, in order to faciliate porting
to early architectures the fstrings were converted to .format

Change-Id: Ib23097c149ec8ff06cc70bb873b53ee45645ff15
This commit is contained in:
apetrich 2022-01-06 10:53:45 +01:00
parent e875e1671b
commit 68adc1fe16
5 changed files with 56 additions and 36 deletions

View File

@ -132,9 +132,9 @@ class Ansible(object):
community_library = ""
community_lookup = ""
if utils.community_validations_on(validation_cfg_file):
community_roles = f"{constants.COMMUNITY_ROLES_DIR}:"
community_library = f"{constants.COMMUNITY_LIBRARY_DIR}:"
community_lookup = f"{constants.COMMUNITY_LOOKUP_DIR}:"
community_roles = "{}:".format(constants.COMMUNITY_ROLES_DIR)
community_library = "{}:".format(constants.COMMUNITY_LIBRARY_DIR)
community_lookup = "{}:".format(constants.COMMUNITY_LOOKUP_DIR)
cwd = os.getcwd()
env['ANSIBLE_SSH_ARGS'] = (

View File

@ -42,9 +42,10 @@ class CommunityValidationInit(BaseCommand):
"with an alpha character. \n"
"Ex: my-val, my_val2. \n"
"This will generate an Ansible role and a playbook in "
f"{constants.COMMUNITY_VALIDATIONS_BASEDIR}. "
"{}. "
"Note that the structure of this directory will be created at "
"the first use."
.format(constants.COMMUNITY_VALIDATIONS_BASEDIR)
)
)
@ -61,7 +62,8 @@ class CommunityValidationInit(BaseCommand):
LOG.debug(
(
"Checking the presence of the community validations "
f"{constants.COMMUNITY_VALIDATIONS_BASEDIR} directory..."
"{} directory..."
.format(constants.COMMUNITY_VALIDATIONS_BASEDIR)
)
)
@ -70,20 +72,28 @@ class CommunityValidationInit(BaseCommand):
if co_validation.is_role_exists():
raise RuntimeError(
(
f"An Ansible role called {co_validation.role_name} "
"An Ansible role called {} "
"already exist in: \n"
f" - {constants.COMMUNITY_ROLES_DIR}\n"
f" - {constants.ANSIBLE_ROLES_DIR}"
" - {}\n"
" - {}"
.format(
co_validation.role_name,
constants.COMMUNITY_ROLES_DIR,
constants.ANSIBLE_ROLES_DIR)
)
)
if co_validation.is_playbook_exists():
raise RuntimeError(
(
f"An Ansible playbook called {co_validation.playbook_name} "
"An Ansible playbook called {} "
"already exist in: \n"
f" - {constants.COMMUNITY_PLAYBOOKS_DIR}\n"
f" - {constants.ANSIBLE_VALIDATION_DIR}"
" - {}\n"
" - {}"
.format(
co_validation.playbook_name,
constants.COMMUNITY_PLAYBOOKS_DIR,
constants.ANSIBLE_VALIDATION_DIR)
)
)

View File

@ -60,24 +60,28 @@ class CommunityValidation:
if result != 0:
raise RuntimeError(
(
f"Ansible Galaxy failed to create the role "
f"{self.role_name}, returned {result}."
"Ansible Galaxy failed to create the role "
"{}, returned {}."
.format(self.role_name, result)
)
)
LOG.info(f"New role created successfully in {self.role_dir_path}")
LOG.info("New role created successfully in {}"
.format(self.role_dir_path))
try:
self.create_playbook()
except (PermissionError, OSError) as error:
raise RuntimeError(
(
f"Exception {error} encountered while trying to write "
f"the community validation playbook file {self.playbook_path}."
"Exception {} encountered while trying to write "
"the community validation playbook file {}."
.format(error, self.playbook_path)
)
)
LOG.info(f"New playbook created successfully in {self.playbook_path}")
LOG.info("New playbook created successfully in {}"
.format(self.playbook_path))
def create_playbook(self, content=constants.COMMUNITY_PLAYBOOK_TEMPLATE):
"""Create the playbook for the new community validation"""

View File

@ -185,9 +185,9 @@ class TestAnsible(TestCase):
callback_whitelist="", base_dir="", python_interpreter="",
env={}, validation_cfg_file=None)
assert(f"{constants.COMMUNITY_LIBRARY_DIR}:" in env["ANSIBLE_LIBRARY"])
assert(f"{constants.COMMUNITY_ROLES_DIR}:" in env["ANSIBLE_ROLES_PATH"])
assert(f"{constants.COMMUNITY_LOOKUP_DIR}:" in env["ANSIBLE_LOOKUP_PLUGINS"])
assert("{}:".format(constants.COMMUNITY_LIBRARY_DIR) in env["ANSIBLE_LIBRARY"])
assert("{}:".format(constants.COMMUNITY_ROLES_DIR) in env["ANSIBLE_ROLES_PATH"])
assert("{}:".format(constants.COMMUNITY_LOOKUP_DIR) in env["ANSIBLE_LOOKUP_PLUGINS"])
# AP config file with no settting (use the default True)
env = self.run._ansible_env_var(
@ -197,9 +197,9 @@ class TestAnsible(TestCase):
callback_whitelist="", base_dir="", python_interpreter="",
env={}, validation_cfg_file={"default": {}})
assert(f"{constants.COMMUNITY_LIBRARY_DIR}:" in env["ANSIBLE_LIBRARY"])
assert(f"{constants.COMMUNITY_ROLES_DIR}:" in env["ANSIBLE_ROLES_PATH"])
assert(f"{constants.COMMUNITY_LOOKUP_DIR}:" in env["ANSIBLE_LOOKUP_PLUGINS"])
assert("{}:".format(constants.COMMUNITY_LIBRARY_DIR) in env["ANSIBLE_LIBRARY"])
assert("{}:".format(constants.COMMUNITY_ROLES_DIR) in env["ANSIBLE_ROLES_PATH"])
assert("{}:".format(constants.COMMUNITY_LOOKUP_DIR) in env["ANSIBLE_LOOKUP_PLUGINS"])
# AP config file with settting True
env = self.run._ansible_env_var(
@ -209,9 +209,9 @@ class TestAnsible(TestCase):
callback_whitelist="", base_dir="", python_interpreter="",
env={}, validation_cfg_file={"default": {"enable_community_validations": True}})
assert(f"{constants.COMMUNITY_LIBRARY_DIR}:" in env["ANSIBLE_LIBRARY"])
assert(f"{constants.COMMUNITY_ROLES_DIR}:" in env["ANSIBLE_ROLES_PATH"])
assert(f"{constants.COMMUNITY_LOOKUP_DIR}:" in env["ANSIBLE_LOOKUP_PLUGINS"])
assert("{}:".format(constants.COMMUNITY_LIBRARY_DIR) in env["ANSIBLE_LIBRARY"])
assert("{}:".format(constants.COMMUNITY_ROLES_DIR) in env["ANSIBLE_ROLES_PATH"])
assert("{}:".format(constants.COMMUNITY_LOOKUP_DIR) in env["ANSIBLE_LOOKUP_PLUGINS"])
def test_ansible_env_var_without_community_validations(self):
# AP config file with settting False
@ -222,9 +222,9 @@ class TestAnsible(TestCase):
callback_whitelist="", base_dir="", python_interpreter="",
env={}, validation_cfg_file={"default": {"enable_community_validations": False}})
assert(f"{constants.COMMUNITY_LIBRARY_DIR}:" not in env["ANSIBLE_LIBRARY"])
assert(f"{constants.COMMUNITY_ROLES_DIR}:" not in env["ANSIBLE_ROLES_PATH"])
assert(f"{constants.COMMUNITY_LOOKUP_DIR}:" not in env["ANSIBLE_LOOKUP_PLUGINS"])
assert("{}:".format(constants.COMMUNITY_LIBRARY_DIR) not in env["ANSIBLE_LIBRARY"])
assert("{}:".format(constants.COMMUNITY_ROLES_DIR) not in env["ANSIBLE_ROLES_PATH"])
assert("{}:".format(constants.COMMUNITY_LOOKUP_DIR) not in env["ANSIBLE_LOOKUP_PLUGINS"])
def test_get_extra_vars_dict(self):
extra_vars = {

View File

@ -702,12 +702,14 @@ def check_community_validations_dir(
def create_subdir(subdir):
for _dir in subdir:
LOG.debug(
f"Missing {Path(_dir).name} directory in {basedir}:"
"Missing {} directory in {}:"
.format(Path(_dir).name, basedir)
)
Path.mkdir(_dir)
recreated_comval_dir.append(_dir)
LOG.debug(
f"└── {_dir} directory created successfully..."
"└── {} directory created successfully..."
.format(_dir)
)
if Path(basedir).exists and Path(basedir).is_dir():
@ -720,22 +722,26 @@ def check_community_validations_dir(
create_subdir(missing_dirs)
else:
LOG.debug(
f"The community validations {basedir} directory is not present:"
"The community validations {} directory is not present:"
.format(basedir)
)
Path.mkdir(basedir)
recreated_comval_dir.append(basedir)
LOG.debug(f"└── {basedir} directory created...")
LOG.debug("└── {} directory created...".format(basedir))
create_subdir(subdirs)
LOG.debug(
(
f"The {basedir} directory and its required subtree are present "
f"and correct:\n"
f"{basedir}/\n"
"The {} directory and its required subtree are present "
"and correct:\n"
"{}/\n"
"├── library OK\n"
"├── lookup_plugins OK\n"
"├── playbooks OK\n"
"└── roles OK\n"
.format(
basedir,
basedir)
)
)
return recreated_comval_dir