-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(robot): add uninstallation check test case
ref: longhorn/longhorn#9222 Signed-off-by: Chris <chris.chien@suse.com>
- Loading branch information
1 parent
ba5a86a
commit 7bea403
Showing
20 changed files
with
476 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from longhorn_deploy import LonghornDeploy | ||
class longhorn_deploy_keywords: | ||
|
||
def __init__(self): | ||
self.longhorn = LonghornDeploy() | ||
|
||
def uninstall_longhorn(self, longhorn_branch): | ||
self.longhorn.uninstall(longhorn_branch) | ||
|
||
def check_longhorn_crd_removed(self): | ||
self.longhorn.check_longhorn_crd_removed() | ||
|
||
def install_longhorn(self, longhorn_branch): | ||
self.longhorn.install(longhorn_branch) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from uninstallation import Uninstallation | ||
|
||
class uninstallation_keywords: | ||
|
||
def __init__(self): | ||
self.uninstallation = Uninstallation() | ||
|
||
def uninstall_longhorn(self, longhor_branch, install_method): | ||
self.uninstallation.uninstall_longhorn(longhor_branch, install_method) | ||
|
||
def check_longhorn_crd_removed(self): | ||
self.uninstallation.check_longhorn_crd_removed() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from longhorn_deploy.longhorn_deploy import LonghornDeploy | ||
from longhorn_deploy.longhorn_kubectl import LonghornKubectl | ||
from longhorn_deploy.longhorn_helm_chart import LonghornHelmChart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from abc import ABC, abstractmethod | ||
from k8s import k8s | ||
from kubernetes.client.rest import ApiException | ||
from utility.constant import LONGHORN_NAMESPACE | ||
from utility.constant import LONGHORN_UNINSTALL_JOB_LABEL | ||
import time | ||
from utility.utility import logging | ||
from node_exec import NodeExec | ||
from node import Node | ||
|
||
class Base(ABC): | ||
|
||
@abstractmethod | ||
def install(self): | ||
return NotImplemented | ||
|
||
@abstractmethod | ||
def uninstall(self, longhorn_branch=None): | ||
return NotImplemented | ||
|
||
def check_longhorn_crd_removed(self): | ||
all_crd = k8s.get_all_custom_resources() | ||
for crd in all_crd.items: | ||
assert "longhorn.io" not in crd.metadata.name | ||
|
||
def check_longhorn_uninstall_pod_log(self): | ||
logs = k8s.get_pod_logs(LONGHORN_NAMESPACE, LONGHORN_UNINSTALL_JOB_LABEL) | ||
assert "error" not in logs | ||
assert "level=fatal" not in logs | ||
|
||
def wait_longhorn_status_running(self): | ||
RETRY_COUNTS = 10 | ||
RETRY_INTERVAL = 60 | ||
retries = 0 | ||
|
||
while True: | ||
try: | ||
pods = k8s.list_namespace_pods(LONGHORN_NAMESPACE) | ||
|
||
csi_pods = [pod for pod in pods.items if 'csi-' in pod.metadata.name] | ||
engine_image_pods = [pod for pod in pods.items if 'engine-image-' in pod.metadata.name] | ||
non_running_pods = [pod for pod in pods.items if pod.status.phase != 'Running'] | ||
|
||
if csi_pods and engine_image_pods and not non_running_pods: | ||
logging(f"Longhorn is fully running.") | ||
break | ||
else: | ||
logging("Longhorn is still installing ... re-checking in 1m") | ||
except ApiException as e: | ||
logging("Exception when calling CoreV1Api->list_namespaced_pod: %s\n" % e) | ||
|
||
time.sleep(RETRY_INTERVAL) | ||
retries += 1 | ||
|
||
if retries == RETRY_COUNTS: | ||
logging("Error: longhorn installation timeout") | ||
return 1 | ||
|
||
def expose_longhorn_ui(self): | ||
control_plane_nodes = Node.list_node_names_by_role(self, role="control-plane") | ||
control_plane_node = control_plane_nodes[0] | ||
|
||
cmd = "kubectl expose --type=NodePort deployment longhorn-ui -n longhorn-system "\ | ||
"--port 8000 --name longhorn-ui-nodeport "\ | ||
"--overrides '{\"apiVersion\": \"v1\",\"spec\":{\"ports\": [{\"port\":8000,\"protocol\":\"TCP\",\"targetPort\":8000,\"nodePort\":30000}]}}'" | ||
|
||
res = NodeExec.get_instance().issue_cmd(control_plane_node, cmd) | ||
assert res, "expose longhorn-ui failed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from longhorn_deploy.base import Base | ||
from longhorn_deploy.longhorn_kubectl import LonghornKubectl | ||
from longhorn_deploy.longhorn_helm_chart import LonghornHelmChart | ||
import os | ||
|
||
class LonghornDeploy(Base): | ||
|
||
_method = os.getenv("INSTALL_METHOD") | ||
|
||
def __init__(self): | ||
|
||
if self._method == "kubectl": | ||
self.longhorn = LonghornKubectl() | ||
elif self._method == "helm": | ||
self.longhorn = LonghornHelmChart() | ||
|
||
def uninstall(self, longhorn_branch): | ||
return self.longhorn.uninstall(longhorn_branch) | ||
|
||
def check_longhorn_crd_removed(self): | ||
return self.longhorn.check_longhorn_crd_removed() | ||
|
||
def install(self, longhorn_branch): | ||
return self.longhorn.install(longhorn_branch) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from longhorn_deploy.base import Base | ||
from node import Node | ||
from node_exec import NodeExec | ||
from k8s import k8s | ||
from utility.constant import LONGHORN_NAMESPACE | ||
import os | ||
|
||
class LonghornHelmChart(Base): | ||
|
||
def uninstall(self, longhorn_branch): | ||
control_plane_nodes = Node.list_node_names_by_role(self, role="control-plane") | ||
control_plane_node = control_plane_nodes[0] | ||
|
||
cmd = f"export KUBECONFIG={os.getenv("KUBECONFIG")} && helm uninstall longhorn -n {LONGHORN_NAMESPACE}" | ||
res = NodeExec.get_instance().issue_cmd(control_plane_node, cmd) | ||
assert res, "apply helm uninstall command failed" | ||
|
||
k8s.delete_namespace(namespace=LONGHORN_NAMESPACE) | ||
k8s.wait_namespace_terminated(namespace=LONGHORN_NAMESPACE) | ||
|
||
def install(self, longhorn_branch): | ||
control_plane_nodes = Node.list_node_names_by_role(self, role="control-plane") | ||
control_plane_node = control_plane_nodes[0] | ||
|
||
k8s.create_namespace(LONGHORN_NAMESPACE) | ||
|
||
cmd = f"export KUBECONFIG={os.getenv("KUBECONFIG")} && helm repo add longhorn https://charts.longhorn.io" | ||
res = NodeExec.get_instance().issue_cmd(control_plane_node, cmd) | ||
assert res, "apply helm repo add longhorn command failed" | ||
|
||
cmd = f"export KUBECONFIG={os.getenv("KUBECONFIG")} && helm repo update" | ||
res = NodeExec.get_instance().issue_cmd(control_plane_node, cmd) | ||
assert res, "apply helm repo update command failed" | ||
|
||
cmd = f"export KUBECONFIG={os.getenv("KUBECONFIG")} && helm install longhorn longhorn/longhorn --version {longhorn_branch} -n {LONGHORN_NAMESPACE}" | ||
res = NodeExec.get_instance().issue_cmd(control_plane_node, cmd) | ||
assert res, "apply helm install command failed" | ||
|
||
self.wait_longhorn_status_running() | ||
self.expose_longhorn_ui() |
Oops, something went wrong.