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 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_reboot_instance(self): expected_status = "REBOOT" expected_status_found = False expected_task_desc = "No tasks for the instance." initial_updated = "" # list instance details and store updated time value instance_details = test_actions.mgmt_dbaas.management.show( \ self.instance) httpCode = testutil.get_last_response_code(test_actions.mgmt_dbaas) if httpCode != '200': raise Exception("List instance details failed with code %s" % httpCode) initial_updated = instance_details.updated self.fixture_log.debug("\t\tInstance %r initial update on %r" % (instance_details.id, initial_updated)) # call reboot instance try: self.mgmt_dbaas.management.reboot(self.instance_id) httpCode = testutil.get_last_response_code(self.mgmt_dbaas) self.assertTrue(httpCode == '202', "Reboot instance failed with code %s" % httpCode) except Exception as e: self.fixture_log.debug("\tException: %r" % (e)) raise # check instance for Reboot status current_status, elapsed = testutil.wait_for_status(self.mgmt_dbaas, self.instance_id, expected_status) self.fixture_log.debug("\t\tInstance status encountered: %r" % (current_status)) self.assertEqual(current_status, expected_status, "Expected status %r , Actual status %r" % (expected_status, current_status)) if current_status == expected_status: expected_status_found = True self.fixture_log.debug("\t\tExpected status found? %r" % (expected_status_found)) # verify it comes up in an Active state status, elapsed = testutil.waitForActive(self.mgmt_dbaas, instanceId=self.instance_id) self.fixture_log.debug("\t\tInstance status encountered: %r" % (status)) self.assertEqual(status, 'ACTIVE', "Expected status %r , Actual status %r" % ('ACTIVE', status)) # make final checks self.assertTrue(expected_status_found, "Expected status %r was not seen!" % (expected_status)) instance_details = test_actions.mgmt_dbaas.management.show( \ self.instance) httpCode = testutil.get_last_response_code(test_actions.mgmt_dbaas) if httpCode != '200': raise Exception("List instance details failed with code %s" % httpCode) self.assertTrue(initial_updated != instance_details.updated, "Instance %r was not updated!" % (instance_details.id)) self.fixture_log.debug("\t\tInstance %r final update on %r" % (instance_details.id, instance_details.updated))
def test_usage_06_resize_reboot_volume_up(self): """ Resize the Volume Storage and then reboot, ensure only two AH events """ tc_name = "Usage 06 tests" tc_num = 06 NEW_VOLUME = 6 instance_id = self.instance_id_list[0] 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_volume" response = self.client.instances.resize_volume(instance_id, NEW_VOLUME) 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"), ) 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 * 2) 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) # confirm the new flavor self.assertEqual( NEW_VOLUME, self.instance.volume["size"], "Error: Expected flavor of: %r != Actual flavor: %r" % (NEW_VOLUME, self.instance.volume["size"]), ) time.sleep(2 * self.ONEMIN) # restart the instance self.mgmt_client.management.reboot(instance_id) self.assertEqual( str(testutil.get_last_response_code(self.client)), "200", "Error: Resize instance. Unexpected resp code: %r != %r" % (str(testutil.get_last_response_code(self.client)), "200"), ) testutil.wait_for_status(self.client, instance_id, "REBOOT") 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)) time.sleep(2 * 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)