Add an option to force the name of the logfile. 51/21751/1
authorThomas Duval <thomas.duval@orange.com>
Mon, 5 Sep 2016 15:13:09 +0000 (17:13 +0200)
committerThomas Duval <thomas.duval@orange.com>
Tue, 20 Sep 2016 08:38:37 +0000 (10:38 +0200)
Change-Id: Iea61a1045c9d60a157725dfc7df8dad5b9ca905a
(cherry picked from commit 347dbd9d0ec41fe4951210eea9dad2b41bf7f142)

moonclient/Changelog
moonclient/moonclient/__init__.py
moonclient/moonclient/tests.py
moonclient/moonclient/tests/tests_empty_policy_new_user.json
moonclient/moonclient/tests/tests_empty_policy_swift.json
tests/run_tests.py

index f641f3a..1326511 100644 (file)
@@ -7,6 +7,11 @@
 CHANGES
 =======
 
+0.4.0
+-----
+
+* Add an argument to force the name of the logfile for test command.
+
 0.3.0
 -----
 
index 493f741..6a9beea 100644 (file)
@@ -1 +1 @@
-__version__ = "0.3.0"
+__version__ = "0.4.0"
index 7da7d5e..3ef2aa9 100644 (file)
@@ -43,6 +43,12 @@ class TestsLaunch(Lister):
                  '(examples: /path/to/test.json, /path/to/directory/, '
                  '"/path/to/*-file.json" -- don\'t forget the quote)',
         )
+        parser.add_argument(
+            '--logfile',
+            metavar='<logfile-str>',
+            help='Force Log filename.',
+            default=None
+        )
         return parser
 
     def __replace_var_in_str(self, data_str):
@@ -62,6 +68,8 @@ class TestsLaunch(Lister):
         return False
 
     def take_action(self, parsed_args):
+        if parsed_args.logfile:
+            self.logfile_name = parsed_args.logfile
         self.log.info("Write tests output to {}".format(self.logfile_name))
         if parsed_args.self:
             import sys
@@ -103,8 +111,11 @@ class TestsLaunch(Lister):
             )
 
     def test_file(self, testfile):
-        self.logfile_name = "/tmp/moonclient_test_{}.log".format(time.strftime("%Y%m%d-%H%M%S"))
-        self.logfile = open(self.logfile_name, "w")
+        if not self.logfile_name:
+            self.logfile_name = "/tmp/moonclient_test_{}.log".format(time.strftime("%Y%m%d-%H%M%S"))
+        self.logfile = open(self.logfile_name, "a")
+        self.logfile.write(80*"=" + "\n")
+        self.logfile.write(testfile + "\n\n")
         stdout_back = self.app.stdout
         tests_dict = json.load(open(testfile))
         self.log.debug("tests_dict = {}".format(tests_dict))
@@ -184,7 +195,9 @@ class TestsLaunch(Lister):
                     else:
                         command = test["command"] + " " + global_command_options
                     command = self.__replace_var_in_str(command)
-                    self.logfile.write(time.strftime(self.TIME_FORMAT) + " " + "-----> {}\n".format(command))
+                    self.logfile.write(time.strftime(self.TIME_FORMAT) + " " +
+                                       test["name"] + " " +
+                                       "-----> {}\n".format(command))
                     self.log.info("    \\-executing {}".format(command))
                     self.app.stdout = tmp_filename_fd
                     result_id = self.app.run_subcommand(shlex.split(command))
index 96fb37d..d2ca0e2 100644 (file)
@@ -22,7 +22,7 @@
         "description": "Upload the Cirros image in glance"
       },
       {
-        "name": "nova image-list",
+        "name": "openstack image list",
         "external_command": "nova image-list",
         "result": "(?P<uuid_image>[\\w-]+)\\s+\\| cirros",
         "description": "Get an Image ID"
       },
       {
         "name": "add_subject",
-        "command": "subject add admin --subject_pass nomoresecrete",
+        "command": "subject add admin --subject_pass console",
         "result": "",
         "description": "",
         "command_options": ""
 
       {
         "name": "add_subject",
-        "command": "subject add admin --subject_pass nomoresecrete",
+        "command": "subject add admin --subject_pass console",
         "result": "",
         "description": "Add admin subject.",
         "command_options": ""
       {
         "auth_name": "demo",
         "auth_password": "console",
-        "auth_tenant": "admin",
+        "auth_tenant": "demo",
         "description": "Change user to demo"
       },
 
index 93b39d6..6d8de2e 100644 (file)
@@ -4,6 +4,7 @@
     "authz": [
       {
         "auth_name": "admin",
+        "auth_tenant": "demo",
         "description": "Change user to admin (just in case...)"
       },
 
index 8030294..2ed011b 100755 (executable)
@@ -67,11 +67,12 @@ def test_federation():
 
 
 def test_moon_openstack():
-    cmd = "moon test --password console --self"
+    log_filename = "moonclient_selftest.log"
+    cmd = "moon test --password console --self --logfile {}".format(log_filename)
 
-    ret_val = functest_utils.execute_command(cmd, logger)
+    ret_val = functest_utils.execute_command(cmd, exit_on_error=False)
 
-    return ret_val
+    return ret_val, open(log_filename, "rt").read()
 
 
 def main():
@@ -88,6 +89,10 @@ def main():
     else:
         logger.info("OS MOON ERROR")
         test_status = 'FAIL'
+        logger.info("Errors from OpenStack tests:")
+        logger.info(result_os[1])
+        logger.info("Errors from Federation tests:")
+        logger.info(result_odl[1])
 
     details = {
         'timestart': start_time,