-
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.
ci: config vpn, add harvester terraform script, and implement harvest…
…er vm reboot operation Signed-off-by: Yang Chiu <[email protected]>
- Loading branch information
Showing
16 changed files
with
404 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from host.host import Host | ||
from host.aws import Aws | ||
from host.harvester import Harvester |
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,32 @@ | ||
import yaml | ||
from abc import ABC, abstractmethod | ||
from node.node import Node | ||
|
||
|
||
class Base(ABC): | ||
|
||
def __init__(self): | ||
with open('/tmp/instance_mapping', 'r') as f: | ||
self.mapping = yaml.safe_load(f) | ||
self.node = Node() | ||
|
||
@abstractmethod | ||
def reboot_all_nodes(self, shut_down_time_in_sec): | ||
return NotImplemented | ||
|
||
@abstractmethod | ||
def reboot_node(self, node_name, shut_down_time_in_sec): | ||
return NotImplemented | ||
|
||
@abstractmethod | ||
def reboot_all_worker_nodes(self, shut_down_time_in_sec): | ||
return NotImplemented | ||
|
||
@abstractmethod | ||
def power_off_node(self, node_name): | ||
return NotImplemented | ||
|
||
@abstractmethod | ||
def power_on_node(self, node_name): | ||
return NotImplemented | ||
|
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,92 @@ | ||
import requests | ||
import os | ||
import time | ||
from host.constant import NODE_REBOOT_DOWN_TIME_SECOND | ||
from utility.utility import logging | ||
from utility.utility import wait_for_cluster_ready | ||
from utility.utility import get_retry_count_and_interval | ||
from host.base import Base | ||
import urllib3 | ||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | ||
|
||
class Harvester(Base): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.url = f"{os.getenv('LAB_URL')}/k8s/clusters/{os.getenv('LAB_CLUSTER_ID')}/v1/harvester/kubevirt.io.virtualmachines/longhorn-qa" | ||
self.cookies = { | ||
'R_SESS': f"{os.getenv('LAB_ACCESS_KEY')}:{os.getenv('LAB_SECRET_KEY')}" | ||
} | ||
self.retry_count, self.retry_interval = get_retry_count_and_interval() | ||
|
||
def reboot_all_nodes(self, shut_down_time_in_sec=NODE_REBOOT_DOWN_TIME_SECOND): | ||
node_names = [key for key in self.mapping.keys()] | ||
|
||
for node_name in node_names: | ||
self.power_off_node(node_name) | ||
|
||
logging(f"Wait for {shut_down_time_in_sec} seconds before starting vms") | ||
time.sleep(shut_down_time_in_sec) | ||
|
||
for node_name in node_names: | ||
self.power_on_node(node_name) | ||
|
||
wait_for_cluster_ready() | ||
|
||
def reboot_node(self, node_name, shut_down_time_in_sec): | ||
self.power_off_node(node_name) | ||
|
||
logging(f"Wait for {shut_down_time_in_sec} seconds before starting vms") | ||
time.sleep(shut_down_time_in_sec) | ||
|
||
self.power_on_node(node_name) | ||
|
||
def reboot_all_worker_nodes(self, shut_down_time_in_sec): | ||
node_names = self.node.list_node_names_by_role("worker") | ||
|
||
for node_name in node_names: | ||
self.power_off_node(node_name) | ||
|
||
logging(f"Wait for {shut_down_time_in_sec} seconds before starting vms") | ||
time.sleep(shut_down_time_in_sec) | ||
|
||
for node_name in node_names: | ||
self.power_on_node(node_name) | ||
|
||
def power_off_node(self, node_name): | ||
vm_id = self.mapping[node_name] | ||
|
||
url = f"{self.url}/{vm_id}" | ||
resp = requests.post(f"{url}?action=stop", cookies=self.cookies, verify=False) | ||
logging(f"resp = {resp}") | ||
assert resp.status_code == 204, f"Failed to stop vm {vm_id} response: {resp.status_code} {resp.reason}, request: {resp.request.url} {resp.request.headers}" | ||
logging(f"Stopping vm {vm_id}") | ||
|
||
stopped = False | ||
for i in range(self.retry_count): | ||
logging(f"Waiting for vm {vm_id} stopped ... ({i})") | ||
resp = requests.get(url, cookies=self.cookies, verify=False) | ||
if "Stopped" in resp.json()['metadata']['fields']: | ||
stopped = True | ||
break | ||
time.sleep(self.retry_interval) | ||
assert stopped, f"Expected vm {vm_id} to be stopped but it's not" | ||
|
||
def power_on_node(self, node_name): | ||
vm_id = self.mapping[node_name] | ||
|
||
url = f"{self.url}/{vm_id}" | ||
resp = requests.post(f"{url}?action=start", cookies=self.cookies, verify=False) | ||
logging(f"resp = {resp}") | ||
assert resp.status_code == 204, f"Failed to start vm {vm_id} response: {resp.status_code} {resp.reason}, request: {resp.request.url} {resp.request.headers}" | ||
logging(f"Starting vm {vm_id}") | ||
|
||
started = False | ||
for i in range(self.retry_count): | ||
logging(f"Waiting for vm {vm_id} started ... ({i})") | ||
resp = requests.get(url, cookies=self.cookies, verify=False) | ||
if "Running" in resp.json()['metadata']['fields']: | ||
started = True | ||
break | ||
time.sleep(self.retry_interval) | ||
assert started, f"Expected vm {vm_id} to be started but it's not" |
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
Oops, something went wrong.