Added tempest subcommand for subunit_describe_calls

We are adding a subcommand to tempest that is a parser for subunit
streams to determine what REST API calls are made inside of a test
and in what order they are called. Right now the implementation of
utility is as a console script and which is in argparse.

We are porting it to cliff to give a similar experience across
the codebase.

Change-Id: If95042898d8b2a148246c991d73d1a577fbcf7a0
Signed-off-by: Soniya Vyas <svyas@redhat.com>
diff --git a/releasenotes/notes/subunit_describe_calls-ad7df689b9d63e3f.yaml b/releasenotes/notes/subunit_describe_calls-ad7df689b9d63e3f.yaml
new file mode 100644
index 0000000..e7fc3a0
--- /dev/null
+++ b/releasenotes/notes/subunit_describe_calls-ad7df689b9d63e3f.yaml
@@ -0,0 +1,8 @@
+---
+deprecations:
+  - |
+    Deprecated command for subunit-describe-calls
+
+features:
+  - |
+    Added new tempest subcommand for subunit-describe-calls
diff --git a/setup.cfg b/setup.cfg
index 5c1d24c..1e9b8e9 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -36,6 +36,7 @@
     subunit-describe-calls = tempest.cmd.subunit_describe_calls:entry_point
 tempest.cm =
     account-generator = tempest.cmd.account_generator:TempestAccountGenerator
+    subunit-describe-calls = tempest.cmd.subunit_describe_calls:TempestSubunitDescribeCalls
     init = tempest.cmd.init:TempestInit
     cleanup = tempest.cmd.cleanup:TempestCleanup
     list-plugins = tempest.cmd.list_plugins:TempestListPlugins
diff --git a/tempest/cmd/subunit_describe_calls.py b/tempest/cmd/subunit_describe_calls.py
index 081fa7a..e029538 100644
--- a/tempest/cmd/subunit_describe_calls.py
+++ b/tempest/cmd/subunit_describe_calls.py
@@ -81,13 +81,19 @@
 import os
 import re
 import sys
+import traceback
 
+from cliff.command import Command
 from oslo_serialization import jsonutils as json
 import subunit
 import testtools
 
 
+DESCRIPTION = "Outputs all HTTP calls a given test made that were logged."
+
+
 class UrlParser(testtools.TestResult):
+
     uuid_re = re.compile(r'(^|[^0-9a-f])[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-'
                          '[0-9a-f]{4}-[0-9a-f]{12}([^0-9a-f]|$)')
     id_re = re.compile(r'(^|[^0-9a-z])[0-9a-z]{8}[0-9a-z]{4}[0-9a-z]{4}'
@@ -241,33 +247,12 @@
 
 
 class ArgumentParser(argparse.ArgumentParser):
+
     def __init__(self):
-        desc = "Outputs all HTTP calls a given test made that were logged."
+        desc = DESCRIPTION
         super(ArgumentParser, self).__init__(description=desc)
-
         self.prog = "subunit-describe-calls"
-
-        self.add_argument(
-            "-s", "--subunit", metavar="<subunit file>",
-            nargs="?", type=argparse.FileType('rb'), default=sys.stdin,
-            help="The path to the subunit output file.")
-
-        self.add_argument(
-            "-n", "--non-subunit-name", metavar="<non subunit name>",
-            default="pythonlogging",
-            help="The name used in subunit to describe the file contents.")
-
-        self.add_argument(
-            "-o", "--output-file", metavar="<output file>", default=None,
-            help="The output file name for the json.")
-
-        self.add_argument(
-            "-p", "--ports", metavar="<ports file>", default=None,
-            help="A JSON file describing the ports for each service.")
-
-        self.add_argument(
-            "-v", "--verbose", action='store_true', default=False,
-            help="Add Request and Response header and body data to stdout.")
+        _parser_add_args(self)
 
 
 def parse(stream, non_subunit_name, ports):
@@ -321,11 +306,63 @@
         sys.stdout.write('\n')
 
 
-def entry_point():
-    cl_args = ArgumentParser().parse_args()
+def entry_point(cl_args=None):
+    print('Running subunit_describe_calls ...')
+    if not cl_args:
+        print("Use of: 'subunit-describe-calls' is deprecated, "
+              "please use: 'tempest subunit-describe-calls'")
+        cl_args = ArgumentParser().parse_args()
     parser = parse(cl_args.subunit, cl_args.non_subunit_name, cl_args.ports)
     output(parser, cl_args.output_file, cl_args.verbose)
 
 
+def _parser_add_args(parser):
+    parser.add_argument(
+        "-s", "--subunit", metavar="<subunit file>",
+        nargs="?", type=argparse.FileType('rb'), default=sys.stdin,
+        help="The path to the subunit output file(default:stdin v1/v2 stream)"
+    )
+
+    parser.add_argument(
+        "-n", "--non-subunit-name", metavar="<non subunit name>",
+        default="pythonlogging",
+        help="The name used in subunit to describe the file contents."
+    )
+
+    parser.add_argument(
+        "-o", "--output-file", metavar="<output file>", default=None,
+        help="The output file name for the json."
+    )
+
+    parser.add_argument(
+        "-p", "--ports", metavar="<ports file>", default=None,
+        help="A JSON file describing the ports for each service."
+    )
+
+    parser.add_argument(
+        "-v", "--verbose", action='store_true', default=False,
+        help="Add Request and Response header and body data to stdout."
+    )
+
+
+class TempestSubunitDescribeCalls(Command):
+
+    def get_parser(self, prog_name):
+        parser = super(TempestSubunitDescribeCalls, self).get_parser(prog_name)
+        _parser_add_args(parser)
+        return parser
+
+    def take_action(self, parsed_args):
+        try:
+            entry_point(parsed_args)
+
+        except Exception:
+            traceback.print_exc()
+            raise
+
+    def get_description(self):
+        return DESCRIPTION
+
+
 if __name__ == "__main__":
     entry_point()