MODULE

PYTEST_HELM_CHARTS.CLUSTERS

This module introduces classes for handling different clusters.

Classes
  • Cluster(kube_config_path) — Represents an abstract cluster.</>
  • ExistingCluster — Implementation of Cluster that uses kube.config file to connect to external existing cluster.</>
abstract class

pytest_helm_charts.clusters.Cluster(kube_config_path=None)

Represents an abstract cluster.

Parameters
  • kube_config_path (str, optional) —
Attributes
  • _kube_client —
  • kube_client (HTTPClient, optional) — Returns the HTTP client you can use to access Kubernetes API of the cluster under test.
    Please refer to pykube to get docs for HTTPClient.</>
  • kube_config_path —
Methods
  • create() (HTTPClient) — Creates an instance of a cluster and returns HTTPClient to connect to it.</>
  • destroy() — Destroys the cluster created earlier with a call to create.</>
  • kubectl(subcmd_string, std_input, output_format, use_shell, **kwargs) (str) — Execute command by running 'kubectl' binary.</>
abstract method

create() → HTTPClient

Creates an instance of a cluster and returns HTTPClient to connect to it.

abstract method

destroy()

Destroys the cluster created earlier with a call to create.

method

kubectl(subcmd_string, std_input='', output_format='json', use_shell=False, **kwargs)

Execute command by running 'kubectl' binary.

If your cluster delivers the kube.config file, run a kubectl command against the cluster and return the output. Otherwise, exception is raised.

Parameters
  • subcmd_string (str) — Command to run, like "delete pod abc"
  • std_input (str) — Use this to pass a manifest file directly as a string (results in 'kubectl [cmd] -f -')
  • output_format (str) — Option "--output" as passed to 'kubectl'. Default is 'json', make sure to change to "" for commands that don't return JSON.
  • use_shell (bool, optional) — Whether the 'kubectl' command should be invoked directly (when 'False') or wrapped in system shell ('True'). 'False' by default.
  • **kwargs (str) —
  • kwargs — arbitrary dictionary of options and values that will be passed directly to 'kubectl'
Returns (str)

The output printed by 'kubectl', if the command succeeded (exit code was 0)

Raises
  • subprocess.CalledProcessError — If the command exited with non-zero exit code
class

pytest_helm_charts.clusters.ExistingCluster(kube_config_path)

Implementation of Cluster that uses kube.config file to connect to external existing cluster.

Parameters
  • kube_config_path (str) —
Attributes
  • _kube_client —
  • kube_client (HTTPClient, optional) — Returns the HTTP client you can use to access Kubernetes API of the cluster under test.
    Please refer to pykube to get docs for HTTPClient.</>
  • kube_config_path —
Methods
  • create() (HTTPClient) — Creates an instance of a cluster and returns HTTPClient to connect to it.</>
  • destroy() — Destroys the cluster created earlier with a call to create.</>
  • kubectl(subcmd_string, std_input, output_format, use_shell, **kwargs) (str) — Execute command by running 'kubectl' binary.</>
method

kubectl(subcmd_string, std_input='', output_format='json', use_shell=False, **kwargs)

Execute command by running 'kubectl' binary.

If your cluster delivers the kube.config file, run a kubectl command against the cluster and return the output. Otherwise, exception is raised.

Parameters
  • subcmd_string (str) — Command to run, like "delete pod abc"
  • std_input (str) — Use this to pass a manifest file directly as a string (results in 'kubectl [cmd] -f -')
  • output_format (str) — Option "--output" as passed to 'kubectl'. Default is 'json', make sure to change to "" for commands that don't return JSON.
  • use_shell (bool, optional) — Whether the 'kubectl' command should be invoked directly (when 'False') or wrapped in system shell ('True'). 'False' by default.
  • **kwargs (str) —
Returns (str)

The output printed by 'kubectl', if the command succeeded (exit code was 0)

Raises
  • subprocess.CalledProcessError — If the command exited with non-zero exit code
method

create() → HTTPClient

Creates an instance of a cluster and returns HTTPClient to connect to it.

method

destroy()

Destroys the cluster created earlier with a call to create.