Module harvester_e2e_tests.apis.test_settings

Functions

def test_get_all_settings(api_client, expected_settings)
Expand source code
@pytest.mark.p0
@pytest.mark.settings
def test_get_all_settings(api_client, expected_settings):
    expected_settings = expected_settings['default']
    code, data = api_client.settings.get()

    available_settings = {m['metadata']['name'] for m in data['items']}

    assert 200 == code, (code, data)
    assert expected_settings <= available_settings, (
        "Some setting missing:\n"
        f"{expected_settings - available_settings}"
    )
def test_get_all_settings_v110(api_client, expected_settings)
Expand source code
@pytest.mark.p0
@pytest.mark.settings
@pytest.mark.skip_version_before('v1.1.0')
def test_get_all_settings_v110(api_client, expected_settings):
    expected_settings = expected_settings['default'] | expected_settings['1.1.0']
    code, data = api_client.settings.get()

    available_settings = {m['metadata']['name'] for m in data['items']}

    assert 200 == code, (code, data)
    assert expected_settings <= available_settings, (
        "Some setting missing:\n"
        f"{expected_settings - available_settings}"
    )

    removed = expected_settings - available_settings
    added = available_settings - expected_settings

    if removed:
        warnings.warn(UserWarning(f"Few setting(s) been removed: {removed}."))
    if added:
        warnings.warn(UserWarning(f"New setting(s) added: {added}"))
def test_get_storage_network(api_client)
Expand source code
@pytest.mark.p0
@pytest.mark.settings
def test_get_storage_network(api_client):
    code, data = api_client.settings.get("storage-network")
    assert 200 == code, (f"Failed to get storage-network setting with error: {code}, {data}")
def test_update_log_level(api_client)
Expand source code
@pytest.mark.p0
@pytest.mark.settings
def test_update_log_level(api_client):
    code, data = api_client.settings.get("log-level")
    assert 200 == code, (f"Failed to get log-level setting with error: {code}, {data}")

    original_value = data.get("value", data['default'])
    updates = {"value": "Debug"}
    code, data = api_client.settings.update("log-level", updates)

    assert 200 == code, (f"Failed to update log-level setting with error: {code}, {data}")

    # For teardown
    updates = {"value": original_value}
    api_client.settings.update("log-level", updates)

Classes

class TestUpdateInvalidBackupTarget
Expand source code
@pytest.mark.p0
@pytest.mark.negative
@pytest.mark.settings
class TestUpdateInvalidBackupTarget:
    def test_invalid_nfs(self, api_client):
        NFSSpec = api_client.settings.BackupTargetSpec.NFS

        spec = NFSSpec('not_starts_with_nfs://')
        code, data = api_client.settings.update('backup-target', spec)
        assert 422 == code, (
            f"NFS backup-target should check endpoint starting with `nfs://`\n"
            f"API Status({code}): {data}"
        )

        spec = NFSSpec('nfs://:/lack_server')
        code, data = api_client.settings.update('backup-target', spec)
        assert 422 == code, (
            f"NFS backup-target should check endpoint had server path\n"
            f"API Status({code}): {data}"
        )

        spec = NFSSpec('nfs://127.0.0.1:')
        code, data = api_client.settings.update('backup-target', spec)
        assert 422 == code, (
            f"NFS backup-target should check endpoint had mount path\n"
            f"API Status({code}): {data}"
        )

    def test_invalid_S3(self, api_client):
        S3Spec = api_client.settings.BackupTargetSpec.S3

        spec = S3Spec('bogus_bucket', 'bogus_region', 'bogus_key', 'bogus_secret')
        code, data = api_client.settings.update('backup-target', spec)
        assert 422 == code, (
            f"S3 backup-target should check key/secret/bucket/region"
            f"API Status({code}): {data}"
        )

        spec = S3Spec('', '', '', '', endpoint="http://127.0.0.1")
        code, data = api_client.settings.update('backup-target', spec)
        assert 422 == code, (
            f"S3 backup-target should check key/secret/bucket/region"
            f"API Status({code}): {data}"
        )

Class variables

var pytestmark

Methods

def test_invalid_S3(self, api_client)
Expand source code
def test_invalid_S3(self, api_client):
    S3Spec = api_client.settings.BackupTargetSpec.S3

    spec = S3Spec('bogus_bucket', 'bogus_region', 'bogus_key', 'bogus_secret')
    code, data = api_client.settings.update('backup-target', spec)
    assert 422 == code, (
        f"S3 backup-target should check key/secret/bucket/region"
        f"API Status({code}): {data}"
    )

    spec = S3Spec('', '', '', '', endpoint="http://127.0.0.1")
    code, data = api_client.settings.update('backup-target', spec)
    assert 422 == code, (
        f"S3 backup-target should check key/secret/bucket/region"
        f"API Status({code}): {data}"
    )
def test_invalid_nfs(self, api_client)
Expand source code
def test_invalid_nfs(self, api_client):
    NFSSpec = api_client.settings.BackupTargetSpec.NFS

    spec = NFSSpec('not_starts_with_nfs://')
    code, data = api_client.settings.update('backup-target', spec)
    assert 422 == code, (
        f"NFS backup-target should check endpoint starting with `nfs://`\n"
        f"API Status({code}): {data}"
    )

    spec = NFSSpec('nfs://:/lack_server')
    code, data = api_client.settings.update('backup-target', spec)
    assert 422 == code, (
        f"NFS backup-target should check endpoint had server path\n"
        f"API Status({code}): {data}"
    )

    spec = NFSSpec('nfs://127.0.0.1:')
    code, data = api_client.settings.update('backup-target', spec)
    assert 422 == code, (
        f"NFS backup-target should check endpoint had mount path\n"
        f"API Status({code}): {data}"
    )
class TestUpdateInvalidStorageNetwork
Expand source code
@pytest.mark.p0
@pytest.mark.negative
@pytest.mark.settings
class TestUpdateInvalidStorageNetwork:
    invalid_vlan_id = 4095
    invalid_ip_range = "127.0.0.1/24"
    mgmt_network = "mgmt"

    def test_invalid_vlanid(self, api_client):
        spec = api_client.settings.StorageNetworkSpec.enable_with(
            self.invalid_vlan_id, self.mgmt_network, "192.168.1.0/24"
        )
        code, data = api_client.settings.update('storage-network', spec)

        assert 422 == code, (
            f"Storage Network should NOT able to create with VLAN ID: {self.invalid_vlan_id}\n"
            f"API Status({code}): {data}"
        )

    def test_invalid_iprange(self, api_client):
        valid_vlan_id = 1
        spec = api_client.settings.StorageNetworkSpec.enable_with(
            valid_vlan_id, self.mgmt_network, self.invalid_ip_range
        )
        code, data = api_client.settings.update('storage-network', spec)

        assert 422 == code, (
            f"Storage Network should NOT able to create with IP Range: {self.invalid_ip_range}\n"
            f"API Status({code}): {data}"
        )

Class variables

var invalid_ip_range
var invalid_vlan_id
var mgmt_network
var pytestmark

Methods

def test_invalid_iprange(self, api_client)
Expand source code
def test_invalid_iprange(self, api_client):
    valid_vlan_id = 1
    spec = api_client.settings.StorageNetworkSpec.enable_with(
        valid_vlan_id, self.mgmt_network, self.invalid_ip_range
    )
    code, data = api_client.settings.update('storage-network', spec)

    assert 422 == code, (
        f"Storage Network should NOT able to create with IP Range: {self.invalid_ip_range}\n"
        f"API Status({code}): {data}"
    )
def test_invalid_vlanid(self, api_client)
Expand source code
def test_invalid_vlanid(self, api_client):
    spec = api_client.settings.StorageNetworkSpec.enable_with(
        self.invalid_vlan_id, self.mgmt_network, "192.168.1.0/24"
    )
    code, data = api_client.settings.update('storage-network', spec)

    assert 422 == code, (
        f"Storage Network should NOT able to create with VLAN ID: {self.invalid_vlan_id}\n"
        f"API Status({code}): {data}"
    )
class TestUpdateKubeconfigDefaultToken
Expand source code
@pytest.mark.p0
@pytest.mark.settings
class TestUpdateKubeconfigDefaultToken:
    @pytest.mark.skip_version_before("v1.3.2", reason="Issue#5891 fixed after v1.3.2")
    def test_invalid_kubeconfig_ttl_min(self, api_client):
        KubeconfigTTLMinSpec = api_client.settings.KubeconfigDefaultTokenTTLSpec.TTL
        spec = KubeconfigTTLMinSpec(99999999999999)
        code, data = api_client.settings.update('kubeconfig-default-token-ttl-minutes', spec)
        assert 422 == code, (
            f"Kubeconfig Default Token TTL Minutes should not exceed 100yrs\n"
            f"API Status({code}): {data}"
        )

    @pytest.mark.skip_version_before('v1.3.1')
    def test_valid_kubeconfig_ttl_min(self, api_client):
        KubeconfigTTLMinSpec = api_client.settings.KubeconfigDefaultTokenTTLSpec.TTL
        spec = KubeconfigTTLMinSpec(172800)
        code, data = api_client.settings.update('kubeconfig-default-token-ttl-minutes', spec)
        assert 200 == code, (
            f"Kubeconfig Default Token TTL Minutes be allowed to be set for 120 days\n"
            f"API Status({code}): {data}"
        )

Class variables

var pytestmark

Methods

def test_invalid_kubeconfig_ttl_min(self, api_client)
Expand source code
@pytest.mark.skip_version_before("v1.3.2", reason="Issue#5891 fixed after v1.3.2")
def test_invalid_kubeconfig_ttl_min(self, api_client):
    KubeconfigTTLMinSpec = api_client.settings.KubeconfigDefaultTokenTTLSpec.TTL
    spec = KubeconfigTTLMinSpec(99999999999999)
    code, data = api_client.settings.update('kubeconfig-default-token-ttl-minutes', spec)
    assert 422 == code, (
        f"Kubeconfig Default Token TTL Minutes should not exceed 100yrs\n"
        f"API Status({code}): {data}"
    )
def test_valid_kubeconfig_ttl_min(self, api_client)
Expand source code
@pytest.mark.skip_version_before('v1.3.1')
def test_valid_kubeconfig_ttl_min(self, api_client):
    KubeconfigTTLMinSpec = api_client.settings.KubeconfigDefaultTokenTTLSpec.TTL
    spec = KubeconfigTTLMinSpec(172800)
    code, data = api_client.settings.update('kubeconfig-default-token-ttl-minutes', spec)
    assert 200 == code, (
        f"Kubeconfig Default Token TTL Minutes be allowed to be set for 120 days\n"
        f"API Status({code}): {data}"
    )