예제 #1
0
    def validate_stats(self, ui=False):
        """ Validates that the detail page matches the Providers information.

        This method logs into the provider using the mgmt_system interface and collects
        a set of statistics to be matched against the UI. The details page is then refreshed
        continuously until the matching of all items is complete. A error will be raised
        if the match is not complete within a certain defined time period.
        """

        # If we're not using db, make sure we are on the provider detail page
        if ui:
            self.load_details()

        # Initial bullet check
        if self._do_stats_match(self.mgmt, self.STATS_TO_MATCH, ui=ui):
            self.mgmt.disconnect()
            return
        else:
            # Set off a Refresh Relationships
            method = 'ui' if ui else None
            self.refresh_provider_relationships(method=method)

            refresh_timer = RefreshTimer(time_for_refresh=300)
            wait_for(self._do_stats_match,
                     [self.mgmt, self.STATS_TO_MATCH, refresh_timer],
                     {'ui': ui},
                     message="do_stats_match_db",
                     num_sec=1000,
                     delay=60)

        self.mgmt.disconnect()
def test_provision_from_template(appliance, provider, testing_instance,
                                 soft_assert):
    """ Tests instance provision from template

    Metadata:
        test_flag: provision
    """
    instance, inst_args, image = testing_instance
    instance.create(**inst_args)
    logger.info('Waiting for cfme provision request for vm %s', instance.name)
    request_description = 'Provision from [{}] to [{}]'.format(
        image, instance.name)
    provision_request = RequestCollection(appliance).instantiate(
        request_description)
    try:
        provision_request.wait_for_request(method='ui')
    except Exception as e:
        logger.info("Provision failed {}: {}".format(
            e, provision_request.row.last_message.text()))
        raise e
    assert provision_request.is_succeeded(method='ui'), \
        "Provisioning failed with the message {}".format(provision_request.row.last_message.text)
    instance.wait_to_appear(timeout=800)
    provider.refresh_provider_relationships()
    logger.info("Refreshing provider relationships and power states")
    refresh_timer = RefreshTimer(time_for_refresh=300)
    wait_for(provider.is_refreshed, [refresh_timer],
             message="is_refreshed",
             num_sec=1000,
             delay=60,
             handle_exception=True)
    soft_assert(instance.does_vm_exist_on_provider(),
                "Instance wasn't provisioned")
def wait_for_ui_state_refresh(instance,
                              provider,
                              state_change_time,
                              timeout=900):
    """ Waits for 'State Changed On' refresh
    """
    view = navigate_to(instance, 'Details')

    def _wait_for_state_refresh():
        try:
            state = view.entities.summary('Power Management').get_text_of(
                'State Changed On')
            return state_change_time != state
        except NameError:
            logger.warning(
                'NameError caught while waiting for state change, continuing')
            return False

    refresh_timer = RefreshTimer(time_for_refresh=180)

    def _fail_func():
        provider.is_refreshed(refresh_timer)
        view.toolbar.reload.click()

    try:
        wait_for(_wait_for_state_refresh,
                 fail_func=_fail_func,
                 num_sec=timeout,
                 delay=30,
                 message='Waiting for instance state refresh')
    except TimedOutError:
        return False
예제 #4
0
def provisioned_instance(provider, testing_instance, appliance):
    """ Checks provisioning status for instance """
    instance, inst_args, image = testing_instance
    instance.create(**inst_args)
    logger.info('Waiting for cfme provision request for vm %s', instance.name)
    request_description = 'Provision from [{}] to [{}]'.format(
        image, instance.name)
    provision_request = appliance.collections.requests.instantiate(
        request_description)
    try:
        provision_request.wait_for_request(method='ui')
    except Exception as e:
        logger.info("Provision failed {}: {}".format(
            e, provision_request.request_state))
        raise e
    assert provision_request.is_succeeded(
        method='ui'), ("Provisioning failed with the message {}".format(
            provision_request.row.last_message.text))
    instance.wait_to_appear(timeout=800)
    provider.refresh_provider_relationships()
    logger.info("Refreshing provider relationships and power states")
    refresh_timer = RefreshTimer(time_for_refresh=300)
    wait_for(provider.is_refreshed, [refresh_timer],
             message="is_refreshed",
             num_sec=1000,
             delay=60,
             handle_exception=True)
    return instance
예제 #5
0
def wait_for_termination(provider, instance):
    """ Waits for VM/instance termination and refreshes power states and relationships
    """
    view = navigate_to(instance, 'Details')
    pwr_mgmt = view.entities.summary('Power Management')
    state_change_time = pwr_mgmt.get_text_of('State Changed On')
    provider.refresh_provider_relationships()
    logger.info("Refreshing provider relationships and power states")
    refresh_timer = RefreshTimer(time_for_refresh=300)
    wait_for(provider.is_refreshed,
             [refresh_timer],
             message="Waiting for provider.is_refreshed",
             num_sec=1000,
             delay=60,
             handle_exception=True)
    wait_for_ui_state_refresh(instance, provider, state_change_time, timeout=720)
    term_states = {instance.STATE_TERMINATED, instance.STATE_ARCHIVED, instance.STATE_UNKNOWN}
    if pwr_mgmt.get_text_of('Power State') not in term_states:
        """Wait for one more state change as transitional state also changes "State Changed On" time
        """
        logger.info("Instance is still powering down. please wait before termination")
        state_change_time = pwr_mgmt.get_text_of('State Changed On')
        wait_for_ui_state_refresh(instance, provider, state_change_time, timeout=720)

    return (instance.mgmt.state == VmState.DELETED
            if provider.one_of(EC2Provider)
            else pwr_mgmt.get_text_of('Power State') in term_states)
def wait_for_termination(provider, instance):
    """ Waits for VM/instance termination and refreshes power states and relationships
    """
    state_change_time = instance.get_detail(properties=('Power Management', 'State Changed On'))
    provider.refresh_provider_relationships()
    logger.info("Refreshing provider relationships and power states")
    refresh_timer = RefreshTimer(time_for_refresh=300)
    wait_for(provider.is_refreshed,
             [refresh_timer],
             message="Waiting for provider.is_refreshed",
             num_sec=1000,
             delay=60,
             handle_exception=True)
    wait_for_ui_state_refresh(instance, provider, state_change_time, timeout=720)
    if instance.get_detail(properties=('Power Management', 'Power State')) not in \
            {instance.STATE_TERMINATED, instance.STATE_ARCHIVED, instance.STATE_UNKNOWN}:
        """Wait for one more state change as transitional state also changes "State Changed On" time
        """
        logger.info("Instance is still powering down. please wait before termination")
        state_change_time = instance.get_detail(properties=('Power Management', 'State Changed On'))
        wait_for_ui_state_refresh(instance, provider, state_change_time, timeout=720)
    if provider.type == 'ec2':
        return True if provider.mgmt.is_vm_state(instance.name, provider.mgmt.states['deleted'])\
            else False
    elif instance.get_detail(properties=('Power Management', 'Power State')) in \
            {instance.STATE_TERMINATED, instance.STATE_ARCHIVED, instance.STATE_UNKNOWN}:
        return True
    else:
        logger.info("Instance is still running")
        return False
예제 #7
0
def wait_for_ui_state_refresh(instance,
                              provider,
                              state_change_time,
                              timeout=900):
    """ Waits for 'State Changed On' refresh
    """
    def _wait_for_state_refresh():
        try:
            navigate_to(instance, 'Details')
            return state_change_time != instance.get_detail(
                properties=("Power Management", "State Changed On"))
        except NameError:
            logger.warning(
                'NameError caught while waiting for state change, continuing')
            return False

    refresh_timer = RefreshTimer(time_for_refresh=180)
    try:
        wait_for(_wait_for_state_refresh,
                 fail_func=lambda: provider.is_refreshed(refresh_timer),
                 num_sec=timeout,
                 delay=30,
                 message='Waiting for instance state refresh')
    except TimedOutError:
        return False
예제 #8
0
 def validate(self):
     refresh_timer = RefreshTimer(time_for_refresh=300)
     try:
         wait_for(self.is_refreshed, [refresh_timer],
                  message="is_refreshed",
                  num_sec=1000,
                  delay=60,
                  handle_exception=True)
     except Exception:
         # To see the possible error.
         self.load_details(refresh=True)
         raise
예제 #9
0
 def validate(self):
     refresh_timer = RefreshTimer(time_for_refresh=300)
     try:
         wait_for(self.is_refreshed, [refresh_timer],
                  message="is_refreshed",
                  num_sec=1000,
                  delay=60,
                  handle_exception=True)
     except Exception:
         # To see the possible error.
         self.load_details(refresh=True)
         raise
     else:
         if self.last_refresh_error() is not None:
             raise AddProviderError(
                 "Cannot validate the provider. Error occured: {}".format(
                     self.last_refresh_error()))
예제 #10
0
def test_gce_preemptible_provision(provider, testing_instance, soft_assert):
    instance, inst_args, image = testing_instance
    instance.create(**inst_args)
    instance.wait_to_appear(timeout=800)
    provider.refresh_provider_relationships()
    logger.info("Refreshing provider relationships and power states")
    refresh_timer = RefreshTimer(time_for_refresh=300)
    wait_for(provider.is_refreshed, [refresh_timer],
             message="is_refreshed",
             num_sec=1000,
             delay=60,
             handle_exception=True)
    soft_assert(
        'Yes' in instance.get_detail(properties=("Properties", "Preemptible")),
        "GCE Instance isn't Preemptible")
    soft_assert(instance.does_vm_exist_on_provider(),
                "Instance wasn't provisioned")
예제 #11
0
def test_gce_preemptible_provision(appliance, provider, instance_args, soft_assert):
    vm_name, inst_args = instance_args
    instance = appliance.collections.cloud_instances.create(vm_name,
                                                            provider,
                                                            form_values=inst_args)
    instance.wait_to_appear(timeout=800)
    provider.refresh_provider_relationships()
    logger.info("Refreshing provider relationships and power states")
    wait_for(provider.is_refreshed,
             [RefreshTimer(time_for_refresh=300)],
             message="is_refreshed",
             num_sec=1000,
             delay=60,
             handle_exception=True)
    view = navigate_to(instance, "Details")
    preemptible = view.entities.summary("Properties").get_text_of("Preemptible")
    soft_assert('Yes' in preemptible, "GCE Instance isn't Preemptible")
    soft_assert(instance.does_vm_exist_on_provider(), "Instance wasn't provisioned")
예제 #12
0
def provisioned_instance(provider, instance_args, appliance):
    """ Checks provisioning status for instance """
    vm_name, inst_args = instance_args
    instance = appliance.collections.cloud_instances.create(vm_name,
                                                            provider,
                                                            form_values=inst_args)
    view = appliance.browser.create_view(BaseLoggedInPage)  # not the page we're on, but has flash
    view.flash.assert_success_message(instance.PROVISION_START)

    logger.info('Waiting for cfme provision request for vm %s', instance.name)
    request_description = 'Provision from [{}] to [{}]'.format(inst_args.get('template_name'),
                                                               instance.name)
    provision_request = appliance.collections.requests.instantiate(request_description)
    try:
        provision_request.wait_for_request(method='ui')
    except Exception:
        logger.exception(
            "Provision failed: {}".format(provision_request.request_state))
        raise
    assert provision_request.is_succeeded(method='ui'), (
        "Provisioning failed with the message {}".format(
            provision_request.row.last_message.text))
    instance.wait_to_appear(timeout=800)
    provider.refresh_provider_relationships()
    logger.info("Refreshing provider relationships and power states")
    refresh_timer = RefreshTimer(time_for_refresh=300)
    wait_for(provider.is_refreshed,
             [refresh_timer],
             message="is_refreshed",
             num_sec=1000,
             delay=60,
             handle_exception=True)
    yield instance

    logger.info('Instance cleanup, deleting %s', instance.name)
    try:
        instance.delete_from_provider()
    except Exception as ex:
        logger.warning('Exception while deleting instance fixture, continuing: {}'
                       .format(ex.message))