Esempio n. 1
0
    def check(self, deploy_id=None):
        """Check the deployment.

        Check keystone authentication and list all available services.

        :param deploy_id: a UUID of the deployment
        """
        headers = ['services', 'type', 'status']
        table_rows = []
        try:
            endpoints = db.deployment_get(deploy_id)['endpoints']
            for endpoint_dict in endpoints:
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                client = clients.verified_keystone()
                print("keystone endpoints are valid and following "
                      "services are available:")
                for service in client.service_catalog.get_data():
                    data = [service['name'], service['type'], 'Available']
                    table_rows.append(utils.Struct(**dict(zip(headers, data))))
        except exceptions.InvalidArgumentsException:
            data = ['keystone', 'identity', 'Error']
            table_rows.append(utils.Struct(**dict(zip(headers, data))))
            print(_("Authentication Issues: %s.")
                  % sys.exc_info()[1])
            return(1)
        common_cliutils.print_list(table_rows, headers)
Esempio n. 2
0
    def flavors(self, deploy_id=None):
        """Show the flavors that are available in a deployment.

        :param deploy_id: the UUID of a deployment
        """
        headers = ['ID', 'Name', 'vCPUs', 'RAM (MB)', 'Swap (MB)', 'Disk (GB)']
        mixed_case_fields = ['ID', 'Name', 'vCPUs']
        float_cols = ['RAM (MB)', 'Swap (MB)', 'Disk (GB)']
        formatters = dict(zip(float_cols,
                              [cliutils.pretty_float_formatter(col)
                               for col in float_cols]))
        table_rows = []
        try:
            endpoints = db.deployment_get(deploy_id)['endpoints']
            for endpoint_dict in endpoints:
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                nova_client = clients.nova()
                for flavor in nova_client.flavors.list():
                    data = [flavor.id, flavor.name, flavor.vcpus,
                            flavor.ram, flavor.swap, flavor.disk]
                    table_rows.append(utils.Struct(**dict(zip(headers, data))))

        except exceptions.InvalidArgumentsException:
            print(_("Authentication Issues: %s") % sys.exc_info()[1])
            return(1)
        common_cliutils.print_list(table_rows,
                                   fields=headers,
                                   formatters=formatters,
                                   mixed_case_fields=mixed_case_fields)
Esempio n. 3
0
    def check(self, deployment=None):
        """Check keystone authentication and list all available services.

        :param deployment: a UUID or name of the deployment
        """

        headers = ['services', 'type', 'status']
        table_rows = []
        try:
            admin = db.deployment_get(deployment)['admin']
            # TODO(boris-42): make this work for users in future
            for endpoint_dict in [admin]:
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                client = clients.verified_keystone()
                print("keystone endpoints are valid and following "
                      "services are available:")
                for service in client.services.list():
                    data = [service.name, service.type, 'Available']
                    table_rows.append(utils.Struct(**dict(zip(headers, data))))
        except exceptions.InvalidArgumentsException:
            data = ['keystone', 'identity', 'Error']
            table_rows.append(utils.Struct(**dict(zip(headers, data))))
            print(_("Authentication Issues: %s.")
                  % sys.exc_info()[1])
            return(1)
        common_cliutils.print_list(table_rows, headers)
Esempio n. 4
0
 def _print_iterations_data(raw):
     headers = ['iteration', "full duration"]
     float_cols = ['full duration']
     for i in range(0, len(raw)):
         if raw[i]['atomic_actions']:
             for (c, a) in enumerate(raw[i]['atomic_actions'], 1):
                 action = str(c) + "-" + a['action']
                 headers.append(action)
                 float_cols.append(action)
             break
     table_rows = []
     formatters = dict(zip(float_cols,
                           [cliutils.pretty_float_formatter(col, 3)
                            for col in float_cols]))
     for (c, r) in enumerate(raw, 1):
         dlist = [c]
         d = []
         if r['atomic_actions']:
             for l in r['atomic_actions']:
                 d.append(l['duration'])
             dlist.append(sum(d))
             dlist = dlist + d
             table_rows.append(rutils.Struct(**dict(zip(headers,
                                                        dlist))))
         else:
             data = dlist + ["N/A" for i in range(1, len(headers))]
             table_rows.append(rutils.Struct(**dict(zip(headers,
                                                        data))))
     common_cliutils.print_list(table_rows,
                                fields=headers,
                                formatters=formatters)
     print()
Esempio n. 5
0
    def images(self, deploy_id=None):
        """Display available images.

        :param deploy_id: the UUID of a deployment
        """

        headers = ['UUID', 'Name', 'Size (B)']
        mixed_case_fields = ['UUID', 'Name']
        float_cols = ["Size (B)"]
        table_rows = []
        formatters = dict(zip(float_cols,
                              [cliutils.pretty_float_formatter(col)
                               for col in float_cols]))

        try:
            for endpoint_dict in self._get_endpoints(deploy_id):
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                glance_client = clients.glance()
                for image in glance_client.images.list():
                    data = [image.id, image.name, image.size]
                    table_rows.append(utils.Struct(**dict(zip(headers, data))))

                common_cliutils.print_list(table_rows,
                                           fields=headers,
                                           formatters=formatters,
                                           mixed_case_fields=mixed_case_fields)

        except exceptions.InvalidArgumentsException as e:
            print(_("Authentication Issues: %s") % e)
            return(1)
Esempio n. 6
0
    def images(self, deploy_id=None):
        """Show the images that are available in a deployment.

        :param deploy_id: the UUID of a deployment
        """
        headers = ['UUID', 'Name', 'Size (B)']
        mixed_case_fields = ['UUID', 'Name']
        float_cols = ["Size (B)"]
        table_rows = []
        formatters = dict(zip(float_cols,
                              [cliutils.pretty_float_formatter(col)
                               for col in float_cols]))
        try:
            endpoints = db.deployment_get(deploy_id)['endpoints']
            for endpoint_dict in endpoints:
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                glance_client = clients.glance()
                for image in glance_client.images.list():
                    data = [image.id, image.name, image.size]
                    table_rows.append(utils.Struct(**dict(zip(headers, data))))

        except exceptions.InvalidArgumentsException:
            print(_("Authentication Issues: %s") % sys.exc_info()[1])
            return(1)
        common_cliutils.print_list(table_rows,
                                   fields=headers,
                                   formatters=formatters,
                                   mixed_case_fields=mixed_case_fields)
Esempio n. 7
0
    def flavors(self, deploy_id=None):
        """Display available flavors.

        :param deploy_id: the UUID of a deployment
        """

        headers = ['ID', 'Name', 'vCPUs', 'RAM (MB)', 'Swap (MB)', 'Disk (GB)']
        mixed_case_fields = ['ID', 'Name', 'vCPUs']
        float_cols = ['RAM (MB)', 'Swap (MB)', 'Disk (GB)']
        formatters = dict(zip(float_cols,
                              [cliutils.pretty_float_formatter(col)
                               for col in float_cols]))
        table_rows = []
        try:
            for endpoint_dict in self._get_endpoints(deploy_id):
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                nova_client = clients.nova()
                for flavor in nova_client.flavors.list():
                    data = [flavor.id, flavor.name, flavor.vcpus,
                            flavor.ram, flavor.swap, flavor.disk]
                    table_rows.append(utils.Struct(**dict(zip(headers, data))))

                common_cliutils.print_list(table_rows,
                                           fields=headers,
                                           formatters=formatters,
                                           mixed_case_fields=mixed_case_fields)

        except exceptions.InvalidArgumentsException as e:
            print(_("Authentication Issues: %s") % e)
            return(1)
Esempio n. 8
0
File: task.py Progetto: congto/rally
 def _print_iterations_data(raw):
     headers = ['iteration', "full duration"]
     float_cols = ['full duration']
     for i in range(0, len(raw)):
         if raw[i]['atomic_actions']:
             for (c, a) in enumerate(raw[i]['atomic_actions'], 1):
                 action = str(c) + "-" + a['action']
                 headers.append(action)
                 float_cols.append(action)
             break
     table_rows = []
     formatters = dict(zip(float_cols,
                           [cliutils.pretty_float_formatter(col, 3)
                            for col in float_cols]))
     for (c, r) in enumerate(raw, 1):
         dlist = [c]
         d = []
         if r['atomic_actions']:
             for l in r['atomic_actions']:
                 d.append(l['duration'])
             dlist.append(sum(d))
             dlist = dlist + d
             table_rows.append(rutils.Struct(**dict(zip(headers,
                                                        dlist))))
         else:
             data = dlist + ["N/A" for i in range(1, len(headers))]
             table_rows.append(rutils.Struct(**dict(zip(headers,
                                                        data))))
     common_cliutils.print_list(table_rows,
                                fields=headers,
                                formatters=formatters)
     print()
Esempio n. 9
0
 def _print_iterations_data(raw_data):
     headers = ["iteration", "full duration"]
     float_cols = ["full duration"]
     atomic_actions = []
     for row in raw_data:
         # find first non-error result to get atomic actions names
         if not row["error"] and "atomic_actions" in row:
             atomic_actions = row["atomic_actions"].keys()
     for row in raw_data:
         if row["atomic_actions"]:
             for (c, a) in enumerate(atomic_actions, 1):
                 action = "%(no)i. %(action)s" % {"no": c, "action": a}
                 headers.append(action)
                 float_cols.append(action)
             break
     table_rows = []
     formatters = dict(zip(float_cols,
                           [cliutils.pretty_float_formatter(col, 3)
                            for col in float_cols]))
     for (c, r) in enumerate(raw_data, 1):
         dlist = [c]
         if r["atomic_actions"]:
             dlist.append(r["duration"])
             for action in atomic_actions:
                 dlist.append(r["atomic_actions"].get(action) or 0)
             table_rows.append(rutils.Struct(**dict(zip(headers,
                                                        dlist))))
         else:
             data = dlist + [None for i in range(1, len(headers))]
             table_rows.append(rutils.Struct(**dict(zip(headers,
                                                        data))))
     common_cliutils.print_list(table_rows,
                                fields=headers,
                                formatters=formatters)
     print()
Esempio n. 10
0
    def images(self, deployment=None):
        """Display available images.

        :param deployment: UUID or name of a deployment
        """

        headers = ['UUID', 'Name', 'Size (B)']
        mixed_case_fields = ['UUID', 'Name']
        float_cols = ["Size (B)"]
        table_rows = []
        formatters = dict(zip(float_cols,
                              [cliutils.pretty_float_formatter(col)
                               for col in float_cols]))

        try:
            for endpoint_dict in self._get_endpoints(deployment):
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                glance_client = clients.glance()
                for image in glance_client.images.list():
                    data = [image.id, image.name, image.size]
                    table_rows.append(utils.Struct(**dict(zip(headers, data))))

                common_cliutils.print_list(table_rows,
                                           fields=headers,
                                           formatters=formatters,
                                           mixed_case_fields=mixed_case_fields)

        except exceptions.InvalidArgumentsException as e:
            print(_("Authentication Issues: %s") % e)
            return(1)
Esempio n. 11
0
    def sla_check(self, task_id=None, tojson=False):
        """Display SLA check results table.

        :param task_id: Task uuid.
        :returns: Number of failed criteria.
        """
        results = objects.Task.get(task_id).get_results()
        failed_criteria = 0
        data = []
        STATUS_PASS = "******"
        STATUS_FAIL = "FAIL"
        for result in results:
            key = result["key"]
            for sla in result["data"]["sla"]:
                success = sla.pop("success")
                sla["status"] = success and STATUS_PASS or STATUS_FAIL
                sla["benchmark"] = key["name"]
                sla["pos"] = key["pos"]
                failed_criteria += int(not success)
                data.append(sla if tojson else rutils.Struct(**sla))
        if tojson:
            print(json.dumps(data))
        else:
            common_cliutils.print_list(data, ("benchmark", "pos", "criterion",
                                              "status", "detail"))
        return failed_criteria
Esempio n. 12
0
    def check(self, deploy_id=None):
        """Check the deployment.

        Check keystone authentication and list all available services.

        :param deploy_id: a UUID of the deployment
        """
        headers = ['services', 'type', 'status']
        table_rows = []
        try:
            endpoints = db.deployment_get(deploy_id)['endpoints']
            for endpoint_dict in endpoints:
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                client = clients.verified_keystone()
                print("keystone endpoints are valid and following "
                      "services are available:")
                for service in client.services.list():
                    data = [service.name, service.type, 'Available']
                    table_rows.append(utils.Struct(**dict(zip(headers, data))))
        except exceptions.InvalidArgumentsException:
            data = ['keystone', 'identity', 'Error']
            table_rows.append(utils.Struct(**dict(zip(headers, data))))
            print(_("Authentication Issues: %s.")
                  % sys.exc_info()[1])
            return(1)
        common_cliutils.print_list(table_rows, headers)
Esempio n. 13
0
    def flavors(self, deployment=None):
        """Display available flavors.

        :param deployment: UUID or name of a deployment
        """

        headers = ['ID', 'Name', 'vCPUs', 'RAM (MB)', 'Swap (MB)', 'Disk (GB)']
        mixed_case_fields = ['ID', 'Name', 'vCPUs']
        float_cols = ['RAM (MB)', 'Swap (MB)', 'Disk (GB)']
        formatters = dict(zip(float_cols,
                              [cliutils.pretty_float_formatter(col)
                               for col in float_cols]))
        table_rows = []
        try:
            for endpoint_dict in self._get_endpoints(deployment):
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                nova_client = clients.nova()
                for flavor in nova_client.flavors.list():
                    data = [flavor.id, flavor.name, flavor.vcpus,
                            flavor.ram, flavor.swap, flavor.disk]
                    table_rows.append(utils.Struct(**dict(zip(headers, data))))

                common_cliutils.print_list(table_rows,
                                           fields=headers,
                                           formatters=formatters,
                                           mixed_case_fields=mixed_case_fields)

        except exceptions.InvalidArgumentsException as e:
            print(_("Authentication Issues: %s") % e)
            return(1)
Esempio n. 14
0
 def list(self, task_list=None):
     """Print a list of all tasks."""
     headers = ['uuid', 'created_at', 'status', 'failed', 'tag']
     task_list = task_list or db.task_list()
     if task_list:
         common_cliutils.print_list(task_list, headers)
     else:
         print(_("There are no tasks. To run a new task, use:"
                 "\nrally task start"))
Esempio n. 15
0
 def list(self, task_list=None):
     """Print a list of all tasks."""
     headers = ['uuid', 'created_at', 'status', 'failed', 'tag']
     task_list = task_list or db.task_list()
     if task_list:
         common_cliutils.print_list(task_list, headers)
     else:
         print(
             _("There are no tasks. To run a new task, use:"
               "\nrally task start"))
Esempio n. 16
0
 def list(self):
     """Print a result list of verifications."""
     fields = ['UUID', 'Deployment UUID', 'Set name', 'Tests', 'Failures',
               'Created at', 'Status']
     verifications = db.verification_list()
     if verifications:
         common_cliutils.print_list(verifications, fields, sortby_index=6)
     else:
         print(_("There are no results from verifier. To run a verifier, "
                 "use:\nrally verify start"))
Esempio n. 17
0
    def list(self):
        """Display all verifications table, started and finished."""

        fields = ['UUID', 'Deployment UUID', 'Set name', 'Tests', 'Failures',
                  'Created at', 'Status']
        verifications = db.verification_list()
        if verifications:
            common_cliutils.print_list(verifications, fields,
                                       sortby_index=fields.index('Created at'))
        else:
            print(_("There are no results from verifier. To run a verifier, "
                    "use:\nrally verify start"))
Esempio n. 18
0
    def list(self, task_list=None):
        """List all tasks, started and finished."""

        headers = ['uuid', 'created_at', 'status', 'failed', 'tag']
        task_list = task_list or db.task_list()
        if task_list:
            common_cliutils.print_list(
                task_list, headers, sortby_index=headers.index('created_at'))
        else:
            print(
                _("There are no tasks. To run a new task, use:"
                  "\nrally task start"))
Esempio n. 19
0
 def endpoint(self, deploy_id=None):
     """Print endpoint of the deployment.
     :param deploy_id: a UUID of the deployment
     """
     headers = ['auth_url', 'username', 'password', 'tenant_name',
                'region_name', 'use_public_urls', 'admin_port']
     table_rows = []
     endpoints = db.deployment_get(deploy_id)['endpoints']
     for ep in endpoints:
         data = [ep.get(m, '') for m in headers]
         table_rows.append(utils.Struct(**dict(zip(headers, data))))
     common_cliutils.print_list(table_rows, headers)
Esempio n. 20
0
    def list(self):
        """Display all verifications table, started and finished."""

        fields = ["UUID", "Deployment UUID", "Set name", "Tests", "Failures",
                  "Created at", "Status"]
        verifications = db.verification_list()
        if verifications:
            common_cliutils.print_list(verifications, fields,
                                       sortby_index=fields.index("Created at"))
        else:
            print(_("There are no results from verifier. To run a verifier, "
                    "use:\nrally verify start"))
Esempio n. 21
0
    def list(self, task_list=None):
        """List all tasks, started and finished."""

        headers = ['uuid', 'created_at', 'status', 'failed', 'tag']
        task_list = task_list or db.task_list()
        if task_list:
            common_cliutils.print_list(task_list, headers,
                                       sortby_index=headers.index(
                                           'created_at'))
        else:
            print(_("There are no tasks. To run a new task, use:"
                    "\nrally task start"))
Esempio n. 22
0
    def endpoint(self, deploy_id=None):
        """Print endpoint of the deployment.

        :param deploy_id: a UUID of the deployment
        """
        headers = ['auth_url', 'username', 'password', 'tenant_name',
                   'region_name', 'use_public_urls', 'admin_port']
        table_rows = []
        endpoints = db.deployment_get(deploy_id)['endpoints']
        for ep in endpoints:
            data = [ep.get(m, '') for m in headers]
            table_rows.append(utils.Struct(**dict(zip(headers, data))))
        common_cliutils.print_list(table_rows, headers)
Esempio n. 23
0
    def show(self, verification_uuid=None, sort_by="name", detailed=False):
        """Display results table of the verification."""

        try:
            sortby_index = ("name", "duration").index(sort_by)
        except ValueError:
            print("Sorry, but verification results can't be sorted "
                  "by '%s'." % sort_by)
            return 1

        try:
            verification = db.verification_get(verification_uuid)
            tests = db.verification_result_get(verification_uuid)
        except exceptions.NotFoundException as e:
            print(six.text_type(e))
            return 1

        print("Total results of verification:\n")
        total_fields = [
            "UUID", "Deployment UUID", "Set name", "Tests", "Failures",
            "Created at", "Status"
        ]
        common_cliutils.print_list([verification], fields=total_fields)

        print("\nTests:\n")
        fields = ["name", "time", "status"]

        values = map(objects.Verification,
                     six.itervalues(tests.data["test_cases"]))
        common_cliutils.print_list(values, fields, sortby_index=sortby_index)

        if detailed:
            for test in six.itervalues(tests.data["test_cases"]):
                if test["status"] == "FAIL":
                    formatted_test = (
                        "====================================================="
                        "=================\n"
                        "FAIL: %(name)s\n"
                        "Time: %(time)s\n"
                        "Type: %(type)s\n"
                        "-----------------------------------------------------"
                        "-----------------\n"
                        "%(log)s\n") % {
                            "name": test["name"],
                            "time": test["time"],
                            "type": test["failure"]["type"],
                            "log": test["failure"]["log"]
                        }
                    print(formatted_test)
Esempio n. 24
0
 def list(self):
     """Print a result list of verifications."""
     fields = [
         'UUID', 'Deployment UUID', 'Set name', 'Tests', 'Failures',
         'Created at', 'Status'
     ]
     verifications = db.verification_list()
     if verifications:
         common_cliutils.print_list(verifications,
                                    fields,
                                    sortby_index=fields.index('Created at'))
     else:
         print(
             _("There are no results from verifier. To run a verifier, "
               "use:\nrally verify start"))
Esempio n. 25
0
    def list(self):
        """Display all verifications table, started and finished."""

        fields = [
            "UUID", "Deployment UUID", "Set name", "Tests", "Failures",
            "Created at", "Status"
        ]
        verifications = db.verification_list()
        if verifications:
            common_cliutils.print_list(verifications,
                                       fields,
                                       sortby_index=fields.index("Created at"))
        else:
            print(
                _("There are no results from verifier. To run a verifier, "
                  "use:\nrally verify start"))
Esempio n. 26
0
    def show(self, verification_uuid, sort_by='name', detailed=False):
        try:
            sortby_index = ('name', 'duration').index(sort_by)
        except ValueError:
            print("Sorry, but verification results can't be sorted "
                  "by '%s'." % sort_by)
            return 1

        try:
            verification = db.verification_get(verification_uuid)
            tests = db.verification_result_get(verification_uuid)
        except exceptions.NotFoundException as e:
            print(six.text_type(e))
            return 1

        print("Total results of verification:\n")
        total_fields = [
            'UUID', 'Deployment UUID', 'Set name', 'Tests', 'Failures',
            'Created at', 'Status'
        ]
        common_cliutils.print_list([verification], fields=total_fields)

        print("\nTests:\n")
        fields = ['name', 'time', 'status']

        values = map(objects.Verification,
                     six.itervalues(tests.data['test_cases']))
        common_cliutils.print_list(values, fields, sortby_index=sortby_index)

        if detailed:
            for test in six.itervalues(tests.data['test_cases']):
                if test['status'] == 'FAIL':
                    formatted_test = (
                        '====================================================='
                        '=================\n'
                        'FAIL: %(name)s\n'
                        'Time: %(time)s\n'
                        'Type: %(type)s\n'
                        '-----------------------------------------------------'
                        '-----------------\n'
                        '%(log)s\n') % {
                            'name': test['name'],
                            'time': test['time'],
                            'type': test['failure']['type'],
                            'log': test['failure']['log']
                        }
                    print(formatted_test)
Esempio n. 27
0
    def list(self, deployment_list=None):
        """Print list of deployments."""
        headers = ['uuid', 'created_at', 'name', 'status', 'active']
        current_deploy_id = envutils.get_global('RALLY_DEPLOYMENT')
        deployment_list = deployment_list or db.deployment_list()

        table_rows = []
        if deployment_list:
            for t in deployment_list:
                r = [str(t[column]) for column in headers[:-1]]
                r.append("" if t["uuid"] != current_deploy_id else "*")
                table_rows.append(utils.Struct(**dict(zip(headers, r))))
            common_cliutils.print_list(table_rows, headers)
        else:
            print(_("There are no deployments. "
                    "To create a new deployment, use:"
                    "\nrally deployment create"))
Esempio n. 28
0
    def show(self, verification_uuid, sort_by='name', detailed=False):
        try:
            sortby_index = ('name', 'duration').index(sort_by)
        except ValueError:
            print("Sorry, but verification results can't be sorted "
                  "by '%s'." % sort_by)
            return 1

        try:
            verification = db.verification_get(verification_uuid)
            tests = db.verification_result_get(verification_uuid)
        except exceptions.NotFoundException as e:
            print(six.text_type(e))
            return 1

        print ("Total results of verification:\n")
        total_fields = ['UUID', 'Deployment UUID', 'Set name', 'Tests',
                        'Failures', 'Created at', 'Status']
        common_cliutils.print_list([verification], fields=total_fields,
                                   sortby_index=total_fields.index(
                                       'Created at'))

        print ("\nTests:\n")
        fields = ['name', 'time', 'status']

        values = map(objects.Verification,
                     six.itervalues(tests.data['test_cases']))
        common_cliutils.print_list(values, fields, sortby_index=sortby_index)

        if detailed:
            for test in six.itervalues(tests.data['test_cases']):
                if test['status'] == 'FAIL':
                    formatted_test = (
                        '====================================================='
                        '=================\n'
                        'FAIL: %(name)s\n'
                        'Time: %(time)s\n'
                        'Type: %(type)s\n'
                        '-----------------------------------------------------'
                        '-----------------\n'
                        '%(log)s\n'
                    ) % {
                        'name': test['name'], 'time': test['time'],
                        'type': test['failure']['type'],
                        'log': test['failure']['log']}
                    print (formatted_test)
Esempio n. 29
0
    def show(self, verification_uuid=None, sort_by="name", detailed=False):
        """Display results table of the verification."""

        try:
            sortby_index = ("name", "duration").index(sort_by)
        except ValueError:
            print("Sorry, but verification results can't be sorted "
                  "by '%s'." % sort_by)
            return 1

        try:
            verification = db.verification_get(verification_uuid)
            tests = db.verification_result_get(verification_uuid)
        except exceptions.NotFoundException as e:
            print(six.text_type(e))
            return 1

        print ("Total results of verification:\n")
        total_fields = ["UUID", "Deployment UUID", "Set name", "Tests",
                        "Failures", "Created at", "Status"]
        common_cliutils.print_list([verification], fields=total_fields)

        print ("\nTests:\n")
        fields = ["name", "time", "status"]

        values = map(objects.Verification,
                     six.itervalues(tests.data["test_cases"]))
        common_cliutils.print_list(values, fields, sortby_index=sortby_index)

        if detailed:
            for test in six.itervalues(tests.data["test_cases"]):
                if test["status"] == "FAIL":
                    formatted_test = (
                        "====================================================="
                        "=================\n"
                        "FAIL: %(name)s\n"
                        "Time: %(time)s\n"
                        "Type: %(type)s\n"
                        "-----------------------------------------------------"
                        "-----------------\n"
                        "%(log)s\n"
                    ) % {
                        "name": test["name"], "time": test["time"],
                        "type": test["failure"]["type"],
                        "log": test["failure"]["log"]}
                    print (formatted_test)
Esempio n. 30
0
    def endpoint(self, deploy_id=None):
        """Print all endpoints of the deployment.

        :param deploy_id: a UUID of the deployment
        """
        headers = ['auth_url', 'username', 'password', 'tenant_name',
                   'region_name', 'endpoint_type', 'admin_port']
        table_rows = []

        deployment = db.deployment_get(deploy_id)
        users = deployment.get("users", [])
        admin = deployment.get("admin")
        endpoints = users + [admin] if admin else users

        for ep in endpoints:
            data = [ep.get(m, '') for m in headers]
            table_rows.append(utils.Struct(**dict(zip(headers, data))))
        common_cliutils.print_list(table_rows, headers)
Esempio n. 31
0
    def networks(self, deploy_id=None):
        headers = ['ID', 'Label', 'CIDR']
        mixed_case_fields = ['ID', 'Label', 'CIDR']
        table_rows = []
        try:
            for endpoint_dict in self._get_endpoints(deploy_id):
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                nova_client = clients.nova()
                for network in nova_client.networks.list():
                    data = [network.id, network.label, network.cidr]
                    table_rows.append(utils.Struct(**dict(zip(headers, data))))

                common_cliutils.print_list(table_rows,
                                           fields=headers,
                                           mixed_case_fields=mixed_case_fields)
        except exceptions.InvalidArgumentsException as e:
            print(_("Authentication Issues: %s") % e)
            return(1)
Esempio n. 32
0
    def keypairs(self, deploy_id=None):
        headers = ['Name', 'Fingerprint']
        mixed_case_fields = ['Name', 'Fingerprint']
        table_rows = []
        try:
            for endpoint_dict in self._get_endpoints(deploy_id):
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                nova_client = clients.nova()
                for keypair in nova_client.keypairs.list():
                    data = [keypair.name, keypair.fingerprint]
                    table_rows.append(utils.Struct(**dict(zip(headers, data))))
                common_cliutils.print_list(table_rows,
                                           fields=headers,
                                           mixed_case_fields=mixed_case_fields)

        except exceptions.InvalidArgumentsException as e:
            print(_("Authentication Issues: %s") % e)
            return(1)
Esempio n. 33
0
    def list(self, deployment_list=None):
        """Print list of deployments."""
        headers = ['uuid', 'created_at', 'name', 'status', 'active']
        current_deploy_id = envutils.get_global('RALLY_DEPLOYMENT')
        deployment_list = deployment_list or db.deployment_list()

        table_rows = []
        if deployment_list:
            for t in deployment_list:
                r = [str(t[column]) for column in headers[:-1]]
                r.append("" if t["uuid"] != current_deploy_id else "*")
                table_rows.append(utils.Struct(**dict(zip(headers, r))))
            common_cliutils.print_list(table_rows, headers)
        else:
            print(
                _("There are no deployments. "
                  "To create a new deployment, use:"
                  "\nrally deployment create"))
Esempio n. 34
0
 def networks(self, deploy_id=None):
     headers = ['ID', 'Label', 'CIDR']
     mixed_case_fields = ['ID', 'Label', 'CIDR']
     table_rows = []
     try:
         endpoints = db.deployment_get(deploy_id)['endpoints']
         for endpoint_dict in endpoints:
             clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
         nova_client = clients.nova()
         for network in nova_client.networks.list():
             data = [network.id, network.label, network.cidr]
             table_rows.append(utils.Struct(**dict(zip(headers, data))))
     except exceptions.InvalidArgumentsException:
         print(_("Authentication Issues: %s") % sys.exc_info()[1])
         return (1)
     common_cliutils.print_list(table_rows,
                                fields=headers,
                                mixed_case_fields=mixed_case_fields)
Esempio n. 35
0
 def secgroups(self, deploy_id=None):
     headers = ['ID', 'Name', 'Description']
     mixed_case_fields = ['ID', 'Name', 'Description']
     table_rows = []
     try:
         endpoints = db.deployment_get(deploy_id)['endpoints']
         for endpoint_dict in endpoints:
             clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
             nova_client = clients.nova()
             for secgroup in nova_client.security_groups.list():
                 data = [secgroup.id, secgroup.name, secgroup.description]
                 table_rows.append(utils.Struct(**dict(zip(headers, data))))
     except exceptions.InvalidArgumentsException:
         print(_("Authentication Issues: %s") % sys.exc_info()[1])
         return (1)
     common_cliutils.print_list(table_rows,
                                fields=headers,
                                mixed_case_fields=mixed_case_fields)
Esempio n. 36
0
 def keypairs(self, deploy_id=None):
     headers = ['Name', 'Fingerprint']
     mixed_case_fields = ['Name', 'Fingerprint']
     table_rows = []
     try:
         endpoints = db.deployment_get(deploy_id)['endpoints']
         for endpoint_dict in endpoints:
             clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
             nova_client = clients.nova()
             for keypair in nova_client.keypairs.list():
                 data = [keypair.name, keypair.fingerprint]
                 table_rows.append(utils.Struct(**dict(zip(headers, data))))
     except exceptions.InvalidArgumentsException:
         print(_("Authentication Issues: %s") % sys.exc_info()[1])
         return (1)
     common_cliutils.print_list(table_rows,
                                fields=headers,
                                mixed_case_fields=mixed_case_fields)
Esempio n. 37
0
File: task.py Progetto: congto/rally
    def sla_check(self, task_id=None, tojson=False):
        """Check if task was succeded according to SLA.

        :param task_id: Task uuid.
        :returns: Number of failed criteria.
        """
        task = db.task_get_detailed(task_id)
        failed_criteria = 0
        rows = []
        for row in base_sla.SLA.check_all(task):
            failed_criteria += 0 if row['success'] else 1
            rows.append(row if tojson else rutils.Struct(**row))
        if tojson:
            print(json.dumps(rows))
        else:
            common_cliutils.print_list(rows, ('benchmark', 'pos',
                                              'criterion', 'success'))
        return failed_criteria
Esempio n. 38
0
    def sla_check(self, task_id=None, tojson=False):
        """Check if task was succeded according to SLA.

        :param task_id: Task uuid.
        :returns: Number of failed criteria.
        """
        task = db.task_get_detailed(task_id)
        failed_criteria = 0
        rows = []
        for row in base_sla.SLA.check_all(task):
            failed_criteria += 0 if row['success'] else 1
            rows.append(row if tojson else rutils.Struct(**row))
        if tojson:
            print(json.dumps(rows))
        else:
            common_cliutils.print_list(rows, ('benchmark', 'pos',
                                              'criterion', 'success',
                                              'detail'))
        return failed_criteria
Esempio n. 39
0
    def list(self, deployment=None, all_deployments=False, status=None):
        """List tasks, started and finished.

        Displayed tasks could be filtered by status or deployment.
        By default 'rally task list' will display tasks from active deployment
        without filtering by status.
        :param deployment: UUID or name of deployment
        :param status: task status to filter by.
            Available task statuses are in rally.consts.TaskStatus
        :param all_deployments: display tasks from all deployments
        """

        filters = dict()
        headers = ["uuid", "deployment_name", "created_at", "status",
                   "failed", "tag"]

        if status in consts.TaskStatus:
            filters.setdefault("status", status)
        elif status is not None:
            print(_("Error: Invalid task status '%s'.\n"
                    "Available statuses: %s") % (
                  status, ", ".join(consts.TaskStatus)))
            return(1)

        if not all_deployments:
            filters.setdefault("deployment", deployment)

        task_list = objects.Task.list(**filters)

        if task_list:
            common_cliutils.print_list(map(lambda x: x.to_dict(), task_list),
                                       headers,
                                       sortby_index=headers.index(
                                           'created_at'))
        else:
            if status:
                print(_("There are no tasks in '%s' status. "
                        "To run a new task, use:"
                        "\trally task start") % status)
            else:
                print(_("There are no tasks. To run a new task, use:"
                        "\trally task start"))
Esempio n. 40
0
    def keypairs(self, deploy_id=None):
        """Display available ssh keypairs."""

        headers = ['Name', 'Fingerprint']
        mixed_case_fields = ['Name', 'Fingerprint']
        table_rows = []
        try:
            for endpoint_dict in self._get_endpoints(deploy_id):
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                nova_client = clients.nova()
                for keypair in nova_client.keypairs.list():
                    data = [keypair.name, keypair.fingerprint]
                    table_rows.append(utils.Struct(**dict(zip(headers, data))))
                common_cliutils.print_list(table_rows,
                                           fields=headers,
                                           mixed_case_fields=mixed_case_fields)

        except exceptions.InvalidArgumentsException as e:
            print(_("Authentication Issues: %s") % e)
            return(1)
Esempio n. 41
0
    def networks(self, deploy_id=None):
        """Display configured networks."""

        headers = ['ID', 'Label', 'CIDR']
        mixed_case_fields = ['ID', 'Label', 'CIDR']
        table_rows = []
        try:
            for endpoint_dict in self._get_endpoints(deploy_id):
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                nova_client = clients.nova()
                for network in nova_client.networks.list():
                    data = [network.id, network.label, network.cidr]
                    table_rows.append(utils.Struct(**dict(zip(headers, data))))

                common_cliutils.print_list(table_rows,
                                           fields=headers,
                                           mixed_case_fields=mixed_case_fields)
        except exceptions.InvalidArgumentsException as e:
            print(_("Authentication Issues: %s") % e)
            return(1)
Esempio n. 42
0
 def secgroups(self, deploy_id=None):
     headers = ['ID', 'Name', 'Description']
     mixed_case_fields = ['ID', 'Name', 'Description']
     table_rows = []
     try:
         endpoints = db.deployment_get(deploy_id)['endpoints']
         for endpoint_dict in endpoints:
             clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
             nova_client = clients.nova()
             for secgroup in nova_client.security_groups.list():
                 data = [secgroup.id, secgroup.name,
                         secgroup.description]
                 table_rows.append(utils.Struct(**dict(zip(headers,
                                                           data))))
     except exceptions.InvalidArgumentsException:
         print(_("Authentication Issues: %s") % sys.exc_info()[1])
         return(1)
     common_cliutils.print_list(table_rows,
                                fields=headers,
                                mixed_case_fields=mixed_case_fields)
Esempio n. 43
0
    def show(self, deploy_id=None):
        """Show the endpoints of the deployment.

        :param deploy_id: a UUID of the deployment
        """

        headers = [
            'auth_url', 'username', 'password', 'tenant_name', 'region_name',
            'endpoint_type', 'admin_port'
        ]
        table_rows = []

        deployment = db.deployment_get(deploy_id)
        users = deployment.get("users", [])
        admin = deployment.get("admin")
        endpoints = users + [admin] if admin else users

        for ep in endpoints:
            data = [ep.get(m, '') for m in headers]
            table_rows.append(utils.Struct(**dict(zip(headers, data))))
        common_cliutils.print_list(table_rows, headers)
Esempio n. 44
0
    def sla_check(self, task_id=None, tojson=False):
        """Display SLA check results table.

        :param task_id: Task uuid.
        :returns: Number of failed criteria.
        """
        task = db.task_result_get_all_by_uuid(task_id)
        failed_criteria = 0
        results = []
        for result in task:
            key = result["key"]
            for sla in result["data"]["sla"]:
                sla["benchmark"] = key["name"]
                sla["pos"] = key["pos"]
                failed_criteria += 0 if sla['success'] else 1
                results.append(sla if tojson else rutils.Struct(**sla))
        if tojson:
            print(json.dumps(results))
        else:
            common_cliutils.print_list(
                results,
                ('benchmark', 'pos', 'criterion', 'success', 'detail'))
        return failed_criteria
Esempio n. 45
0
    def secgroups(self, deploy_id=None):
        """Display security groups."""

        headers = ['ID', 'Name', 'Description']
        mixed_case_fields = ['ID', 'Name', 'Description']
        table_rows = []
        try:
            for endpoint_dict in self._get_endpoints(deploy_id):
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                nova_client = clients.nova()
                for secgroup in nova_client.security_groups.list():
                    data = [secgroup.id, secgroup.name,
                            secgroup.description]
                    table_rows.append(utils.Struct(**dict(zip(headers,
                                                              data))))
                    common_cliutils.print_list(
                        table_rows,
                        fields=headers,
                        mixed_case_fields=mixed_case_fields)

        except exceptions.InvalidArgumentsException as e:
            print(_("Authentication Issues: %s") % e)
            return(1)
Esempio n. 46
0
    def secgroups(self, deployment=None):
        """Display security groups."""

        headers = ['ID', 'Name', 'Description']
        mixed_case_fields = ['ID', 'Name', 'Description']
        table_rows = []
        try:
            for endpoint_dict in self._get_endpoints(deployment):
                clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
                nova_client = clients.nova()
                for secgroup in nova_client.security_groups.list():
                    data = [secgroup.id, secgroup.name,
                            secgroup.description]
                    table_rows.append(utils.Struct(**dict(zip(headers,
                                                              data))))
                    common_cliutils.print_list(
                        table_rows,
                        fields=headers,
                        mixed_case_fields=mixed_case_fields)

        except exceptions.InvalidArgumentsException as e:
            print(_("Authentication Issues: %s") % e)
            return(1)
Esempio n. 47
0
    def sla_check(self, task_id=None, tojson=False):
        """Check if task was succeded according to SLA.

        :param task_id: Task uuid.
        :returns: Number of failed criteria.
        """
        task = db.task_result_get_all_by_uuid(task_id)
        failed_criteria = 0
        results = []
        for result in task:
            key = result["key"]
            for sla in result["data"]["sla"]:
                sla["benchmark"] = key["name"]
                sla["pos"] = key["pos"]
                failed_criteria += 0 if sla['success'] else 1
                results.append(sla if tojson else rutils.Struct(**sla))
        if tojson:
            print(json.dumps(results))
        else:
            common_cliutils.print_list(results, ('benchmark', 'pos',
                                                 'criterion', 'success',
                                                 'detail'))
        return failed_criteria
Esempio n. 48
0
 def _print_iterations_data(raw_data):
     headers = ["iteration", "full duration"]
     float_cols = ["full duration"]
     atomic_actions = []
     for row in raw_data:
         # find first non-error result to get atomic actions names
         if not row["error"] and "atomic_actions" in row:
             atomic_actions = row["atomic_actions"].keys()
     for row in raw_data:
         if row["atomic_actions"]:
             for (c, a) in enumerate(atomic_actions, 1):
                 action = "%(no)i. %(action)s" % {"no": c, "action": a}
                 headers.append(action)
                 float_cols.append(action)
             break
     table_rows = []
     formatters = dict(
         zip(float_cols, [
             cliutils.pretty_float_formatter(col, 3)
             for col in float_cols
         ]))
     for (c, r) in enumerate(raw_data, 1):
         dlist = [c]
         if r["atomic_actions"]:
             dlist.append(r["duration"])
             for action in atomic_actions:
                 dlist.append(r["atomic_actions"].get(action) or 0)
             table_rows.append(
                 rutils.Struct(**dict(zip(headers, dlist))))
         else:
             data = dlist + [None for i in range(1, len(headers))]
             table_rows.append(
                 rutils.Struct(**dict(zip(headers, data))))
     common_cliutils.print_list(table_rows,
                                fields=headers,
                                formatters=formatters)
     print()
Esempio n. 49
0
    def detailed(self, task_id=None, iterations_data=False):
        """Display results table.

        :param task_id: Task uuid
        :param iterations_data: print detailed results for each iteration
        Prints detailed information of task.
        """
        def _print_iterations_data(raw_data):
            headers = ["iteration", "full duration"]
            float_cols = ["full duration"]
            atomic_actions = []
            for row in raw_data:
                # find first non-error result to get atomic actions names
                if not row["error"] and "atomic_actions" in row:
                    atomic_actions = row["atomic_actions"].keys()
            for row in raw_data:
                if row["atomic_actions"]:
                    for (c, a) in enumerate(atomic_actions, 1):
                        action = "%(no)i. %(action)s" % {"no": c, "action": a}
                        headers.append(action)
                        float_cols.append(action)
                    break
            table_rows = []
            formatters = dict(
                zip(float_cols, [
                    cliutils.pretty_float_formatter(col, 3)
                    for col in float_cols
                ]))
            for (c, r) in enumerate(raw_data, 1):
                dlist = [c]
                if r["atomic_actions"]:
                    dlist.append(r["duration"])
                    for action in atomic_actions:
                        dlist.append(r["atomic_actions"].get(action) or 0)
                    table_rows.append(
                        rutils.Struct(**dict(zip(headers, dlist))))
                else:
                    data = dlist + [None for i in range(1, len(headers))]
                    table_rows.append(
                        rutils.Struct(**dict(zip(headers, data))))
            common_cliutils.print_list(table_rows,
                                       fields=headers,
                                       formatters=formatters)
            print()

        if task_id == "last":
            task = db.task_get_detailed_last()
            task_id = task.uuid
        else:
            task = db.task_get_detailed(task_id)

        if task is None:
            print("The task %s can not be found" % task_id)
            return (1)

        print()
        print("=" * 80)
        print(
            _("Task %(task_id)s is %(status)s.") % {
                "task_id": task_id,
                "status": task["status"]
            })

        if task["failed"]:
            print("-" * 80)
            verification = yaml.safe_load(task["verification_log"])

            if not cfg.CONF.debug:
                print(verification[0])
                print(verification[1])
                print()
                print(
                    _("For more details run:\nrally -vd task detailed %s") %
                    task["uuid"])
            else:
                print(yaml.safe_load(verification[2]))
            return

        for result in task["results"]:
            key = result["key"]
            print("-" * 80)
            print()
            print("test scenario %s" % key["name"])
            print("args position %s" % key["pos"])
            print("args values:")
            pprint.pprint(key["kw"])

            scenario_time = result["data"]["scenario_duration"]
            raw = result["data"]["raw"]
            table_cols = [
                "action", "min (sec)", "avg (sec)", "max (sec)",
                "90 percentile", "95 percentile", "success", "count"
            ]
            float_cols = [
                "min (sec)", "avg (sec)", "max (sec)", "90 percentile",
                "95 percentile"
            ]
            formatters = dict(
                zip(float_cols, [
                    cliutils.pretty_float_formatter(col, 3)
                    for col in float_cols
                ]))
            table_rows = []

            actions_data = utils.get_atomic_actions_data(raw)
            for action in actions_data:
                durations = actions_data[action]
                if durations:
                    data = [
                        action,
                        min(durations),
                        utils.mean(durations),
                        max(durations),
                        utils.percentile(durations, 0.90),
                        utils.percentile(durations, 0.95),
                        "%.1f%%" % (len(durations) * 100.0 / len(raw)),
                        len(raw)
                    ]
                else:
                    data = [
                        action, None, None, None, None, None, "0.0%",
                        len(raw)
                    ]
                table_rows.append(rutils.Struct(**dict(zip(table_cols, data))))

            common_cliutils.print_list(table_rows,
                                       fields=table_cols,
                                       formatters=formatters)

            if iterations_data:
                _print_iterations_data(raw)

            print(_("Whole scenario time without context preparation: "),
                  scenario_time)

            # NOTE(hughsaunders): ssrs=scenario specific results
            ssrs = []
            for result in raw:
                data = result["scenario_output"].get("data")
                if data:
                    ssrs.append(data)
            if ssrs:
                keys = set()
                for ssr in ssrs:
                    keys.update(ssr.keys())
                headers = [
                    "key", "max", "avg", "min", "90 pecentile", "95 pecentile"
                ]
                float_cols = [
                    "max", "avg", "min", "90 pecentile", "95 pecentile"
                ]
                formatters = dict(
                    zip(float_cols, [
                        cliutils.pretty_float_formatter(col, 3)
                        for col in float_cols
                    ]))
                table_rows = []
                for key in keys:
                    values = [float(ssr[key]) for ssr in ssrs if key in ssr]

                    if values:
                        row = [
                            str(key),
                            max(values),
                            utils.mean(values),
                            min(values),
                            utils.percentile(values, 0.90),
                            utils.percentile(values, 0.95)
                        ]
                    else:
                        row = [str(key)] + ['n/a'] * 5
                    table_rows.append(rutils.Struct(**dict(zip(headers, row))))
                print("\nScenario Specific Results\n")
                common_cliutils.print_list(table_rows,
                                           fields=headers,
                                           formatters=formatters)

                for result in raw:
                    errors = result["scenario_output"].get("errors")
                    if errors:
                        print(errors)

        print()
        print("HINTS:")
        print(_("* To plot HTML graphics with this data, run:"))
        print("\trally task report %s --out output.html" % task["uuid"])
        print()
        print(_("* To get raw JSON output of task results, run:"))
        print("\trally task results %s\n" % task["uuid"])
Esempio n. 50
0
File: task.py Progetto: congto/rally
    def detailed(self, task_id=None, iterations_data=False):
        """Get detailed information about task

        :param task_id: Task uuid
        :param iterations_data: print detailed results for each iteration
        Prints detailed information of task.
        """
        def _print_iterations_data(raw):
            headers = ['iteration', "full duration"]
            float_cols = ['full duration']
            for i in range(0, len(raw)):
                if raw[i]['atomic_actions']:
                    for (c, a) in enumerate(raw[i]['atomic_actions'], 1):
                        action = str(c) + "-" + a['action']
                        headers.append(action)
                        float_cols.append(action)
                    break
            table_rows = []
            formatters = dict(zip(float_cols,
                                  [cliutils.pretty_float_formatter(col, 3)
                                   for col in float_cols]))
            for (c, r) in enumerate(raw, 1):
                dlist = [c]
                d = []
                if r['atomic_actions']:
                    for l in r['atomic_actions']:
                        d.append(l['duration'])
                    dlist.append(sum(d))
                    dlist = dlist + d
                    table_rows.append(rutils.Struct(**dict(zip(headers,
                                                               dlist))))
                else:
                    data = dlist + ["N/A" for i in range(1, len(headers))]
                    table_rows.append(rutils.Struct(**dict(zip(headers,
                                                               data))))
            common_cliutils.print_list(table_rows,
                                       fields=headers,
                                       formatters=formatters)
            print()

        def _get_atomic_action_durations(raw):
            atomic_actions_names = []
            for r in raw:
                if 'atomic_actions' in r:
                    for a in r['atomic_actions']:
                        atomic_actions_names.append(a["action"])
                    break
            result = {}
            for atomic_action in atomic_actions_names:
                result[atomic_action] = utils.get_durations(
                    raw,
                    lambda r: next(a["duration"] for a in r["atomic_actions"]
                                   if a["action"] == atomic_action),
                    lambda r: any((a["action"] == atomic_action)
                                  for a in r["atomic_actions"]))
            return result

        if task_id == "last":
            task = db.task_get_detailed_last()
            task_id = task.uuid
        else:
            task = db.task_get_detailed(task_id)

        if task is None:
            print("The task %s can not be found" % task_id)
            return(1)

        print()
        print("=" * 80)
        print(_("Task %(task_id)s is %(status)s.")
              % {"task_id": task_id, "status": task["status"]})

        if task["failed"]:
            print("-" * 80)
            verification = yaml.safe_load(task["verification_log"])

            if not cfg.CONF.debug:
                print(verification[0])
                print(verification[1])
                print()
                print(_("For more details run:\nrally -vd task detailed %s")
                      % task["uuid"])
            else:
                print(yaml.safe_load(verification[2]))
            return

        for result in task["results"]:
            key = result["key"]
            print("-" * 80)
            print()
            print("test scenario %s" % key["name"])
            print("args position %s" % key["pos"])
            print("args values:")
            pprint.pprint(key["kw"])

            raw = result["data"]["raw"]
            table_cols = ["action", "min (sec)", "avg (sec)", "max (sec)",
                          "90 percentile", "95 percentile", "success",
                          "count"]
            float_cols = ["min (sec)", "avg (sec)", "max (sec)",
                          "90 percentile", "95 percentile"]
            formatters = dict(zip(float_cols,
                                  [cliutils.pretty_float_formatter(col, 3)
                                   for col in float_cols]))
            table_rows = []

            action_durations = _get_atomic_action_durations(raw)
            actions_list = action_durations.keys()
            action_durations["total"] = utils.get_durations(
                        raw, lambda x: x["duration"], lambda r: not r["error"])
            actions_list.append("total")
            for action in actions_list:
                durations = action_durations[action]
                if durations:
                    data = [action,
                            min(durations),
                            utils.mean(durations),
                            max(durations),
                            utils.percentile(durations, 0.90),
                            utils.percentile(durations, 0.95),
                            "%.1f%%" % (len(durations) * 100.0 / len(raw)),
                            len(raw)]
                else:
                    data = [action, None, None, None, None, None, 0, len(raw)]
                table_rows.append(rutils.Struct(**dict(zip(table_cols, data))))

            common_cliutils.print_list(table_rows, fields=table_cols,
                                       formatters=formatters)

            if iterations_data:
                _print_iterations_data(raw)

            # NOTE(hughsaunders): ssrs=scenario specific results
            ssrs = []
            for result in raw:
                data = result["scenario_output"].get("data")
                if data:
                    ssrs.append(data)
            if ssrs:
                keys = set()
                for ssr in ssrs:
                    keys.update(ssr.keys())
                headers = ["key", "max", "avg", "min",
                           "90 pecentile", "95 pecentile"]
                float_cols = ["max", "avg", "min",
                              "90 pecentile", "95 pecentile"]
                formatters = dict(zip(float_cols,
                                  [cliutils.pretty_float_formatter(col, 3)
                                   for col in float_cols]))
                table_rows = []
                for key in keys:
                    values = [float(ssr[key]) for ssr in ssrs if key in ssr]

                    if values:
                        row = [str(key),
                               max(values),
                               utils.mean(values),
                               min(values),
                               utils.percentile(values, 0.90),
                               utils.percentile(values, 0.95)]
                    else:
                        row = [str(key)] + ['n/a'] * 5
                    table_rows.append(rutils.Struct(**dict(zip(headers, row))))
                print("\nScenario Specific Results\n")
                common_cliutils.print_list(table_rows,
                                           fields=headers,
                                           formatters=formatters)

                for result in raw:
                    errors = result["scenario_output"].get("errors")
                    if errors:
                        print(errors)

        print()
        print("HINTS:")
        print(_("* To plot HTML graphics with this data, run:"))
        print("\trally task plot2html %s --out output.html" % task["uuid"])
        print()
        print(_("* To get raw JSON output of task results, run:"))
        print("\trally task results %s\n" % task["uuid"])
Esempio n. 51
0
    def detailed(self, task_id=None, iterations_data=False):
        """Get detailed information about task

        :param task_id: Task uuid
        :param iterations_data: print detailed results for each iteration
        Prints detailed information of task.
        """
        def _print_iterations_data(raw_data):
            headers = ["iteration", "full duration"]
            float_cols = ["full duration"]
            atomic_actions = []
            for row in raw_data:
                # find first non-error result to get atomic actions names
                if not row["error"] and "atomic_actions" in row:
                    atomic_actions = row["atomic_actions"].keys()
            for row in raw_data:
                if row["atomic_actions"]:
                    for (c, a) in enumerate(atomic_actions, 1):
                        action = "%(no)i. %(action)s" % {"no": c, "action": a}
                        headers.append(action)
                        float_cols.append(action)
                    break
            table_rows = []
            formatters = dict(zip(float_cols,
                                  [cliutils.pretty_float_formatter(col, 3)
                                   for col in float_cols]))
            for (c, r) in enumerate(raw_data, 1):
                dlist = [c]
                if r["atomic_actions"]:
                    dlist.append(r["duration"])
                    for action in atomic_actions:
                        dlist.append(r["atomic_actions"].get(action) or 0)
                    table_rows.append(rutils.Struct(**dict(zip(headers,
                                                               dlist))))
                else:
                    data = dlist + [None for i in range(1, len(headers))]
                    table_rows.append(rutils.Struct(**dict(zip(headers,
                                                               data))))
            common_cliutils.print_list(table_rows,
                                       fields=headers,
                                       formatters=formatters)
            print()

        if task_id == "last":
            task = db.task_get_detailed_last()
            task_id = task.uuid
        else:
            task = db.task_get_detailed(task_id)

        if task is None:
            print("The task %s can not be found" % task_id)
            return(1)

        print()
        print("=" * 80)
        print(_("Task %(task_id)s is %(status)s.")
              % {"task_id": task_id, "status": task["status"]})

        if task["failed"]:
            print("-" * 80)
            verification = yaml.safe_load(task["verification_log"])

            if not cfg.CONF.debug:
                print(verification[0])
                print(verification[1])
                print()
                print(_("For more details run:\nrally -vd task detailed %s")
                      % task["uuid"])
            else:
                print(yaml.safe_load(verification[2]))
            return

        for result in task["results"]:
            key = result["key"]
            print("-" * 80)
            print()
            print("test scenario %s" % key["name"])
            print("args position %s" % key["pos"])
            print("args values:")
            pprint.pprint(key["kw"])

            scenario_time = result["data"]["scenario_duration"]
            raw = result["data"]["raw"]
            table_cols = ["action", "min (sec)", "avg (sec)", "max (sec)",
                          "90 percentile", "95 percentile", "success",
                          "count"]
            float_cols = ["min (sec)", "avg (sec)", "max (sec)",
                          "90 percentile", "95 percentile"]
            formatters = dict(zip(float_cols,
                                  [cliutils.pretty_float_formatter(col, 3)
                                   for col in float_cols]))
            table_rows = []

            actions_data = utils.get_atomic_actions_data(raw)
            for action in actions_data:
                durations = actions_data[action]
                if durations:
                    data = [action,
                            min(durations),
                            utils.mean(durations),
                            max(durations),
                            utils.percentile(durations, 0.90),
                            utils.percentile(durations, 0.95),
                            "%.1f%%" % (len(durations) * 100.0 / len(raw)),
                            len(raw)]
                else:
                    data = [action, None, None, None, None, None,
                            "0.0%", len(raw)]
                table_rows.append(rutils.Struct(**dict(zip(table_cols, data))))

            common_cliutils.print_list(table_rows, fields=table_cols,
                                       formatters=formatters)

            if iterations_data:
                _print_iterations_data(raw)

            print(_("Whole scenario time without context preparation: "),
                  scenario_time)

            # NOTE(hughsaunders): ssrs=scenario specific results
            ssrs = []
            for result in raw:
                data = result["scenario_output"].get("data")
                if data:
                    ssrs.append(data)
            if ssrs:
                keys = set()
                for ssr in ssrs:
                    keys.update(ssr.keys())
                headers = ["key", "max", "avg", "min",
                           "90 pecentile", "95 pecentile"]
                float_cols = ["max", "avg", "min",
                              "90 pecentile", "95 pecentile"]
                formatters = dict(zip(float_cols,
                                  [cliutils.pretty_float_formatter(col, 3)
                                   for col in float_cols]))
                table_rows = []
                for key in keys:
                    values = [float(ssr[key]) for ssr in ssrs if key in ssr]

                    if values:
                        row = [str(key),
                               max(values),
                               utils.mean(values),
                               min(values),
                               utils.percentile(values, 0.90),
                               utils.percentile(values, 0.95)]
                    else:
                        row = [str(key)] + ['n/a'] * 5
                    table_rows.append(rutils.Struct(**dict(zip(headers, row))))
                print("\nScenario Specific Results\n")
                common_cliutils.print_list(table_rows,
                                           fields=headers,
                                           formatters=formatters)

                for result in raw:
                    errors = result["scenario_output"].get("errors")
                    if errors:
                        print(errors)

        print()
        print("HINTS:")
        print(_("* To plot HTML graphics with this data, run:"))
        print("\trally task report %s --out output.html" % task["uuid"])
        print()
        print(_("* To get raw JSON output of task results, run:"))
        print("\trally task results %s\n" % task["uuid"])
Esempio n. 52
0
    def detailed(self, task_id=None, iterations_data=False):
        """Get detailed information about task

        :param task_id: Task uuid
        :param iterations_data: print detailed results for each iteration
        Prints detailed information of task.
        """
        def _print_iterations_data(raw):
            headers = ['iteration', "full duration"]
            float_cols = ['full duration']
            for i in range(0, len(raw)):
                if raw[i]['atomic_actions']:
                    for (c, a) in enumerate(raw[i]['atomic_actions'], 1):
                        action = str(c) + "-" + a['action']
                        headers.append(action)
                        float_cols.append(action)
                    break
            table_rows = []
            formatters = dict(zip(float_cols,
                                  [cliutils.pretty_float_formatter(col, 3)
                                   for col in float_cols]))
            for (c, r) in enumerate(raw, 1):
                dlist = [c]
                d = []
                if r['atomic_actions']:
                    for l in r['atomic_actions']:
                        d.append(l['duration'])
                    dlist.append(sum(d))
                    dlist = dlist + d
                    table_rows.append(rutils.Struct(**dict(zip(headers,
                                                               dlist))))
                else:
                    data = dlist + ["N/A" for i in range(1, len(headers))]
                    table_rows.append(rutils.Struct(**dict(zip(headers,
                                                               data))))
            common_cliutils.print_list(table_rows,
                                       fields=headers,
                                       formatters=formatters)
            print()

        def _get_atomic_action_durations(raw):
            atomic_actions_names = []
            for r in raw:
                if 'atomic_actions' in r:
                    for a in r['atomic_actions']:
                        atomic_actions_names.append(a["action"])
                    break
            result = {}
            for atomic_action in atomic_actions_names:
                result[atomic_action] = utils.get_durations(
                    raw,
                    lambda r: next(a["duration"] for a in r["atomic_actions"]
                                   if a["action"] == atomic_action),
                    lambda r: any((a["action"] == atomic_action)
                                  for a in r["atomic_actions"]))
            return result

        if task_id == "last":
            task = db.task_get_detailed_last()
            task_id = task.uuid
        else:
            task = db.task_get_detailed(task_id)

        if task is None:
            print("The task %s can not be found" % task_id)
            return(1)

        print()
        print("=" * 80)
        print(_("Task %(task_id)s is %(status)s.")
              % {"task_id": task_id, "status": task["status"]})

        if task["failed"]:
            print("-" * 80)
            verification = yaml.safe_load(task["verification_log"])

            if not cfg.CONF.debug:
                print(verification[0])
                print(verification[1])
                print()
                print(_("For more details run:\nrally -vd task detailed %s")
                      % task["uuid"])
            else:
                print(yaml.safe_load(verification[2]))
            return

        for result in task["results"]:
            key = result["key"]
            print("-" * 80)
            print()
            print("test scenario %s" % key["name"])
            print("args position %s" % key["pos"])
            print("args values:")
            pprint.pprint(key["kw"])

            scenario_time = result["data"]["scenario_duration"]
            raw = result["data"]["raw"]
            table_cols = ["action", "min (sec)", "avg (sec)", "max (sec)",
                          "90 percentile", "95 percentile", "success",
                          "count"]
            float_cols = ["min (sec)", "avg (sec)", "max (sec)",
                          "90 percentile", "95 percentile"]
            formatters = dict(zip(float_cols,
                                  [cliutils.pretty_float_formatter(col, 3)
                                   for col in float_cols]))
            table_rows = []

            action_durations = _get_atomic_action_durations(raw)
            actions_list = action_durations.keys()
            action_durations["total"] = utils.get_durations(
                        raw, lambda x: x["duration"], lambda r: not r["error"])
            actions_list.append("total")
            for action in actions_list:
                durations = action_durations[action]
                if durations:
                    data = [action,
                            min(durations),
                            utils.mean(durations),
                            max(durations),
                            utils.percentile(durations, 0.90),
                            utils.percentile(durations, 0.95),
                            "%.1f%%" % (len(durations) * 100.0 / len(raw)),
                            len(raw)]
                else:
                    data = [action, None, None, None, None, None, 0, len(raw)]
                table_rows.append(rutils.Struct(**dict(zip(table_cols, data))))

            common_cliutils.print_list(table_rows, fields=table_cols,
                                       formatters=formatters)

            if iterations_data:
                _print_iterations_data(raw)

            print(_("Whole scenario time without context preparation: "),
                  scenario_time)

            # NOTE(hughsaunders): ssrs=scenario specific results
            ssrs = []
            for result in raw:
                data = result["scenario_output"].get("data")
                if data:
                    ssrs.append(data)
            if ssrs:
                keys = set()
                for ssr in ssrs:
                    keys.update(ssr.keys())
                headers = ["key", "max", "avg", "min",
                           "90 pecentile", "95 pecentile"]
                float_cols = ["max", "avg", "min",
                              "90 pecentile", "95 pecentile"]
                formatters = dict(zip(float_cols,
                                  [cliutils.pretty_float_formatter(col, 3)
                                   for col in float_cols]))
                table_rows = []
                for key in keys:
                    values = [float(ssr[key]) for ssr in ssrs if key in ssr]

                    if values:
                        row = [str(key),
                               max(values),
                               utils.mean(values),
                               min(values),
                               utils.percentile(values, 0.90),
                               utils.percentile(values, 0.95)]
                    else:
                        row = [str(key)] + ['n/a'] * 5
                    table_rows.append(rutils.Struct(**dict(zip(headers, row))))
                print("\nScenario Specific Results\n")
                common_cliutils.print_list(table_rows,
                                           fields=headers,
                                           formatters=formatters)

                for result in raw:
                    errors = result["scenario_output"].get("errors")
                    if errors:
                        print(errors)

        print()
        print("HINTS:")
        print(_("* To plot HTML graphics with this data, run:"))
        print("\trally task plot2html %s --out output.html" % task["uuid"])
        print()
        print(_("* To get raw JSON output of task results, run:"))
        print("\trally task results %s\n" % task["uuid"])