def test_full_absent_comp_import_vol(): yml = "%s/import_vol_as_clone/import-vol-full-absent-comp.yml" % globals.yaml_dir sc = None pvc = None pod = None try: """hpe3par_cli = manager.get_3par_cli_client(yml) array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml) logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" % (str(yml), protocol, manager.get_array_version(hpe3par_cli)))""" yaml_values = manager.get_details_for_volume(yml) options = prepare_options(yaml_values, globals.hpe3par_version) # Create volume in array to be cloned and later imported to csi vol_name = yaml_values['vol_name'] volume, secret, sc, pvc, pod = create_import_verify_volume( yml, globals.hpe3par_cli, globals.access_protocol) finally: # Now cleanup secret, sc, pv, pvc, pod cleanup(None, sc, pvc, pod) delete_vol_from_array(globals.hpe3par_cli, vol_name)
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
def test_import_vol_as_clone_sanity(): yml = '%s/import_vol_as_clone/import-vol-as-clone.yml' % globals.yaml_dir sc = None pvc_obj = None pod_obj = None vol_name = None try: # 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########################### test_import_cloned_vol test %s::%s::%s ###########################" % (str(yml), protocol, hpe3par_version[0:5]))""" yaml_values = manager.get_details_for_volume(yml) options = prepare_options(yaml_values, globals.hpe3par_version) # Create volume in array to be cloned and later imported to csi vol_name = yaml_values['vol_name'] volume = None volume, exception = create_vol_in_array(globals.hpe3par_cli, options, vol_name=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." % (vol_name, exception)) return logging.getLogger().info( "Volume %s created successfully on array. Now Create clone..." % volume['name']) #clone_volume, message = create_clone_in_array(globals.hpe3par_cli, source_vol_name=vol_name, option={'online': True, 'tpvv': True}) #logging.getLogger().info("Cloned volume is :: %s" % clone_volume) #message = "Clone volume creation on array failed with error %s. Terminating test." % message #assert clone_volume is not None, message #clone_vol_name = clone_volume['name'] # Now import base of the clone to 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) 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 for base volume %s status check timed out, not in Bound state yet..." % \ (pvc_obj.metadata.name, vol_name) logging.getLogger().info( "\n\nBase volume (after cloning at array) has been imported successfully to CSI." ) # 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) 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." ) pod_obj = create_verify_pod(yml, globals.hpe3par_cli, pvc_obj, imported_volume_name, globals.access_protocol) finally: # Now cleanup secret, sc, pv, pvc, pod cleanup(None, sc, pvc_obj, pod_obj) delete_vol_from_array(globals.hpe3par_cli, vol_name)