def test_rbac_database_admin_rights(self): db_name = "rpadm_DB" db_body = [{"name": db_name}] try: self.dbaas_admin.databases.create(self.admin_instance_id, db_body) httpCode = testutil.get_last_response_code(self.dbaas_admin) self.assertTrue(httpCode == '202', "Expected http code: %s | Actual http code: %s " % ('202', httpCode)) except Exception as e: self.fail(e) try: self.dbaas_admin.databases.list( self.dbaas_creator.instances.get(self.admin_instance_id)) self.assertTrue(httpCode == '202', "Expected http code: %s | Actual http code: %s " % ('200', httpCode)) except Exception as e: self.fail(e) try: self.dbaas_admin.databases.delete(self.admin_instance_id, db_name) httpCode = testutil.get_last_response_code(self.dbaas_admin) self.assertTrue(httpCode == '202', "Expected http code: %s | Actual http code: %s " % ('200', httpCode)) except Exception as e: self.fail(e)
def test_resize_to_xxlarge_instance(self): """ Resize the instance to xxlarge """ dbaas = self.dbaas_provider.client.reddwarfclient if testutil.isInstanceActive(dbaas, instanceId=self.instance_id): dbaas.instances.resize_instance(self.instance_id, self.flavorTypes.xxlarge) httpCode = testutil.get_last_response_code(dbaas) self.assertTrue(httpCode == '202', "Create instance failed with code %s" % httpCode) testutil.waitForActive(dbaas, instanceId=self.instance_id) self.assertTrue(testutil.getInstanceStatus(dbaas, instanceId=self.instance_id) == 'ACTIVE', "Instance is not in Active statue") newFlavorSize = dbaas.instances.get(self.instance_id).flavor['id'] self.assertTrue(newFlavorSize == str(self.flavorTypes.xxlarge), "Unexpected flavor size for resize: %s" % newFlavorSize) #Resize back to tiny if testutil.isInstanceActive(dbaas, instanceId=self.instance_id): dbaas.instances.resize_instance(self.instance_id, self.flavorTypes.tiny) httpCode = testutil.get_last_response_code(dbaas) self.assertTrue(httpCode == '202', "Create instance failed with code %s" % httpCode) testutil.waitForActive(dbaas, instanceId=self.instance_id) self.assertTrue(testutil.getInstanceStatus(dbaas, instanceId=self.instance_id) == 'ACTIVE', "Instance is not in Active statue")
def setUpClass(cls): """ Creating an instance for database testing """ tc_name = "Create Instance" super(test_accounts, cls).setUpClass() cls.mgmt_dbaas = cls.dbaas_provider.mgmt_client.reddwarfclient cls.mgmt_dbaas.authenticate() NAME = "qe-mgmt-accounts-testing" FLAVOR = 1 VOLUME = 1 instance = test_accounts.mgmt_dbaas.instances.create( name=NAME, flavor_id=FLAVOR, volume={"size": VOLUME}) httpCode = testutil.get_last_response_code(test_accounts.mgmt_dbaas) if httpCode != '200': raise Exception("Create instance failed with code %s" % httpCode) cls.instance_id = instance.id #status = instance.status testutil.waitForActive(test_accounts.mgmt_dbaas, instanceId=test_accounts.instance_id) instance_details = test_accounts.mgmt_dbaas.management.show( \ instance) httpCode = testutil.get_last_response_code(test_accounts.mgmt_dbaas) if httpCode != '200': raise Exception("List instance details failed with code %s" % httpCode) cls.tenant_id = instance_details.tenant_id
def test_rbac_database_observer_rights(self): db_name = "obs_DB" db_body = [{"name": db_name}] try: self.dbaas_observer.databases.create(self.creator_instance_id, db_body) except Exception as e: httpCode = testutil.get_last_response_code(self.dbaas_observer) self.assertTrue(httpCode == '405', "DB Create: Expected http code: %s | Actual http code: %s " % ('405', httpCode)) try: self.dbaas_observer.databases.list( self.dbaas_observer.instances.get(self.creator_instance_id)) httpCode = testutil.get_last_response_code(self.dbaas_observer) self.assertTrue(httpCode == '200', "DB List: Expected http code: %s | Actual http code: %s " % ('200', httpCode)) except Exception as e: self.fail(e) try: self.dbaas_observer.databases.delete(self.creator_instance_id, db_name) except Exception as e: httpCode = testutil.get_last_response_code(self.dbaas_observer) self.assertTrue(httpCode == '405', "DB Delete: Expected http code: %s | Actual http code: %s " % ('405', httpCode))
def test_usage_02_resize_flavor_up(self): """ Dynamically increase the memory size of an instance """ tc_name = "Usage 02 tests" tc_num = 02 NEW_FLAVOR_UP = 4 instance_id = self.instance_id_list[0] # insure instance was ACTIVE for 10 minutes running_time = (datetime.utcnow() - self.starttime_list[tc_num]).seconds if 10 * self.ONEMIN > running_time: time.sleep((10 * self.ONEMIN) - running_time) # resize the instance UP rootAction = "reddwarf.instance.modify_flavor" response = self.client.instances.resize_instance(instance_id, NEW_FLAVOR_UP) self.assertEqual( str(testutil.get_last_response_code(self.client)), "202", "Error: Resize instance. Unexpected resp code: %r != %r" % (str(testutil.get_last_response_code(self.client)), "202"), ) # wait for it to return to Active testutil.wait_for_status(self.client, instance_id, "RESIZE") status, elapsed_time = testutil.waitForActive(self.client, instanceId=instance_id) self.fixture_log.debug("Inst: %r is: %r after: %r seconds" % (instance_id, status, elapsed_time)) duration = datetime.utcnow() - self.starttime_list[tc_num] startTime = datetime.utcnow() # AH Event Sent - Check instance as a result of RESIZE time.sleep(self.AHDELAY) AHEventsList = self.dbaas_atomhopper_provider.events_by_resourceId(instance_id) single_event = [event for event in AHEventsList if event.rootAction == rootAction].pop() self.assertEqual( single_event.resourceId, instance_id, "AH resourceID:%r != created instanceID:%r" % (single_event.resourceId, instance_id), ) testutil.valid_duration(duration, single_event, self.dateFormat) self.instance = self.client.instances.get(instance_id) self.assertEqual( str(NEW_FLAVOR_UP), self.instance.flavor["id"], "Error: Expected flavor of: %r != Actual flavor: %r" % (str(NEW_FLAVOR_UP), self.instance.flavor["id"]), ) time.sleep(5 * self.ONEMIN) # Capture the duration and delete the instance if testutil.getInstanceStatus(self.client, instance_id) == "ACTIVE": self.client.instances.get(instance_id).delete() self.instance_id_list.remove(instance_id) duration = datetime.utcnow() - startTime rootAction = "reddwarf.instance.delete" # AH Event Sent - Check instance data AFTER the DELETE time.sleep(self.AHDELAY) AHEventsList = self.dbaas_atomhopper_provider.events_by_resourceId(instance_id) single_event = [event for event in AHEventsList if event.rootAction == rootAction].pop() self.assertEqual( single_event.resourceId, instance_id, "AH resourceID:%r != created instanceID:%r" % (single_event.resourceId, instance_id), ) testutil.valid_duration(duration, single_event, self.dateFormat)
def setUpClass(cls): """ Creating an instance for smoke testing """ super(test_resize_volume_instances, cls).setUpClass() test_resize_volume_instances.dbaas = cls.dbaas_provider.client.reddwarfclient NAME = "qe-resize_instances" FLAVOR = 1 VOLUME = test_resize_volume_instances.ResizeUpSizes.origLevel instance = test_resize_volume_instances.dbaas.instances.create( name=NAME, flavor_id=FLAVOR, volume={"size": VOLUME}, databases=[{"databases": [{"name": "databaseA"}], "name": "dbuser1", "password": "******"}]) httpCode = testutil.get_last_response_code(test_resize_volume_instances.dbaas) if httpCode != '200': raise Exception("Create instance failed with code %s" % httpCode) test_resize_volume_instances.instance_id = instance.id #status = instance.status testutil.waitForActive(test_resize_volume_instances.dbaas, instanceId=test_resize_volume_instances.instance_id)
def setUp(self): """ Run this setup for each test to ensure an active instance is available """ super(SmokeTest, self).setUp() tc_name = "Create Instance" instance_status = testutil.getInstanceStatus(self.dbaas, instanceId=self.instance_id) if (testutil.isInstanceActive(self.dbaas, instanceStatus=instance_status) is False): #start a new instance and set the global instance ID NAME = "qe-smoke" FLAVOR = 4 VOLUME = 1 try: instance = self.dbaas.instances.create( name=NAME, flavor_id=FLAVOR, volume={"size": VOLUME}, databases=[{"databases": [{"name": "databaseA"}], "name": "dbuser1", "password": "******"}]) httpCode = testutil.get_last_response_code(self.dbaas) if httpCode != '200': raise Exception("Create instance failed with code %s" % httpCode) self.instance_id = instance.id testutil.waitForActive(self.dbaas, instanceId=self.instance_id) if self.stability_mode: testutil.write_to_report(tc_name, tc_pass=True) except Exception as e: if self.stability_mode: testutil.write_to_error_report(self.instance_id, repr(e)) testutil.write_to_report(tc_name, tc_pass=False) raise
def test_create_db_singular(self): db_name = "1234FiRstdb" _databases = [{"name": db_name, "character_set": "latin2", "collate": "latin2_general_ci"}] self.dbaas.databases.create(self.instance_id, _databases) httpCode = testutil.get_last_response_code(self.dbaas) self.assertTrue(httpCode == '202', "Create instance failed with code %s" % httpCode) testutil.waitForActive(self.dbaas, instanceId=self.instance_id) #print (self.instance_id) self.assertTrue(testutil.getInstanceStatus(self.dbaas, instanceId=self.instance_id) == 'ACTIVE', "Instance is not in Active statue") #Get the instance and check instance attribs: such as the flavor / volume size _databases = self.dbaas.databases.list(self.dbaas.instances.get(self.instance_id)) self.assertTrue(len(_databases) == 1, "Expected 1 database: Got: %s " % len(_databases)) #try to find our instance in the list self.assertTrue(testutil.found_resource(self.dbaas, instanceId=self.instance_id, databaseName=db_name), "Did not find our database name: %s in the list." % db_name) self.dbaas.databases.delete(self.instance_id, db_name) self.assertFalse(testutil.found_resource(self.dbaas, instanceId=self.instance_id, databaseName=db_name), "Delete error: Found database name: %s in the list." % db_name)
def test_list_all_active_accounts(self): try: _accounts = self.mgmt_dbaas.accounts.index() httpCode = testutil.get_last_response_code(self.mgmt_dbaas) self.assertTrue(httpCode == '200', "List all active accounts failed with code %s" % (httpCode)) except Exception as e: self.fixture_log.debug("\tException: %r" % (e)) raise self.assertIs(type(_accounts.accounts), list, "Expected %r , Actual %r" % (list, type(_accounts.accounts))) for acct in _accounts.accounts: self.fixture_log.debug("\tAccount: %r" % (acct)) self.fixture_log.debug("\t\tAccount ID: %r" % (acct["id"])) self.fixture_log.debug("\t\tAccount number of instances: %r" % (acct["num_instances"])) self.assertIs(type(acct), dict, "Expected %r , Actual %r" % (dict, type(acct))) self.assertIs(type(acct["id"]), unicode, "Expected %r , Actual %r" % (unicode, type(acct["id"]))) self.assertIs(type(acct["num_instances"]), int, "Expected %r , Actual %r" % (int, type(acct["num_instances"])))
def setUp(cls): """ Run this setup for each test to ensure an active instance is available """ tc_name = "Create Instance" instance_status = testutil.getInstanceStatus(cls.mgmt_dbaas, instanceId=cls.instance_id) if (testutil.isInstanceActive(cls.mgmt_dbaas, instanceStatus=instance_status) is False): # delete non-Active instance test_actions.mgmt_dbaas.instances.get(cls.instance_id).delete() # start a new instance and set the global instance ID NAME = "qe-mgmt-actions-testing" FLAVOR = 1 VOLUME = 1 try: instance = cls.mgmt_dbaas.instances.create( name=NAME, flavor_id=FLAVOR, volume={"size": VOLUME}, databases=[{"databases": [{"name": "databaseA"}], "name": "dbuser1", "password": "******"}]) httpCode = testutil.get_last_response_code(cls.mgmt_dbaas) if httpCode != '200': raise Exception("Create instance failed with code %s" % (httpCode)) cls.instance_id = instance.id cls.instance = instance testutil.waitForActive(cls.mgmt_dbaas, instanceId=cls.instance_id) except Exception as e: self.fixture_log.debug("\tException: %r" % (e)) raise
def test_rbac_flavors_observer_rights(self): expectedFlavorRamName = {512: "512MB Instance", 1024: "1GB Instance", 2048: "2GB Instance", 4096: "4GB Instance", 8192: "8GB Instance", 16384: "16GB Instance"} try: flavorList = self.dbaas_observer.flavors.list() httpCode = testutil.get_last_response_code(self.dbaas_observer) self.assertTrue(httpCode == '200', "DB Flavor List: Expected http code: %s | Actual http code: %s " % ('200', httpCode)) #print(flavorList) actualFlavorRamName = {} self.assertIsNotNone(flavorList, "Error: no flavors returned") for flavor in flavorList: self.assertIsNotNone(flavor.id, "Error: flavor id is None") self.assertIsNotNone(flavor.links, "Error: flavor links is None") self.assertIsNotNone(flavor.name, "Error: flavor name is None") self.assertIsNotNone(flavor.ram, "Error: flavor ram is None") actualFlavorRamName[flavor.ram] = str(flavor.name) self.assertEqual(expectedFlavorRamName, actualFlavorRamName, "Flavors expected %s | Actual were %s" % (expectedFlavorRamName, actualFlavorRamName)) except Exception as e: self.fail(e)
def test_create_tiny_instance(self): """ Creating an instance for smoke testing """ #database = self.dbaas_provider.client.reddwarfclient NAME = "qe-tiny-instance" FLAVOR = 1 VOLUME = 20 instance = self.dbaas.instances.create( name=NAME, flavor_id=FLAVOR, volume={"size": VOLUME}, databases=[{"databases": [{"name": "databaseA"}], "name": "dbuser1", "password": "******"}]) httpCode = testutil.get_last_response_code(self.dbaas) self.assertTrue(httpCode == '200', "Create instance failed with code %s" % httpCode) testutil.waitForActive(self.dbaas, instanceId=instance.id) self.tiny_instance_id = instance.id #print (self.instance_id) self.assertTrue(testutil.getInstanceStatus(self.dbaas, instanceId=instance.id) == 'ACTIVE', "Instance is not in Active statue") #Get the instance and check instance attribs: such as the flavor / volume size instance = self.dbaas.instances.get(instance) self.assertTrue(instance.flavor['id'] == str(FLAVOR)) self.assertTrue(instance.volume['size'] == VOLUME) self.assertTrue(instance.name == NAME) #try to find our instance in the list self.assertTrue(testutil.found_resource(self.dbaas, instanceId=instance.id), "Did not find our instance id: %s in the list." % instance.id)
def test_create_required_params_instance(self): """ Creating an instance for smoke testing """ dbaas = self.dbaas_provider.client.reddwarfclient NAME = "qe-req-params-instance" FLAVOR = 1 VOLUME = 10 instance = dbaas.instances.create( name=NAME, flavor_id=FLAVOR, volume={"size": VOLUME}) httpCode = testutil.get_last_response_code(dbaas) self.req_params_instance_id = instance.id self.assertTrue(httpCode == '200', "Create instance failed with code %s" % httpCode) testutil.waitForActive(dbaas, instanceId=instance.id) self.assertTrue(testutil.getInstanceStatus(dbaas, instanceId=instance.id) == 'ACTIVE', "Instance is not in Active statue") #Get the instance and check instance attribs: such as the flavor / volume size instance = self.dbaas.instances.get(instance) self.assertTrue(instance.flavor['id'] == str(FLAVOR)) self.assertTrue(instance.volume['size'] == VOLUME) self.assertTrue(instance.name == NAME) #try to find our instance in the list self.assertTrue(testutil.found_resource(self.dbaas, instanceId=instance.id), "Did not find our instance id: %s in the list." % instance.id)
def test_list_versions(self): """ Tests the list versions api """ tc_name = "Test List Versions" try: versions = self.dbaas.versions.index(self.version_url) self.assertEquals(len(versions), 1, "Get an unexpected number of versions back %s" % len(versions)) version_details = self.dbaas.versions.index(''.join(self.version_url, versions[0])) last_result_code = testutil.get_last_response_code(self.dbaas) self.assertTrue(last_result_code == 200, "Expected http result code %s: Got %s" % (last_result_code, 200)) self.assertTrue(version_details.id == 'v1.0', "Expected http result code %s: Got %s" % (version_details.id, 'v1.0')) self.assertTrue(version_details.status == 'CURRENT', "Expected http result code %s: Got %s" % (version_details.status, 'CURRENT')) if self.stability_mode: testutil.write_to_report(tc_name, tc_pass=True) except Exception as e: if self.stability_mode: testutil.write_to_error_report(self.instance_id, repr(e)) testutil.write_to_report(tc_name, tc_pass=False) raise
def test_create_user_req_params(self): _user = [] _user_name = "F343jasdf" _user.append({"name": _user_name, "password": "******"}) self.dbaas.users.create(self.instance_id, _user) httpCode = testutil.get_last_response_code(self.dbaas) self.assertTrue(httpCode == '202', "Create instance failed with code %s" % httpCode) testutil.waitForActive(self.dbaas, instanceId=self.instance_id) #print (self.instance_id) self.assertTrue(testutil.getInstanceStatus(self.dbaas, instanceId=self.instance_id) == 'ACTIVE', "Instance is not in Active statue") #Get the instance and check instance attribs: such as the flavor / volume size #TODO: need to verify this list later... _users = self.dbaas.users.list(self.dbaas.instances.get(self.instance_id)) #self.assertTrue(len(_users) == 1, "Expected 1 user: Got: %s " % len(_users)) #try to find our instance in the list self.assertTrue(testutil.found_resource(self.dbaas, instanceId=self.instance_id, userName=_user_name), "Did not find our user name: %s in the list." % _user_name) self.dbaas.users.delete(self.instance_id, _user_name) self.assertFalse(testutil.found_resource(self.dbaas, instanceId=self.instance_id, userName=_user_name), "Delete error: Found user name: %s in the list." % _user_name)
def test_list_all_compute_hosts(self): try: _hosts = self.mgmt_dbaas.hosts.index() httpCode = testutil.get_last_response_code(self.mgmt_dbaas) self.assertTrue(httpCode == '200', "List all compute hosts failed with code %s" % (httpCode)) except Exception as e: self.fixture_log.debug("\tException: %r" % (e)) raise self.assertIs(type(_hosts), list, "Expected %r , Actual %r" % (list, type(_hosts))) for host in _hosts: self.fixture_log.debug("\tHost: %r" % (host)) self.fixture_log.debug("\t\tHost name: %r" % (host.name)) self.fixture_log.debug("\t\tHost instance count: %r" % (host.instanceCount)) self.assertIs(type(host.name), unicode, "Expected %r , Actual %r" % (unicode, type(host.name))) self.assertIs(type(host.instanceCount), int, "Expected %r , Actual %r" % (int, type(host.instanceCount)))
def test_bad_resize_instance_data(self): try: self.dbaas.instances.resize_instance(self.instance_id, "bad data") except Exception as e: httpCode = testutil.get_last_response_code(self.dbaas) self.assertTrue(httpCode == '400', "Create instance failed with code %s, excpetion %s" % (httpCode, e.message))
def test_bad_instance_data(self): try: self.dbaas.instances.create("bad_instance", 3, 3, databases="foo", users="bar") except Exception as e: httpCode = testutil.get_last_response_code(self.dbaas) self.assertTrue(httpCode == '400', "Create instance failed with code %s, excpetion %s" % (httpCode, e.message))
def test_resize_volume_instance(self): """ Resize the volume of an instance """ dbaas = self.dbaas_provider.client.reddwarfclient if testutil.isInstanceActive(dbaas, instanceId=self.instance_id): dbaas.instances.resize_volume(self.instance_id, self.ResizeUpSizes.lev1) httpCode = testutil.get_last_response_code(dbaas) self.assertTrue(httpCode == '202', "Create instance failed with code %s" % httpCode) testutil.waitForActive(dbaas, instanceId=self.instance_id) self.assertTrue(testutil.getInstanceStatus(dbaas, instanceId=self.instance_id) == 'ACTIVE', "Instance is not in Active statue") newVolume = dbaas.instances.get(self.instance_id).volume['size'] self.assertTrue(newVolume == self.ResizeUpSizes.lev1, "Expected new volume size %s: Got %s " % (self.ResizeUpSizes.lev1, newVolume)) if testutil.isInstanceActive(dbaas, instanceId=self.instance_id): dbaas.instances.resize_volume(self.instance_id, self.ResizeUpSizes.lev2) httpCode = testutil.get_last_response_code(dbaas) self.assertTrue(httpCode == '202', "Create instance failed with code %s" % httpCode) testutil.waitForActive(dbaas, instanceId=self.instance_id) self.assertTrue(testutil.getInstanceStatus(dbaas, instanceId=self.instance_id) == 'ACTIVE', "Instance is not in Active statue") newVolume = dbaas.instances.get(self.instance_id).volume['size'] self.assertTrue(newVolume == self.ResizeUpSizes.lev2, "Expected new volume size %s: Got %s " % (self.ResizeUpSizes.lev2, newVolume)) if testutil.isInstanceActive(dbaas, instanceId=self.instance_id): dbaas.instances.resize_volume(self.instance_id, self.ResizeUpSizes.lev3) httpCode = testutil.get_last_response_code(dbaas) self.assertTrue(httpCode == '202', "Create instance failed with code %s" % httpCode) testutil.waitForActive(dbaas, instanceId=self.instance_id) self.assertTrue(testutil.getInstanceStatus(dbaas, instanceId=self.instance_id) == 'ACTIVE', "Instance is not in Active statue") newVolume = dbaas.instances.get(self.instance_id).volume['size'] self.assertTrue(newVolume == self.ResizeUpSizes.lev3, "Expected new volume size %s: Got %s " % (self.ResizeUpSizes.lev3, newVolume))
def test_bad_database_data(self): _bad_db_data = "{foo}" try: self.dbaas.databases.create(self.instance_id, _bad_db_data) except Exception as e: httpCode = testutil.get_last_response_code(self.dbaas) self.assertTrue(httpCode == '400', "Create instance failed with code %s, excpetion %s" % (httpCode, e.message))
def test_storage_details(self): try: _storage_details = self.mgmt_client.storage.index() httpCode = testutil.get_last_response_code(self.mgmt_client) self.assertEqual(httpCode, '200', "List storage details failed with %s" % httpCode) except Exception as e: self.fixture_log.debug("\tException: %r" % (e)) raise self.assertIs(type(_storage_details), list, "Expected %r , Actual %r" % (list, type(_storage_details))) for device in _storage_details: self.fixture_log.debug("\tStorage device: %r" % (device)) self.fixture_log.debug("\t\tStorage capacity: %r" % (device.capacity)) self.fixture_log.debug("\t\tStorage name: %r" % (device.name)) self.fixture_log.debug("\t\tStorage provision: %r" % (device.provision)) self.fixture_log.debug("\t\tStorage type: %r" % (device.type)) self.fixture_log.debug("\t\tStorage used: %r" % (device.used)) self.assertIs(type(device.capacity), dict, "Expected %r , Actual %r" % (dict, type(device.capacity))) for val in device.capacity.values(): self.assertIs(type(val), float, "Expected %r , Actual %r" % (float, type(val))) self.assertIs(type(device.name), unicode, "Expected %r , Actual %r" % (unicode, type(device.name))) self.assertIs(type(device.provision), dict, "Expected %r , Actual %r" % (dict, type(device.provision))) self.assertIs(type(device.provision["available"]), float, "Expected %r , Actual %r" % (float, type(device.provision["available"]))) self.assertIs(type(device.provision["percent"]), int, "Expected %r , Actual %r" % (int, type(device.provision["percent"]))) self.assertIs(type(device.provision["total"]), float, "Expected %r , Actual %r" % (float, type(device.provision["total"]))) self.assertIs(type(device.type), unicode, "Expected %r , Actual %r" % (unicode, type(device.type))) self.assertIs(type(device.used), float, "Expected %r , Actual %r" % (float, type(device.used)))
def test_usage_08_duplicate_create(self): """ Delete one instance then recreate it, ensure separate AH events """ tc_name = "Usage 08 tests" tc_num = 8 instance_id = self.instance_id_list[0] inst_name = self.client.instances.get(instance_id).name # delete the existing instance if testutil.getInstanceStatus(self.client, instance_id) == "ACTIVE": self.client.instances.get(instance_id).delete() self.instance_id_list.remove(instance_id) duration = datetime.utcnow() - self.starttime_list[tc_num] rootAction = "reddwarf.instance.delete" # AH Event Sent - Check AH data data AFTER the DELETE time.sleep(self.AHDELAY) AHEventsList = self.dbaas_atomhopper_provider.events_by_resourceId(instance_id) single_event = [event for event in AHEventsList if event.rootAction == rootAction].pop() self.assertEqual( single_event.resourceId, instance_id, "AH resourceID:%r != created instanceID:%r" % (single_event.resourceId, instance_id), ) testutil.valid_duration(duration, single_event, self.dateFormat) # now create an exact duplicate instance startTime1 = datetime.utcnow() instance_id1, elapsed_time = testutil.create_active_instance( self.client, name=inst_name, flavor_id=2, volume={"size": 2}, databases=[{"name": "db_name"}] ) httpCode = testutil.get_last_response_code(self.client) if httpCode != "200": raise Exception("Create instance failed with code %s" % httpCode) self.fixture_log.debug( "Inst: %r is: %r after: %r seconds" % (instance_id, self.client.instances.get(instance_id).status, elapsed_time) ) running_time = (datetime.utcnow() - self.starttime_list[tc_num]).seconds if 5 * self.ONEMIN > running_time: time.sleep((5 * self.ONEMIN) - running_time) # delete the ACTIVE instance if testutil.getInstanceStatus(self.client, instance_id1) == "ACTIVE": self.client.instances.get(instance_id1).delete() duration = datetime.utcnow() - self.starttime_list[tc_num] rootAction = "reddwarf.instance.delete" # AH Event Sent - Check AH data data AFTER the DELETE time.sleep(self.AHDELAY) AHEventsList = self.dbaas_atomhopper_provider.events_by_resourceId(instance_id1) single_event = [event for event in AHEventsList if event.rootAction == rootAction].pop() self.assertEqual( single_event.resourceId, instance_id1, "AH resourceID:%r != created instanceID:%r" % (single_event.resourceId, instance_id1), ) testutil.valid_duration(duration, single_event, self.dateFormat)
def test_bad_user_data(self): _user = [] _user_name = "F343jasdf" _user.append({"name12": _user_name, "password12": "password"}) try: self.dbaas.users.create(self.instance_id, _user) except Exception as e: httpCode = testutil.get_last_response_code(self.dbaas) self.assertTrue(httpCode == '400', "Create instance failed with code %s, excpetion %s" % (httpCode, e.message))
def test_change_user_pw(self): """ Changes the password of a user Issue: You cannot verify the new password since that is never returned from the server. @return: """ _db_name1 = "test_change_user_pw" _db_name2 = "test_change_user_pw2" _databases = [{"name": _db_name1}, {"name": _db_name2}] _test_user = [] _user_name = "F343jasdf1234" _test_user.append({"name": _user_name, "password": "******", "databases": _databases}) self.dbaas.users.create(self.instance_id, _test_user) httpCode = testutil.get_last_response_code(self.dbaas) self.assertTrue(httpCode == '202', "Create instance failed with code %s" % httpCode) testutil.waitForActive(self.dbaas, instanceId=self.instance_id) _test_user[0]['password'] = "******" self.dbaas.users.change_passwords(self.instance_id, _test_user) httpCode = testutil.get_last_response_code(self.dbaas) self.assertTrue(httpCode == '202', "Create instance failed with code %s" % httpCode) self.dbaas.users.delete(self.instance_id, _user_name) self.assertFalse(testutil.found_resource(self.dbaas, instanceId=self.instance_id, userName=_user_name), "Delete error: Found user name: %s in the list." % _user_name)
def test_rbac_users_admin_rights(self): db_name = "rp_db" db_body = [{"name": db_name}] user_name = "rp_user" user_body = [{"databases": db_body, "name": user_name, "password": "******"}] try: self.dbaas_admin.users.create(self.admin_instance_id, user_body) httpCode = testutil.get_last_response_code(self.dbaas_admin) self.assertTrue(httpCode == '202', "Users Create: Expected http code: %s | Actual http code: %s " % ('202', httpCode)) self.dbaas_admin.users.list( self.dbaas_admin.instances.get(self.admin_instance_id)) httpCode = testutil.get_last_response_code(self.dbaas_admin) self.assertTrue(httpCode == '200', "Users list: Expected http code: %s | Actual http code: %s " % ('200', httpCode)) self.dbaas_admin.users.delete(self.admin_instance_id, db_name) httpCode = testutil.get_last_response_code(self.dbaas_admin) self.assertTrue(httpCode == '202', "Users Delete: Expected http code: %s | Actual http code: %s " % ('202', httpCode)) self.dbaas_admin.users.list_access(self.admin_instance_id, user_name) httpCode = testutil.get_last_response_code(self.dbaas_admin) self.assertTrue(httpCode == '200', "Users List Access: Expected http code: %s | Actual http code: %s " % ('200', httpCode)) self.dbaas_admin.users.revoke(self.admin_instance_id, user_name, db_name) httpCode = testutil.get_last_response_code(self.dbaas_admin) self.assertTrue(httpCode == '202', "Users Revoke: Expected http code: %s | Actual http code: %s " % ('200', httpCode)) _db_list = [db_name] self.dbaas_admin.users.grant(self.admin_instance_id, user_name, _db_list) httpCode = testutil.get_last_response_code(self.dbaas_admin) self.assertTrue(httpCode == '202', "Users Grant: Expected http code: %s | Actual http code: %s " % ('202', httpCode)) user_body[0]['password'] = "******" self.dbaas_admin.users.change_passwords(self.admin_instance_id, user_body) httpCode = testutil.get_last_response_code(self.dbaas_admin) self.assertTrue(httpCode == '202', "Users Password Change: Expected http code: %s | Actual http code: %s " % ('202', httpCode)) except Exception as e: self.fail(e)
def test_usage_05_restart_mysql(self): """ Restart MySQL then Delete one instance after 10 minutes """ tc_name = "Usage 05 tests" tc_num = 05 instance_id = self.instance_id_list[0] self.client.instances.restart(instance_id) self.assertEqual( str(testutil.get_last_response_code(self.client)), "202", "Error: Resize instance. Unexpected resp code: %r != %r" % (str(testutil.get_last_response_code(self.client)), "202"), ) # check interim status of REBOOT testutil.wait_for_status(self.client, instance_id, "REBOOT") # wait for active, ensure time elapsed, record the duration status, elapsed_time = testutil.waitForActive(self.client, instanceId=instance_id) self.fixture_log.debug("Inst: %r is: %r after: %r seconds" % (instance_id, status, elapsed_time)) running_time = (datetime.utcnow() - self.starttime_list[tc_num]).seconds if 10 * self.ONEMIN > running_time: time.sleep((10 * self.ONEMIN) - running_time) # delete the ACTIVE instance if testutil.getInstanceStatus(self.client, instance_id) == "ACTIVE": self.client.instances.get(instance_id).delete() self.instance_id_list.remove(instance_id) duration = datetime.utcnow() - self.starttime_list[tc_num] rootAction = "reddwarf.instance.delete" # AH Event Sent - Check AH data data AFTER the DELETE time.sleep(self.AHDELAY) AHEventsList = self.dbaas_atomhopper_provider.events_by_resourceId(instance_id) single_event = [event for event in AHEventsList if event.rootAction == rootAction].pop() self.assertEqual( single_event.resourceId, instance_id, "AH resourceID:%r != created instanceID:%r" % (single_event.resourceId, instance_id), ) testutil.valid_duration(duration, single_event, self.dateFormat)
def test_create_multi_user_with_multi_db(self): _db_name1 = "multi_user_with_multi-database" _db_name2 = "multi_user_with_multi-db2" _databases = [{"name": _db_name1}, {"name": _db_name2}] _test_users = [] _test_users.append({"name": "F343jasdf_", "password": "******", "databases": _databases}) _test_users.append({"name": "403F23F343jasdf", "password": "******", "databases": _databases}) _test_users.append({"name": "easy_user_name", "password": "******", "databases": _databases}) self.dbaas.users.create(self.instance_id, _test_users) httpCode = testutil.get_last_response_code(self.dbaas) self.assertTrue(httpCode == '202', "Create instance failed with code %s" % httpCode) testutil.waitForActive(self.dbaas, instanceId=self.instance_id) #print (self.instance_id) self.assertTrue(testutil.getInstanceStatus(self.dbaas, instanceId=self.instance_id) == 'ACTIVE', "Instance is not in Active statue") #Get the instance and check user dbs _user_list = self.dbaas.users.list(self.dbaas.instances.get(self.instance_id)) #self.assertTrue(len(_user_list) == len(_test_users), "Expected %s user: Got: %s " # % (len(_test_users), len(_user_list))) for _user in _user_list: self.assertEqual(_user.databases, _databases) #try to find our user in the list self.assertTrue(testutil.found_resource(self.dbaas, instanceId=self.instance_id, userName=_user.name), "Did not find our user name: %s in the list." % _user.name) self.dbaas.users.delete(self.instance_id, _user.name) self.assertFalse(testutil.found_resource(self.dbaas, instanceId=self.instance_id, userName=_user.name), "Delete error: Found user name: %s in the list." % _user.name)
def test_update_all_instances_on_host(self): # TODO: To property test this call, a new sneaky pete image has to be # available in the apt repo to update the instances with. # If not available, instances will not be updated. # This test case will only verify the requested call's response code, # and nothing more for now. try: self.mgmt_dbaas.hosts.update_all(self.host) httpCode = testutil.get_last_response_code(self.mgmt_dbaas) self.assertTrue(httpCode == '202', "Update all instances on host failed with code %s" % (httpCode)) self.fixture_log.debug("\tUpdate all instances on host code: %r" % (httpCode)) except Exception as e: self.fixture_log.debug("\tException: %r" % (e)) raise
def test_create_2_users_instance(self): """ Creating an instance for smoke testing """ dbaas = self.dbaas_provider.client.reddwarfclient NAME = "qe-2users-instance" FLAVOR = 1 VOLUME = 10 databases = [] databases.append({"name": "firstdb", "character_set": "latin2", "collate": "latin2_general_ci"}) users = [] users.append({"name": "lite", "password": "******", "databases": [{"name": "firstdb"}]}) users.append({"name": "lite1", "password": "******", "databases": [{"name": "firstdb"}]}) instance = dbaas.instances.create( name=NAME, flavor_id=FLAVOR, volume={"size": VOLUME}, databases=databases, users=users) httpCode = testutil.get_last_response_code(dbaas) self.multi_users_instance_id = instance.id self.assertTrue(httpCode == '200', "Create instance failed with code %s" % httpCode) testutil.waitForActive(dbaas, instanceId=instance.id) self.assertTrue(testutil.getInstanceStatus(dbaas, instanceId=instance.id) == 'ACTIVE', "Instance is not in Active statue") #Get the instance and check instance attribs: such as the flavor / volume size instance = self.dbaas.instances.get(instance) self.assertTrue(instance.flavor['id'] == str(FLAVOR)) self.assertTrue(instance.volume['size'] == VOLUME) self.assertTrue(instance.name == NAME) #try to find our instance in the list self.assertTrue(testutil.found_resource(self.dbaas, instanceId=instance.id), "Did not find our instance id: %s in the list." % instance.id)
def setUpClass(cls): """ Creating an instance for database testing """ super(test_users, cls).setUpClass() test_users.dbaas = cls.dbaas_provider.client.reddwarfclient NAME = "qe-user-testing" FLAVOR = 1 VOLUME = 1 instance = test_users.dbaas.instances.create( name=NAME, flavor_id=FLAVOR, volume={"size": VOLUME}) httpCode = testutil.get_last_response_code(test_users.dbaas) if httpCode != '200': raise Exception("Create instance failed with code %s" % httpCode) test_users.instance_id = instance.id testutil.waitForActive(test_users.dbaas, instanceId=test_users.instance_id)