def wait_for_pid(self): """Wait for instance PID.""" pid = None while pid is None: guest_status = dbapi.guest_status_get(self.local_id) rest_api_result = self.dbaas.instances.get(self.id) out, err = process("pstree -ap | grep init | cut -d',' -f2 | vzpid - | grep %s | awk '{print $1}'" % str(self.local_id)) pid = out.strip() if not pid: # Make sure the guest status is BUILDING during this time. assert_equal(guest_status.state, power_state.BUILDING) # REST API should return BUILDING as the status as well. assert_equal(dbaas_mapping[power_state.BUILDING], rest_api_result.status) time.sleep(10)
def test_instance_created(self): while True: guest_status = dbapi.guest_status_get(instance_info.local_id) if guest_status.state != power_state.RUNNING: result = dbaas.instances.get(instance_info.id) # I think there's a small race condition which can occur # between the time you grab "guest_status" and "result," so # RUNNING is allowed in addition to BUILDING. self.assertTrue( result.status == dbaas_mapping[power_state.BUILDING] or result.status == dbaas_mapping[power_state.RUNNING], "Result status was %s" % result.status) time.sleep(5) else: break report.log("Created an instance, ID = %s." % instance_info.id) report.log("Local id = %d" % instance_info.get_local_id()) report.log("Rerun the tests with TESTS_USE_INSTANCE_ID=%s to skip ahead " "to this point." % instance_info.id)
def test_instance_created(self): if WHITE_BOX: # Checks the db status as well as the REST API status. while True: guest_status = dbapi.guest_status_get(instance_info.local_id) if guest_status.state != power_state.RUNNING: result = dbaas.instances.get(instance_info.id) # I think there's a small race condition which can occur # between the time you grab "guest_status" and "result," so # RUNNING is allowed in addition to BUILDING. self.assertTrue( result.status == dbaas_mapping[power_state.BUILDING] or result.status == dbaas_mapping[power_state.RUNNING], "Result status was %s" % result.status) time.sleep(5) else: break report.log("Local id = %d" % instance_info.get_local_id()) else: # This version just checks the REST API status. def result_is_active(): instance = dbaas.instances.get(instance_info.id) if instance.status == "ACTIVE": return True else: # If its not ACTIVE, anything but BUILD must be # an error. assert_equal("BUILD", instance.status) assert_equal(instance.volume.get('used', None), None) return False poll_until(result_is_active) result = dbaas.instances.get(instance_info.id) report.log("Created an instance, ID = %s." % instance_info.id) report.log("TIP:") report.log("Rerun the tests with TESTS_USE_INSTANCE_ID=%s to skip " "ahead to this point." % instance_info.id) report.log("Add TESTS_DO_NOT_DELETE_INSTANCE=True to avoid deleting " "the instance at the end of the tests.")
def _get_status_tuple(self): """Grabs the db guest status and the API instance status.""" return (dbapi.guest_status_get(self.local_id), self.dbaas.instances.get(self.id))