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 API documentation + + + + + + + + + + + +
+
+
+

Module harvester_e2e_tests.fixtures.base

+
+
+
+
+
+
+
+
+

Functions

+
+
+def wait_until(timeout, snooze=3) +
+
+
+
+
+
+
+
+
+ +
+ + + diff --git a/backend/fixtures/images.html b/backend/fixtures/images.html index 96b40a5bb..1cd1a7664 100644 --- a/backend/fixtures/images.html +++ b/backend/fixtures/images.html @@ -33,6 +33,12 @@

Module harvester_e2e_tests.fixtures.images

Functions

+
+def image_checker(api_client, wait_timeout, sleep_timeout) +
+
+
+
def image_k3s(request)
@@ -133,6 +139,7 @@

Instance variables

  • Functions

  • @@ -75,11 +87,14 @@

    Sub-modules

  • Sub-modules

  • diff --git a/backend/fixtures/networks.html b/backend/fixtures/networks.html index 0ccbfb67e..018daa15d 100644 --- a/backend/fixtures/networks.html +++ b/backend/fixtures/networks.html @@ -33,6 +33,12 @@

    Module harvester_e2e_tests.fixtures.networks

    Functions

    +
    +def network_checker(api_client, wait_timeout, sleep_timeout) +
    +
    +
    +
    def vlan_id(request)
    @@ -62,6 +68,7 @@

    Functions

  • Functions

    diff --git a/backend/fixtures/settings.html b/backend/fixtures/settings.html new file mode 100644 index 000000000..70698d80c --- /dev/null +++ b/backend/fixtures/settings.html @@ -0,0 +1,69 @@ + + + + + + +harvester_e2e_tests.fixtures.settings API documentation + + + + + + + + + + + +
    +
    +
    +

    Module harvester_e2e_tests.fixtures.settings

    +
    +
    +
    +
    +
    +
    +
    +
    +

    Functions

    +
    +
    +def setting_checker(api_client, wait_timeout, sleep_timeout) +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    + + + diff --git a/backend/fixtures/volumes.html b/backend/fixtures/volumes.html new file mode 100644 index 000000000..8af91f503 --- /dev/null +++ b/backend/fixtures/volumes.html @@ -0,0 +1,69 @@ + + + + + + +harvester_e2e_tests.fixtures.volumes API documentation + + + + + + + + + + + +
    +
    +
    +

    Module harvester_e2e_tests.fixtures.volumes

    +
    +
    +
    +
    +
    +
    +
    +
    +

    Functions

    +
    +
    +def volume_checker(api_client, wait_timeout, sleep_timeout) +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    + + + diff --git a/backend/integrations/test_0_storage_network.html b/backend/integrations/test_0_storage_network.html index 02cb6ec3e..13a38f8ec 100644 --- a/backend/integrations/test_0_storage_network.html +++ b/backend/integrations/test_0_storage_network.html @@ -40,7 +40,7 @@

    Functions

    -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 @@

    Functions

    -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

    +
      +
    1. Have at least one Running VM
    2. +
    3. Enable storage-network (should fail)
    4. +
    5. Stop all VMs via API
    6. +
    7. Enable storage-network
    8. +
    +
    +
    +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. +
    3. Enable storage-network (should fail)
    4. +
    5. Stop all VMs via VM CLI
    6. +
    7. Enable storage-network
    8. +
    +
    +
    +
    +