def deploy_template(provider_key, vm_name, template_name=None, timeout=900, **deploy_args): """ Args: provider_key: Provider key on which the VM is to be created vm_name: Name of the VM to be deployed template_name: Name of the template that the VM is deployed from timeout: the timeout for template deploy """ allow_skip = deploy_args.pop("allow_skip", ()) if isinstance(allow_skip, dict): skip_exceptions = allow_skip.keys() callable_mapping = allow_skip elif isinstance(allow_skip, six.string_types) and allow_skip.lower() == "default": skip_exceptions = DEFAULT_SKIP callable_mapping = {} else: skip_exceptions = allow_skip callable_mapping = {} provider_crud = get_crud(provider_key) deploy_args.update(vm_name=vm_name) if template_name is None: try: deploy_args.update(template=provider_crud.data['templates']['small_template']['name']) except KeyError: raise KeyError('small_template not defined for Provider {} in cfme_data.yaml' .format(provider_key)) else: deploy_args.update(template=template_name) deploy_args.update(provider_crud.deployment_helper(deploy_args)) logger.info("Getting ready to deploy VM/instance %s from template %s on provider %s", vm_name, deploy_args['template'], provider_crud.data['name']) try: try: logger.debug("Deploy args: %s", deploy_args) vm_name = provider_crud.mgmt.deploy_template(timeout=timeout, **deploy_args) logger.info("Provisioned VM/instance %s", vm_name) # instance ID in case of EC2 except Exception as e: logger.exception('Could not provisioning VM/instance %s (%s: %s)', vm_name, type(e).__name__, str(e)) try: provider_crud.mgmt.delete_vm(vm_name) except Exception: logger.exception("Unable to clean up vm:", vm_name) raise except skip_exceptions as e: e_c = type(e) if e_c in callable_mapping and not callable_mapping[e_c](e): raise # Make it visible also in the log. store.write_line( "Skipping due to a provider error: {}: {}\n".format(e_c.__name__, str(e)), purple=True) logger.exception(e) pytest.skip("{}: {}".format(e_c.__name__, str(e))) return vm_name
def appliance_police(appliance): if not store.slave_manager: return try: available_ports = { 'ssh': (appliance.hostname, appliance.ssh_port), 'https': (appliance.hostname, appliance.ui_port), 'postgres': (appliance.db_host or appliance.hostname, appliance.db_port)} port_results = {pn: net_check(addr=p_addr, port=p_port, force=True) for pn, (p_addr, p_port) in available_ports.items()} for port, result in port_results.items(): if port == 'ssh' and appliance.is_pod: # ssh is not available for podified appliance continue if not result: raise AppliancePoliceException('Unable to connect', available_ports[port][1]) try: status_code = requests.get(appliance.url, verify=False, timeout=120).status_code except Exception: raise AppliancePoliceException('Getting status code failed', available_ports['https'][1]) if status_code != 200: raise AppliancePoliceException('Status code was {}, should be 200'.format( status_code), available_ports['https'][1]) return except AppliancePoliceException as e: # special handling for known failure conditions if e.port == 443: # Lots of rdbs lately where evm seems to have entirely crashed # and (sadly) the only fix is a rude restart appliance.restart_evm_service(rude=True) try: appliance.wait_for_web_ui(900) store.write_line('EVM was frozen and had to be restarted.', purple=True) return except TimedOutError: pass e_message = str(e) except Exception as e: e_message = str(e) # Regardles of the exception raised, we didn't return anywhere above # time to call a human msg = 'Help! My appliance {} crashed with: {}'.format(appliance.url, e_message) store.slave_manager.message(msg) if 'appliance_police_recipients' in rdb: rdb_kwargs = { 'subject': 'RDB Breakpoint: Appliance failure', 'recipients': rdb.appliance_police_recipients, } else: rdb_kwargs = {} Rdb(msg).set_trace(**rdb_kwargs) store.slave_manager.message('Resuming testing following remote debugging')
def pytest_sessionstart(session): if store.parallelizer_role == 'master': return if not session.config.getoption("update_appliance"): return store.write_line("Initiating appliance update ...") urls = session.config.getoption("update_urls") store.current_appliance.update_rhel(*urls, reboot=True) store.write_line("Appliance update finished, waiting for UI ...") store.current_appliance.wait_for_miq_ready() store.write_line("Appliance update finished ...")
def pytest_sessionstart(session): if store.parallelizer_role == 'master': return if session.config.getoption("dev_repo") is None: return if store.current_appliance.is_downstream: store.write_line("Cannot git update downstream appliances ...") pytest.exit( 'Failed to git update this appliance, because it is downstream') dev_repo = session.config.getoption("dev_repo") dev_branch = session.config.getoption("dev_branch") store.write_line("Changing the upstream appliance {} to {}#{} ...".format( store.current_appliance.hostname, dev_repo, dev_branch)) store.current_appliance.use_dev_branch(dev_repo, dev_branch) store.write_line("Appliance change finished ...")
def deploy_template(provider_key, vm_name, template_name=None, timeout=900, **deploy_args): """ Args: provider_key: Provider key on which the VM is to be created vm_name: Name of the VM to be deployed template_name: Name of the template that the VM is deployed from timeout: the timeout for template deploy """ allow_skip = deploy_args.pop("allow_skip", ()) if isinstance(allow_skip, dict): skip_exceptions = allow_skip.keys() callable_mapping = allow_skip elif isinstance(allow_skip, six.string_types) and allow_skip.lower() == "default": skip_exceptions = DEFAULT_SKIP callable_mapping = {} else: skip_exceptions = allow_skip callable_mapping = {} provider_crud = get_crud(provider_key) deploy_args.update(vm_name=vm_name) if template_name is None: try: deploy_args.update(template=provider_crud.data['templates'] ['small_template']['name']) except KeyError: raise KeyError( 'small_template not defined for Provider {} in cfme_data.yaml'. format(provider_key)) else: deploy_args.update(template=template_name) deploy_args.update(provider_crud.deployment_helper(deploy_args)) logger.info( "Getting ready to deploy VM/instance %s from template %s on provider %s", vm_name, deploy_args['template'], provider_crud.data['name']) try: try: logger.debug("Deploy args: %s", deploy_args) vm_name = provider_crud.mgmt.deploy_template(timeout=timeout, **deploy_args) logger.info("Provisioned VM/instance %s", vm_name) # instance ID in case of EC2 except Exception as e: logger.exception('Could not provisioning VM/instance %s (%s: %s)', vm_name, type(e).__name__, str(e)) try: provider_crud.mgmt.delete_vm(vm_name) except Exception: logger.exception("Unable to clean up vm:", vm_name) raise except skip_exceptions as e: e_c = type(e) if e_c in callable_mapping and not callable_mapping[e_c](e): raise # Make it visible also in the log. store.write_line("Skipping due to a provider error: {}: {}\n".format( e_c.__name__, str(e)), purple=True) logger.exception(e) pytest.skip("{}: {}".format(e_c.__name__, str(e))) return vm_name
def deploy_template(provider_key, vm_name, template_name=None, timeout=900, **deploy_args): """ Args: provider_key: Provider key on which the VM is to be created vm_name: Name of the VM to be deployed template_name: Name of the template that the VM is deployed from timeout: the timeout for template deploy Returns: wrapanapi.entities.Vm or wrapanapi.entities.Instance object """ allow_skip = deploy_args.pop("allow_skip", ()) if isinstance(allow_skip, dict): skip_exceptions = list(allow_skip.keys()) callable_mapping = allow_skip elif isinstance(allow_skip, str) and allow_skip.lower() == "default": skip_exceptions = DEFAULT_SKIP callable_mapping = {} else: skip_exceptions = allow_skip callable_mapping = {} provider_crud = get_crud(provider_key) deploy_args.update(vm_name=vm_name) if template_name is None: try: template_name = provider_crud.data['templates']['small_template']['name'] except KeyError: raise KeyError('small_template not defined for Provider {} in cfme_data.yaml' .format(provider_key)) deploy_args.update(template=template_name) deploy_args.update(provider_crud.deployment_helper(deploy_args)) logger.info("Getting ready to deploy VM/instance %s from template %s on provider %s", vm_name, deploy_args['template'], provider_crud.data['name']) try: try: logger.debug("Deploy args: %s", deploy_args) if isinstance(provider_crud.mgmt, AzureSystem): template = provider_crud.mgmt.get_template( template_name, container=deploy_args['template_container']) else: template = provider_crud.mgmt.get_template(template_name) vm = template.deploy(timeout=timeout, **deploy_args) logger.info("Provisioned VM/instance %r", vm) except Exception: logger.exception('Could not provisioning VM/instance %s', vm_name) for vm_to_cleanup in provider_crud.mgmt.find_vms(vm_name): try: vm_to_cleanup.cleanup() except Exception: logger.exception("Unable to clean up vm: %r", vm_to_cleanup.name) raise except skip_exceptions as e: e_c = type(e) if e_c in callable_mapping and not callable_mapping[e_c](e): raise # Make it visible also in the log. store.write_line( "Skipping due to a provider error: {}: {}\n".format(e_c.__name__, str(e)), purple=True) logger.exception(e) pytest.skip("{}: {}".format(e_c.__name__, str(e))) return vm