From bd76e8ec7e8b63e7bd78c5b9e01d6cb558f71fc8 Mon Sep 17 00:00:00 2001 From: alaa-bish Date: Wed, 26 Jan 2022 10:34:40 +0000 Subject: [PATCH] solve python 2.7 issues --- plugins/module_utils/entity.py | 8 ++++---- plugins/module_utils/prism/vms.py | 10 +++++----- tests/unit/plugins/module_utils/test_entity.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/module_utils/entity.py b/plugins/module_utils/entity.py index b11dee8d0..9d93940db 100644 --- a/plugins/module_utils/entity.py +++ b/plugins/module_utils/entity.py @@ -158,9 +158,9 @@ def send_request(module, method, req_url, req_data, username, password, timeout= module.fail_json( msg="Fail: " + "Status: " - + f'{str(info["msg"])}' + + '{0}'.format(str(info["msg"])) + ", Message: " - + f'{str(info.get("body"))}' + + '{0}'.format(str(info.get("body"))) ) body = resp.read() if resp else info.get("body") @@ -201,7 +201,7 @@ def generate_url_from_operations(self, name, netloc=None, ops=None): elif type(each) is dict: key = list(each.keys())[0] val = each[key] - path += f"/{key}/{val}" + path += "/{0}/{1}".format(key, val) url += path return self.validate_url(url, netloc, path) @@ -239,7 +239,7 @@ def get_spec(self): ) file_path = join(ncp_dir, self.spec_file) - with open(file_path, encoding="utf_8") as f: + with open(file_path, "rb") as f: # spec = json.loads(str(f.read())) spec = yaml.safe_load(f.read()) return spec diff --git a/plugins/module_utils/prism/vms.py b/plugins/module_utils/prism/vms.py index adc45a505..8d137feaa 100644 --- a/plugins/module_utils/prism/vms.py +++ b/plugins/module_utils/prism/vms.py @@ -29,7 +29,7 @@ def get_attr_spec(self, param, param_spec, **kwargs): def get_entity_by_name(self, name="", kind=""): url = self.generate_url_from_operations(kind, netloc=self.url, ops=["list"]) - data = {"filter": f"name=={name}", "length": 1} + data = {"filter": "name=={0}".format(name), "length": 1} resp = self.send_request( self.module, self.methods_of_actions["list"], @@ -44,7 +44,7 @@ def get_entity_by_name(self, name="", kind=""): except IndexError: - self.result["message"] = f"Entity with name {name} does not exist." + self.result["message"] = "Entity with name {0} does not exist.".format(name) self.result["failed"] = True self.module.exit_json(**self.result) @@ -53,12 +53,12 @@ def get_entity_by_name(self, name="", kind=""): class VMSpec: def get_default_spec(self): raise NotImplementedError( - f"Get Default Spec helper not implemented for {self.entity_type}" + "Get Default Spec helper not implemented for {0}".format(self.entity_type) ) def _get_api_spec(self, param_spec, **kwargs): raise NotImplementedError( - f"Get Api Spec helper not implemented for {self.entity_type}" + "Get Api Spec helper not implemented for {0}".format(self.entity_type) ) def remove_null_references(self, spec, parent_spec=None, spec_key=None): @@ -246,7 +246,7 @@ def _get_api_spec(self, param_spec, **kwargs): gc_spec = self.get_default_spec() script_file_path = param_spec["script_path"] - with open(script_file_path, "rb", encoding="utf_8") as f: + with open(script_file_path, "rb") as f: content = f.read() content = b64encode(content) type = param_spec["type"] diff --git a/tests/unit/plugins/module_utils/test_entity.py b/tests/unit/plugins/module_utils/test_entity.py index 50bc345fb..ccd9a7996 100644 --- a/tests/unit/plugins/module_utils/test_entity.py +++ b/tests/unit/plugins/module_utils/test_entity.py @@ -207,7 +207,7 @@ def test_generate_url(self): elif isinstance(each, dict): key = list(each.keys())[0] val = each[key] - path += f"/{key}/{val}" + path += "/{0}/{1}".format(key, val) self.assertTrue("http" in actual.scheme) self.assertEqual(netloc, actual.netloc) self.assertEqual(path, actual.path)