Example #1
0
 def nodes_status(self, client: str = "", node: int = None):
     """Get info about a client plugin."""
     client_plugin = self._select_client(instance_id=client).plugin
     nodes = client_plugin.nodes()
     if node is None:
         return cli_output(list(node.status.to_dict() for node in nodes))
     return cli_output(nodes[node].status.to_dict())
Example #2
0
    def poll(self, instance_id: str = "", period: int = 10):
        """Return the current health from the healthpoller."""
        fixture = self._select_fixture(instance_id=instance_id)
        plugin = fixture.plugin

        plugin.prepare(self._environment.fixtures())
        plugin.apply()
        time.sleep(5)

        i = 0
        last_message_time = 0
        while True:
            i += 1
            health = plugin.health()
            messages = list(health.messages(since=last_message_time))

            print(
                cli_output({
                    "poll_count": plugin.poll_count(),
                    "status": health.status(),
                    "messages": {
                        "since": int(last_message_time),
                        "items": messages,
                    },
                }))

            # next round we won't include many repeat messages
            if len(messages) > 0:
                last_message_time = max(message.time for message in messages)

            time.sleep(period)
Example #3
0
 def info(self,
          instance_id: str = "",
          deep: bool = False,
          children: bool = True):
     """Get info about a plugin."""
     fixture = self._select_fixture(instance_id=instance_id)
     return cli_output(fixture.info(deep=deep, children=children))
Example #4
0
    def livez(self, client: str = ""):
        """Get kubernetes livez info from the plugin."""
        client_plugin = self._select_client(instance_id=client).plugin
        try:
            return cli_output(client_plugin.livez())

        except Exception as err:
            raise RuntimeError("Kubernetes is not ready") from err
Example #5
0
 def check_plugin(self, instance_id: str, client: str = ""):
     """Output health status of a specific fixture/plugin."""
     # Health Client plugin for asking health questions.
     healthclient_plugin = self._select_client(instance_id=client).plugin
     # Speific plugin to check.
     fixture = healthclient_plugin.health_fixtures().get(
         instance_id=instance_id)
     return cli_output(fixture)
Example #6
0
    def destroy(self, workload: str = ""):
        """Run workload destroy."""
        workload_plugin = self._select_fixture(instance_id=workload).plugin
        workload_plugin.prepare()

        destroy = workload_plugin.destroy()

        return cli_output(destroy)
Example #7
0
    def destroy(self, workload: str = "", debug: bool = False) -> str:
        """Run helm workload destroy."""
        workload_plugin = self._select_fixture(instance_id=workload).plugin
        workload_plugin.prepare()

        destroy = workload_plugin.destroy(debug=debug)

        return cli_output(destroy)
Example #8
0
    def apply(self, workload: str = ""):
        """Run workload apply."""
        workload_plugin = self._select_fixture(instance_id=workload).plugin
        workload_plugin.prepare()

        objects = workload_plugin.apply()

        return cli_output(objects)
Example #9
0
 def health(self, client: str = ""):
     """Retrieve the health status from the instance."""
     client_plugin = self._select_client(instance_id=client).plugin
     health = client_plugin.health()
     return cli_output({
         "status": health.status(),
         "messages": list(health.messages()),
     })
Example #10
0
    def check(self, verbosity: str = "", client: str = ""):
        """Output health status of healthchecks."""
        fixture = self._select_client(instance_id=client)
        verbosity_status = HealthStatus[
            verbosity.upper()] if verbosity else None

        # return a single aggregate health object
        return cli_output(
            cli_fixture_health_output(fixture, verbosity=verbosity_status))
Example #11
0
 def swarm_info(self, client: str = ""):
     """List all containers on the docker client."""
     docker_client = self._select_client(instance_id=client).plugin
     return cli_output(
         {
             "version": docker_client.swarm.version,
             "attrs": docker_client.swarm.attrs,
         }
     )
Example #12
0
    def health(self, instance_id: str = ""):
        """Retrieve the results from the sonobuoy workload instance."""
        client_plugin = self._select_fixture(instance_id=instance_id).plugin
        health = client_plugin.health()

        return cli_output({
            "status": health.status(),
            "messages": list(health.messages()),
        })
Example #13
0
    def health(self, workload: str = ""):
        """Retrieve the results from the deployment workload instance."""
        workload_plugin = self._select_fixture(instance_id=workload).plugin
        workload_plugin.prepare()
        health = workload_plugin.health()

        return cli_output({
            "status": health.status(),
            "messages": list(health.messages()),
        })
Example #14
0
    def health(self, verbosity: str = "", workload: str = "") -> str:
        """Get health status info about a helm workload plugin."""
        workload_plugin = self._select_fixture(instance_id=workload).plugin
        workload_plugin.prepare()

        health = workload_plugin.health()
        return cli_output({
            "status": health.status(),
            "messages": list(health.messages()),
        })
Example #15
0
    def status(self, workload: str = "") -> str:
        """Run helm workload destroy."""
        workload_plugin = self._select_fixture(instance_id=workload).plugin
        workload_plugin.prepare()

        try:
            status = workload_plugin.status()
            status_info = {
                "name": status.name,
                "version": status.version,
                "namespace": status.namespace,
                "deleted": status.deleted,
                "description": status.description,
                "status": status.status,
                "config": status.config,
                "manifest": status.manifest,
            }
            return cli_output(status_info)
        except CalledProcessError:
            return cli_output("No status retrievable.")
Example #16
0
    def apply(self,
              workload: str = "",
              wait: bool = True,
              debug: bool = False) -> str:
        """Run helm workload apply."""
        workload_plugin = self._select_fixture(instance_id=workload).plugin
        workload_plugin.prepare()

        objects = workload_plugin.apply(wait=wait, debug=debug)

        return cli_output(objects)
Example #17
0
    def checks(self, verbosity: str = "", client: str = ""):
        """Output health status of healthchecks per plugin."""
        fixture = self._select_client(instance_id=client)
        verbosity_status = HealthStatus[
            verbosity.upper()] if verbosity else None

        # return a dict of healtchecks per plugin instance_id
        return cli_output({
            fixture.instance_id:
            cli_fixture_health_output(fixture, verbosity=verbosity_status)
            for fixture in fixture.plugin.health_fixtures()
        })
Example #18
0
    def config_file(self, client: str = ""):
        """Dump the config file."""
        client_plugin: LaunchpadClientPlugin = self._select_client(
            instance_id=client).plugin

        try:
            with open(client_plugin.config_file,
                      encoding="utf8") as config_file:
                config_contents = yaml.load(config_file)
        except FileNotFoundError as err:
            raise ValueError("No config file was found") from err

        return cli_output(config_contents)
Example #19
0
    def info(self, deep: bool = False):
        """Output any user related information."""
        user_config = self._environment.config().load("user")
        user_config_dir = _user_path()

        info = {
            "config": user_config.get(default={}),
            "system": {
                "path": user_config_dir,
                "exists": os.path.isdir(user_config_dir),
            },
        }

        return cli_output(info)
Example #20
0
 def health(self, client: str = ""):
     """Run client healthcheck."""
     fixture = self._select_client(instance_id=client)
     plugin = fixture.plugin
     health: Health = plugin.health()
     return cli_output({
         "fixture": {
             "plugin_id": fixture.plugin_id,
             "instance_id": fixture.instance_id,
             "priority": fixture.priority,
         },
         "status": health.status(),
         "messages": list(health.messages()),
     })
Example #21
0
 def nodes_list(self, client: str = ""):
     """List all nodes in the docker swarm."""
     docker_client = self._select_client(instance_id=client).plugin
     return cli_output(
         list(
             {
                 "id": node.id,
                 "short_id": node.short_id,
                 "version": node.version,
                 "attrs": node.attrs,
             }
             for node in docker_client.nodes.list()
         )
     )
Example #22
0
    def container_list(self, client: str = "", all: bool = True):
        """List all containers on the docker client."""
        docker_client = self._select_client(instance_id=client).plugin
        container_info = []
        for container in docker_client.containers.list(all=all):
            container_info.append(
                {
                    "name": container.name,
                    "id": container.id,
                    "image": container.image.tags,
                    "status": container.status,
                }
            )

        return cli_output(container_info)
Example #23
0
    def health(self, instance_id: str = ""):
        """Return the current health from the healthpoller."""
        fixture = self._select_fixture(instance_id=instance_id)
        plugin = fixture.plugin

        plugin.prepare(self._environment.fixtures())
        healths = plugin._healthcheck()

        health_info = {}
        for health_id, health in healths.items():
            health_info[health_id] = {
                "status": health.status(),
                "message": list(health.messages(0)),
            }

        return cli_output(health_info)
Example #24
0
    def client_bundle(self,
                      client: str = "",
                      user: str = "admin",
                      reload: bool = False):
        """Tell Launchpad to download the client bundle."""
        client_plugin = self._select_client(instance_id=client)
        plugin = client_plugin.plugin

        logger.info("Downloading client bungle for user: %s", user)
        try:
            # access private method for manual interaction
            # pylint: disable=protected-access
            bundle = plugin._mke_client_bundle(user=user, reload=reload)
        except Exception as err:
            raise Exception("Launchpad command failed.") from err

        return cli_output(bundle)
Example #25
0
    def status(self, instance_id: str = ""):
        """Get active sonobuoy status."""
        client_plugin = self._select_fixture(instance_id=instance_id).plugin
        status = client_plugin.status()

        if status is None:
            status_info = {"status": "None", "plugins": {}}
        else:
            status_info = {
                "status": status.status,
                "plugins": {
                    plugin_id: status.plugin(plugin_id)
                    for plugin_id in status.plugin_list()
                },
            }

        return cli_output(status_info)
Example #26
0
    def connect_service_proxy(self,
                              namespace: str,
                              service: str,
                              client: str = ""):
        """Create a service proxy."""
        client_plugin = self._select_client(instance_id=client).plugin
        try:
            # Thank you kubernetes for the naming pattern
            # pylint: disable=invalid-name
            CoreV1Api = client_plugin.get_api("CoreV1Api")
            sc = CoreV1Api.connect_post_namespaced_service_proxy(
                namespace=namespace, name=service)

            return cli_output(sc)

        except Exception as err:
            raise RuntimeError(
                "Exception trying to open the service proxy") from err
Example #27
0
    def fixtures(
        self,
        client: str = "",
        plugin_id: str = "",
        interfaces: List[str] = None,
        instance_id: str = "",
    ):
        """List all outputs."""
        client_plugin: LaunchpadClientPlugin = self._select_client(
            instance_id=client).plugin

        fixture_list = [
            fixture.info() for fixture in client_plugin.fixtures().filter(
                interfaces=interfaces,
                plugin_id=plugin_id,
                instance_id=instance_id)
        ]

        return cli_output(fixture_list)
Example #28
0
 def state(self, client: str = ""):
     """Run client check."""
     plugin = self._select_client(instance_id=client).plugin
     return cli_output(plugin.state())
Example #29
0
 def info(self, client: str = "", deep: bool = False) -> Dict[str, Any]:
     """Get info about a client plugin."""
     fixture = self._select_client(instance_id=client)
     return cli_output(fixture.info(deep=deep))
Example #30
0
 def info(self,
          provisioner: str = "",
          deep: bool = False) -> Dict[str, Any]:
     """Get info about a provisioner plugin."""
     fixture = self._select_provisioner(instance_id=provisioner)
     return cli_output(fixture.info(deep=deep))