def test_provision_from_template(request, setup_provider, 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) row_description = 'Provision from [{}] to [{}]'.format( image, instance.name) cells = {'Description': row_description} try: row, __ = wait_for(requests.wait_for_request, [cells], fail_func=requests.reload, num_sec=1500, delay=20) except Exception as e: requests.debug_requests() raise e assert normalize_text(row.status.text) == 'ok' and \ normalize_text(row.request_state.text) == 'finished', \ "Provisioning failed with the message {}".format(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 test_provision_from_template(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 = Request(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 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 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
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_state_change_time_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_state_change_time_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
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) except Exception: # To see the possible error. self.load_details(refresh=True) raise
def test_gce_preemtible_provision(request, setup_provider, provider, testing_instance, soft_assert): instance, inst_args = 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")
def validate(self, db=True): """ 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. """ client = self.get_mgmt_system() # If we're not using db, make sure we are on the provider detail page if not db: sel.force_navigate('{}_provider'.format(self.page_name), context={'provider': self}) # Initial bullet check if self._do_stats_match(client, self.STATS_TO_MATCH, db=db): client.disconnect() return else: # Set off a Refresh Relationships sel.force_navigate('{}_provider'.format(self.page_name), context={'provider': self}) tb.select("Configuration", "Refresh Relationships and Power States", invokes_alert=True) sel.handle_alert() refresh_timer = RefreshTimer(time_for_refresh=300) wait_for(self._do_stats_match, [client, self.STATS_TO_MATCH, refresh_timer], {'db': db}, message="do_stats_match_db", num_sec=1000, delay=60) client.disconnect()