Example #1
0
def test_no_domain():
    hpe3par_cli = None
    objs_dict = None
    try:
        # yml = "YAML/multi-domain-no-domain.yml"
        yml = "YAML/MD-cpg-1-domain-no.yml"
        array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
        hpe3par_cli = manager.get_3par_cli_client(yml)

        cpg_domain, host_domain, host, cpg_name = get_domain(yml, hpe3par_cli)
        hpe3par_version = manager.get_array_version(hpe3par_cli)
        print("\n########################### Multi-Domain::test_no_domain::%s%s::START ###########################" %
              (hpe3par_version[0:5],protocol))

        assert cpg_domain is None, "CPG %s belongs to domain %s, terminating test" % (cpg_name, cpg_domain)
        assert host_domain is None, "Host %s belongs to domain %s, terminating test" % (host, host_domain)

        # run_pod(yml, hpe3par_cli, protocol)
        print("=== Creating pod for CPG and host in no domain")
        status, kind, reason, obj, objs_dict = create_pod(yml, hpe3par_cli)
        assert status is True, "Test for CPG and HOST both in no domain is failed as % failed to %" % (kind, reason)
        verify(hpe3par_cli, protocol, objs_dict['pvc'], objs_dict['pod'], objs_dict['sc'], objs_dict['secret'])
        print("\n########################### Multi-Domain::test_no_domain::%s%s::END ###########################" %
              (hpe3par_version[0:5], protocol))
    except Exception as e:
        print("Exception in test_no_domain :: %s" % e)
    finally:
        if hpe3par_cli is not None:
            hpe3par_cli.logout()
        if objs_dict is not None:
            cleanup(objs_dict['secret'], objs_dict['sc'], objs_dict['pvc'], objs_dict['pod'])
Example #2
0
def test_diff_domain():
    hpe3par_cli = None
    base_objs_dict = None
    objs_dict = None
    try:
        yml_1 = 'YAML/MD-cpg-2-domain-x.yml'
        hpe3par_cli = manager.get_3par_cli_client(yml_1)

        cpg_domain, host_domain, host, cpg_name = get_domain(yml_1, hpe3par_cli)
        hpe3par_version = manager.get_array_version(hpe3par_cli)
        array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml_1)
        print("\n########################### Multi-Domain::test_diff_domain::%s%s::START ###########################" %
              (hpe3par_version[0:5], protocol))

        """print("\n\n%s" % cpg_domain)
        print("\n\n%s" % host_domain)

        assert host is None or (host is not None and cpg_domain != host_domain), \
            "Host entry exists with domain %s whereas cpg %s belongs to %s. Terminating test." % (
            host_domain, cpg_name, cpg_domain)"""

        if host is None:
            base_status, base_kind, base_reason, base_obj, base_objs_dict = create_pod(yml_1, hpe3par_cli)
            assert base_status is True, "Terminating test since %s failed to %s" % (base_kind, base_reason)
            print("Volume created and publishes successfully for domain %s" % cpg_domain)
            cpg_domain, host_domain, host, cpg_name = get_domain(yml_1, hpe3par_cli)

        yml_2 = "YAML/MD-cpg-4-domain-y.yml"
        array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml_2)
        cpg_domain_2, host_domain_2, host_2, cpg_name_2 = get_domain(yml_2, hpe3par_cli)

        assert host_domain != cpg_domain_2, \
            "Terminating test since host %s is in domain %s and cpg %s also belongs to same domain" % (host, host_domain, cpg_name_2)
        print("Now creating and publishing volume in different domain %s ..." % cpg_domain_2)
        status, kind, reason, obj, objs_dict = create_pod(yml_2, hpe3par_cli)
        assert status is False and kind == 'POD' and reason == 'Running', \
            'multi-domain test failed as %s failed to %s while exporting volume on different domain' % (kind, obj)

        print("Verifying Volume, CRD and vluns for published volume...")
        verify(hpe3par_cli, protocol, objs_dict['pvc'], objs_dict['pod'], objs_dict['sc'], objs_dict['secret'])
        print("Second volume created and publishes successfully in same domain")
        print("\n########################### Multi-Domain::test_diff_domain::%s%s::END ###########################" %
              (hpe3par_version[0:5], protocol))
    except Exception as e:
        print("Exception in test_diff_domain :: %s" % e)

    finally:
        if hpe3par_cli is not None:
            hpe3par_cli.logout()
        if base_objs_dict is not None:
            cleanup(base_objs_dict['secret'], base_objs_dict['sc'], base_objs_dict['pvc'], base_objs_dict['pod'])
        if objs_dict is not None:
            cleanup(objs_dict['secret'], objs_dict['sc'], objs_dict['pvc'], objs_dict['pod'])
Example #3
0
def test_same_domain():
    hpe3par_cli = None
    objs_dict = None
    base_objs_dict = None
    try:
        yml_1 = 'YAML/MD-cpg-2-domain-x.yml'
        hpe3par_cli = manager.get_3par_cli_client(yml_1)
        array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml_1)

        cpg_domain, host_domain, host, cpg_name = get_domain(yml_1, hpe3par_cli)
        hpe3par_version = manager.get_array_version(hpe3par_cli)
        print("\n########################### Multi-Domain::test_same_domain::%s%s::START ###########################" %
              (hpe3par_version[0:5], protocol))
        print("\n\n%s" % cpg_domain)
        print("\n\n%s" % host_domain)

        assert host is None or (host is not None and cpg_domain == host_domain), \
            "Host entry exists with domain %s whereas cpg %s belongs to %s. Terminating test for same domain." % (host_domain, cpg_name, cpg_domain)

        base_status, base_kind, base_reason, base_obj, base_objs_dict = create_pod(yml_1, hpe3par_cli)
        assert base_status is True, "Terminating test since %s failed to %s" % (base_kind, base_reason)
        print("Volume created and publishes successfully for domain %s" % cpg_domain)

        yml_2 = "YAML/MD-cpg-3-domain-x.yml"
        # array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml_2)
        cpg_domain_2, host_domain_2, host_2, cpg_name_2 = get_domain(yml_2, hpe3par_cli)
        assert cpg_domain == cpg_domain_2, "Terminating test as %s does not belong to % domain" % (cpg_name_2,
                                                                                                   cpg_domain)
        print("Now creating and publishing another volume in same domain %s ..." % cpg_domain)

        status, kind, reason, obj, objs_dict = create_pod(yml_2, hpe3par_cli)
        assert status is True, "Failed to publish volume on existing domain %s as %s failed to %s" % (cpg_domain, kind, reason)

        print("Verifying Volume, CRD and vluns for published volume...")
        verify(hpe3par_cli, protocol, objs_dict['pvc'], objs_dict['pod'], objs_dict['sc'], objs_dict['secret'])
        print("Second volume created and publishes successfully in same domain")
        print("\n########################### Multi-Domain::test_same_domain::%s%s::END ###########################" %
          (hpe3par_version[0:5], protocol))
    except Exception as e:
        print("Exception in test_same_domain :: %s" % e)

    finally:
        if hpe3par_cli is not None:
            hpe3par_cli.logout()
        if base_objs_dict is not None:
            cleanup(base_objs_dict['secret'], base_objs_dict['sc'], base_objs_dict['pvc'], base_objs_dict['pod'])
        if objs_dict is not None:
            cleanup(objs_dict['secret'], objs_dict['sc'], objs_dict['pvc'], objs_dict['pod'])
def secret():
    global enc_secret
    if globals.encryption_test:
        enc_secret()
    if globals.replication_test is False:
        yml = None
        global array_ip, array_uname, array_pwd, access_protocol, hpe3par_version, hpe3par_cli, namespace, secret_dir
        #if array_ip is None or namespace is None or access_protocol is None:
        if secret_dir is not None:
            yml = "%s/secret.yml" % secret_dir
            array_ip, array_uname, array_pwd = manager.read_array_prop(yml)
            logging.getLogger().info(
                "Did not find backend, protocol and namespace in command line, picking from %s"
                % yml)

        logging.getLogger().info("Backend :: %s, namespace :: %s" %
                                 (array_ip, namespace))
        hpe3par_cli = manager.get_3par_cli_client(array_ip)
        hpe3par_version = manager.get_array_version(hpe3par_cli)
        globals.hpe3par_cli = hpe3par_cli
        globals.hpe3par_version = hpe3par_version
        logging.getLogger().info(
            '=============================== Test Automation START ========================'
        )
        logging.getLogger().info("Array :: %s [%s] " %
                                 (array_ip, hpe3par_version[0:5]))
        """logging.error("\n########################### test_publish::%s::%s###########################" %
                      (protocol, hpe3par_version))"""
        if yml is None:
            yml = "{'apiVersion': 'v1', " \
                  "'kind': 'Secret', " \
                  "'metadata': {'name': 'ci-primera3par-csp-secret', 'namespace': %s}, " \
                  "'stringData': {'serviceName': 'primera3par-csp-svc', 'servicePort': '8080', " \
                                "'backend': %s, 'username': %s}, " \
                  "'data': {'password': %s}}" % (namespace, array_ip, '3paradm', 'M3BhcmRhdGE=')
            secret = manager.hpe_create_secret_object(yaml.load(yml))
        else:
            secret = manager.create_secret(yml, globals.namespace)
    yield
    if globals.replication_test is False:
        manager.delete_secret(secret.metadata.name, secret.metadata.namespace)
        hpe3par_cli.logout()
    if globals.encryption_test:
        manager.delete_secret(enc_secret.metadata.name,
                              enc_secret.metadata.namespace)
        pass
Example #5
0
def test_publish():
    secret = None
    sc = None
    pvc = None
    pod = None
    try:
        yml = "YAML/test-publish.yml"
        array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(
            yml)
        hpe3par_cli = manager.get_3par_cli_client(yml)
        hpe3par_version = manager.get_array_version(hpe3par_cli)
        print(
            "\n########################### test_publish::%s::%s ###########################"
            % (protocol, hpe3par_version[0:5]))
        """logging.error("\n########################### test_publish::%s::%s###########################" %
                      (protocol, hpe3par_version))"""
        secret = manager.create_secret(yml)
        step = "secret"
        sc = manager.create_sc(yml)
        step = "sc"
        pvc = manager.create_pvc(yml)
        step = "pvc"
        flag, pvc_obj = manager.check_status(timeout,
                                             pvc.metadata.name,
                                             kind='pvc',
                                             status='Bound',
                                             namespace=pvc.metadata.namespace)
        assert flag is True, "PVC %s status check timed out, not in Bound state yet..." % pvc_obj.metadata.name

        pvc_crd = manager.get_pvc_crd(pvc_obj.spec.volume_name)
        #print(pvc_crd)
        volume_name = manager.get_pvc_volume(pvc_crd)
        print("hpe3par_cli object :: %s " % hpe3par_cli)
        volume = manager.get_volume_from_array(hpe3par_cli, volume_name)
        assert volume is not None, "Volume is not created on 3PAR for pvc %s " % volume_name
        """assert manager.verify_volume_properties(volume, provisioning='thin', compression='true') is True, \
            "tpvv no comp volume verification failed""" ""

        pod = manager.create_pod(yml)

        flag, pod_obj = manager.check_status(timeout,
                                             pod.metadata.name,
                                             kind='pod',
                                             status='Running',
                                             namespace=pod.metadata.namespace)

        assert flag is True, "Pod %s status check timed out, not in Running state yet..." % pod.metadata.name

        # Verify crd fpr published status
        assert manager.verify_pvc_crd_published(pvc_obj.spec.volume_name) is True, \
            "PVC CRD %s Published is false after Pod is running" % pvc_obj.spec.volume_name

        hpe3par_vlun = manager.get_3par_vlun(hpe3par_cli, volume_name)
        assert manager.verify_pod_node(hpe3par_vlun, pod_obj) is True, \
            "Node for pod received from 3par and cluster do not match"

        if protocol == 'iscsi':
            iscsi_ips = manager.get_iscsi_ips(hpe3par_cli)

            flag, disk_partition = manager.verify_by_path(
                iscsi_ips, pod_obj.spec.node_name)
            assert flag is True, "partition not found"
            print("disk_partition received are %s " % disk_partition)

            flag, disk_partition_mod = manager.verify_multipath(
                hpe3par_vlun, disk_partition)
            assert flag is True, "multipath check failed"
            print("disk_partition after multipath check are %s " %
                  disk_partition)
            print("disk_partition_mod after multipath check are %s " %
                  disk_partition_mod)
            assert manager.verify_partition(
                disk_partition_mod), "partition mismatch"

            assert manager.verify_lsscsi(
                pod_obj.spec.node_name,
                disk_partition), "lsscsi verificatio failed"

        assert manager.delete_pod(pod.metadata.name, pod.metadata.namespace), "Pod %s is not deleted yet " % \
                                                                              pod.metadata.name
        assert manager.check_if_deleted(timeout, pod.metadata.name, "Pod", namespace=pod.metadata.namespace) is True, \
            "Pod %s is not deleted yet " % pod.metadata.name

        if protocol == 'iscsi':
            flag, ip = manager.verify_deleted_partition(
                iscsi_ips, pod_obj.spec.node_name)
            assert flag is True, "Partition(s) not cleaned after volume deletion for iscsi-ip %s " % ip

            paths = manager.verify_deleted_multipath_entries(
                pod_obj.spec.node_name, hpe3par_vlun)
            assert paths is None or len(
                paths) == 0, "Multipath entries are not cleaned"

            # partitions = manager.verify_deleted_lsscsi_entries(pod_obj.spec.node_name, disk_partition)
            # assert len(partitions) == 0, "lsscsi verificatio failed for vlun deletion"
            flag = manager.verify_deleted_lsscsi_entries(
                pod_obj.spec.node_name, disk_partition)
            print("flag after deleted lsscsi verificatio is %s " % flag)
            assert flag, "lsscsi verification failed for vlun deletion"

        # Verify crd for unpublished status
        try:
            assert manager.verify_pvc_crd_published(pvc_obj.spec.volume_name) is False, \
                "PVC CRD %s Published is true after Pod is deleted" % pvc_obj.spec.volume_name
            print("PVC CRD published is false after pod deletion.")
            #logging.warning("PVC CRD published is false after pod deletion.")
        except Exception as e:
            print(
                "Resuming test after failure of publishes status check for pvc crd... \n%s"
                % e)
            #logging.error("Resuming test after failure of publishes status check for pvc crd... \n%s" % e)
        assert manager.delete_pvc(pvc.metadata.name)

        assert manager.check_if_deleted(timeout, pvc.metadata.name, "PVC", namespace=pvc.metadata.namespace) is True, \
            "PVC %s is not deleted yet " % pvc.metadata.name

        #pvc_crd = manager.get_pvc_crd(pvc_obj.spec.volume_name)
        #print("PVC crd after PVC object deletion :: %s " % pvc_crd)
        assert manager.check_if_crd_deleted(pvc_obj.spec.volume_name, "hpevolumeinfos") is True, \
            "CRD %s of %s is not deleted yet. Taking longer..." % (pvc_obj.spec.volume_name, 'hpevolumeinfos')

        assert manager.verify_delete_volume_on_3par(hpe3par_cli, volume_name), \
            "Volume %s from 3PAR for PVC %s is not deleted" % (volume_name, pvc.metadata.name)

        assert manager.delete_sc(sc.metadata.name) is True

        assert manager.check_if_deleted(timeout, sc.metadata.name, "SC") is True, "SC %s is not deleted yet " \
                                                                                  % sc.metadata.name

        assert manager.delete_secret(secret.metadata.name,
                                     secret.metadata.namespace) is True

        assert manager.check_if_deleted(timeout, secret.metadata.name, "Secret", namespace=secret.metadata.namespace) is True, \
            "Secret %s is not deleted yet " % secret.metadata.name

    except Exception as e:
        print("Exception in test_publish :: %s" % e)
        #logging.error("Exception in test_publish :: %s" % e)
        """if step == 'pvc':
            manager.delete_pvc(pvc.metadata.name)
            manager.delete_sc(sc.metadata.name)
            manager.delete_secret(secret.metadata.name, secret.metadata.namespace)
        if step == 'sc':
            manager.delete_sc(sc.metadata.name)
            manager.delete_secret(secret.metadata.name, secret.metadata.namespace)
        if step == 'secret':
            manager.delete_secret(secret.metadata.name, secret.metadata.namespace)"""
        raise e

    finally:
        hpe3par_cli.logout()
        cleanup(secret, sc, pvc, pod)
Example #6
0
def pvc_create_verify(yml):
    secret = None
    sc = None
    pvc = None
    pod = None
    try:
        array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(
            yml)
        hpe3par_cli = manager.get_3par_cli_client(yml)
        hpe3par_version = manager.get_array_version(hpe3par_cli)
        print(
            "\n########################### new_method %s::%s::%s ###########################"
            % (str(yml), protocol, hpe3par_version[0:5]))
        #logging.info("\n########################### test_thin_absent_comp::%s::%s###########################" %
        #(protocol, hpe3par_version))
        secret = manager.create_secret(yml)
        step = "secret"
        sc = manager.create_sc(yml)
        step = "sc"
        pvc = manager.create_pvc(yml)
        print("PVC created :: %s " % pvc)
        step = "pvc"
        # Check PVC status in events
        provisioning = None
        compression = None
        size = None
        is_cpg_ssd = None
        provisioning, compression, cpg_name, size = manager.get_sc_properties(
            yml)
        print("Check if cpg is ssd")
        is_cpg_ssd = manager.check_cpg_prop_at_array(hpe3par_cli,
                                                     cpg_name,
                                                     property='ssd')
        print("Check in events if volume is created...")
        status, message = manager.check_status_from_events(
            kind='PersistentVolumeClaim',
            name=pvc.metadata.name,
            namespace=pvc.metadata.namespace,
            uid=pvc.metadata.uid)
        print("Check if test passed...")
        flag = manager.is_test_passed(array_version=hpe3par_version,
                                      status=status,
                                      is_cpg_ssd=is_cpg_ssd,
                                      provisioning=provisioning,
                                      compression=compression)
        print("Test passed :: %s " % flag)
        assert flag is True, "Volume created on %s with provisioning=%s, compression=%s" % (
            hpe3par_version, provisioning, compression)

        if status == 'ProvisioningSucceeded':
            flag, pvc_obj = manager.check_status(
                timeout,
                pvc.metadata.name,
                kind='pvc',
                status='Bound',
                namespace=pvc.metadata.namespace)
            assert flag is True, "PVC %s status check timed out, not in Bound state yet..." % pvc_obj.metadata.name

            pvc_crd = manager.get_pvc_crd(pvc_obj.spec.volume_name)
            #print(pvc_crd)
            volume_name = manager.get_pvc_volume(pvc_crd)
            print(hpe3par_cli)
            volume = manager.get_volume_from_array(hpe3par_cli, volume_name)
            assert volume is not None, "Volume is not created on 3PAR for pvc %s " % volume_name
            print(volume)
            flag, failure_cause = manager.verify_volume_properties_3par(
                volume,
                size=size,
                provisioning=provisioning,
                compression=compression,
                cpg=cpg_name)
            assert flag is True, "Volume properties verification at array is failed for %s" % failure_cause

        assert manager.delete_pvc(pvc.metadata.name)

        assert manager.check_if_deleted(timeout, pvc.metadata.name, "PVC", namespace=pvc.metadata.namespace) is True, \
            "PVC %s is not deleted yet " % pvc.metadata.name

        if status == 'ProvisioningSucceeded':
            assert manager.check_if_crd_deleted(pvc_obj.spec.volume_name, "hpevolumeinfos") is True, \
                "CRD %s of %s is not deleted yet. Taking longer..." % (pvc_obj.spec.volume_name, 'hpevolumeinfos')

            assert manager.verify_delete_volume_on_3par(hpe3par_cli, volume_name), \
                "Volume %s from 3PAR for PVC %s is not deleted" % (volume_name, pvc.metadata.name)

        assert manager.delete_sc(sc.metadata.name) is True

        assert manager.check_if_deleted(timeout, sc.metadata.name, "SC") is True, "SC %s is not deleted yet " \
                                                                                  % sc.metadata.name

        assert manager.delete_secret(secret.metadata.name,
                                     secret.metadata.namespace) is True

        assert manager.check_if_deleted(timeout, secret.metadata.name, "Secret", namespace=secret.metadata.namespace) is True, \
            "Secret %s is not deleted yet " % secret.metadata.name

    except Exception as e:
        print("Exception in pvc_create_verify :: %s" % e)
        #logging.error("Exception in test_thin_absent :: %s" % e)
        """if step == 'pvc':
            manager.delete_pvc(pvc.metadata.name)
            manager.delete_sc(sc.metadata.name)
            manager.delete_secret(secret.metadata.name, secret.metadata.namespace)
        if step == 'sc':
            manager.delete_sc(sc.metadata.name)
            manager.delete_secret(secret.metadata.name, secret.metadata.namespace)
        if step == 'secret':
            manager.delete_secret(secret.metadata.name, secret.metadata.namespace)"""
        raise e

    finally:
        hpe3par_cli.logout()
        cleanup(secret, sc, pvc, None)
Example #7
0
def test_expand_volume():
    secret = None
    sc = None
    pvc = None
    pod = None
    try:
        yml = "YAML/test-expand_vol_pvc.yml"
        hpe3par_cli = manager.get_3par_cli_client(yml)
        array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(
            yml)
        hpe3par_version = manager.get_array_version(hpe3par_cli)
        print(
            "\n########################### test_expand_volume::%s::%s ###########################"
            % (protocol, hpe3par_version[0:5]))
        """logging.info("\n########################### test_expand_volume::%s::%s###########################" %
                     (protocol, hpe3par_version))"""
        secret = manager.create_secret(yml)
        step = "secret"
        sc = manager.create_sc(yml)
        step = "sc"
        pvc = manager.create_pvc(yml)
        step = "pvc"
        flag, pvc_obj = manager.check_status(timeout,
                                             pvc.metadata.name,
                                             kind='pvc',
                                             status='Bound',
                                             namespace=pvc.metadata.namespace)
        assert flag is True, "PVC %s status check timed out, not in Bound state yet..." % pvc_obj.metadata.name

        pvc_crd = manager.get_pvc_crd(pvc_obj.spec.volume_name)
        # print(pvc_crd)
        volume_name = manager.get_pvc_volume(pvc_crd)
        print("volume_name :: %s " % volume_name)
        print(hpe3par_cli)
        volume = manager.get_volume_from_array(hpe3par_cli, volume_name)
        assert volume is not None, "Volume is not created on 3PAR for pvc %s " % volume_name
        print("Volume verification at array done successfully")
        # patch pvc for expand size
        size_in_gb = '20'
        patch_json = {
            'spec': {
                'resources': {
                    'requests': {
                        'storage': size_in_gb + 'Gi'
                    }
                }
            }
        }
        mod_pvc = manager.patch_pvc(pvc.metadata.name, pvc.metadata.namespace,
                                    patch_json)
        print("Patched PVC %s" % mod_pvc)

        pod = manager.create_pod("YAML/test-expand_vol_pod.yml")

        flag, pod_obj = manager.check_status(timeout,
                                             pod.metadata.name,
                                             kind='pod',
                                             status='Running',
                                             namespace=pod.metadata.namespace)

        assert flag is True, "Pod %s status check timed out, not in Running state yet..." % pod.metadata.name

        # Now check if volume in 3par has increased size
        volume = manager.get_volume_from_array(hpe3par_cli, volume_name)
        assert volume['sizeMiB'] == int(
            size_in_gb) * 1024, "Volume on array does not have updated size"

        # Check if PVC has increaded size
        mod_pvc = manager.hpe_read_pvc_object(pvc.metadata.name,
                                              pvc.metadata.namespace)
        print("\n PVC after expansion %s" % mod_pvc)
        # assert mod_pvc['spec']['resources']['requests']['storage'] == "%sGi" % size_in_gb, "PVC %s does not have updated size" % pvc.metadata.name
        assert mod_pvc.spec.resources.requests[
            'storage'] == "%sGi" % size_in_gb, "PVC %s does not have updated size" % pvc.metadata.name

        # check size of mounted vlun
        """node = pod_obj.spec.node_name
        hpe3par_vlun = manager.get_3par_vlun(hpe3par_cli,volume_name)
        vv_wwn = hpe3par_vlun['volumeWWN']

        command = "mount | grep -i 3%s" % vv_wwn"""
        assert manager.delete_pod(pod.metadata.name, pod.metadata.namespace), "Pod %s is not deleted yet " % \
                                                                              pod.metadata.name
        assert manager.check_if_deleted(timeout, pod.metadata.name, "Pod", namespace=pod.metadata.namespace) is True, \
            "Pod %s is not deleted yet " % pod.metadata.name

        assert manager.delete_pvc(pvc.metadata.name)

        assert manager.check_if_deleted(timeout, pvc.metadata.name, "PVC", namespace=pvc.metadata.namespace) is True, \
            "PVC %s is not deleted yet " % pvc.metadata.name

        assert manager.check_if_crd_deleted(pvc_obj.spec.volume_name, "hpevolumeinfos") is True, \
            "CRD %s of %s is not deleted yet. Taking longer..." % (pvc_obj.spec.volume_name, 'hpevolumeinfos')

        assert manager.verify_delete_volume_on_3par(hpe3par_cli, volume_name), \
            "Volume %s from 3PAR for PVC %s is not deleted" % (volume_name, pvc.metadata.name)

        assert manager.delete_sc(sc.metadata.name) is True

        assert manager.check_if_deleted(timeout, sc.metadata.name, "SC") is True, "SC %s is not deleted yet " \
                                                                                  % sc.metadata.name

        assert manager.delete_secret(secret.metadata.name,
                                     secret.metadata.namespace) is True

        assert manager.check_if_deleted(timeout, secret.metadata.name, "Secret",
                                        namespace=secret.metadata.namespace) is True, \
            "Secret %s is not deleted yet " % secret.metadata.name

    except Exception as e:
        print("Exception in test_expand_volume :: %s" % e)
        #logging.error("Exception in test_snapshot :: %s" % e)
        """if step == 'pvc':
                manager.delete_pvc(pvc.metadata.name)
                manager.delete_sc(sc.metadata.name)
                manager.delete_secret(secret.metadata.name, secret.metadata.namespace)
            if step == 'sc':
                manager.delete_sc(sc.metadata.name)
                manager.delete_secret(secret.metadata.name, secret.metadata.namespace)
            if step == 'secret':
                manager.delete_secret(secret.metadata.name, secret.metadata.namespace)"""
        raise e

    finally:
        hpe3par_cli.logout()
        cleanup(secret, sc, pvc, pod)
Example #8
0
def test_snapshot():
    secret = None
    sc = None
    pvc = None
    pod = None
    try:
        base_yml = "YAML/source-pvc-snap.yml"
        hpe3par_cli = manager.get_3par_cli_client(base_yml)
        array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(
            base_yml)
        hpe3par_version = manager.get_array_version(hpe3par_cli)
        print(
            "\n########################### test_snapshot::%s::%s ###########################"
            % (protocol, hpe3par_version[0:5]))
        """logging.info("\n########################### test_clone::%s::%s###########################" %
                     (protocol, hpe3par_version))"""
        secret = manager.create_secret(base_yml)
        step = "secret"
        sc = manager.create_sc(base_yml)
        step = "sc"
        pvc = manager.create_pvc(base_yml)
        step = "pvc"
        flag, pvc_obj = manager.check_status(timeout,
                                             pvc.metadata.name,
                                             kind='pvc',
                                             status='Bound',
                                             namespace=pvc.metadata.namespace)
        assert flag is True, "PVC %s status check timed out, not in Bound state yet..." % pvc_obj.metadata.name

        pvc_crd = manager.get_pvc_crd(pvc_obj.spec.volume_name)
        # print(pvc_crd)
        volume_name = manager.get_pvc_volume(pvc_crd)
        print(hpe3par_cli)
        volume = manager.get_volume_from_array(hpe3par_cli, volume_name)
        assert volume is not None, "Volume is not created on 3PAR for pvc %s " % volume_name
        print()

        assert manager.create_snapclass(
            "YAML/snapshot-class.yaml"
        ) is True, 'Snapclass ci-snapclass is not created.'

        assert manager.verify_snapclass_created(
        ) is True, 'Snapclass ci-snapclass is not found in crd list.'

        assert manager.create_snapshot(
            "YAML/snapshot.yaml"
        ) is True, 'Snapshot ci-pvc-snapshot is not created.'

        assert manager.verify_snapshot_created(
        ) is True, 'Snapshot ci-pvc-snapshot is not found in crd list.'

        flag, snap_uid = manager.verify_snapshot_ready()
        assert flag is True, "Snapshot ci-pvc-snapshot is not ready to use"

        snap_uid = "snapshot-" + snap_uid
        snap_volume = manager.get_volume_from_array(hpe3par_cli,
                                                    snap_uid[0:31])
        snap_volume_name = snap_volume['name']
        print("\nsnap_volume :: %s " % snap_volume)
        flag, message = manager.verify_snapshot_on_3par(
            snap_volume, volume_name)
        assert flag is True, message
        print()
        assert manager.delete_snapshot(
        ), "Snapshot ci-pvc-snapshot deletion request failed"
        #sleep(180)
        assert manager.check_if_crd_deleted('ci-pvc-snapshot', "volumesnapshots") is True, \
            "CRD %s of %s is not deleted yet. Taking longer..." % ('ci-pvc-snapshot', 'volumesnapshots')
        #assert manager.verify_snapshot_deleted() is False, 'Snapshot CRD ci-pvc-snapshot is not deleted yet.'
        #sleep(180)
        assert manager.delete_snapclass(
        ), "Snapclass ci-snapclass deletion request failed"
        assert manager.check_if_crd_deleted('ci-snapclass', "volumesnapshotclasses") is True, \
            "CRD %s of %s is not deleted yet. Taking longer..." % ('ci-snapclass', 'volumesnapshotclasses')
        #sleep(180)
        #assert manager.verify_snapclass_deleted is False, 'Snapclass CRD ci-snapclass is not deleted yet.'
        #sleep(180)
        assert manager.verify_delete_volume_on_3par(hpe3par_cli, snap_volume_name) is True, \
            "Snap Volume %s from 3PAR for PVC %s is not deleted" % (snap_volume_name, pvc.metadata.name)

        assert manager.delete_pvc(pvc.metadata.name)

        assert manager.check_if_deleted(timeout, pvc.metadata.name, "PVC", namespace=pvc.metadata.namespace) is True, \
            "PVC %s is not deleted yet " % pvc.metadata.name

        assert manager.check_if_crd_deleted(pvc_obj.spec.volume_name, "hpevolumeinfos") is True, \
            "CRD %s of %s is not deleted yet. Taking longer..." % (pvc_obj.spec.volume_name, 'hpevolumeinfos')

        assert manager.verify_delete_volume_on_3par(hpe3par_cli, volume_name), \
            "Volume %s from 3PAR for PVC %s is not deleted" % (volume_name, pvc.metadata.name)

        assert manager.delete_sc(sc.metadata.name) is True

        assert manager.check_if_deleted(timeout, sc.metadata.name, "SC") is True, "SC %s is not deleted yet " \
                                                                                  % sc.metadata.name

        assert manager.delete_secret(secret.metadata.name,
                                     secret.metadata.namespace) is True

        assert manager.check_if_deleted(timeout, secret.metadata.name, "Secret",
                                        namespace=secret.metadata.namespace) is True, \
            "Secret %s is not deleted yet " % secret.metadata.name

    except Exception as e:
        print("Exception in test_snapshot :: %s" % e)
        #logging.error("Exception in test_snapshot :: %s" % e)
        """if step == 'pvc':
            manager.delete_pvc(pvc.metadata.name)
            manager.delete_sc(sc.metadata.name)
            manager.delete_secret(secret.metadata.name, secret.metadata.namespace)
        if step == 'sc':
            manager.delete_sc(sc.metadata.name)
            manager.delete_secret(secret.metadata.name, secret.metadata.namespace)
        if step == 'secret':
            manager.delete_secret(secret.metadata.name, secret.metadata.namespace)"""
        raise e

    finally:
        hpe3par_cli.logout()
        cleanup(secret, sc, pvc, None)
        cleanup_snapshot()
Example #9
0
def test_clone():
    secret = None
    sc = None
    pvc = None
    pod = None
    clone_pvc = None
    try:
        base_yml = "YAML//base-pvc-clone.yml"
        clone_yml = "YAML/test-clone.yml"
        hpe3par_cli = manager.get_3par_cli_client(base_yml)
        array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(
            base_yml)
        hpe3par_version = manager.get_array_version(hpe3par_cli)
        print(
            "\n########################### test_clone::%s::%s ###########################"
            % (protocol, hpe3par_version[0:5]))
        """logging.info("\n########################### test_clone::%s::%s###########################" %
                     (protocol, hpe3par_version))"""
        secret = manager.create_secret(base_yml)
        step = "secret"
        sc = manager.create_sc(base_yml)
        step = "sc"
        pvc = manager.create_pvc(base_yml)
        step = "pvc"
        flag, pvc_obj = manager.check_status(timeout,
                                             pvc.metadata.name,
                                             kind='pvc',
                                             status='Bound',
                                             namespace=pvc.metadata.namespace)
        assert flag is True, "PVC %s status check timed out, not in Bound state yet..." % pvc_obj.metadata.name

        pvc_crd = manager.get_pvc_crd(pvc_obj.spec.volume_name)
        #print(pvc_crd)
        volume_name = manager.get_pvc_volume(pvc_crd)
        print(hpe3par_cli)
        volume = manager.get_volume_from_array(hpe3par_cli, volume_name)
        assert volume is not None, "Volume is not created on 3PAR for pvc %s " % volume_name

        clone_pvc = manager.create_pvc(clone_yml)
        step = "clone_pvc"
        flag, clone_pvc_obj = manager.check_status(
            timeout,
            clone_pvc.metadata.name,
            kind='pvc',
            status='Bound',
            namespace=clone_pvc.metadata.namespace)
        assert flag is True, "PVC %s status check timed out, not in Bound state yet..." % clone_pvc_obj.metadata.name

        assert manager.verify_clone_crd_status(clone_pvc_obj.spec.volume_name) is True, \
            "Clone PVC CRD is not yet completed"
        """assert manager.verify_volume_properties(volume, provisioning='thin', compression='true') is True, \
            "tpvv no comp volume verification failed""" ""
        clone_pvc_crd = manager.get_pvc_crd(clone_pvc_obj.spec.volume_name)
        # print(pvc_crd)
        clone_volume_name = manager.get_pvc_volume(clone_pvc_crd)

        assert manager.delete_pvc(clone_pvc.metadata.name)

        assert manager.check_if_deleted(timeout, clone_pvc.metadata.name, "PVC", namespace=clone_pvc.metadata.namespace)\
               is True, "Clone PVC %s is not deleted yet " % clone_pvc.metadata.name

        assert manager.check_if_crd_deleted(clone_pvc_obj.spec.volume_name, "hpevolumeinfos") is True, \
            "Clone PVC CRD %s of %s is not deleted yet. Taking longer..." % (clone_pvc_obj.spec.volume_name, 'hpevolumeinfos')

        assert manager.verify_delete_volume_on_3par(hpe3par_cli, clone_volume_name), \
            "Volume %s from 3PAR for PVC %s is not deleted" % (clone_volume_name, clone_pvc.metadata.name)

        assert manager.delete_pvc(pvc.metadata.name)

        assert manager.check_if_deleted(timeout, pvc.metadata.name, "PVC", namespace=pvc.metadata.namespace) is True, \
            "PVC %s is not deleted yet " % pvc.metadata.name

        assert manager.check_if_crd_deleted(pvc_obj.spec.volume_name, "hpevolumeinfos") is True, \
            "CRD %s of %s is not deleted yet. Taking longer..." % (pvc_obj.spec.volume_name, 'hpevolumeinfos')

        sleep(30)
        assert manager.verify_delete_volume_on_3par(hpe3par_cli, volume_name), \
            "Volume %s from 3PAR for PVC %s is not deleted" % (volume_name, pvc.metadata.name)

        assert manager.delete_sc(sc.metadata.name) is True

        assert manager.check_if_deleted(timeout, sc.metadata.name, "SC") is True, "SC %s is not deleted yet " \
                                                                                  % sc.metadata.name

        assert manager.delete_secret(secret.metadata.name,
                                     secret.metadata.namespace) is True

        assert manager.check_if_deleted(timeout, secret.metadata.name, "Secret", namespace=secret.metadata.namespace) is True, \
            "Secret %s is not deleted yet " % secret.metadata.name

    except Exception as e:
        print("Exception in test_clone :: %s" % e)
        #logging.error("Exception in test_clone :: %s" % e)
        """if step == 'pvc':
            manager.delete_pvc(pvc.metadata.name)
            manager.delete_sc(sc.metadata.name)
            manager.delete_secret(secret.metadata.name, secret.metadata.namespace)
        if step == 'sc':
            manager.delete_sc(sc.metadata.name)
            manager.delete_secret(secret.metadata.name, secret.metadata.namespace)
        if step == 'secret':
            manager.delete_secret(secret.metadata.name, secret.metadata.namespace)"""
        raise e

    finally:
        hpe3par_cli.logout()
        cleanup(None, None, clone_pvc, None)
        cleanup(secret, sc, pvc, None)
def test_chap():
    sc_yml = 'YAML_CHAP/sc_140.yaml'
    pvc_yml = 'YAML_CHAP/pvc_140.yaml'
    pod_yml = 'YAML_CHAP/pod_140.yml'
    hpe3par_cli = None
    secret = None
    sc = None
    pvc = None
    pod = None
    timeout = 900
    
    # Fetching chap details from install yml
    with open("INSTALL/values.yaml", 'r') as ymlfile:
        cfg = yaml.load(ymlfile)

    chapUsr = cfg['iscsi']['chapUser']
    chapPwd = cfg['iscsi']['chapPassword']
    try:
        yml = "YAML_CHAP/sc_140.yaml"
        array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
        hpe3par_cli = manager.get_3par_cli_client(yml)

        hpe3par_version = manager.get_array_version(hpe3par_cli)

        # Call uninstall of plugin, to re-install the product with chap enabled
        tc.test_helm_uninstall()
        time.sleep(20)

        # Call install with CHAP enabled 
        tc.test_helm_install()


        # Get node details.
        node_list = manager.hpe_list_node_objects()
        workers = {}
        for _ in node_list.items:
            if 'worker_id' in _.metadata.labels:
                workers[ _.metadata.name] = _.status.addresses[0].address
            else:
                continue

        # Validate node crd
        worker_node_name = [ keys for keys in workers]
        for node_name in worker_node_name:
            flag = manager.verify_node_crd_chap(node_name,chapUser=chapUsr,chapPassword=chapPwd)
        assert flag is True, "Crd validation failed"

        # Create sc, pvc, pod
        secret = manager.create_secret(sc_yml)
        step = "secret"
        sc = manager.create_sc(sc_yml)
        step = "sc"
        pvc = manager.create_pvc(pvc_yml)
        step = "pvc"
        flag, pvc_obj = manager.check_status(timeout, pvc.metadata.name, kind='pvc', status='Bound',
                                             namespace=pvc.metadata.namespace)
        assert flag is True, "PVC %s status check timed out, not in Bound state yet..." % pvc_obj.metadata.name
        pvc_crd = manager.get_pvc_crd(pvc_obj.spec.volume_name)
        #print(pvc_crd)
        volume_name = manager.get_pvc_volume(pvc_crd)
        print("hpe3par_cli object :: %s " % hpe3par_cli)
        volume = manager.get_volume_from_array(hpe3par_cli, volume_name)
        assert volume is not None, "Volume is not created on 3PAR for pvc %s " % volume_name

        pod = manager.create_pod(pod_yml)
        flag, pod_obj = manager.check_status(timeout, pod.metadata.name, kind='pod', status='Running',
                                             namespace=pod.metadata.namespace)

        assert flag is True, "Pod %s status check timed out, not in Running state yet..." % pod.metadata.name

        
        #Validate chap details on 3par
        host_name = (pod_obj.spec.node_name).split(".")[0]
        host_ip = pod_obj.status.host_ip
        hpe3par_host = manager.get_host_from_array(hpe3par_cli, host_name)
        flag = manager.verify_host_properties(hpe3par_host, chapUser=chapUsr,chapPassword=chapPwd)
        assert flag is True, "Verification of crd on array failed" 
        
        #Validate chap details on host. 
        command = "iscsiadm -m node -o show | grep -w node.session.auth.username"
        raw_output = manager.get_command_output(host_name,command) 
        assert raw_output[0].split(",")[0].split("=")[1].strip() == chapUsr, "Chap user not as in input file %s " % raw_output[0].split(",")[0].split("=")[1]
        command = "iscsiadm -m node -o show | grep -w node.session.auth.password"
        raw_output = manager.get_command_output(host_name,command)
        assert raw_output[0].split(",")[0].split("=")[1], "Chap password on host is 'NULL' %s " % raw_output[0].split(",")[0].split("=")[1]
        
    finally:
        # Now cleanup secret, sc, pv, pvc, pod
        print("Inside Finally")
        cleanup(secret, sc, pvc, pod)
        hpe3par_cli.logout()
Example #11
0
def test_same_domain():
    #hpe3par_cli = None
    objs_dict = None
    base_objs_dict = None
    try:
        yml_1 = '%s/MD-cpg-2-domain-x.yml' % globals.yaml_dir
        """hpe3par_cli = manager.get_3par_cli_client(yml_1)
        array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml_1)"""

        cpg_domain, host_domain, host, cpg_name = get_domain(
            yml_1, globals.hpe3par_cli)
        hpe3par_version = manager.get_array_version(globals.hpe3par_cli)
        #print("\n########################### Multi-Domain::test_same_domain::%s%s::START ###########################" %
        #(hpe3par_version[0:5], globals.access_protocol))
        logging.getLogger().info("\n\n%s" % cpg_domain)
        logging.getLogger().info("\n\n%s" % host_domain)

        assert host is None or (host is not None and cpg_domain == host_domain), \
            "Host entry exists with domain %s whereas cpg %s belongs to %s. Terminating test for same domain." % (host_domain, cpg_name, cpg_domain)

        base_status, base_kind, base_reason, base_obj, base_objs_dict = create_pod(
            yml_1, globals.hpe3par_cli)
        assert base_status is True, "Terminating test since %s failed to %s" % (
            base_kind, base_reason)
        logging.getLogger().info(
            "Volume created and publishes successfully for domain %s" %
            cpg_domain)

        yml_2 = "%s/MD-cpg-3-domain-x.yml" % globals.yaml_dir
        # array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml_2)
        cpg_domain_2, host_domain_2, host_2, cpg_name_2 = get_domain(
            yml_2, globals.hpe3par_cli)
        assert cpg_domain == cpg_domain_2, "Terminating test as CPG %s does not belong to domain %s" % (
            cpg_name_2, cpg_domain)
        logging.getLogger().info(
            "Now creating and publishing another volume in same domain %s ..."
            % cpg_domain)

        status, kind, reason, obj, objs_dict = create_pod(
            yml_2, globals.hpe3par_cli)
        assert status is True, "Failed to publish volume on existing domain %s as %s failed to %s" % (
            cpg_domain, kind, reason)

        logging.getLogger().info(
            "Verifying Volume, CRD and vluns for published volume...")
        verify(globals.hpe3par_cli, globals.access_protocol, objs_dict['pvc'],
               objs_dict['pod'], objs_dict['sc'], None)
        logging.getLogger().info(
            "Second volume created and publishes successfully in same domain")
        logging.getLogger().info(
            "\n########################### Multi-Domain::test_same_domain::%s%s::END ###########################"
            % (hpe3par_version[0:5], globals.access_protocol))

    finally:
        """if hpe3par_cli is not None:
            hpe3par_cli.logout()"""
        if base_objs_dict is not None:
            cleanup(None, base_objs_dict['sc'], base_objs_dict['pvc'],
                    base_objs_dict['pod'])
        if objs_dict is not None:
            cleanup(None, objs_dict['sc'], objs_dict['pvc'], objs_dict['pod'])
Example #12
0
def create_import_verify_volume(yml,
                                hpe3par_cli,
                                protocol,
                                publish=True,
                                pvc_bound=True,
                                pvc_message='',
                                pod_run=True,
                                pod_message=''):
    secret = None
    sc = None
    pvc_obj = None
    pod_obj = None
    volume = None

    # Create volume
    """hpe3par_cli = manager.get_3par_cli_client(yml)
    array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
    hpe3par_version = manager.get_array_version(hpe3par_cli)
    logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
              (str(yml), protocol, hpe3par_version[0:5]))"""
    hpe3par_version = manager.get_array_version(hpe3par_cli)
    yaml_values = manager.get_details_for_volume(yml)
    if yaml_values['provisioning'].lower(
    ) == 'full' and hpe3par_version[0:1] == '4':
        logging.getLogger().info(
            "Full Provisioning not supported on primera. Terminating test.")
        return None, None, None, None, None
    options = prepare_options(yaml_values, hpe3par_version)
    # Create volume in array to be imported
    logging.getLogger().info("Options to 3par cli for creating volume :: %s " %
                             options)
    volume, exception = create_vol_in_array(hpe3par_cli,
                                            options,
                                            vol_name=yaml_values['vol_name'],
                                            size=yaml_values['size'],
                                            cpg_name=yaml_values['cpg'])
    # assert volume is not None, "Volume %s is not created on array as %s. Terminating test." % (vol_name, exception)
    if volume is None:
        logging.getLogger().info(
            "Volume %s is not created on array as %s. Terminating test." %
            (yaml_values['vol_name'], exception))
        return None, None, None, None, None
    logging.getLogger().info(
        "Volume %s created successfully on array. Now import it to CSI..." %
        volume['name'])

    # Import volume now in CSI
    #secret = manager.create_secret(yml)
    sc = manager.create_sc(yml)
    pvc = manager.create_pvc(yml)
    logging.getLogger().info("Check in events if volume is created...")
    status, message = manager.check_status_from_events(
        kind='PersistentVolumeClaim',
        name=pvc.metadata.name,
        namespace=pvc.metadata.namespace,
        uid=pvc.metadata.uid)
    #logging.getLogger().info(status)
    #logging.getLogger().info(message)
    if pvc_bound:
        assert status == 'ProvisioningSucceeded', f"{message}"
        flag, pvc_obj = manager.check_status(30,
                                             pvc.metadata.name,
                                             kind='pvc',
                                             status='Bound',
                                             namespace=pvc.metadata.namespace)
        assert flag is True, "PVC %s status check timed out, not in Bound state yet..." % pvc_obj.metadata.name

        # Compare imported volume object with old volume object on array
        pvc_crd = manager.get_pvc_crd(pvc_obj.spec.volume_name)
        # logging.getLogger().info(pvc_crd)
        imported_volume_name = manager.get_pvc_volume(pvc_crd)
        assert manager.verify_clone_crd_status(pvc_obj.spec.volume_name) is True, \
            "Clone PVC CRD is not yet completed"
        csi_volume = manager.get_volume_from_array(globals.hpe3par_cli,
                                                   imported_volume_name)
        csi_volume = manager.get_volume_from_array(hpe3par_cli,
                                                   imported_volume_name)
        vol_has_diff, diff = compare_volumes(volume, csi_volume)
        assert vol_has_diff is False, "After import volume properties are changed. Modified properties are %s" % diff
        logging.getLogger().info(
            "\nImported volume's properties have been verified successfully, all property values retain."
        )

    else:
        pvc_obj = pvc
        """assert status == 'ProvisioningFailed', "Imported volume that starts from PVC (%s)" % yaml_values['vol_name']
        logging.getLogger().info("\n\nCould not import volume starts with PVC, as expected.")"""
        assert status == 'ProvisioningFailed', "Imported volume that %s" % pvc_message
        logging.getLogger().info(
            "\n\nCould not import volume %s, as expected." % pvc_message)
        # return status, "\n\nCould not import volume starts with PVC, as expected.", secret, pvc_obj, None

    # Now publish this volume and verify vluns
    if publish is True:
        if protocol is None:  # not specified at command line
            # read it from sc yml
            protocol = manager.read_protocol(yml)

        pod_obj = create_verify_pod(yml, hpe3par_cli, pvc_obj,
                                    imported_volume_name, protocol, pod_run,
                                    pod_message)

    return volume, secret, sc, pvc_obj, pod_obj