-
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
c084457
commit deed55c
Showing
20 changed files
with
643 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
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_system(self): | ||
self.longhorn.uninstall() | ||
|
||
def check_longhorn_crd_removed(self): | ||
self.longhorn.check_longhorn_crd_removed() | ||
|
||
def install_longhorn_system(self): | ||
self.longhorn.install() |
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,48 @@ | ||
from abc import ABC, abstractmethod | ||
from k8s import k8s | ||
from utility.constant import LONGHORN_NAMESPACE | ||
from utility.constant import LONGHORN_UNINSTALL_JOB_LABEL | ||
from utility.constant import LONGHORN_INSTALL_SCRIPT_PATH | ||
from utility.constant import LONGHORN_INSTALL_TIMEOUT | ||
import time | ||
import subprocess | ||
import os | ||
from utility.utility import logging | ||
from utility.utility import get_retry_count_and_interval | ||
|
||
class Base(ABC): | ||
|
||
def __init__(self): | ||
self.retry_count, self.retry_interval = get_retry_count_and_interval() | ||
|
||
@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 install_longhorn(self): | ||
current_path=os.getcwd() | ||
full_path = os.path.join(current_path, LONGHORN_INSTALL_SCRIPT_PATH) | ||
process = subprocess.Popen(['bash', full_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | ||
for i in range(LONGHORN_INSTALL_TIMEOUT): | ||
if process.poll() is not None: | ||
return | ||
else: | ||
output = process.stdout.readline() | ||
logging(f"{output.strip()}") | ||
time.sleep(self.retry_interval) | ||
|
||
assert False, f"Error occurred while installing longhorn" |
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,22 @@ | ||
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): | ||
|
||
def __init__(self): | ||
|
||
if self._method == "manifest": | ||
self.longhorn = LonghornKubectl() | ||
elif self._method == "helm": | ||
self.longhorn = LonghornHelmChart() | ||
|
||
def uninstall(self): | ||
return self.longhorn.uninstall() | ||
|
||
def check_longhorn_crd_removed(self): | ||
return self.longhorn.check_longhorn_crd_removed() | ||
|
||
def install(self): | ||
return self.longhorn.install() |
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,23 @@ | ||
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): | ||
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): | ||
self.install_longhorn() |
Oops, something went wrong.