summaryrefslogtreecommitdiffstats
path: root/moonclient
diff options
context:
space:
mode:
authorasteroide <thomas.duval@orange.com>2015-09-16 10:41:36 +0200
committerasteroide <thomas.duval@orange.com>2015-09-16 10:41:36 +0200
commit451454bed17c832740f32cfd8235661e3f5390c3 (patch)
treee15b4365e95428f18db84f079be8d9caa4533314 /moonclient
parentabe028e7984be2d7f9dff7aabe461cc82a3b60c0 (diff)
Add the tests command to MoonClient.
Change-Id: I7f294e7f388af25473aba686958d4d9207580baf
Diffstat (limited to 'moonclient')
-rw-r--r--moonclient/moonclient/tests.py54
-rw-r--r--moonclient/moonclient/tests/tests_tenants.json70
-rw-r--r--moonclient/setup.py2
3 files changed, 104 insertions, 22 deletions
diff --git a/moonclient/moonclient/tests.py b/moonclient/moonclient/tests.py
index e058fd9b..b259feb6 100644
--- a/moonclient/moonclient/tests.py
+++ b/moonclient/moonclient/tests.py
@@ -9,44 +9,80 @@ import shlex
import re
from cliff.lister import Lister
from cliff.command import Command
+from uuid import uuid4
+import os
+import time
class TestsLaunch(Lister):
- """List all Intra_Extensions."""
+ """Tests launcher."""
log = logging.getLogger(__name__)
result_vars = dict()
+ logfile = open("/tmp/moonclient_test_{}.log".format(time.strftime("%Y%m%d-%H%M%S")), "w")
def get_parser(self, prog_name):
parser = super(TestsLaunch, self).get_parser(prog_name)
parser.add_argument(
- '--testfile',
+ 'testfile',
metavar='<filename>',
help='Filename that contains tests to run',
)
return parser
def __replace_var_in_str(self, data_str):
- for exp in re.findall("\$\w+"):
+ for exp in re.findall("\$\w+", data_str):
if exp.replace("$", "") in self.result_vars:
- data_str.replace(exp, self.result_vars[exp.replace("$", "")])
+ data_str = data_str.replace(exp, self.result_vars[exp.replace("$", "")])
return data_str
def __compare_results(self, expected, observed):
- if expected in observed:
+ match = re.search(expected, observed)
+ if match:
+ self.result_vars.update(match.groupdict())
return True
return False
def take_action(self, parsed_args):
+ self.log.info("Write tests output to {}".format(self.logfile))
+ stdout_back = self.app.stdout
+ if not parsed_args.testfile:
+ self.log.error("You don't give a test filename.")
+ raise Exception("Cannot execute tests.")
tests_dict = json.load(open(parsed_args.testfile))
+ self.log.debug("tests_dict = {}".format(tests_dict))
+ global_command_options = ""
+ if "command_options" in tests_dict:
+ global_command_options = tests_dict["command_options"]
data = list()
- for group_name, tests_list in tests_dict.iteritems():
+ for group_name, tests_list in tests_dict["tests_group"].iteritems():
+ self.logfile.write("{}:\n\n".format(group_name))
for test in tests_list:
data_tmp = list()
- command = self.__replace_var_in_str(test["command"])
- result = self.app.run_subcommand(shlex.split(command))
+ tmp_filename = os.path.join("/tmp", uuid4().hex)
+ tmp_filename_fd = open(tmp_filename, "w")
+ self.log.debug("test={}".format(test))
+ if "command_options" in test:
+ command = test["command"] + " " + test["command_options"]
+ else:
+ command = test["command"] + " " + global_command_options
+ command = self.__replace_var_in_str(command)
+ self.logfile.write("-----> {}\n".format(command))
+ self.log.info("executing {}".format(command))
+ self.app.stdout = tmp_filename_fd
+ result_id = self.app.run_subcommand(shlex.split(command))
+ tmp_filename_fd.close()
+ self.app.stdout = stdout_back
+ result_str = open(tmp_filename, "r").read()
+ self.logfile.write("{}".format(result_str))
data_tmp.append(test["name"])
- data_tmp.append(self.__compare_results(test["result"], result))
+ compare = self.__compare_results(self.__replace_var_in_str(test["result"]), result_str)
+ self.logfile.write("----->{} ({})\n\n".format(compare, self.__replace_var_in_str(test["result"])))
+ if compare:
+ compare = "\033[32mTrue\033[m"
+ else:
+ compare = "\033[1m\033[31mFalse\033[m"
+ data_tmp.append(compare)
data_tmp.append(test["description"])
data.append(data_tmp)
diff --git a/moonclient/moonclient/tests/tests_tenants.json b/moonclient/moonclient/tests/tests_tenants.json
index 76e2b10c..ca2d228c 100644
--- a/moonclient/moonclient/tests/tests_tenants.json
+++ b/moonclient/moonclient/tests/tests_tenants.json
@@ -1,24 +1,32 @@
{
- "command_prefix": "moon",
+ "command_options": "-f value",
"tests_group": {
"group1": [
{
"name": "list tenant",
"command": "tenant list",
- "result": "^$",
+ "result": "(?!alt_demo)",
"description": "List all tenants (must be empty)"
},
{
- "name": "add tenant demo",
- "command": "tenant add demo",
- "result": "Tenant created: (?P<uuid>\\w+)",
- "description": "Add a new tenant"
+ "name": "add tenant alt_demo",
+ "command": "tenant add alt_demo",
+ "result": "^$",
+ "description": "Add a new tenant",
+ "command_options": ""
+ },
+ {
+ "name": "check tenant alt_demo",
+ "command": "tenant list",
+ "result": "(?P<uuid>\\w+)\\s+alt_demo",
+ "description": "Check that tenant alt_demo has been correctly added"
},
{
"name": "create_intraextension_admin",
- "command": "intraextension create --policy_model policy_admin func_test",
- "result": "%uuid_admin%",
- "description": "Create an admin intra extension"
+ "command": "intraextension create --policy_model policy_admin admin_test",
+ "result": "IntraExtension created: (?P<uuid_admin>\\w+)",
+ "description": "Create an admin intra extension",
+ "command_options": ""
},
{
"name": "list_intraextension_admin",
@@ -27,16 +35,52 @@
"description": "Check the existence of that admin intra extension"
},
{
+ "name": "create_intraextension_authz",
+ "command": "intraextension create --policy_model policy_authz authz_test",
+ "result": "IntraExtension created: (?P<uuid_authz>\\w+)",
+ "description": "Create an authz intra extension",
+ "command_options": ""
+ },
+ {
+ "name": "list_intraextension_authz",
+ "command": "intraextension list",
+ "result": "$uuid_authz",
+ "description": "Check the existence of that authz intra extension"
+ },
+ {
"name": "set_tenant_authz",
- "command": "intraextension tenant set authz $uuid_authz demo",
+ "command": "tenant set --authz $uuid_authz demo",
"result": "",
- "description": "Connect the authz intra extension to the tenant demo"
+ "description": "Connect the authz intra extension to the tenant demo",
+ "command_options": ""
},
{
"name": "set_tenant_admin",
- "command": "intraextension tenant set authz $uuid_authz demo",
+ "command": "tenant set --admin $uuid_admin demo",
+ "result": "",
+ "description": "Connect the admin intra extension to the tenant demo",
+ "command_options": ""
+ },
+ {
+ "name": "delete_admin_intra_extension",
+ "command": "intraextension delete $uuid_admin",
+ "result": "",
+ "description": "Delete the admin intra extension",
+ "command_options": ""
+ },
+ {
+ "name": "delete_authz_intra_extension",
+ "command": "intraextension delete $uuid_authz",
+ "result": "",
+ "description": "Delete the authz intra extension",
+ "command_options": ""
+ },
+ {
+ "name": "delete_tenant",
+ "command": "tenant delete $uuid",
"result": "",
- "description": "Connect the admin intra extension to the tenant demo"
+ "description": "Delete the tenant alt_demo",
+ "command_options": ""
}
]
}
diff --git a/moonclient/setup.py b/moonclient/setup.py
index 2da0ab1b..39afdf8d 100644
--- a/moonclient/setup.py
+++ b/moonclient/setup.py
@@ -120,6 +120,8 @@ setup(
'rule_add = moonclient.rules:RuleAdd',
'rule_delete = moonclient.rules:RuleDelete',
'log = moonclient.logs:LogsList',
+
+ 'tests = moonclient.tests:TestsLaunch',
],
},