Our tests frequently need to run commands on units to do things like interact with kubectl or issue workload queries (e.g., prometheus queries). There's a bit of boilerplate that is associated with that, such as: selecting a unit to run on, checking the response status and exit code, ensuring a reasonable timeout, etc. It would be nice to have a helper around that, and examples can already be found in kube-state-metrics-operator and kubernetes-master.
Definition of done:
A new juju_run helper is added to OpsTest
It should take either an explicit unit instance, an app name as a string to select an arbitrary unit from that app, or f"{app_name}/leader" to select the leader unit of that app
A default timeout should be provided, with the option to override
An appropriate TimeoutError should be raised if the job didn't complete
An appropriate exception should be raised if the process returned a non-zero exit code
The stdout from the command should be returned
New helper(s) are included in the library docs
Stretch goal:
Add a kubectl wrapper that defaults to "kubernetes-master/leader" for the unit and prepends "kubectl --kubeconfig=/root/.kube/config" to the command.
Our tests frequently need to run commands on units to do things like interact with
kubectl
or issue workload queries (e.g., prometheus queries). There's a bit of boilerplate that is associated with that, such as: selecting a unit to run on, checking the response status and exit code, ensuring a reasonable timeout, etc. It would be nice to have a helper around that, and examples can already be found in kube-state-metrics-operator and kubernetes-master.Definition of done:
juju_run
helper is added toOpsTest
f"{app_name}/leader"
to select the leader unit of that appTimeoutError
should be raised if the job didn't completeStretch goal:
kubectl
wrapper that defaults to "kubernetes-master/leader" for the unit and prepends"kubectl --kubeconfig=/root/.kube/config"
to the command.