From f2e68e9fc94d99b1b3511d7a1fad5b76ca8845e4 Mon Sep 17 00:00:00 2001 From: khushboo-rancher Date: Fri, 11 Oct 2024 18:38:30 +0000 Subject: [PATCH] Update testing docs Signed-off-by: khushboo-rancher --- backend/fixtures/api_client.html | 14 ++ backend/fixtures/images.html | 5 +- backend/integrations/test_1_images.html | 5 +- backend/integrations/test_1_volumes.html | 220 +++++------------- index.html | 2 +- integration/modules/skel_skel_spec.html | 6 +- ..._settings_cloud_config_templates_spec.html | 2 +- .../testcases_VM_settings_ssh_keys_spec.html | 4 +- .../testcases_networks_network_spec.html | 8 +- ..._virtualmachines_virtual_machine_spec.html | 4 +- 10 files changed, 89 insertions(+), 181 deletions(-) diff --git a/backend/fixtures/api_client.html b/backend/fixtures/api_client.html index 42b571986..42f942ca4 100644 --- a/backend/fixtures/api_client.html +++ b/backend/fixtures/api_client.html @@ -75,6 +75,12 @@

Functions

+
+def opensuse_checksum(request) +
+
+

Returns openSUSE checksum from config

+
def polling_for(wait_timeout, sleep_timeout)
@@ -132,6 +138,12 @@

Args

+
+def ubuntu_checksum(request) +
+
+

Returns Ubuntu checksum from config

+
def unique_name()
@@ -180,6 +192,7 @@

Args

  • harvester_metadata
  • host_shell
  • host_state
  • +
  • opensuse_checksum
  • polling_for
  • rancher_wait_timeout
  • skip_version_after
  • @@ -188,6 +201,7 @@

    Args

  • sleep_timeout
  • ssh_keypair
  • support_bundle_state
  • +
  • ubuntu_checksum
  • unique_name
  • upgrade_timeout
  • version_check
  • diff --git a/backend/fixtures/images.html b/backend/fixtures/images.html index 1cd1a7664..2dfb8f120 100644 --- a/backend/fixtures/images.html +++ b/backend/fixtures/images.html @@ -64,7 +64,7 @@

    Classes

    class ImageInfo -(url_result, name='', ssh_user=None) +(url_result, image_checksum=None, name='', ssh_user=None)
    @@ -73,13 +73,14 @@

    Classes

    Expand source code
    class ImageInfo:
    -    def __init__(self, url_result, name="", ssh_user=None):
    +    def __init__(self, url_result, image_checksum=None, name="", ssh_user=None):
             self.url_result = url_result
             if name:
                 self.name = name
             else:
                 self.name = self.url.rsplit("/", 1)[-1]
             self.ssh_user = ssh_user
    +        self.image_checksum = image_checksum
     
         def __repr__(self):
             return f"{__class__.__name__}({self.url_result})"
    diff --git a/backend/integrations/test_1_images.html b/backend/integrations/test_1_images.html
    index 31f622104..a34262d5b 100644
    --- a/backend/integrations/test_1_images.html
    +++ b/backend/integrations/test_1_images.html
    @@ -40,7 +40,7 @@ 

    Functions

    -def create_image_url(api_client, name, image_url, wait_timeout) +def create_image_url(api_client, name, image_url, image_checksum, wait_timeout)
    @@ -186,7 +186,8 @@

    Classes

    """ image_name = f"{image_info.name}-{unique_name}" image_url = image_info.url - create_image_url(api_client, image_name, image_url, wait_timeout) + create_image_url(api_client, image_name, image_url, + image_info.image_checksum, wait_timeout) @pytest.mark.skip_version_if("> v1.2.0", "<= v1.4.0", reason="Issue#4293 fix after `v1.4.0`") @pytest.mark.p0 diff --git a/backend/integrations/test_1_volumes.html b/backend/integrations/test_1_volumes.html index 244ce3458..33edf7efe 100644 --- a/backend/integrations/test_1_volumes.html +++ b/backend/integrations/test_1_volumes.html @@ -33,23 +33,67 @@

    Module harvester_e2e_tests.integrations.test_1_volumes

    Functions

    -
    -def test_volume_export(api_client, wait_timeout, unique_name, ubuntu_image) +
    +def test_create_volume(api_client, unique_name, ubuntu_image, create_as, source_type, polling_for)
    -

    ref: https://github.com/harvester/tests/issues/1057

    -
      -
    1. Create image
    2. -
    3. Create volume from the image
    4. -
    5. export the volume to new image
    6. -
    7. delete the new image
    8. +
        +
      1. Create a volume from image
      2. +
      3. Create should respond with 201
      4. +
      5. Wait for volume to create
      6. +
      7. Failures should be at 0
      8. +
      9. Get volume metadata
      10. +
      11. Volume should not be in error or transitioning state
      12. +
      13. ImageId should match what was used in create
      14. +
      15. Delete volume
      16. +
      17. Delete volume should reply 404 after delete +Ref.
      18. +
      +
    +
    +def test_create_volume_bad_checksum(api_client, unique_name, ubuntu_image_bad_checksum, create_as, source_type, polling_for) +
    +
    +
      +
    1. Create a volume from image with a bad checksum
    2. +
    3. Create should respond with 201
    4. +
    5. Wait for volume to create
    6. +
    7. Wait for 4 failures in the volume fail status
    8. +
    9. Failures should be set at 4
    10. +
    11. Delete volume
    12. +
    13. Delete volume should reply 404 after delete +Ref. https://github.com/harvester/tests/issues/1121
    def ubuntu_image(api_client, unique_name, image_ubuntu, polling_for)
    -
    +

    Generates a Ubuntu image

    +
      +
    1. Creates an image name based on unique_name
    2. +
    3. Create the image based on URL
    4. +
    5. Response for creation should be 201
    6. +
    7. Loop while waiting for image to be created
    8. +
    9. Yield the image with the namespace and name
    10. +
    11. Delete the image
    12. +
    13. The response for getting the image name should be 404 after deletion
    14. +
    +
    +
    +def ubuntu_image_bad_checksum(api_client, unique_name, image_ubuntu, polling_for) +
    +
    +

    Generates a Ubuntu image with a bad sha512 checksum

    +
      +
    1. Creates an image name based on unique_name
    2. +
    3. Create the image based on URL with a bad statically assigned checksum
    4. +
    5. Response for creation should be 201
    6. +
    7. Loop while waiting for image to be created
    8. +
    9. Yield the image with the namespace and name
    10. +
    11. Delete the image
    12. +
    13. The response for getting the image name should be 404 after deletion
    14. +
    def ubuntu_vm(api_client, unique_name, ubuntu_image, polling_for) @@ -62,149 +106,6 @@

    Functions

    Classes

    -
    -class TestVolume -
    -
    -
    -
    - -Expand source code - -
    @pytest.mark.p0
    -@pytest.mark.volumes
    -@pytest.mark.parametrize("source_type", ["New", "VM-Image"])
    -@pytest.mark.parametrize("create_as", ["json", "yaml"])
    -class TestVolume:
    -    fixtures, volumes = dict(), dict()
    -
    -    @pytest.mark.dependency()
    -    def test_create_volume(
    -        self, api_client, unique_name, ubuntu_image, create_as, source_type, polling_for
    -    ):
    -        image_id, storage_cls = None, None
    -        unique_name = f"{create_as}-{source_type.lower()}-{unique_name}"
    -        self.volumes[f"{create_as}-{source_type}"] = unique_name
    -
    -        if source_type == "VM-Image":
    -            image_id, storage_cls = ubuntu_image['id'], f"longhorn-{ubuntu_image['display_name']}"
    -
    -        spec = api_client.volumes.Spec("10Gi", storage_cls)
    -        if create_as == 'yaml':
    -            kws = dict(headers={'Content-Type': 'application/yaml'}, json=None,
    -                       data=yaml.dump(spec.to_dict(unique_name, 'default', image_id=image_id)))
    -        else:
    -            kws = dict()
    -        code, data = api_client.volumes.create(unique_name, spec, image_id=image_id, **kws)
    -        assert 201 == code, (code, unique_name, data, image_id)
    -
    -        polling_for("volume do created",
    -                    lambda code, data: 200 == code and data['status']['phase'] == "Bound",
    -                    api_client.volumes.get, unique_name)
    -
    -        code, data = api_client.volumes.get(unique_name)
    -        mdata, annotations = data['metadata'], data['metadata']['annotations']
    -        assert 200 == code, (code, data)
    -        assert unique_name == mdata['name'], (code, data)
    -        # status
    -        assert not mdata['state']['error'], (code, data)
    -        assert not mdata['state']['transitioning'], (code, data)
    -        assert data['status']['phase'] == "Bound", (code, data)
    -        # source
    -        if source_type == "VM-Image":
    -            assert image_id == annotations['harvesterhci.io/imageId'], (code, data)
    -        else:
    -            assert not annotations.get('harvesterhci.io/imageId'), (code, data)
    -        # attachment
    -        assert not annotations.get("harvesterhci.io/owned-by"), (code, data)
    -
    -    @pytest.mark.dependency(depends=["TestVolume::test_create_volume"], param=True)
    -    def test_clone_volume(self, api_client, wait_timeout, create_as, source_type):
    -        self.fixtures.update(api_client=api_client, wait_timeout=wait_timeout)
    -        unique_name = self.volumes[f"{create_as}-{source_type}"]
    -        code, data = api_client.volumes.get(unique_name)
    -        assert 200 == code, (code, data)
    -
    -        cloned_name = f"cloned-{unique_name}"
    -        code, data = api_client.volumes.clone(unique_name, cloned_name)
    -        assert 204 == code, (code, data)
    -
    -        endtime = datetime.now() + timedelta(seconds=wait_timeout)
    -        while endtime > datetime.now():
    -            code, data = api_client.volumes.get(cloned_name)
    -            if "Bound" == data['status']['phase']:
    -                break
    -            sleep(5)
    -        else:
    -            raise AssertionError(
    -                "Volume not changed to phase: _Bound_ with {wait_timeout} timed out\n"
    -                f"Got error: {code}, {data}"
    -            )
    -
    -        self.volumes[cloned_name] = cloned_name
    -
    -    @classmethod
    -    def teardown_class(cls):
    -        api_client, wait_timeout = cls.fixtures['api_client'], cls.fixtures['wait_timeout']
    -
    -        vol_names = cls.volumes.values()
    -        for name in vol_names:
    -            api_client.volumes.delete(name)
    -
    -        endtime = datetime.now() + timedelta(seconds=wait_timeout)
    -        while endtime > datetime.now():
    -            code, data = api_client.volumes.get()
    -            volumes = [v['metadata']['name'] for v in data['data']]
    -            if all(v not in volumes for v in vol_names):
    -                break
    -            sleep(3)
    -        else:
    -            raise AssertionError(
    -                "Volumes not deleted correctly\n"
    -                f"existing: {volumes}\n"
    -                f"created: {vol_names}"
    -            )
    -
    -

    Class variables

    -
    -
    var fixtures
    -
    -
    -
    -
    var pytestmark
    -
    -
    -
    -
    var volumes
    -
    -
    -
    -
    -

    Static methods

    -
    -
    -def teardown_class() -
    -
    -
    -
    -
    -

    Methods

    -
    -
    -def test_clone_volume(self, api_client, wait_timeout, create_as, source_type) -
    -
    -
    -
    -
    -def test_create_volume(self, api_client, unique_name, ubuntu_image, create_as, source_type, polling_for) -
    -
    -
    -
    -
    -
    class TestVolumeWithVM
    @@ -375,25 +276,16 @@

    Methods

  • Functions

  • Classes