Skip to content

Commit

Permalink
Creae the GCP node functionalities in the file 'ocs_ci/utility/gcp.py…
Browse files Browse the repository at this point in the history
…', Add the necessary pip packages for Google Cloud platform, create the GCPNodes class in the 'platform_nodes' file" (red-hat-storage#8775)

Signed-off-by: Itzhak Kave <[email protected]>
Co-authored-by: Itzhak Kave <[email protected]>
  • Loading branch information
yitzhak12 and Itzhak Kave authored Nov 16, 2023
1 parent 8977201 commit 7d8ac17
Show file tree
Hide file tree
Showing 5 changed files with 412 additions and 2 deletions.
9 changes: 9 additions & 0 deletions ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2354,3 +2354,12 @@

# dir of template for html reports
HTML_REPORT_TEMPLATE_DIR = "ocs_ci/templates/html_reports/"


# Google Cloud platform
GCP_PROJECT_ODF_QE = "odf-qe"
# Operation names
OPERATION_STOP = "stop"
OPERATION_START = "start"
OPERATION_RESTART = "restart"
OPERATION_TERMINATE = "terminate"
4 changes: 4 additions & 0 deletions ocs_ci/ocs/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,3 +653,7 @@ class NoThreadingLockUsedError(Exception):

class VSLMNotFoundException(Exception):
pass


class OperationFailedToCompleteException(Exception):
pass
110 changes: 108 additions & 2 deletions ocs_ci/ocs/platform_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
get_module_ip,
get_terraform_ignition_provider,
)
from ocs_ci.ocs.node import wait_for_nodes_status
from ocs_ci.ocs.node import wait_for_nodes_status, get_nodes_in_statuses
from ocs_ci.utility.vsphere_nodes import VSPHERENode
from paramiko.ssh_exception import NoValidConnectionsError, AuthenticationException
from semantic_version import Version
Expand All @@ -83,7 +83,7 @@ def __init__(self):
"aws": AWSNodes,
"baremetal": BaremetalNodes,
"azure": AZURENodes,
"gcp": NodesBase,
"gcp": GCPNodes,
"vsphere_lso": VMWareLSONodes,
"powervs": IBMPowerNodes,
"rhv": RHVNodes,
Expand Down Expand Up @@ -2963,3 +2963,109 @@ def terminate_nodes(self, nodes, wait=True):
for vm_name in vm_names:
node_cls_obj.change_terraform_statefile_after_remove_vm(vm_name)
node_cls_obj.change_terraform_tfvars_after_remove_vm()


class GCPNodes(NodesBase):
"""
Google Cloud Platform Nodes class
"""

def __init__(self):
super(GCPNodes, self).__init__()
from ocs_ci.utility import gcp

self.gcp = gcp.GoogleCloud()

def stop_nodes(self, nodes, wait=True):
"""
Stop nodes
Args:
nodes (list): The OCS objects of the nodes
wait (bool): True for waiting the instances to stop, False otherwise
Raises:
OperationFailedToCompleteException: In case that not all the operations completed successfully
"""
node_names = [n.name for n in nodes]
self.gcp.stop_instances(node_names)

def start_nodes(self, nodes, wait=True):
"""
Start nodes
Args:
nodes (list): The OCS objects of the nodes
wait (bool): True for waiting the instances to start, False otherwise
Raises:
OperationFailedToCompleteException: In case that not all the operations completed successfully
"""
node_names = [n.name for n in nodes]
self.gcp.start_instances(node_names)

def restart_nodes(self, nodes, wait=True):
"""
Restart nodes. This is a hard reset - the instance does not do a graceful shutdown
Args:
nodes (list): The OCS objects of the nodes
wait (bool): True for waiting the instances to start, False otherwise
Raises:
OperationFailedToCompleteException: In case that not all the operations completed successfully
"""
node_names = [n.name for n in nodes]
self.gcp.restart_instances(node_names, wait)

def terminate_nodes(self, nodes, wait=True):
"""
Terminate nodes
Args:
nodes (list): The OCS objects of the nodes
wait (bool): True for waiting the instances to terminate, False otherwise
Raises:
OperationFailedToCompleteException: In case that not all the operations completed successfully
"""
node_names = [n.name for n in nodes]
self.gcp.terminate_instances(node_names, wait)

def restart_nodes_by_stop_and_start(self, nodes, wait=True, force=True):
"""
Restart nodes by stop and start
Args:
nodes (list): The OCS objects of the nodes
wait (bool): True for waiting the instances to stop, False otherwise
force (bool): True for force node stop, False otherwise
Raises:
OperationFailedToCompleteException: In case that not all the operations completed successfully
"""
node_names = [n.name for n in nodes]
# In the Google Compute Engine instance, the stop operation is a clean shutdown without force.
# To perform a force stop and start, we need to use the GCP restart method, which performs a hard reset.
if force:
self.gcp.restart_instances(node_names, wait)
else:
self.gcp.restart_instances_by_stop_and_start(node_names, wait)

def restart_nodes_by_stop_and_start_teardown(self):
"""
Start the nodes in a NotReady state
Raises:
OperationFailedToCompleteException: In case that not all the operations completed successfully
"""
not_ready_nodes = get_nodes_in_statuses([constants.NODE_NOT_READY])
node_names = [n.name for n in not_ready_nodes]
self.gcp.start_instances(node_names)
Loading

0 comments on commit 7d8ac17

Please sign in to comment.