Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 35 additions & 25 deletions harvester_robot_tests/keywords/addon.resource
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ Library Process
Resource variables.resource
Resource common.resource

*** Variables ***
${LVM_ADDON_URL} https://raw.githubusercontent.com/harvester/experimental-addons/main/harvester-csi-driver-lvm/harvester-csi-driver-lvm.yaml

*** Keywords ***
Get Initial State
Install Addon From URL
[Arguments] ${url}
[Documentation] Install an addon by applying a YAML manifest from the given URL
Log Installing addon from ${url}
addon_keywords.install_addon_yaml ${url}
Log Addon YAML applied successfully

Get Addon Initial State
[Arguments] ${addon_name}
[Documentation] Get initial state of addon (enabled/disabled)
... Args:
Expand All @@ -18,7 +28,7 @@ Get Initial State
Log Addon ${addon_name} initial state: ${initial_state}
RETURN ${initial_state}

Enable
Enable Addon
[Arguments] ${addon_name}
[Documentation] Enable an addon
... Args:
Expand All @@ -27,7 +37,7 @@ Enable
addon_keywords.enable_addon ${addon_name}
Log Addon ${addon_name} enable request sent

Disable
Disable Addon
[Arguments] ${addon_name}
[Documentation] Disable an addon
... Args:
Expand All @@ -36,7 +46,7 @@ Disable
addon_keywords.disable_addon ${addon_name}
Log Addon ${addon_name} disable request sent

Wait For Enabled
Wait For Addon Enabled
[Arguments] ${addon_name} ${timeout}=${WAIT_TIMEOUT}
[Documentation] Wait until addon is enabled
... Args:
Expand All @@ -46,7 +56,7 @@ Wait For Enabled
addon_keywords.wait_for_addon_enabled ${addon_name} ${timeout}
Log Addon ${addon_name} is now enabled

Wait For Disabled
Wait For Addon Disabled
[Arguments] ${addon_name} ${timeout}=${WAIT_TIMEOUT}
[Documentation] Wait until addon is disabled
... Args:
Expand All @@ -56,7 +66,7 @@ Wait For Disabled
addon_keywords.wait_for_addon_disabled ${addon_name} ${timeout}
Log Addon ${addon_name} is now disabled

Is Enabled
Is Addon Enabled
[Arguments] ${addon_name}
[Documentation] Check if addon is enabled
... Args:
Expand All @@ -76,7 +86,7 @@ Wait For Monitoring Pods Running
addon_keywords.wait_for_monitoring_pods_running ${namespace} ${timeout}
Log Monitoring pods are now running

Wait For Pods Running
Wait For Addon Pods Running
[Arguments] ${namespace} ${label} ${timeout}=${WAIT_TIMEOUT}
[Documentation] Wait for pods matching label to be running in namespace
... Args:
Expand All @@ -87,7 +97,7 @@ Wait For Pods Running
addon_keywords.wait_for_pods_running ${namespace} ${label} ${timeout}
Log Pods with label ${label} are running in ${namespace}

Wait For Service Running
Wait For Addon Service Running
[Arguments] ${namespace} ${service_name} ${timeout}=${WAIT_TIMEOUT}
[Documentation] Wait for service to be running in namespace
... Args:
Expand All @@ -98,7 +108,7 @@ Wait For Service Running
addon_keywords.wait_for_service_running ${namespace} ${service_name} ${timeout}
Log Service ${service_name} is running in ${namespace}

Configure Nvidia Toolkit
Configure Nvidia Toolkit Addon
[Arguments] ${addon_name} ${image_repo} ${image_tag} ${driver_location}
[Documentation] Configure the nvidia-driver-toolkit addon with image repo, tag, and driver location
... Args:
Expand All @@ -110,7 +120,7 @@ Configure Nvidia Toolkit
addon_keywords.configure_nvidia_toolkit_addon ${addon_name} ${image_repo} ${image_tag} ${driver_location}
Log Nvidia-driver-toolkit addon configured

Verify Nvidia Toolkit Configured
Verify Nvidia Toolkit Addon Configured
[Arguments] ${addon_name} ${image_repo} ${image_tag} ${driver_location}
[Documentation] Verify nvidia-driver-toolkit addon configuration is applied
... Args:
Expand Down Expand Up @@ -141,7 +151,7 @@ Port Forward To Prometheus
addon_keywords.port_forward_to_prometheus ${namespace} ${pod_name} ${local_port}
Log Port forward established

Stop Port Forward
Stop Prometheus Port Forward
[Documentation] Stop port forwarding
Log Stopping port forward
addon_keywords.stop_port_forward
Expand Down Expand Up @@ -173,7 +183,7 @@ Verify Prometheus Metric Exists
Should Be True ${exists} Metric ${query} should exist
Log Metric ${query} verified successfully

Restore State
Restore Addon State
[Arguments] ${addon_name} ${initial_state}
[Documentation] Restore addon to its initial state
... Args:
Expand All @@ -187,16 +197,16 @@ Restore State
Initial Addon State Is Captured
[Arguments] ${addon_name}
[Documentation] Capture and store the initial state of the addon
${initial_state}= Get Initial State ${addon_name}
${initial_state}= Get Addon Initial State ${addon_name}
Set Suite Variable ${INITIAL_STATE_MONITORING} ${initial_state}
Log Captured initial addon state: ${initial_state}

Monitoring Addon Is Enabled
[Arguments] ${addon_name}
[Documentation] Enable the monitoring addon and wait for deployment
${is_enabled}= Is Enabled ${addon_name}
Run Keyword If not ${is_enabled} Enable ${addon_name}
Wait For Enabled ${addon_name} timeout=900
${is_enabled}= Is Addon Enabled ${addon_name}
Run Keyword If not ${is_enabled} Enable Addon ${addon_name}
Wait For Addon Enabled ${addon_name} timeout=900
Log Monitoring addon ${addon_name} is enabled

Monitoring Pods Should Be Running
Expand Down Expand Up @@ -237,11 +247,11 @@ Suite Teardown For Addon Tests
Log Running suite teardown for addon tests

# Stop port forward if still running
Run Keyword And Ignore Error Stop Port Forward
Run Keyword And Ignore Error Stop Prometheus Port Forward

# Restore addon to initial state
Run Keyword If '${INITIAL_STATE_MONITORING}' != 'None'
... Restore State ${ADDON_MONITORING} ${INITIAL_STATE_MONITORING}
... Restore Addon State ${ADDON_MONITORING} ${INITIAL_STATE_MONITORING}

# Standard cleanup
Cleanup test resources
Expand All @@ -265,28 +275,28 @@ Get Prometheus Pod Name
Initial PCI Addon State Is Captured
[Arguments] ${addon_name}
[Documentation] Capture and store the initial state of the addon
${initial_state}= Get Initial State ${addon_name}
${initial_state}= Get Addon Initial State ${addon_name}
Set Suite Variable ${INITIAL_STATE_PCIDEVICES} ${initial_state}
Log Captured initial addon state: ${initial_state}

PCI Devices Addon Is Enabled
[Arguments] ${addon_name}
[Documentation] Enable the pcidevices-controller addon and wait for deployment
${is_enabled}= Is Enabled ${addon_name}
Run Keyword If not ${is_enabled} Enable ${addon_name}
Wait For Enabled ${addon_name} timeout=900
${is_enabled}= Is Addon Enabled ${addon_name}
Run Keyword If not ${is_enabled} Enable Addon ${addon_name}
Wait For Addon Enabled ${addon_name} timeout=900
Log PCI Devices addon ${addon_name} is enabled

PCI Devices Controller Pods Should Be Running
[Arguments] ${namespace} ${label}
[Documentation] Verify pcidevices-controller pods are running
Wait For Pods Running ${namespace} ${label} timeout=900
Wait For Addon Pods Running ${namespace} ${label} timeout=900
Log All pcidevices-controller pods are running in ${namespace}

PCI Devices Webhook Service Should Be Running
[Arguments] ${namespace} ${service_name}
[Documentation] Verify pcidevices-webhook service is running
Wait For Service Running ${namespace} ${service_name} timeout=300
Wait For Addon Service Running ${namespace} ${service_name} timeout=300
Log pcidevices-webhook service is running in ${namespace}

Suite Setup For PCI Devices Addon Tests
Expand All @@ -299,6 +309,6 @@ Suite Teardown For PCI Devices Addon Tests
[Documentation] Cleanup and restore addon state after tests
Log Running suite teardown for PCI Devices addon tests
Run Keyword If '${INITIAL_STATE_PCIDEVICES}' != ${None}
... Restore State ${ADDON_PCIDEVICES} ${INITIAL_STATE_PCIDEVICES}
... Restore Addon State ${ADDON_PCIDEVICES} ${INITIAL_STATE_PCIDEVICES}
Cleanup test resources
Log Suite teardown completed
50 changes: 50 additions & 0 deletions harvester_robot_tests/keywords/common.resource
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
*** Settings ***
Documentation Common Keywords
Library ../libs/keywords/common_keywords.py
Library ../libs/keywords/image_keywords.py
Library ../libs/keywords/network_keywords.py
Library ../libs/keywords/volume_keywords.py
Resource variables.resource


Expand Down Expand Up @@ -32,3 +35,50 @@ Count Pods By Label
${pods}= common_keywords.list_pods_by_label ${namespace} ${label_selector} ${status}
${count}= Get Length ${pods}
RETURN ${count}

Suite Setup For Shared Resources
[Documentation] Suite setup for shared resources
Log Setting up shared resources for the test suite

# Initialize test variables
${timestamp}= Evaluate __import__('datetime').datetime.now().strftime("%Y%m%d%H%M%S")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fetching timestamps is a frequently used operation, may have a common keyword Get Timestamp and support different forms?

Set Suite Variable ${UNIQUE_NAME} ${timestamp}
Set Suite Variable ${VLAN_NETWORK_NAME} vlan-network-${VLAN_ID}
# Harvester enforces a 12-character max on ClusterNetwork and VlanConfig names.
${ts_short}= Evaluate '${timestamp}'[-7:]
Set Suite Variable ${CLUSTER_NETWORK_NAME} cnet-${ts_short}
Set Suite Variable ${VLAN_CONFIG_NAME} vcfg-${ts_short}
Set Suite Variable ${IP_POOL_NAME} ippool-vlan${VLAN_ID}
Set Suite Variable ${IMAGE_NAME} opensuse-${timestamp}

# Create shared resources
network_keywords.create_cluster_network ${CLUSTER_NETWORK_NAME}
network_keywords.create_vlan_config ${VLAN_CONFIG_NAME} ${CLUSTER_NETWORK_NAME} ${VLAN_NIC}
network_keywords.wait_for_cluster_network_ready ${CLUSTER_NETWORK_NAME}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we prefer the style to handle most logic in python layer and just call them in the RF layer?
If that's the case, we can make it a guide in README.md

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I'll update the Readme

network_keywords.create_vlan_network ${VLAN_NETWORK_NAME} ${VLAN_ID} ${CLUSTER_NETWORK_NAME}
network_keywords.create_ip_pool
... ${IP_POOL_NAME}
... ${IP_POOL_SUBNET}
... ${IP_POOL_START}
... ${IP_POOL_END}
... ${DEFAULT_NAMESPACE}/${VLAN_NETWORK_NAME}
image_keywords.create image from url ${IMAGE_NAME} ${OPENSUSE_IMAGE_URL}
image_keywords.wait for image downloaded ${IMAGE_NAME}

Log Test environment ready (image: ${IMAGE_NAME}, vlan: ${VLAN_NETWORK_NAME}, timestamp: ${timestamp}) console=yes

Suite Teardown For Shared Resources
[Documentation] Cleanup all resources after tests.
Log Running shared resources teardown

# Delete shared resources
Run Keyword And Ignore Error network_keywords.delete_ip_pool ${IP_POOL_NAME}
Run Keyword And Ignore Error network_keywords.delete_vlan_network ${VLAN_NETWORK_NAME}
Run Keyword And Ignore Error network_keywords.delete_vlan_config ${VLAN_CONFIG_NAME}
Run Keyword And Ignore Error network_keywords.wait_for_vlan_config_deleted ${VLAN_CONFIG_NAME}
Run Keyword And Ignore Error network_keywords.delete_cluster_network ${CLUSTER_NETWORK_NAME}
Run Keyword And Ignore Error volume_keywords.cleanup_volumes
Run Keyword And Ignore Error image_keywords.delete image ${IMAGE_NAME}

Cleanup test resources
Log Suite teardown completed for shared resources
1 change: 0 additions & 1 deletion harvester_robot_tests/keywords/image.resource
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
*** Settings ***
Documentation Image Keywords
Resource variables.resource
Resource common.resource
Library ../libs/keywords/image_keywords.py

*** Keywords ***
Expand Down
7 changes: 7 additions & 0 deletions harvester_robot_tests/keywords/network.resource
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ Delete VLAN Config
Log Deleting VLAN config: ${name}
network_keywords.delete_vlan_config ${name}

Wait For VLAN Config Deleted
[Arguments] ${name} ${timeout}=${WAIT_TIMEOUT}
[Documentation] Wait for VLAN config to be fully removed before proceeding.
... Required before deleting the parent ClusterNetwork.
Log Waiting for VLAN config ${name} to be deleted
network_keywords.wait_for_vlan_config_deleted ${name} ${timeout}

Wait For Cluster Network Ready
[Arguments] ${name} ${timeout}=${WAIT_TIMEOUT}
[Documentation] Wait for cluster network to become ready.
Expand Down
20 changes: 19 additions & 1 deletion harvester_robot_tests/keywords/setting.resource
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,22 @@ LHv2 Data Engine Is Enabled

Wait Until LHv2 Data Engine Is Enabled
Wait Until Keyword Succeeds ${WAIT_TIMEOUT} ${RETRY_INTERVAL}
... LHv2 Data Engine Is Enabled
... LHv2 Data Engine Is Enabled

# LVM Setting Keywords
Configure CSI Driver Setting For LVM
[Documentation] Add LVM provisioner entry to csi-driver-config setting
Log Configuring csi-driver-config for LVM snapshots
setting_keywords.configure_csi_driver
... csi-driver-config
... lvm.driver.harvesterhci.io
... lvm-snapshot
Log CSI driver config updated for LVM

Reset CSI Driver Setting For LVM
[Documentation] Remove LVM provisioner entry from csi-driver-config setting
Log Resetting csi-driver-config for LVM
setting_keywords.remove_csi_driver
... csi-driver-config
... lvm.driver.harvesterhci.io
Log CSI driver config reset for LVM
Loading
Loading