Module harvester_e2e_tests.fixtures.base
+Functions
+-
+
+def wait_until(timeout, snooze=3) +
+- + + +
diff --git a/backend/fixtures/base.html b/backend/fixtures/base.html new file mode 100644 index 000000000..91844bf32 --- /dev/null +++ b/backend/fixtures/base.html @@ -0,0 +1,69 @@ + + +
+ + + +harvester_e2e_tests.fixtures.base
+def wait_until(timeout, snooze=3)
+
harvester_e2e_tests.fixtures.images
+def image_checker(api_client, wait_timeout, sleep_timeout)
+
def image_k3s(request)
image_checker
image_k3s
image_opensuse
image_ubuntu
harvester_e2e_tests.fixtures.base
harvester_e2e_tests.fixtures.images
harvester_e2e_tests.fixtures.settings
harvester_e2e_tests.fixtures.terraform
harvester_e2e_tests.fixtures.volumes
harvester_e2e_tests.fixtures.api_client
harvester_e2e_tests.fixtures.base
harvester_e2e_tests.fixtures.images
harvester_e2e_tests.fixtures.networks
harvester_e2e_tests.fixtures.rancher_api_client
harvester_e2e_tests.fixtures.settings
harvester_e2e_tests.fixtures.terraform
harvester_e2e_tests.fixtures.virtualmachines
harvester_e2e_tests.fixtures.volumes
harvester_e2e_tests.fixtures.networks
+def network_checker(api_client, wait_timeout, sleep_timeout)
+
def vlan_id(request)
harvester_e2e_tests.fixtures.settings
+def setting_checker(api_client, wait_timeout, sleep_timeout)
+
harvester_e2e_tests.fixtures.volumes
+def volume_checker(api_client, wait_timeout, sleep_timeout)
+
-def test_storage_network(api_client, cluster_network, vlan_id, unique_name, wait_timeout)
+def test_storage_network(api_client, cluster_network, vlan_id, unique_name, wait_timeout, setting_checker)
To cover test: diff --git a/backend/integrations/test_1_images.html b/backend/integrations/test_1_images.html index 6297de140..4b96c27b5 100644 --- a/backend/integrations/test_1_images.html +++ b/backend/integrations/test_1_images.html @@ -82,10 +82,10 @@
-def storage_network(api_client, cluster_network, vlan_id, vlan_cidr, wait_timeout, sleep_timeout)
+def storage_network(api_client, cluster_network, vlan_id, vlan_cidr, setting_checker)
def vlan_cidr(api_client, cluster_network, vlan_id, wait_timeout, sleep_timeout)
diff --git a/backend/integrations/test_3_vm.html b/backend/integrations/test_3_vm.html
index 92b46be0b..94a9b2dae 100644
--- a/backend/integrations/test_3_vm.html
+++ b/backend/integrations/test_3_vm.html
@@ -39,26 +39,50 @@ Functions
-
-def focal_image(api_client, unique_name, image_ubuntu, wait_timeout)
+
+def cluster_network(api_client, vlan_nic)
+
+def minimal_vm(api_client, unique_name, ubuntu_image, ssh_keypair, vm_checker)
+
+
+
+
+
+def storage_network(api_client, cluster_network, vm_network, setting_checker)
+
+
+
+
-def test_migrate_vm_with_multiple_volumes(api_client, unique_name, focal_image, wait_timeout, available_node_names)
+def test_migrate_vm_with_multiple_volumes(api_client, unique_name, ubuntu_image, wait_timeout, available_node_names, vm_checker)
-def test_migrate_vm_with_user_data(api_client, unique_name, focal_image, wait_timeout, available_node_names)
+def test_migrate_vm_with_user_data(api_client, unique_name, ubuntu_image, wait_timeout, available_node_names, vm_checker)
-def test_multiple_migrations(api_client, unique_name, focal_image, wait_timeout, available_node_names)
+def test_multiple_migrations(api_client, unique_name, ubuntu_image, wait_timeout, available_node_names)
+
+
+
+
+
+def ubuntu_image(api_client, unique_name, image_ubuntu, image_checker)
+
+
+
+
+
+def vm_network(api_client, unique_name, cluster_network, vlan_id, network_checker)
@@ -66,6 +90,144 @@ Functions
+Classes
+
+
+class TestVMWithStorageNetwork
+
+-
+
+
+
+Expand source code
+
+@pytest.mark.p0
+@pytest.mark.networks
+@pytest.mark.settings
+@pytest.mark.virtualmachines
+@pytest.mark.skip_version_if("< v1.0.3")
+class TestVMWithStorageNetwork:
+ def test_enable_storage_network_with_api_stopped_vm(
+ self, api_client, minimal_vm, storage_network, setting_checker, vm_checker, volume_checker
+ ):
+ '''
+ Steps:
+ 1. Have at least one Running VM
+ 2. Enable storage-network (should fail)
+ 3. Stop all VMs via API
+ 4. Enable storage-network
+ '''
+ code, data = api_client.settings.update('storage-network', storage_network.enable_spec)
+ assert 422 == code, (
+ f"storage-network should NOT be enabled with running VM: {code}, {data}"
+ )
+
+ # stop VM by API
+ vm_stopped, (code, data) = vm_checker.wait_status_stopped(minimal_vm.name)
+ assert vm_stopped, (code, data)
+
+ code, data = api_client.vms.get(minimal_vm.name)
+ spec = api_client.vms.Spec.from_dict(data)
+ vol_names = [vol['volume']['persistentVolumeClaim']['claimName'] for vol in spec.volumes]
+ vm_volumes_detached, (code, data) = volume_checker.wait_volumes_detached(vol_names)
+ assert vm_volumes_detached, (code, data)
+
+ # enable storage-network
+ code, data = api_client.settings.update('storage-network', storage_network.enable_spec)
+ assert 200 == code, (code, data)
+ snet_enabled, (code, data) = setting_checker.wait_storage_net_enabled_on_harvester()
+ assert snet_enabled, (code, data)
+ snet_enabled, (code, data) = setting_checker.wait_storage_net_enabled_on_longhorn(
+ storage_network.cidr
+ )
+ assert snet_enabled, (code, data)
+
+ def test_enable_storage_network_with_cli_stopped_vm(
+ self, api_client, ssh_keypair, minimal_vm, storage_network, setting_checker,
+ vm_shell_from_host, wait_timeout, volume_checker
+ ):
+ ''' Refer to https://github.com/harvester/tests/issues/1022
+ Steps:
+ 1. Have at least one Running VM
+ 2. Enable storage-network (should fail)
+ 3. Stop all VMs via VM CLI
+ 4. Enable storage-network
+ '''
+ code, data = api_client.settings.update('storage-network', storage_network.enable_spec)
+ assert 422 == code, (
+ f"storage-network should NOT be enabled with running VM: {code}, {data}"
+ )
+
+ # stop VM by CLI
+ with vm_shell_from_host(
+ minimal_vm.host_ip, minimal_vm.vm_ip, minimal_vm.ssh_user, pkey=ssh_keypair[1]
+ ) as sh:
+ sh.exec_command('sudo shutdown now')
+
+ endtime = datetime.now() + timedelta(seconds=wait_timeout)
+ while endtime > datetime.now():
+ code, data = api_client.vms.get(minimal_vm.name)
+ if 200 == code and "Stopped" == data.get('status', {}).get('printableStatus'):
+ break
+ sleep(3)
+ else:
+ raise AssertionError(
+ f"Fail to shutdown VM {minimal_vm.name} with error: {code}, {data}"
+ )
+
+ code, data = api_client.vms.get(minimal_vm.name)
+ spec = api_client.vms.Spec.from_dict(data)
+ vol_names = [vol['volume']['persistentVolumeClaim']['claimName'] for vol in spec.volumes]
+ vm_volumes_detached, (code, data) = volume_checker.wait_volumes_detached(vol_names)
+ assert vm_volumes_detached, (code, data)
+
+ # enable storage-network
+ code, data = api_client.settings.update('storage-network', storage_network.enable_spec)
+ assert 200 == code, (code, data)
+ snet_enabled, (code, data) = setting_checker.wait_storage_net_enabled_on_harvester()
+ assert snet_enabled, (code, data)
+ snet_enabled, (code, data) = setting_checker.wait_storage_net_enabled_on_longhorn(
+ storage_network.cidr
+ )
+ assert snet_enabled, (code, data)
+
+Class variables
+
+var pytestmark
+-
+
+
+
+Methods
+
+
+def test_enable_storage_network_with_api_stopped_vm(self, api_client, minimal_vm, storage_network, setting_checker, vm_checker, volume_checker)
+
+-
+
Steps
+
+- Have at least one Running VM
+- Enable storage-network (should fail)
+- Stop all VMs via API
+- Enable storage-network
+
+
+
+def test_enable_storage_network_with_cli_stopped_vm(self, api_client, ssh_keypair, minimal_vm, storage_network, setting_checker, vm_shell_from_host, wait_timeout, volume_checker)
+
+-
+
Refer to https://github.com/harvester/tests/issues/1022
+Steps
+
+- Have at least one Running VM
+- Enable storage-network (should fail)
+- Stop all VMs via VM CLI
+- Enable storage-network
+
+
+
+
+