def setup_teardown_for_each_test(before_running_all_testcase, request): # setup operations before yield is called nimosclientbase.log_header(request.function.__name__) global vol_name1, snapcoll_name1, volcoll_name1 volcoll_name1 = nimosclientbase.get_unique_string("snapcolltc-volcoll1") snapcoll_name1 = nimosclientbase.get_unique_string("snapcolltc-snapcoll1") vol_name1 = nimosclientbase.get_unique_string("snapcolltc-vol1") # 1st create a volcoll and 2nd associate a volume to volcoll volcoll_resp = volcoll.create_volcoll(volcoll_name1) assert volcoll_resp is not None # save the volcoll_id here volcoll_resp.attrs.get("id") # create and associate a volume volresp = volume.create_volume(vol_name1) try: nimosclientbase.get_nimos_client().volumes.update( id=volresp.attrs.get("id"), volcoll_id=volcoll_resp.attrs.get("id")) except exceptions.NimOSAPIError as ex: log(f"Failed with exception message : {str(ex)}") raise ex yield setup_teardown_for_each_test # teardown operations below delete_snapcoll() volume.delete_volume() volcoll.delete_volcoll() nimosclientbase.log_footer(request.function.__name__)
def setup_teardown_for_each_test(before_running_all_testcase, request): global vol_name1, vol_name2, vol_name3 # setup operations before yield is called nimosclientbase.log_header(request.function.__name__) # create new volume names for the next testcase vol_name1 = nimosclientbase.get_unique_string("volumetc-vol1") vol_name2 = nimosclientbase.get_unique_string("volumetc-vol2") vol_name3 = nimosclientbase.get_unique_string("volumetc-vol3") yield setup_teardown_for_each_test # teardown operations below delete_volume() nimosclientbase.log_footer(request.function.__name__)
def setup_teardown_for_each_test(before_running_all_testcase, request): # setup operations before yield is called nimosclientbase.log_header(request.function.__name__) global initiator_grp_name1 global initiator_grp_name2 global initiator_name1 initiator_grp_name1 = nimosclientbase.get_unique_string("IGrpTC-IG1") initiator_grp_name2 = nimosclientbase.get_unique_string("IGrpTC-IG2") initiator_name1 = nimosclientbase.get_unique_string("IGrpTC-Initiator1") yield setup_teardown_for_each_test # teardown operations below delete_initiatorgroup() nimosclientbase.log_footer(request.function.__name__)
def setup_teardown_for_each_test(before_running_all_testcase, request): # setup operations before yield is called global prot_template_name1, prot_schedule_name1 nimosclientbase.log_header(request.function.__name__) prot_template_name1 = nimosclientbase.get_unique_string( "unittestcase-protecttemplate1") prot_schedule_name1 = nimosclientbase.get_unique_string( "unittestcase-protectschedule1") resp = create_protection_template(prot_template_name1) assert resp is not None yield setup_teardown_for_each_test # teardown operations below delete_protection_template() nimosclientbase.log_footer(request.function.__name__)
def test_promote_volcoll(setup_teardown_for_each_test): volcoll_resp = create_volcoll(volcoll_name1) voloume_name = nimosclientbase.get_unique_string( "VolumeCollectionTestCase-addtovolcoll") vol_resp = nimosclientbase.get_nimos_client().volumes.create(voloume_name, size=50) volume.vol_to_delete.append(vol_resp.attrs.get("id")) assert volcoll_resp is not None # associate the volume to volcoll vol_associate_resp = nimosclientbase.get_nimos_client().volumes.associate( id=vol_resp.attrs.get("id"), volcoll=volcoll_resp) assert vol_resp is not None # check assert vol_associate_resp.get("volcoll_name") == volcoll_name1 assert vol_associate_resp.get("volcoll_id") == volcoll_resp.attrs.get("id") try: nimosclientbase.get_nimos_client().volume_collections.promote( id=volcoll_resp.attrs.get("id")) except exceptions.NimOSAPIError as ex: if "SM_ealready" in str(ex): log("Failed as expected. volcoll is already promoted") else: log(f"Failed with exception message : {str(ex)}") raise ex
def test_restore_online_volume(setup_teardown_for_each_test): try: snapshot_resp = None # first create volume vol_resp = create_volume(vol_name1, size=5) snapshot_name1 = nimosclientbase.get_unique_string( "volumetc-snapshot1") snapshot_resp = nimosclientbase.get_nimos_client().snapshots.create( name=snapshot_name1, vol_id=vol_to_delete[0], description="created by testcase", online=False, writable=False) assert snapshot_resp is not None # restore the volume vol_restore_resp = nimosclientbase.get_nimos_client().volumes.restore( base_snap_id=snapshot_resp.attrs.get("id"), id=vol_resp.attrs.get("id")) assert vol_restore_resp is not None except exceptions.NimOSAPIError as ex: if "SM_vol_not_offline_on_restore" in str(ex): log("Failed as expected. volume to restore is not offline") else: log(f"Failed with exception message : {str(ex)}") raise ex
def test_delete_volume_in_volcoll_before_disassociating( setup_teardown_for_each_test): volcoll_resp = create_volcoll(volcoll_name1) voloume_name = nimosclientbase.get_unique_string( "VolumeCollectionTestCase-addtovolcoll") vol_resp = nimosclientbase.get_nimos_client().volumes.create(voloume_name, size=50) volume.vol_to_delete.append(vol_resp.attrs.get("id")) assert volcoll_resp is not None # associate the volume to volcoll vol_associate_resp = nimosclientbase.get_nimos_client().volumes.associate( id=vol_resp.attrs.get("id"), volcoll=volcoll_resp) assert vol_resp is not None # check assert vol_associate_resp.get("volcoll_name") == volcoll_name1 assert vol_associate_resp.get("volcoll_id") == volcoll_resp.attrs.get("id") # try deleting the volcoll . this should fail as # volume has not been disassocited try: nimosclientbase.get_nimos_client().volumes.offline( id=vol_resp.attrs.get("id")) nimosclientbase.get_nimos_client().volumes.delete( id=vol_resp.attrs.get("id")) except exceptions.NimOSAPIError as ex: if "SM_vol_assoc_volcoll" in str(ex): log("Failed as expected with exception SM_vol_assoc_volcoll") else: log(f"Failed with exception message : {str(ex)}") raise ex
def test_delete_clone_volume(setup_teardown_for_each_test): # first create volume clone_vol_name = nimosclientbase.get_unique_string("clone-volumetc") resp_vol = create_volume(vol_name1) vol_id = resp_vol.attrs.get("id") # clone a volume snap_resp = nimosclientbase.get_nimos_client().snapshots.create( name="test.volumeclone.snapshot", vol_id=vol_id) clonevol_resp = nimosclientbase.get_nimos_client().volumes.create( name=clone_vol_name, base_snap_id=snap_resp.attrs.get("id"), clone=True) # confirm assert clone_vol_name == clonevol_resp.attrs.get("name") assert clonevol_resp.attrs.get("size") == resp_vol.attrs.get("size") # try deleting parent volume . it should fail with # exception "SM_vol_has_clone" try: nimosclientbase.get_nimos_client().volumes.offline(vol_id) nimosclientbase.get_nimos_client().volumes.delete(vol_id) except exceptions.NimOSAPIError as ex: if "SM_vol_has_clone" in str(ex): log("Failed as expected. volume has clone") # cleanup nimosclientbase.get_nimos_client().volumes.offline( clonevol_resp.attrs.get("id")) nimosclientbase.get_nimos_client().volumes.delete( clonevol_resp.attrs.get("id")) else: log(f"Failed with exception message : {str(ex)}") raise ex
def setup_teardown_for_each_test(before_running_all_testcase, request): global volcoll_name1, snapshot_name1, vol_name1 # setup operations before yield is called nimosclientbase.log_header(request.function.__name__) yield setup_teardown_for_each_test # teardown operations below snapshot.delete_snapshot() volume.delete_volume() volcoll.delete_volcoll() remove_replication_partner() # create new name for next test volcoll_name1 = nimosclientbase.get_unique_string("replicationtc-volcoll1") # snapcoll_name1 = nimosclientbase.get_unique_string( # "replicationtc-snapcoll1") snapshot_name1 = nimosclientbase.get_unique_string( "replicationtc-snapshot1") vol_name1 = nimosclientbase.get_unique_string("replicationtc-vol1") nimosclientbase.log_footer(request.function.__name__)
def test_sortby_asc_volume_name(setup_teardown_for_each_test): vol_name1 = nimosclientbase.get_unique_string("volumetc-vol-vol1-z") vol_name2 = nimosclientbase.get_unique_string("volumetc-vol-vol1-a") create_volume(vol_name1) create_volume(vol_name2) resp = nimosclientbase.get_nimos_client().volumes.list( detail=False, sortBy="name") # ascending # asert that the resp contains only 2 objects. if more than 2 objects # that means the array has volumes which are not created by test. # in that case just fail if resp.__len__() != 2: log("Array has volumes which were not created by unit testcase." " make sure array has no volume present before running the test") else: # after sorting, vol_name2 should be the first object and 2nd object # should be vol_name1. assert vol_name2 == resp[0].attrs.get("name") assert vol_name1 == resp[1].attrs.get("name")
def setup_teardown_for_each_test(before_running_all_testcase, request): global volcoll_name1 volcoll_name1 = nimosclientbase.get_unique_string("volcolltc-volcoll1") # setup operations before yield is called nimosclientbase.log_header(request.function.__name__) yield setup_teardown_for_each_test # teardown operations below volume.delete_volume() delete_volcoll() nimosclientbase.log_footer(request.function.__name__)
def setup_teardown_for_each_test(before_running_all_testcase, request): global app_server_name_1 # setup operations before yield is called nimosclientbase.log_header(request.function.__name__) yield setup_teardown_for_each_test # teardown operations below delete_app_server() # create a new unique name for next test case app_server_name_1 = nimosclientbase.get_unique_string("appservertc-1") nimosclientbase.log_footer(request.function.__name__)
def setup_teardown_for_each_test(before_running_all_testcase, request): global perf_policy_name1 # setup operations before yield is called perf_policy_name1 = nimosclientbase.get_unique_string( "unittestcase-perfpolicy1") nimosclientbase.log_header(request.function.__name__) yield setup_teardown_for_each_test # teardown operations below delete_perf_policy() nimosclientbase.log_footer(request.function.__name__)
def test_volume_page_size(setup_teardown_for_each_test): resp_vol = [] # first atleast create few volume for i in range(0, 5): vol_name = nimosclientbase.get_unique_string("volumetc-vol1-" + str(i)) resp = create_volume(vol_name) resp_vol.append(resp) resp = nimosclientbase.get_nimos_client().volumes.list(detail=True, pageSize=2) assert resp is not None assert resp.__len__() == 2
def test_invalid_volume_page_size(setup_teardown_for_each_test): # first atleast create few volume for i in range(0, 6): vol_name = nimosclientbase.get_unique_string("volumetc-vol1-" + str(i)) create_volume(vol_name) try: nimosclientbase.get_nimos_client().volumes.list(detail=True, pageSize=5000) except Exception as ex: if "SM_too_large_page_size" in str(ex): log("Failed as expected. Invaild pagesize given") else: log(ex)
def test_add_volume_to_volcoll(setup_teardown_for_each_test): volcoll_resp = create_volcoll(volcoll_name1) voloume_name = nimosclientbase.get_unique_string( "VolumeCollectionTestCase-addtovolcoll") vol_resp = nimosclientbase.get_nimos_client().volumes.create(voloume_name, size=50) volume.vol_to_delete.append(vol_resp.attrs.get("id")) assert volcoll_resp is not None # associate the volume to volcoll vol_associate_resp = nimosclientbase.get_nimos_client().volumes.associate( id=vol_resp.attrs.get("id"), volcoll=volcoll_resp) assert vol_resp is not None # check assert vol_associate_resp.get("volcoll_name") == volcoll_name1 assert vol_associate_resp.get("volcoll_id") == volcoll_resp.attrs.get("id") # disassociate nimosclientbase.get_nimos_client().volumes.dissociate( id=vol_resp.attrs.get("id")) # get vol coll and confirm has no volumes volcoll_resp = nimosclientbase.get_nimos_client().volume_collections.get( id=volcoll_resp.attrs.get("id")) assert volcoll_resp.attrs.get("volume_count") == 0
# @author alok ranjan import pytest import tests.nimbleclientbase as nimosclientbase from tests.nimbleclientbase import SKIPTEST, log_to_file as log from nimbleclient.v1 import client as nimclient from nimbleclient import exceptions import tests.test_protection_schedules as prot_sched import tests.test_snapshots as snapshot import tests.test_volume as volume import tests.test_volume_collection as volcoll import time # global variables volcoll_name1 = nimosclientbase.get_unique_string("replicationtc-volcoll1") # snapcoll_name1 = nimosclientbase.get_unique_string("replicationtc-snapcoll1") snapshot_name1 = nimosclientbase.get_unique_string("replicationtc-snapshot1") vol_name1 = nimosclientbase.get_unique_string("replicationtc-vol1") downstream_partner_id = "" # constants REPLICATION_ARRAY_CREDENTIALS = "ReplicationPartnerArrayCredentials" '''ReplicationPartnerTestCase tests the replication partner object functionality ''' @pytest.fixture(scope='module') def before_running_all_testcase(request): log("**** Starting Tests for ReplicationPartner TestCase *****\n") def after_running_all_testcase():
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP # @author alok ranjan import pytest import tests.nimbleclientbase as nimosclientbase from tests.nimbleclientbase import SKIPTEST, log_to_file as log from nimbleclient import exceptions # global variables app_server_name_1 = nimosclientbase.get_unique_string("appservertc-1") app_server_to_delete = [] '''Appserver TestCase tests the app server object functionality ''' @pytest.fixture(scope='module') def before_running_all_testcase(request): log("**** Starting Tests for app_server TestCase *****\n") def after_running_all_testcase(): log("**** Completed Tests for app_server TestCase *****\n") request.addfinalizer(after_running_all_testcase) @pytest.fixture(scope='function') def setup_teardown_for_each_test(before_running_all_testcase, request): global app_server_name_1 # setup operations before yield is called nimosclientbase.log_header(request.function.__name__) yield setup_teardown_for_each_test
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP # @author alok ranjan import pytest import tests.nimbleclientbase as nimosclientbase from tests.nimbleclientbase import SKIPTEST, log_to_file as log from nimbleclient import exceptions # global variables chap_name_1 = nimosclientbase.get_unique_string("chapusertc-1") chap_password = "******" chap_user_to_delete = [] '''Chapusers TestCase tests the chap users object functionality ''' @pytest.fixture(scope='module') def before_running_all_testcase(request): log("**** Starting Tests for chap_users TestCase *****\n") def after_running_all_testcase(): log("**** Completed Tests for chap_users TestCase *****\n") request.addfinalizer(after_running_all_testcase) @pytest.fixture(scope='function') def setup_teardown_for_each_test(before_running_all_testcase, request): # setup operations before yield is called nimosclientbase.log_header(request.function.__name__) yield setup_teardown_for_each_test # teardown operations below
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP # @author alok ranjan import pytest import tests.nimbleclientbase as nimosclientbase from tests.nimbleclientbase import SKIPTEST, log_to_file as log from nimbleclient import exceptions, query from nimbleclient.v1 import query_fields import time import threading '''VolumeTestCase tests the volume object functionality ''' # global variables vol_name1 = nimosclientbase.get_unique_string("volumetc-vol1") vol_name2 = nimosclientbase.get_unique_string("volumetc-vol2") vol_name3 = nimosclientbase.get_unique_string("volumetc-vol3") vol_to_delete = [] delete_volume_counter = 5 # we will try to deletevolume at max 5 times volume_lock = threading.RLock() @pytest.fixture(scope='module') def before_running_all_testcase(request): log("**** Starting Tests for Volume TestCase *****\n") cleanup_old_volumes() def after_running_all_testcase(): log("**** Completed Tests for Volume TestCase *****\n") request.addfinalizer(after_running_all_testcase)
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP # @author alok ranjan import pytest import tests.nimbleclientbase as nimosclientbase from tests.nimbleclientbase import SKIPTEST, log_to_file as log from nimbleclient import exceptions import tests.test_volume as volume import tests.test_volume_collection as volcoll # global variables volcoll_name1 = nimosclientbase.get_unique_string("snapcolltc-volcoll1") snapcoll_name1 = nimosclientbase.get_unique_string("snapcolltc-snapcoll1") vol_name1 = nimosclientbase.get_unique_string("snapcolltc-vol1") snapcoll_to_delete = [] '''SnapCollTestCase class tests the snapshot collection object functionality''' @pytest.fixture(scope='module') def before_running_all_testcase(request): log("**** Starting Tests for Snapcoll TestCase *****\n") def after_running_all_testcase(): log("**** Completed Tests for Snapcoll TestCase *****\n") request.addfinalizer(after_running_all_testcase) @pytest.fixture(scope='function') def setup_teardown_for_each_test(before_running_all_testcase, request): # setup operations before yield is called
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP # @author alok ranjan import pytest import tests.nimbleclientbase as nimosclientbase from tests.nimbleclientbase import SKIPTEST, log_to_file as log from nimbleclient import exceptions # global variables vol_name1 = nimosclientbase.get_unique_string("volumetc-vol1") initiator_grp_name1 = nimosclientbase.get_unique_string("igrptc-ig1") '''ACLTestCase tests the acl object functionality ''' @pytest.fixture(scope='module') def before_running_all_testcase(request): log("**** Starting Tests for ACL TestCase *****\n") def after_running_all_testcase(): log("**** Completed Tests for ACL TestCase *****\n") request.addfinalizer(after_running_all_testcase) @pytest.fixture(scope='function') def setup_teardown_for_each_test(before_running_all_testcase, request): # setup operations before yield is called nimosclientbase.log_header(request.function.__name__) yield setup_teardown_for_each_test # teardown operations below nimosclientbase.log_footer(request.function.__name__)
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP # @author alok ranjan import pytest import tests.nimbleclientbase as nimosclientbase from tests.nimbleclientbase import SKIPTEST, log_to_file as log # global variables folders_name_1 = nimosclientbase.get_unique_string("foldertc-1") folders_to_delete = [] '''FoldersTestCase tests the folders object functionality ''' @pytest.fixture(scope='module') def before_running_all_testcase(request): log("**** Starting Tests for Folders TestCase *****\n") def after_running_all_testcase(): log("**** Completed Tests for Folders TestCase *****\n") request.addfinalizer(after_running_all_testcase) @pytest.fixture(scope='function') def setup_teardown_for_each_test(before_running_all_testcase, request): # setup operations before yield is called nimosclientbase.log_header(request.function.__name__) yield setup_teardown_for_each_test # teardown operations below delete_folders() nimosclientbase.log_footer(request.function.__name__)
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP # @author alok ranjan import pytest import tests.nimbleclientbase as nimosclientbase from tests.nimbleclientbase import SKIPTEST, log_to_file as log from nimbleclient import exceptions # global variables protection_template_to_delete = [] prot_template_name1 = nimosclientbase.get_unique_string( "unittestcase-protection-template1") '''ProtectionTemplate TestCase tests the ProtectionTemplate object functionality ''' @pytest.fixture(scope='module') def before_running_all_testcase(request): log("**** Starting Tests for ProtectionTemplate TestCase *****\n") def after_running_all_testcase(): log("**** Completed Tests for ProtectionTemplate TestCase *****\n") request.addfinalizer(after_running_all_testcase) @pytest.fixture(scope='function') def setup_teardown_for_each_test(before_running_all_testcase, request): # setup operations before yield is called nimosclientbase.log_header(request.function.__name__)
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP # @author alok ranjan import pytest import tests.nimbleclientbase as nimosclientbase from tests.nimbleclientbase import SKIPTEST, log_to_file as log from nimbleclient import exceptions import tests.test_volume as volume import threading # global variables volcoll_name1 = nimosclientbase.get_unique_string("volcolltc-volcoll1") volcoll_to_delete = [] volcoll_lock = threading.RLock() '''VolumeCollectionTestCase tests the volumecollection object functionality ''' @pytest.fixture(scope='module') def before_running_all_testcase(request): log("**** Starting Tests for VolumeCollectionTestCase *****\n") cleanup_old_volume_collection() def after_running_all_testcase(): log("**** Completed Tests for VolumeCollectionTestCase " "Testcase *****\n") request.addfinalizer(after_running_all_testcase) @pytest.fixture(scope='function')
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP # @author alok ranjan import pytest import tests.nimbleclientbase as nimosclientbase from tests.nimbleclientbase import SKIPTEST, log_to_file as log from nimbleclient import exceptions # global variables protection_template_to_delete = [] protection_schedule_to_delete = [] prot_template_name1 = nimosclientbase.get_unique_string( "unittestcase-protecttemplate1") prot_schedule_name1 = nimosclientbase.get_unique_string( "unittestcase-protectschedule1") '''protection_schedule TestCase tests the protection_schedule object functionality ''' @pytest.fixture(scope='module') def before_running_all_testcase(request): log("**** Starting Tests for protection_schedule TestCase *****\n") def after_running_all_testcase(): log("**** Completed Tests for protection_schedule TestCase *****\n") request.addfinalizer(after_running_all_testcase) @pytest.fixture(scope='function')