diff options
author | asteroide <thomas.duval@orange.com> | 2015-11-09 16:07:16 +0100 |
---|---|---|
committer | asteroide <thomas.duval@orange.com> | 2015-11-09 16:07:16 +0100 |
commit | c1f432a46f8c6a1501133a0f18e8556246524904 (patch) | |
tree | 0c9cd0ce635f8a135a3ef7b7704234cc9f770ec7 /moonclient | |
parent | 7e98b5d8b90f18d433fabc34733030ba69e8d584 (diff) |
Add 'special' test operation allowing to change authentication (name, url, ...) during test and add a shell operation in test procedure.
Change-Id: I44f91b19d438dc92183d58f99047228ea5dc257a
Diffstat (limited to 'moonclient')
-rw-r--r-- | moonclient/moonclient/shell.py | 18 | ||||
-rw-r--r-- | moonclient/moonclient/tests.py | 54 | ||||
-rw-r--r-- | moonclient/moonclient/tests/tests_change_auth.json | 32 |
3 files changed, 99 insertions, 5 deletions
diff --git a/moonclient/moonclient/shell.py b/moonclient/moonclient/shell.py index ce59b3c6..49422a45 100644 --- a/moonclient/moonclient/shell.py +++ b/moonclient/moonclient/shell.py @@ -154,6 +154,24 @@ class MoonClient(App): except ValueError: return {"content": content} + def auth_keystone(self, username=None, password=None, host=None, port=None): + """Send a new authentication request to Keystone + + :param username: user identification name + :return: + """ + if username: + self.post["auth"]["identity"]["password"]["user"]["name"] = username + if password: + self.post["auth"]["identity"]["password"]["user"]["password"] = password + if host: + self.host = host + if port: + self.port = port + data = self.get_url("/v3/auth/tokens", post_data=self.post) + if "token" not in data: + raise Exception("Authentication problem ({})".format(data)) + def initialize_app(self, argv): self.log.debug('initialize_app: {}'.format(argv)) if self.options.username: diff --git a/moonclient/moonclient/tests.py b/moonclient/moonclient/tests.py index a97ba61c..ea722955 100644 --- a/moonclient/moonclient/tests.py +++ b/moonclient/moonclient/tests.py @@ -68,16 +68,57 @@ class TestsLaunch(Lister): for test in tests_list: result_str = "" error_str = "" + if "auth_name" in test or "auth_password" in test or "auth_url" in test: + username = None + password = None + host = None + port = None + description = "" + if "auth_name" in test: + username = test["auth_name"] + if "auth_password" in test: + password = test["auth_password"] + if "auth_host" in test: + host = test["auth_host"] + if "auth_port" in test: + port = test["auth_port"] + if "description" in test: + description = test["description"] + self.app.auth_keystone(username, password, host, port) + title = "Change auth to " + if username: + title += username + if host: + title += "@" + host + if port: + title += ":" + port + title += "\n" + self.logfile.write(title) + self.log.info(title) + data_tmp = list() + data_tmp.append("") + data_tmp.append(title.strip()) + data_tmp.append("\033[32mOK\033[m") + data_tmp.append(description.strip()) + data.append(data_tmp) + continue data_tmp = list() tmp_filename = os.path.join("/tmp", uuid4().hex) tmp_filename_fd = open(tmp_filename, "w") self.log.debug("test={}".format(test)) if "command" not in test: - ext_command = test["external_command"] + if "external_command" in test: + ext_command = test["external_command"] + else: + ext_command = test["shell_command"] ext_command = self.__replace_var_in_str(ext_command) self.logfile.write("-----> {}\n".format(ext_command)) self.log.info(" \\-executing external \"{}\"".format(ext_command)) - pipe = subprocess.Popen(shlex.split(ext_command), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if "external_command" in test: + pipe = subprocess.Popen(shlex.split(ext_command), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + else: + # Note (asteroide): security hazard! Must reduce the possible commands here. + pipe = subprocess.Popen(ext_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) com = pipe.communicate() result_str = com[0] error_str = com[1] @@ -104,14 +145,17 @@ class TestsLaunch(Lister): if error_str: if compare: compare = "\033[33mTrue\033[m" - overall_result = True + overall_result = overall_result and True else: compare = "\033[1m\033[31mFalse\033[m" - overall_result = False + overall_result = overall_result and False else: overall_result = overall_result and compare if compare: - compare = "\033[32mTrue\033[m" + if overall_result: + compare = "\033[32mTrue\033[m" + else: + compare = "\033[mTrue\033[m" else: compare = "\033[1m\033[31mFalse\033[m" data_tmp.append(compare) diff --git a/moonclient/moonclient/tests/tests_change_auth.json b/moonclient/moonclient/tests/tests_change_auth.json new file mode 100644 index 00000000..38d1d134 --- /dev/null +++ b/moonclient/moonclient/tests/tests_change_auth.json @@ -0,0 +1,32 @@ +{ + "command_options": "-f value", + "tests_group": { + "authz": [ + + { + "auth_name": "demo", + "description": "Change user to demo" + }, + + { + "name": "list tenant", + "command": "tenant list", + "result": "^$", + "description": "Check if user demo cannot read the list of all tenants." + }, + + { + "auth_name": "admin", + "description": "Change user to admin" + }, + + { + "name": "list tenant", + "command": "tenant list", + "result": "admin", + "description": "Check if user admin can read the list of all tenants." + } + + ] + } +}
\ No newline at end of file |