Ejemplo n.º 1
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 sorted(result["data"]["sla"],
                              key=lambda x: x["criterion"]):
                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, sort_keys=False))
        else:
            cliutils.print_list(
                data, ("benchmark", "pos", "criterion", "status", "detail"))
        return failed_criteria
Ejemplo n.º 2
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]
         dlist.append(r["duration"])
         if r["atomic_actions"]:
             for action in atomic_actions:
                 dlist.append(r["atomic_actions"].get(action) or 0)
     cliutils.print_list(table_rows,
                         fields=headers,
                         formatters=formatters)
     print()
Ejemplo 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(objects.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)
        cliutils.print_list(table_rows, headers)
Ejemplo n.º 4
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]))

        for endpoint_dict in self._get_endpoints(deployment):
            self._print_header("Flavors", endpoint_dict)
            table_rows = []
            clients = osclients.Clients(objects.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))))

            cliutils.print_list(table_rows,
                                fields=headers,
                                formatters=formatters,
                                mixed_case_fields=mixed_case_fields)
Ejemplo n.º 5
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)"]
        formatters = dict(zip(float_cols,
                              [cliutils.pretty_float_formatter(col)
                               for col in float_cols]))

        for endpoint_dict in self._get_endpoints(deployment):
            self._print_header("Images", endpoint_dict)
            table_rows = []

            clients = osclients.Clients(objects.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))))

            cliutils.print_list(table_rows,
                                fields=headers,
                                formatters=formatters,
                                mixed_case_fields=mixed_case_fields)
Ejemplo n.º 6
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]))

        for endpoint_dict in self._get_endpoints(deployment):
            self._print_header("Flavors", endpoint_dict)
            table_rows = []
            clients = osclients.Clients(objects.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))))

            cliutils.print_list(table_rows,
                                fields=headers,
                                formatters=formatters,
                                mixed_case_fields=mixed_case_fields)
Ejemplo n.º 7
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)"]
        formatters = dict(
            zip(float_cols,
                [cliutils.pretty_float_formatter(col) for col in float_cols]))

        for endpoint_dict in self._get_endpoints(deployment):
            self._print_header("Images", endpoint_dict)
            table_rows = []

            clients = osclients.Clients(objects.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))))

            cliutils.print_list(table_rows,
                                fields=headers,
                                formatters=formatters,
                                mixed_case_fields=mixed_case_fields)
Ejemplo n.º 8
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(objects.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)
        cliutils.print_list(table_rows, headers)
Ejemplo n.º 9
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(objects.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))))

                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)
Ejemplo n.º 10
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 sorted(result["data"]["sla"],
                              key=lambda x: x["criterion"]):
                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, sort_keys=False))
        else:
            cliutils.print_list(data, ("benchmark", "pos", "criterion",
                                       "status", "detail"))
        return failed_criteria
Ejemplo n.º 11
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]
         dlist.append(r["duration"])
         if r["atomic_actions"]:
             for action in atomic_actions:
                 dlist.append(r["atomic_actions"].get(action) or 0)
     cliutils.print_list(table_rows,
                         fields=headers,
                         formatters=formatters)
     print()
Ejemplo n.º 12
0
    def list(self,
             deployment=None,
             all_deployments=False,
             status=None,
             uuids_only=False):
        """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
        :param uuids_only: list task UUIDs only
        """

        filters = {}
        headers = [
            "uuid", "deployment_name", "created_at", "duration", "status",
            "tag"
        ]

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

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

        task_list = [task.to_dict() for task in objects.Task.list(**filters)]

        for x in task_list:
            x["duration"] = x["updated_at"] - x["created_at"]

        if uuids_only:
            if task_list:
                cliutils.print_list(task_list, ["uuid"],
                                    print_header=False,
                                    print_border=False)
        elif task_list:
            cliutils.print_list(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:\n"
                      "\trally task start") % status)
            else:
                print(
                    _("There are no tasks. To run a new task, use:\n"
                      "\trally task start"))
Ejemplo n.º 13
0
    def list(self, deployment=None, all_deployments=False, status=None,
             uuids_only=False):
        """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
        :param uuids_only: list task UUIDs only
        """

        filters = {}
        headers = ["uuid", "deployment_name", "created_at", "duration",
                   "status", "tag"]

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

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

        task_list = [task.to_dict() for task in objects.Task.list(**filters)]

        for x in task_list:
            x["duration"] = x["updated_at"] - x["created_at"]

        if uuids_only:
            if task_list:
                cliutils.print_list(task_list, ["uuid"],
                                    print_header=False,
                                    print_border=False)
        elif task_list:
            cliutils.print_list(
                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:\n"
                        "\trally task start") % status)
            else:
                print(_("There are no tasks. To run a new task, use:\n"
                        "\trally task start"))
Ejemplo n.º 14
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"
        ]
        cliutils.print_list([verification], fields=total_fields)

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

        values = [
            objects.Verification(test)
            for test in six.itervalues(tests.data["test_cases"])
        ]
        cliutils.print_list(values, fields, sortby_index=sortby_index)

        if detailed:
            for test in six.itervalues(tests.data["test_cases"]):
                if test["status"] == "FAIL":
                    header = cliutils.make_header(
                        "FAIL: %(name)s\n"
                        "Time: %(time)s\n"
                        "Type: %(type)s" % {
                            "name": test["name"],
                            "time": test["time"],
                            "type": test["failure"]["type"]
                        })
                    formatted_test = "%(header)s%(log)s\n" % {
                        "header": header,
                        "log": test["failure"]["log"]
                    }
                    print(formatted_test)
Ejemplo n.º 15
0
    def secgroups(self, deployment=None):
        """Display security groups."""

        headers = ["ID", "Name", "Description"]
        mixed_case_fields = ["ID", "Name", "Description"]
        for endpoint_dict in self._get_endpoints(deployment):
            self._print_header("Security groups", endpoint_dict)
            table_rows = []
            clients = osclients.Clients(objects.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))))
            cliutils.print_list(table_rows,
                                fields=headers,
                                mixed_case_fields=mixed_case_fields)
Ejemplo n.º 16
0
    def list(self):
        """Display all verifications table, started and finished."""

        fields = ["UUID", "Deployment UUID", "Set name", "Tests", "Failures",
                  "Created at", "Duration", "Status"]
        verifications = db.verification_list()

        for el in verifications:
            el["duration"] = el["updated_at"] - el["created_at"]

        if verifications:
            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"))
Ejemplo n.º 17
0
    def keypairs(self, deployment=None):
        """Display available ssh keypairs."""

        headers = ["Name", "Fingerprint"]
        mixed_case_fields = ["Name", "Fingerprint"]

        for endpoint_dict in self._get_endpoints(deployment):
            self._print_header("Keypairs", endpoint_dict)
            table_rows = []
            clients = osclients.Clients(objects.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))))
            cliutils.print_list(table_rows,
                                fields=headers,
                                mixed_case_fields=mixed_case_fields)
Ejemplo n.º 18
0
    def keypairs(self, deployment=None):
        """Display available ssh keypairs."""

        headers = ["Name", "Fingerprint"]
        mixed_case_fields = ["Name", "Fingerprint"]

        for endpoint_dict in self._get_endpoints(deployment):
            self._print_header("Keypairs", endpoint_dict)
            table_rows = []
            clients = osclients.Clients(objects.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))))
            cliutils.print_list(table_rows,
                                fields=headers,
                                mixed_case_fields=mixed_case_fields)
Ejemplo n.º 19
0
    def networks(self, deployment=None):
        """Display configured networks."""

        headers = ["ID", "Label", "CIDR"]
        mixed_case_fields = ["ID", "Label", "CIDR"]

        for endpoint_dict in self._get_endpoints(deployment):
            self._print_header("Networks", endpoint_dict)
            table_rows = []
            clients = osclients.Clients(objects.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))))

            cliutils.print_list(table_rows,
                                fields=headers,
                                mixed_case_fields=mixed_case_fields)
Ejemplo n.º 20
0
    def networks(self, deployment=None):
        """Display configured networks."""

        headers = ["ID", "Label", "CIDR"]
        mixed_case_fields = ["ID", "Label", "CIDR"]

        for endpoint_dict in self._get_endpoints(deployment):
            self._print_header("Networks", endpoint_dict)
            table_rows = []
            clients = osclients.Clients(objects.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))))

            cliutils.print_list(table_rows,
                                fields=headers,
                                mixed_case_fields=mixed_case_fields)
Ejemplo n.º 21
0
    def show(self, deployment=None):
        """Show the endpoints of the deployment.

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

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

        deployment = db.deployment_get(deployment)
        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))))
        cliutils.print_list(table_rows, headers)
Ejemplo n.º 22
0
    def list(self, deployment_list=None):
        """List existing deployments."""

        headers = ["uuid", "created_at", "name", "status", "active"]
        current_deployment = 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_deployment else "*")
                table_rows.append(utils.Struct(**dict(zip(headers, r))))
            cliutils.print_list(table_rows, headers,
                                sortby_index=headers.index("created_at"))
        else:
            print(_("There are no deployments. "
                    "To create a new deployment, use:"
                    "\nrally deployment create"))
Ejemplo n.º 23
0
    def secgroups(self, deployment=None):
        """Display security groups."""

        headers = ["ID", "Name", "Description"]
        mixed_case_fields = ["ID", "Name", "Description"]
        for endpoint_dict in self._get_endpoints(deployment):
            self._print_header("Security groups", endpoint_dict)
            table_rows = []
            clients = osclients.Clients(objects.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))))
            cliutils.print_list(
                table_rows,
                fields=headers,
                mixed_case_fields=mixed_case_fields)
Ejemplo n.º 24
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"]
        cliutils.print_list([verification], fields=total_fields)

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

        values = [objects.Verification(test)
                  for test in six.itervalues(tests.data["test_cases"])]
        cliutils.print_list(values, fields, sortby_index=sortby_index)

        if detailed:
            for test in six.itervalues(tests.data["test_cases"]):
                if test["status"] == "FAIL":
                    header = cliutils.make_header(
                        "FAIL: %(name)s\n"
                        "Time: %(time)s\n"
                        "Type: %(type)s" % {"name": test["name"],
                                            "time": test["time"],
                                            "type": test["failure"]["type"]})
                    formatted_test = "%(header)s%(log)s\n" % {
                        "header": header,
                        "log": test["failure"]["log"]}
                    print (formatted_test)
Ejemplo n.º 25
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(objects.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))))
                    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)
Ejemplo n.º 26
0
    def networks(self, deployment=None):
        """Display configured networks."""

        headers = ["ID", "Label", "CIDR"]
        mixed_case_fields = ["ID", "Label", "CIDR"]
        table_rows = []
        try:
            for endpoint_dict in self._get_endpoints(deployment):
                clients = osclients.Clients(objects.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))))

                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)
Ejemplo n.º 27
0
    def keypairs(self, deployment=None):
        """Display available ssh keypairs."""

        headers = ["Name", "Fingerprint"]
        mixed_case_fields = ["Name", "Fingerprint"]
        table_rows = []
        try:
            for endpoint_dict in self._get_endpoints(deployment):
                clients = osclients.Clients(objects.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))))
                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)
Ejemplo n.º 28
0
    def show(self, deployment=None):
        """Show the endpoints of the deployment.

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

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

        deployment = db.deployment_get(deployment)
        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))))
        cliutils.print_list(table_rows, headers)
Ejemplo n.º 29
0
    def list(self, deployment_list=None):
        """List existing deployments."""

        headers = ["uuid", "created_at", "name", "status", "active"]
        current_deployment = 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_deployment else "*")
                table_rows.append(utils.Struct(**dict(zip(headers, r))))
            cliutils.print_list(table_rows,
                                headers,
                                sortby_index=headers.index("created_at"))
        else:
            print(
                _("There are no deployments. "
                  "To create a new deployment, use:"
                  "\nrally deployment create"))
Ejemplo n.º 30
0
Archivo: show.py Proyecto: auroaj/rally
    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(objects.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))))
                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)
Ejemplo n.º 31
0
    def show(self, task_id=None, print_failures=False):
        """Display results in pass/fail format.

        :param task_id: Task uuid
        """
        results = [{
            "key": x["key"],
            "result": x["data"]["raw"]
        } for x in objects.Task.get(task_id).get_results()]

        successful_scenarios = 0
        STATUS_PASS = "******"
        STATUS_FAIL = "\033[91mFail\033[0m"
        failure_headers = ["Scenario", "ScenarioName", "Error"]
        show_headers = ["Scenario", "ScenarioName", "RunTime", "Result"]
        show_results_row = []
        fail_results_row = []
        total_scenarios = 0

        for index, result in enumerate(results, start=1):
            scenario_duration = 0
            errors = None
            scenario_name = result["key"]["name"]
            times = result["key"]["kw"]["runner"]["times"]
            for repeat in range(times):
                total_scenarios += 1
                scenario_status = STATUS_PASS
                try:
                    scenario_duration = result["result"][repeat]["duration"]
                    errors = result["result"][repeat]["error"]
                except IndexError:
                    errors = ["In-valid Input"]

                scenario_index = str(index) + "." + str(repeat + 1)
                if errors:
                    scenario_status = STATUS_FAIL
                else:
                    successful_scenarios += 1

                results = {
                    "scenario": scenario_index,
                    "scenarioname": scenario_name
                }
                if print_failures and errors:
                    stripped_err = textwrap.dedent(" ".join(errors)).strip()
                    error_info = textwrap.fill(stripped_err, width=40)
                    results["error"] = error_info
                    fail_results_row.append(rutils.Struct(**results))
                else:
                    results["runtime"] = scenario_duration
                    results["result"] = scenario_status
                    show_results_row.append(rutils.Struct(**results))

        if print_failures:
            if len(fail_results_row):
                cliutils.print_list(fail_results_row, fields=failure_headers)
            else:
                print("***********************")
                print("No Failures to Report")
                print("***********************")
        elif not total_scenarios:
            print("***********************")
            print("No Tests to Report")
            print("***********************")
        else:
            pass_percent = (successful_scenarios * 100) / total_scenarios
            failed_scenarios = total_scenarios - successful_scenarios
            fail_percent = 100 - pass_percent

            print("Summary of results")
            print("-------------------")
            print("Total Scenarios  : %s" % (total_scenarios))
            print("Passed Scenarios : %s [%s%%]" %
                  (successful_scenarios, pass_percent))
            print("Failed Scenarios : %s [%s%%]" %
                  (failed_scenarios, fail_percent))
            cliutils.print_list(show_results_row, fields=show_headers)
Ejemplo n.º 32
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]
                dlist.append(r["duration"])
                if r["atomic_actions"]:
                    for action in atomic_actions:
                        dlist.append(r["atomic_actions"].get(action) or 0)
            cliutils.print_list(table_rows,
                                fields=headers,
                                formatters=formatters)
            print()

        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: %(status)s") % {
                "task_id": task_id,
                "status": task["status"]
            })

        if task["status"] == consts.TaskStatus.FAILED:
            print("-" * 80)
            verification = yaml.safe_load(task["verification_log"])

            if not logging.is_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:")
            print(json.dumps(key["kw"], indent=2))

            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))))

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

            if iterations_data:
                _print_iterations_data(raw)

            print(_("Load duration: %s") % result["data"]["load_duration"])
            print(_("Full duration: %s") % result["data"]["full_duration"])

            # 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")
                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"])
Ejemplo n.º 33
0
    def show(self, task_id=None, print_failures=False):
        """Display results in pass/fail format.

        :param task_id: Task uuid
        """
        results = [{"key": x["key"], "result": x["data"]["raw"]}
                   for x in objects.Task.get(task_id).get_results()]

        successful_scenarios = 0
        STATUS_PASS = "******"
        STATUS_FAIL = "\033[91mFail\033[0m"
        failure_headers = ["Scenario", "ScenarioName", "Error"]
        show_headers = ["Scenario", "ScenarioName", "RunTime", "Result"]
        show_results_row = []
        fail_results_row = []
        total_scenarios = 0

        for index, result in enumerate(results, start=1):
            scenario_duration = 0
            errors = None
            scenario_name = result["key"]["name"]
            times = result["key"]["kw"]["runner"]["times"]
            for repeat in range(times):
                total_scenarios += 1
                scenario_status = STATUS_PASS
                try:
                    scenario_duration = result["result"][repeat]["duration"]
                    errors = result["result"][repeat]["error"]
                except IndexError:
                    errors = ["In-valid Input"]

                scenario_index = str(index) + "." + str(repeat + 1)
                if errors:
                    scenario_status = STATUS_FAIL
                else:
                    successful_scenarios += 1

                results = {"scenario": scenario_index,
                           "scenarioname": scenario_name}
                if print_failures and errors:
                    stripped_err = textwrap.dedent(" ".join(errors)).strip()
                    error_info = textwrap.fill(stripped_err, width=40)
                    results["error"] = error_info
                    fail_results_row.append(rutils.Struct(**results))
                else:
                    results["runtime"] = scenario_duration
                    results["result"] = scenario_status
                    show_results_row.append(rutils.Struct(**results))

        if print_failures:
            if len(fail_results_row):
                cliutils.print_list(fail_results_row, fields=failure_headers)
            else:
                print("***********************")
                print("No Failures to Report")
                print("***********************")
        elif not total_scenarios:
            print("***********************")
            print("No Tests to Report")
            print("***********************")
        else:
            pass_percent = (successful_scenarios * 100) / total_scenarios
            failed_scenarios = total_scenarios - successful_scenarios
            fail_percent = 100 - pass_percent

            print("Summary of results")
            print("-------------------")
            print("Total Scenarios  : %s" % (total_scenarios))
            print("Passed Scenarios : %s [%s%%]" % (successful_scenarios,
                  pass_percent))
            print("Failed Scenarios : %s [%s%%]" % (failed_scenarios,
                  fail_percent))
            cliutils.print_list(show_results_row, fields=show_headers)
Ejemplo n.º 34
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]
                dlist.append(r["duration"])
                if r["atomic_actions"]:
                    for action in atomic_actions:
                        dlist.append(r["atomic_actions"].get(action) or 0)
            cliutils.print_list(table_rows,
                                fields=headers,
                                formatters=formatters)
            print()

        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: %(status)s")
              % {"task_id": task_id, "status": task["status"]})

        if task["status"] == consts.TaskStatus.FAILED:
            print("-" * 80)
            verification = yaml.safe_load(task["verification_log"])

            if not logging.is_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:")
            print(json.dumps(key["kw"], indent=2))

            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))))

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

            if iterations_data:
                _print_iterations_data(raw)

            print(_("Load duration: %s") % result["data"]["load_duration"])
            print(_("Full duration: %s") % result["data"]["full_duration"])

            # 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")
                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"])
Ejemplo n.º 35
0
    def test_print_list(self):
        class TestObj(object):
            x = 1
            y = 2
            z = 3.142857142857143
            aOrB = 3            # mixed case field

        out = moves.StringIO()
        cliutils.print_list([TestObj()], ["x", "y"],
                            print_header=True,
                            print_border=True,
                            sortby_index=None,
                            out=out)
        self.assertEqual("+---+---+\n"
                         "| x | y |\n"
                         "+---+---+\n"
                         "| 1 | 2 |\n"
                         "+---+---+",
                         out.getvalue().strip())

        out = moves.StringIO()
        formatter = cliutils.pretty_float_formatter("z", 5)
        cliutils.print_list([TestObj()], ["z"],
                            print_header=True,
                            print_border=True,
                            sortby_index=None,
                            formatters={"z": formatter},
                            out=out)
        self.assertEqual("+---------+\n"
                         "| z       |\n"
                         "+---------+\n"
                         "| 3.14286 |\n"
                         "+---------+",
                         out.getvalue().strip())

        out = moves.StringIO()
        cliutils.print_list([TestObj()], ["x"],
                            print_header=True,
                            print_border=True,
                            out=out)
        self.assertEqual("+---+\n"
                         "| x |\n"
                         "+---+\n"
                         "| 1 |\n"
                         "+---+",
                         out.getvalue().strip())

        out = moves.StringIO()
        cliutils.print_list([TestObj()], ["x", "y"],
                            print_header=True,
                            print_border=True,
                            out=out)
        self.assertEqual("+---+---+\n"
                         "| x | y |\n"
                         "+---+---+\n"
                         "| 1 | 2 |\n"
                         "+---+---+",
                         out.getvalue().strip())

        out = moves.StringIO()
        cliutils.print_list([TestObj()], ["x"],
                            print_header=False,
                            print_border=False,
                            out=out)
        self.assertEqual("1",
                         out.getvalue().strip())

        out = moves.StringIO()
        cliutils.print_list([TestObj()], ["x", "y"],
                            print_header=False,
                            print_border=False,
                            out=out)
        self.assertEqual("1 2",
                         out.getvalue().strip())

        out = moves.StringIO()
        cliutils.print_list([TestObj()], ["x"],
                            print_header=True,
                            print_border=False,
                            out=out)
        self.assertEqual("x \n1",
                         out.getvalue().strip())

        out = moves.StringIO()
        cliutils.print_list([TestObj()], ["x", "y"],
                            print_header=True,
                            print_border=False,
                            out=out)
        self.assertEqual("x y \n1 2",
                         out.getvalue().strip())

        out = moves.StringIO()
        cliutils.print_list([TestObj()], ["x"],
                            print_header=False,
                            print_border=True,
                            out=out)
        self.assertEqual("+--+\n"
                         "|1 |\n"
                         "+--+",
                         out.getvalue().strip())

        out = moves.StringIO()
        cliutils.print_list([TestObj()], ["x", "y"],
                            print_header=False,
                            print_border=True,
                            out=out)
        self.assertEqual("+--+--+\n"
                         "|1 |2 |\n"
                         "+--+--+",
                         out.getvalue().strip())

        out = moves.StringIO()
        cliutils.print_list([TestObj()], ["aOrB"],
                            mixed_case_fields=["aOrB"],
                            print_header=True,
                            print_border=True,
                            out=out)
        self.assertEqual("+------+\n"
                         "| aOrB |\n"
                         "+------+\n"
                         "| 3    |\n"
                         "+------+",
                         out.getvalue().strip())

        out = moves.StringIO()
        cliutils.print_list([TestObj()], ["aOrB"],
                            mixed_case_fields=["aOrB"],
                            print_header=False,
                            print_border=True,
                            out=out)
        self.assertEqual("+--+\n"
                         "|3 |\n"
                         "+--+",
                         out.getvalue().strip())

        out = moves.StringIO()
        cliutils.print_list([TestObj()], ["aOrB"],
                            mixed_case_fields=["aOrB"],
                            print_header=True,
                            print_border=False,
                            out=out)
        self.assertEqual("aOrB \n"
                         "3",
                         out.getvalue().strip())

        out = moves.StringIO()
        cliutils.print_list([TestObj()], ["aOrB"],
                            mixed_case_fields=["aOrB"],
                            print_header=False,
                            print_border=False,
                            out=out)
        self.assertEqual("3",
                         out.getvalue().strip())

        out = moves.StringIO()
        self.assertRaisesRegexp(ValueError,
                                "Field labels list.*has different number "
                                "of elements than fields list",
                                cliutils.print_list,
                                [TestObj()],
                                ["x"],
                                field_labels=["x", "y"],
                                sortby_index=None,
                                out=out)