Exemplo n.º 1
0
def cleanup_crd(snapshot_name, snapclass_name):
    logging.getLogger().info("====== cleanup_crd :START =========")
    # logging.info("====== cleanup after failure:START =========")
    if snapshot_name is not None:  # and manager.check_if_crd_deleted(snapshot_name, "volumesnapshots") is False:
        manager.delete_snapshot(snapshot_name)
    if snapclass_name is not None:  # and manager.check_if_crd_deleted(snapclass_name, "volumesnapshotclasses") is False:
        manager.delete_snapclass(snapclass_name)
    logging.getLogger().info("====== cleanup_crd :END =========")
Exemplo n.º 2
0
def cleanup_snapshot():
    if manager.verify_snapshot_deleted() is False:
        manager.delete_snapshot()
    if manager.verify_snapclass_deleted is False:
        manager.delete_snapclass()
Exemplo n.º 3
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()