Exemple #1
0
 def list(self, api, verifier_id=None, deployment=None, tags=None,
          status=None):
     """List all verifications."""
     verifications = api.verification.list(verifier_id, deployment, tags,
                                           status)
     if verifications:
         fields = ["UUID", "Tags", "Verifier name", "Deployment name",
                   "Started at", "Finished at", "Duration", "Status"]
         formatters = {
             "Tags": lambda v: ", ".join(v.tags) or "-",
             "Verifier name": (
                 lambda v: api.verifier.get(v.verifier_uuid).name),
             "Deployment name": (
                 lambda v: api.deployment.get(v.deployment_uuid)["name"]),
             "Started at": lambda v: v.created_at.replace(microsecond=0),
             "Finished at": lambda v: v.updated_at.replace(microsecond=0),
             "Duration": lambda v: (v.updated_at.replace(microsecond=0) -
                                    v.created_at.replace(microsecond=0))
         }
         cliutils.print_list(verifications, fields, formatters=formatters,
                             normalize_field_names=True, sortby_index=4)
     elif verifier_id or deployment or status or tags:
         print(_("There are no verifications that meet specified filter "
                 "arguments."))
     else:
         print(_("There are no verifications. You can start verification, "
                 "using command `rally verify start`."))
Exemple #2
0
    def check(self, api, deployment=None):
        """Check all credentials and list all available services.

        :param deployment: UUID or name of the deployment
        """
        def is_field_there(lst, field):
            return bool([item for item in lst if field in item])

        def print_error(user_type, error):
            print(_("Error while checking %s credentials:") % user_type)
            if logging.is_debug():
                print(error["trace"])
            else:
                print("\t%s: %s" % (error["etype"], error["msg"]))

        exit_code = 0

        info = api.deployment.check(deployment)
        for platform in info:
            for i, credentials in enumerate(info[platform]):
                failed = False

                n = "" if len(info[platform]) == 1 else " #%s" % (i + 1)
                header = "Platform %s%s:" % (platform, n)
                print(cliutils.make_header(header))
                if "admin_error" in credentials:
                    print_error("admin", credentials["admin_error"])
                    failed = True
                if "user_error" in credentials:
                    print_error("users", credentials["user_error"])
                    failed = True

                if not failed:
                    print("Available services:")
                    formatters = {
                        "Service": lambda x: x.get("name"),
                        "Service Type": lambda x: x.get("type"),
                        "Status": lambda x: x.get("status", "Available")
                    }
                    if (is_field_there(credentials["services"], "type") and
                            is_field_there(credentials["services"], "name")):
                        headers = ["Service", "Service Type", "Status"]
                    else:
                        headers = ["Service", "Status"]

                    if is_field_there(credentials["services"], "version"):
                        headers.append("Version")

                    if is_field_there(credentials["services"], "description"):
                        headers.append("Description")

                    cliutils.print_list(credentials["services"],
                                        headers,
                                        normalize_field_names=True,
                                        formatters=formatters)
                else:
                    exit_code = 1
                print("\n")

        return exit_code
Exemple #3
0
    def list_verifiers(self, api, status=None):
        """List all verifiers."""

        verifiers = api.verifier.list(status=status)
        if verifiers:
            fields = [
                "UUID", "Name", "Type", "Platform", "Created at", "Updated at",
                "Status", "Version", "System-wide", "Active"
            ]
            cv = envutils.get_global(envutils.ENV_VERIFIER)
            formatters = {
                "Created at": lambda v: v["created_at"],
                "Updated at": lambda v: v["updated_at"],
                "Active": lambda v: ACTIVE if v["uuid"] == cv else "",
            }
            cliutils.print_list(verifiers,
                                fields,
                                formatters=formatters,
                                normalize_field_names=True,
                                sortby_index=4)
        elif status:
            print("There are no verifiers with status '%s'." % status)
        else:
            print("There are no verifiers. You can create verifier, using "
                  "command `rally verify create-verifier`.")
Exemple #4
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 = api.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
Exemple #5
0
    def check(self, deployment=None):
        """Check keystone authentication and list all available services.

        :param deployment: UUID or name of the deployment
        """
        headers = ["services", "type", "status"]
        table_rows = []
        try:
            deployment = api.Deployment.get(deployment)

        except exceptions.DeploymentNotFound:
            print(_("Deployment %s is not found.") % deployment)
            return (1)

        try:
            services = api.Deployment.check(deployment)
        except keystone_exceptions.ConnectionRefused:
            print(_("Unable to connect %s.") % deployment["admin"]["auth_url"])
            return (1)

        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)

        for serv_type, serv in services.items():
            data = [serv, serv_type, "Available"]
            table_rows.append(utils.Struct(**dict(zip(headers, data))))
        print(
            _("keystone endpoints are valid and following"
              " services are available:"))
        cliutils.print_list(table_rows, headers)
Exemple #6
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:
            deployment = db.deployment_get(deployment)
            admin = deployment.get("admin")
            clients = osclients.Clients(objects.Endpoint(**admin))
            client = clients.verified_keystone()
            for service in client.services.list():
                data = [service.name, service.type, "Available"]
                table_rows.append(utils.Struct(**dict(zip(headers, data))))
            users = deployment.get("users")
            for endpoint_dict in users:
                osclients.Clients(objects.Endpoint(**endpoint_dict)).keystone()
            print(
                _("keystone endpoints are valid and following"
                  " services are available:"))
        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)
Exemple #7
0
    def _print_plugins_list(plugin_list):
        rows = [
            utils.Struct(name=f.get_name(), namespace=f.get_namespace(), title=f.get_info()["title"])
            for f in plugin_list
        ]

        cliutils.print_list(rows, fields=["name", "namespace", "title"])
Exemple #8
0
    def show(self, api, deployment=None):
        """Show the credentials of the deployment.

        :param deployment: UUID or name of the deployment
        """
        # TODO(astudenov): make this method platform independent

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

        deployment = api.deployment.get(deployment)

        creds = deployment["credentials"]["openstack"][0]
        users = creds["users"]
        admin = creds["admin"]
        credentials = users + [admin] if admin else users
        for ep in credentials:
            data = [
                "***" if m == "password" else ep.get(m, "") for m in headers
            ]
            table_rows.append(utils.Struct(**dict(zip(headers, data))))
        cliutils.print_list(table_rows, headers)
Exemple #9
0
 def _print_iterations_data(result):
     raw_data = result["data"]["raw"]
     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)
         table_rows.append(rutils.Struct(**dict(zip(headers,
                                                    dlist))))
     cliutils.print_list(table_rows,
                         fields=headers,
                         formatters=formatters)
     print()
Exemple #10
0
    def list(self, api, verifier_id=None, deployment=None, tags=None,
             status=None):
        """List all verifications."""

        verifications = api.verification.list(verifier_id=verifier_id,
                                              deployment_id=deployment,
                                              tags=tags, status=status)
        if verifications:
            fields = ["UUID", "Tags", "Verifier name", "Deployment name",
                      "Started at", "Finished at", "Duration", "Status"]
            formatters = {
                "Tags": lambda v: ", ".join(v["tags"]) or "-",
                "Verifier name": (lambda v: api.verifier.get(
                    verifier_id=v["verifier_uuid"])["name"]),
                "Deployment name": (lambda v: api.deployment.get(
                    deployment=v["deployment_uuid"])["name"]),
                "Started at": lambda v: v["created_at"],
                "Finished at": lambda v: v["updated_at"],
                "Duration": lambda v: (dt.datetime.strptime(v["updated_at"],
                                                            TIME_FORMAT) -
                                       dt.datetime.strptime(v["created_at"],
                                                            TIME_FORMAT))
            }
            cliutils.print_list(verifications, fields, formatters=formatters,
                                normalize_field_names=True, sortby_index=4)
        elif verifier_id or deployment or status or tags:
            print("There are no verifications that meet specified criteria.")
        else:
            print("There are no verifications. You can start verification, "
                  "using command `rally verify start`.")
Exemple #11
0
    def sla_check(self, api, task_id=None, tojson=False):
        """Display SLA check results table."""

        task = api.task.get(task_id=task_id, detailed=True)
        failed_criteria = 0
        data = []
        STATUS_PASS = "******"
        STATUS_FAIL = "FAIL"
        for workload in itertools.chain(
                *[s["workloads"] for s in task["subtasks"]]):
            for sla in sorted(workload["sla_results"].get("sla", []),
                              key=lambda x: x["criterion"]):
                success = sla.pop("success")
                sla["status"] = success and STATUS_PASS or STATUS_FAIL
                sla["benchmark"] = workload["name"]
                sla["pos"] = workload["position"]
                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"))
        if not data:
            return 2
        return failed_criteria
Exemple #12
0
 def _print_iterations_data(result):
     raw_data = result["data"]["raw"]
     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)
         table_rows.append(rutils.Struct(**dict(zip(headers, dlist))))
     cliutils.print_list(table_rows,
                         fields=headers,
                         formatters=formatters)
     print()
Exemple #13
0
    def show(self, name, namespace=None):
        """Show detailed information about a Rally plugin."""
        name_lw = name.lower()
        all_plugins = plugin.Plugin.get_all(namespace=namespace)
        found = [p for p in all_plugins if name_lw in p.get_name().lower()]
        exact_match = [p for p in found if name_lw == p.get_name().lower()]

        if not found:
            if namespace:
                print(
                    "There is no plugin: %(name)s in %(namespace)s namespace" % {"name": name, "namespace": namespace}
                )
            else:
                print("There is no plugin: %s" % name)

        elif len(found) == 1 or exact_match:
            plugin_ = found[0] if len(found) == 1 else exact_match[0]
            plugin_info = plugin_.get_info()
            print(cliutils.make_header(plugin_info["title"]))
            print("NAME\n\t%s" % plugin_info["name"])
            print("NAMESPACE\n\t%s" % plugin_info["namespace"])
            print("MODULE\n\t%s" % plugin_info["module"])
            if plugin_info["description"]:
                print("DESCRIPTION\n\t", end="")
                print(textwrap.fill(plugin_info["description"], subsequent_indent="\t"))
            if plugin_info["parameters"]:
                print("PARAMETERS")
                rows = [utils.Struct(name=p["name"], description="g%s\n" % p["doc"]) for p in plugin_info["parameters"]]
                cliutils.print_list(rows, fields=["name", "description"])
        else:
            print("Multiple plugins found:")
            self._print_plugins_list(found)
Exemple #14
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)
Exemple #15
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:
            deployment = api.Deployment.get(deployment)

        except exceptions.DeploymentNotFound:
            print(_("Deployment %s is not found.") % deployment)
            return(1)

        try:
            services = api.Deployment.check(deployment)
        except keystone_exceptions.ConnectionRefused:
            print(_("Unable to connect %s.") % deployment["admin"]["auth_url"])
            return(1)

        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)

        for serv_type, serv in services.items():
            data = [serv, serv_type, "Available"]
            table_rows.append(utils.Struct(**dict(zip(headers, data))))
        print(_("keystone endpoints are valid and following"
              " services are available:"))
        cliutils.print_list(table_rows, headers)
Exemple #16
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)
Exemple #17
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)
Exemple #18
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)
Exemple #19
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)
Exemple #20
0
    def list(self,
             deployment=None,
             all_deployments=False,
             status=None,
             uuids_only=False):
        """List tasks, started and finished.

        Displayed tasks can be filtered by status or deployment.  By
        default 'rally task list' will display tasks from the 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 api.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"))
Exemple #21
0
    def show(self, verification=None, sort_by="name", detailed=False):
        """Display results table of a verification.

        :param verification: UUID of a verification
        :param sort_by: Sort results by 'name' or 'duration'
        :param detailed: Display detailed errors of failed tests
        """
        try:
            verification = api.Verification.get(verification)
            tests = verification.get_results()
        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"]

        results = tests["test_cases"]
        values = [utils.Struct(**results[test_name]) for test_name in results]
        sortby_index = ("name", "duration").index(sort_by)
        cliutils.print_list(values, fields, sortby_index=sortby_index)

        if detailed:
            for test in six.itervalues(tests["test_cases"]):
                if test["status"] == "fail":
                    header = cliutils.make_header(
                        "FAIL: %(name)s\n" "Time: %(time)s" % {"name": test["name"], "time": test["time"]}
                    )
                    formatted_test = "%(header)s%(log)s\n" % {"header": header, "log": test["traceback"]}
                    print(formatted_test)
Exemple #22
0
 def list_verifiers(self, api, status=None):
     """List all verifiers."""
     verifiers = api.verifier.list(status)
     if verifiers:
         fields = [
             "UUID", "Name", "Type", "Namespace", "Created at",
             "Updated at", "Status", "Version", "System-wide", "Active"
         ]
         cv = envutils.get_global(envutils.ENV_VERIFIER)
         formatters = {
             "Created at": lambda v: v.created_at.replace(microsecond=0),
             "Updated at": lambda v: v.updated_at.replace(microsecond=0),
             "Active": lambda v: u"\u2714" if v.uuid == cv else "",
         }
         cliutils.print_list(verifiers,
                             fields,
                             formatters=formatters,
                             normalize_field_names=True,
                             sortby_index=4)
     elif status:
         print(_("There are no verifiers with status '%s'.") % status)
     else:
         print(
             _("There are no verifiers. You can create verifier, using "
               "command `rally verify create-verifier`."))
Exemple #23
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 = api.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
Exemple #24
0
    def _print_plugins_list(plugin_list):
        rows = [
            utils.Struct(name=f.get_name(),
                         namespace=f.get_namespace(),
                         title=f.get_info()["title"]) for f in plugin_list
        ]

        cliutils.print_list(rows, fields=["name", "namespace", "title"])
Exemple #25
0
    def list(self, api, deployment=None, all_deployments=False, status=None,
             tags=None, uuids_only=False):
        """List tasks, started and finished.

        Displayed tasks can be filtered by status or deployment.  By
        default 'rally task list' will display tasks from the active
        deployment without filtering by status.
        """

        filters = {}
        headers = ["UUID", "Deployment name", "Created at", "Load duration",
                   "Status", "Tag(s)"]

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

        if not all_deployments:
            filters["deployment"] = deployment

        if tags:
            filters["tags"] = tags

        task_list = api.task.list(**filters)

        if uuids_only:
            if task_list:
                print("\n".join([t["uuid"] for t in task_list]))
        elif task_list:
            def tags_formatter(t):
                if not t["tags"]:
                    return ""
                return "'%s'" % "', '".join(t["tags"])

            formatters = {
                "Tag(s)": tags_formatter,
                "Load duration": cliutils.pretty_float_formatter(
                    "task_duration", 3),
                "Created at": lambda t: t["created_at"].replace("T", " ")
            }

            cliutils.print_list(
                task_list, fields=headers, normalize_field_names=True,
                sortby_index=headers.index("Created at"),
                formatters=formatters)
        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")
Exemple #26
0
    def list(self, api, deployment=None, all_deployments=False, status=None,
             tags=None, uuids_only=False):
        """List tasks, started and finished.

        Displayed tasks can be filtered by status or deployment.  By
        default 'rally task list' will display tasks from the active
        deployment without filtering by status.
        """

        filters = {}
        headers = ["UUID", "Deployment name", "Created at", "Load duration",
                   "Status", "Tag(s)"]

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

        if not all_deployments:
            filters["deployment"] = deployment

        if tags:
            filters["tags"] = tags

        task_list = api.task.list(**filters)

        if uuids_only:
            if task_list:
                print("\n".join([t["uuid"] for t in task_list]))
        elif task_list:
            def tags_formatter(t):
                if not t["tags"]:
                    return ""
                return "'%s'" % "', '".join(t["tags"])

            formatters = {
                "Tag(s)": tags_formatter,
                "Load duration": cliutils.pretty_float_formatter(
                    "task_duration", 3),
                "Created at": lambda t: t["created_at"].replace("T", " ")
            }

            cliutils.print_list(
                task_list, fields=headers, normalize_field_names=True,
                sortby_index=headers.index("Created at"),
                formatters=formatters)
        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")
Exemple #27
0
    def check(self, api, deployment=None):
        """Check all credentials and list all available services."""

        def is_field_there(lst, field):
            return bool([item for item in lst if field in item])

        def print_error(user_type, error):
            print("Error while checking %s credentials:" % user_type)
            if logging.is_debug():
                print(error["trace"])
            else:
                print("\t%s: %s" % (error["etype"], error["msg"]))

        exit_code = 0

        info = api.deployment.check(deployment=deployment)
        for platform in info:
            for i, credentials in enumerate(info[platform]):
                failed = False

                n = "" if len(info[platform]) == 1 else " #%s" % (i + 1)
                header = "Platform %s%s:" % (platform, n)
                print(cliutils.make_header(header))
                if "admin_error" in credentials:
                    print_error("admin", credentials["admin_error"])
                    failed = True
                if "user_error" in credentials:
                    print_error("users", credentials["user_error"])
                    failed = True

                if not failed:
                    print("Available services:")
                    formatters = {
                        "Service": lambda x: x.get("name"),
                        "Service Type": lambda x: x.get("type"),
                        "Status": lambda x: x.get("status", "Available")}
                    if (is_field_there(credentials["services"], "type") and
                            is_field_there(credentials["services"], "name")):
                        headers = ["Service", "Service Type", "Status"]
                    else:
                        headers = ["Service", "Status"]

                    if is_field_there(credentials["services"], "version"):
                        headers.append("Version")

                    if is_field_there(credentials["services"], "description"):
                        headers.append("Description")

                    cliutils.print_list(credentials["services"], headers,
                                        normalize_field_names=True,
                                        formatters=formatters)
                else:
                    exit_code = 1
                print("\n")

        return exit_code
Exemple #28
0
    def _print_plugins_list(plugin_list):
        formatters = {
            "Name": lambda p: p.get_name(),
            "Platform": lambda p: p.get_platform(),
            "Title": lambda p: p.get_info()["title"],
            "Plugin base": lambda p: p._get_base().__name__
        }

        cliutils.print_list(plugin_list, formatters=formatters,
                            normalize_field_names=True,
                            fields=["Plugin base", "Name", "Platform",
                                    "Title"])
Exemple #29
0
    def list(self, deployment=None, all_deployments=False, status=None,
             uuids_only=False):
        """List tasks, started and finished.

        Displayed tasks can be filtered by status or deployment.  By
        default 'rally task list' will display tasks from the 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 api.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"))
Exemple #30
0
    def _print_plugins_list(plugin_list):
        formatters = {
            "Name": lambda p: p.get_name(),
            "Platform": lambda p: p.get_platform(),
            "Title": lambda p: p.get_info()["title"],
            "Plugin base": lambda p: p._get_base().__name__
        }

        cliutils.print_list(plugin_list, formatters=formatters,
                            normalize_field_names=True,
                            fields=["Plugin base", "Name", "Platform",
                                    "Title"])
Exemple #31
0
def _print_tabular_resources(resources, table_label):
    cliutils.print_list(
        objs=[dict(r) for r in resources],
        fields=("class", "resource_name", "identifiers"),
        field_labels=("service", "resource type", "identifiers"),
        table_label=table_label,
        formatters={"identifiers":
                    lambda d: " ".join("%s:%s" % (k, v)
                                       for k, v in d.items()
                                       if k not in ("class", "resource_name"))}
    )
    print("")
Exemple #32
0
def _print_tabular_resources(resources, table_label):
    cliutils.print_list(
        objs=[dict(r) for r in resources],
        fields=("class", "resource_name", "identifiers"),
        field_labels=("service", "resource type", "identifiers"),
        table_label=table_label,
        formatters={"identifiers":
                    lambda d: " ".join("%s:%s" % (k, v)
                                       for k, v in d.items()
                                       if k not in ("class", "resource_name"))}
    )
    print("")
Exemple #33
0
def _print_tabular_resources(resources, table_label):
    def dict_formatter(d):
        return "\n".join("%s:%s" % (k, v) for k, v in d.items())

    cliutils.print_list(
        objs=[dict(r) for r in resources],
        fields=("cls", "resource_name", "id", "fields"),
        field_labels=("service", "resource type", "id", "fields"),
        table_label=table_label,
        formatters={"id": lambda d: dict_formatter(d["id"]),
                    "fields": lambda d: dict_formatter(d["props"])}
    )
    print("")
Exemple #34
0
    def list(self):
        """List verification runs."""

        fields = ["UUID", "Deployment UUID", "Set name", "Tests", "Failures", "Created at", "Duration", "Status"]
        verifications = api.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(_("No verification was started yet. " "To start verification use:\nrally verify start"))
Exemple #35
0
    def list_verifier_exts(self, api, verifier_id=None):
        """List all verifier extensions."""

        verifier_exts = api.verifier.list_extensions(verifier_id=verifier_id)
        if verifier_exts:
            fields = ["Name", "Entry point"]
            if logging.is_debug():
                fields.append("Location")
            cliutils.print_list(verifier_exts, fields,
                                normalize_field_names=True)
        else:
            print("There are no verifier extensions. You can add verifier "
                  "extension, using command `rally verify add-verifier-ext`.")
Exemple #36
0
    def list_plugins(self, api, namespace=None):
        """List all plugins for verifiers management."""
        if namespace:
            namespace = namespace.lower()
        verifier_plugins = api.verifier.list_plugins(namespace)

        fields = ["Plugin name", "Namespace", "Description"]
        if logging.is_debug():
            fields.append("Location")

        cliutils.print_list(verifier_plugins, fields,
                            formatters={"Plugin name": lambda p: p["name"]},
                            normalize_field_names=True)
def _print_tabular_resources(resources, table_label):
    def dict_formatter(d):
        return "\n".join("%s:%s" % (k, v) for k, v in d.items())

    cliutils.print_list(
        objs=[dict(r) for r in resources],
        fields=("cls", "resource_name", "id", "fields"),
        field_labels=("service", "resource type", "id", "fields"),
        table_label=table_label,
        formatters={"id": lambda d: dict_formatter(d["id"]),
                    "fields": lambda d: dict_formatter(d["props"])}
    )
    print("")
Exemple #38
0
    def list_plugins(self, api, platform=None):
        """List all plugins for verifiers management."""

        if platform:
            platform = platform.lower()
        verifier_plugins = api.verifier.list_plugins(platform=platform)

        fields = ["Plugin name", "Platform", "Description"]
        if logging.is_debug():
            fields.append("Location")

        cliutils.print_list(verifier_plugins, fields,
                            formatters={"Plugin name": lambda p: p["name"]},
                            normalize_field_names=True)
Exemple #39
0
    def secgroups(self, deployment=None):
        """Display security groups."""

        headers = ["ID", "Name", "Description"]
        mixed_case_fields = ["ID", "Name", "Description"]
        for credential_dict in self._get_credentials(deployment):
            self._print_header("Security groups", credential_dict)
            table_rows = []
            clients = osclients.Clients(objects.Credential(**credential_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)
Exemple #40
0
        def _print_ssrs_result(result):
            raw = result["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", "min", "median", "90%ile", "95%ile", "max", "avg"
                ]
                float_cols = [
                    "min", "median", "90%ile", "95%ile", "max", "avg"
                ]
                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),
                            round(min(values), 3),
                            round(utils.median(values), 3),
                            round(utils.percentile(values, 0.90), 3),
                            round(utils.percentile(values, 0.95), 3),
                            round(max(values), 3),
                            round(utils.mean(values), 3)
                        ]
                    else:
                        row = [str(key)] + ["n/a"] * 6
                    table_rows.append(rutils.Struct(**dict(zip(headers, row))))
                print("\nScenario Specific Results\n")
                cliutils.print_list(table_rows,
                                    fields=headers,
                                    formatters=formatters,
                                    table_label="Response Times (sec)")

                for result in raw:
                    errors = result["scenario_output"].get("errors")
                    if errors:
                        print(errors)
Exemple #41
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)
Exemple #42
0
    def keypairs(self, deployment=None):
        """Display available ssh keypairs."""

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

        for credential_dict in self._get_credentials(deployment):
            self._print_header("Keypairs", credential_dict)
            table_rows = []
            clients = osclients.Clients(objects.Credential(**credential_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)
Exemple #43
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"))
Exemple #44
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)
Exemple #45
0
    def list(self):
        """Display all verifications table, started and finished."""

        fields = ["UUID", "Deployment UUID", "Set name", "Tests", "Failures",
                  "Created at", "Duration", "Status"]
        verifications = api.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"))
Exemple #46
0
    def networks(self, deployment=None):
        """Display configured networks."""

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

        for credential_dict in self._get_credentials(deployment):
            self._print_header("Networks", credential_dict)
            table_rows = []
            clients = osclients.Clients(objects.Credential(**credential_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)
Exemple #47
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)
Exemple #48
0
        def _print_ssrs_result(result):
            raw = result["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", "min", "median",
                           "90%ile", "95%ile", "max",
                           "avg"]
                float_cols = ["min", "median", "90%ile",
                              "95%ile", "max", "avg"]
                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),
                               round(min(values), 3),
                               round(utils.median(values), 3),
                               round(utils.percentile(values, 0.90), 3),
                               round(utils.percentile(values, 0.95), 3),
                               round(max(values), 3),
                               round(utils.mean(values), 3)]
                    else:
                        row = [str(key)] + ["n/a"] * 6
                    table_rows.append(rutils.Struct(**dict(zip(headers,
                                                               row))))
                print("\nScenario Specific Results\n")
                cliutils.print_list(table_rows,
                                    fields=headers,
                                    formatters=formatters,
                                    table_label="Response Times (sec)")

                for result in raw:
                    errors = result["scenario_output"].get("errors")
                    if errors:
                        print(errors)
Exemple #49
0
    def list(self):
        """List verification runs."""

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

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

        if verifications:
            cliutils.print_list(verifications, fields,
                                normalize_field_names=True,
                                sortby_index=fields.index("Created at"))
        else:
            print(_("No verification was started yet. "
                    "To start verification use:\nrally verify start"))
Exemple #50
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)
Exemple #51
0
    def list(self, api, 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 api.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")
Exemple #52
0
    def list(self, api, 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 api.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")
Exemple #53
0
    def show(self, verification=None, sort_by="name", detailed=False):
        """Display results table of a verification.

        :param verification: UUID of a verification
        :param sort_by: Sort results by 'name' or 'duration'
        :param detailed: Display detailed errors of failed tests
        """
        try:
            verification = api.Verification.get(verification)
            tests = verification.get_results()
        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,
                            normalize_field_names=True)

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

        results = tests["test_cases"]
        values = [utils.Struct(**results[test_name]) for test_name in results]
        sortby_index = ("name", "duration").index(sort_by)
        cliutils.print_list(values, fields, sortby_index=sortby_index)

        if detailed:
            for test in six.itervalues(tests["test_cases"]):
                if test["status"] == "fail":
                    header = cliutils.make_header("FAIL: %(name)s\n"
                                                  "Time: %(time)s" % {
                                                      "name": test["name"],
                                                      "time": test["time"]
                                                  })
                    formatted_test = "%(header)s%(log)s\n" % {
                        "header": header,
                        "log": test["traceback"]
                    }
                    print(formatted_test)
Exemple #54
0
    def show(self, api, deployment=None):
        """Show the credentials of the deployment."""
        # TODO(astudenov): make this method platform independent

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

        deployment = api.deployment.get(deployment=deployment)

        creds = deployment["credentials"]["openstack"][0]
        users = creds["users"]
        admin = creds["admin"]
        credentials = users + [admin] if admin else users
        for ep in credentials:
            data = ["***" if m == "password" else ep.get(m, "")
                    for m in headers]
            table_rows.append(utils.Struct(**dict(zip(headers, data))))
        cliutils.print_list(table_rows, headers)
Exemple #55
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)
Exemple #56
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)
Exemple #57
0
    def show(self, deployment=None):
        """Show the credentials 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 = api.Deployment.get(deployment)
        users = deployment["users"]
        admin = deployment["admin"]
        credentials = users + [admin] if admin else users

        for ep in credentials:
            data = ["***" if m == "password" else ep.get(m, "")
                    for m in headers]
            table_rows.append(utils.Struct(**dict(zip(headers, data))))
        cliutils.print_list(table_rows, headers)
Exemple #58
0
    def check(self, deployment=None):
        """Check keystone authentication and list all available services.

        :param deployment: UUID or name of the deployment
        """
        headers = ["services", "type", "status"]
        table_rows = []
        try:
            deployment = api.Deployment.get(deployment)

        except exceptions.DeploymentNotFound:
            print(_("Deployment %s is not found.") % deployment)
            return(1)

        try:
            services = api.Deployment.check(deployment)
        except keystone_exceptions.ConnectionRefused:
            print(_("Unable to connect %s.") % deployment["admin"]["auth_url"])
            return(1)

        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)

        for serv_type, serv in services.items():
            data = [serv, serv_type, "Available"]
            table_rows.append(utils.Struct(**dict(zip(headers, data))))
        print(_("keystone endpoints are valid and following"
              " services are available:"))
        cliutils.print_list(table_rows, headers)
        if "__unknown__" in services.values():
            print(_(
                "NOTE: '__unknown__' service name means that Keystone service "
                "catalog doesn't return name for this service and Rally can "
                "not identify service by its type. BUT you still can use "
                "such services with api_versions context, specifying type of "
                "service (execute `rally plugin show api_versions` for more "
                "details)."))