-
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 <[email protected]>
- Loading branch information
1 parent
1bd7958
commit 56c64a9
Showing
21 changed files
with
483 additions
and
1 deletion.
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
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,45 @@ | ||
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 subprocess | ||
import os | ||
from utility.utility import get_retry_count_and_interval | ||
from utility.utility import logging | ||
|
||
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) | ||
|
||
try: | ||
output = subprocess.check_output(['bash', full_path], timeout=LONGHORN_INSTALL_TIMEOUT) | ||
logging(output) | ||
except subprocess.CalledProcessError as e: | ||
logging(f"Error: {e.stderr}") | ||
except subprocess.TimeoutExpired as e: | ||
logging(f"Command timed out after {e.timeout} seconds") |
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("LONGHORN_INSTALL_METHOD", "manifest") | ||
|
||
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(control_plane_node).issue_cmd(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.