def status_timeout(self, things, thing_id, expected_status): """Given a thing and an expected status, do a loop, sleeping for a configurable amount of time, checking for the expected status to show. At any time, if the returned status of the thing is ERROR, fail out. """ def check_status(): # python-novaclient has resources available to its client # that all implement a get() method taking an identifier # for the singular resource to retrieve. thing = things.get(thing_id) new_status = thing.status.lower() if new_status == 'error': self.fail("Failed to get to expected status. " "In error state.") elif new_status == expected_status.lower(): return True # All good. LOG.debug("Waiting for %s to get to %s status. " "Currently in %s status", thing, expected_status, new_status) conf = config.FuelConfig() if not call_until_true(check_status, conf.compute.build_timeout, conf.compute.build_interval): self.fail("Timed out waiting to become %s" % expected_status)
class BaseTestCase(unittest2.TestCase, testresources.ResourcedTestCase, FuelTestAssertMixin): config = config.FuelConfig() def __init__(self, *args, **kwargs): super(BaseTestCase, self).__init__(*args, **kwargs) @classmethod def setUpClass(cls): if hasattr(super(BaseTestCase, cls), 'setUpClass'): super(BaseTestCase, cls).setUpClass()
def get_image_from_name(): cfg = config.FuelConfig() image_name = cfg.compute.image_name image_client = OfficialClientManager()._get_compute_client() images = image_client.images.list() LOG.debug(images) if images: for im in images: LOG.debug(im.name) if im.name.strip().lower() == image_name.strip().lower(): return im.id else: raise exceptions.ImageFault
def wait_for_stack_status(self, stack_id, expected_status): """ The method is a customization of test.status_timeout(). It addresses `stack_status` instead of `status` field. The rest is the same. """ def check_status(): stack = self.heat_client.stacks.get(stack_id) new_status = stack.stack_status if new_status == 'ERROR': self.fail("Failed to get to expected status. In ERROR state.") elif new_status == expected_status: return True # All good. LOG.debug( "Waiting for %s to get to %s status. " "Currently in %s status", stack, expected_status, new_status) conf = config.FuelConfig() if not fuel_health.test.call_until_true( check_status, self.wait_timeout, self.wait_interval): self.fail("Timed out waiting to become %s" % expected_status)
def setUpClass(cls): if hasattr(super(BaseTestCase, cls), 'setUpClass'): super(BaseTestCase, cls).setUpClass() cls.config = config.FuelConfig()