def temp_pod_appliance(provider, appliance_data): with temp_appliances(preconfigured=False, provider_type='openshift', provider=provider.key, template_type='openshift_pod') as appliances: with appliances[0] as appliance: appliance.openshift_creds = appliance_data['openshift_creds'] appliance.is_pod = True stack.push(appliance) yield appliance stack.pop()
def temp_pod_appliance(appliance, provider, appliance_data, pytestconfig): with sprout_appliances(appliance, config=pytestconfig, preconfigured=False, provider_type='openshift', provider=provider.key, template_type='openshift_pod') as appliances: with appliances[0] as appliance: appliance.openshift_creds = appliance_data['openshift_creds'] appliance.is_pod = True stack.push(appliance) # framework will try work with default appliance if browser restarts w/o this # workaround holder = config.pluginmanager.get_plugin(PLUGIN_KEY) holder.held_appliance = appliance yield appliance stack.pop()
def temp_extdb_pod_appliance(appliance, provider, extdb_template, template_tags, create_external_database, appliance_data): db_host, db_name = create_external_database project = 'test-pod-extdb-{t}'.format( t=fauxfactory.gen_alphanumeric().lower()) provision_data = { 'template': extdb_template['name'], 'tags': template_tags, 'vm_name': project, 'template_params': { 'DATABASE_IP': db_host, 'DATABASE_NAME': db_name }, 'running_pods': set(provider.mgmt.required_project_pods) - {'postgresql'} } try: data = provider.mgmt.deploy_template(**provision_data) params = appliance_data.copy() params['db_host'] = data['external_ip'] params['project'] = project params['hostname'] = data['url'] def is_api_available(appliance): try: return appliance.rest_api.collections.providers.all except Exception: pass with IPAppliance(**params) as appliance: # framework will try work with default appliance if browser restarts w/o this # workaround appliance.is_pod = True stack.push(appliance) holder = config.pluginmanager.get_plugin(PLUGIN_KEY) holder.held_appliance = appliance # workaround, appliance looks ready but api may return errors wait_for(is_api_available, func_args=[appliance], num_sec=30) yield appliance stack.pop() finally: if provider.mgmt.does_vm_exist(project): provider.mgmt.delete_vm(project)
def temp_pod_appliance(appliance, provider, appliance_data, pytestconfig): with sprout_appliances( appliance, config=pytestconfig, preconfigured=False, provider_type='openshift', provider=provider.key, template_type='openshift_pod' ) as appliances: with appliances[0] as appliance: appliance.openshift_creds = appliance_data['openshift_creds'] appliance.is_pod = True stack.push(appliance) # framework will try work with default appliance if browser restarts w/o this # workaround holder = config.pluginmanager.get_plugin(PLUGIN_KEY) holder.held_appliance = appliance yield appliance stack.pop()
def temp_extdb_pod_appliance(appliance, provider, extdb_template, template_tags, create_external_database, appliance_data): db_host, db_name = create_external_database project = 'test-pod-extdb-{t}'.format(t=fauxfactory.gen_alphanumeric().lower()) provision_data = { 'template': extdb_template['name'], 'tags': template_tags, 'vm_name': project, 'template_params': {'DATABASE_IP': db_host, 'DATABASE_NAME': db_name}, 'running_pods': set(provider.mgmt.required_project_pods) - {'postgresql'} } try: data = provider.mgmt.deploy_template(**provision_data) params = appliance_data.copy() params['db_host'] = data['external_ip'] params['project'] = project params['hostname'] = data['url'] def is_api_available(appliance): try: return appliance.rest_api.collections.providers.all except Exception: pass with IPAppliance(**params) as appliance: # framework will try work with default appliance if browser restarts w/o this # workaround appliance.is_pod = True stack.push(appliance) holder = config.pluginmanager.get_plugin(PLUGIN_KEY) holder.held_appliance = appliance # workaround, appliance looks ready but api may return errors wait_for(is_api_available, func_args=[appliance], num_sec=30) yield appliance stack.pop() finally: if provider.mgmt.does_vm_exist(project): provider.mgmt.delete_vm(project)
def temp_pod_appliance(provider): ocp_creds = provider.get_credentials_from_config( provider.provider_data['credentials']) ssh_creds = provider.get_credentials_from_config( provider.provider_data['ssh_creds']) openshift_creds = { 'hostname': provider.provider_data['hostname'], 'username': ocp_creds.principal, 'password': ocp_creds.secret, 'ssh': { 'username': ssh_creds.principal, 'password': ssh_creds.secret, }, } with temp_appliances(preconfigured=False, provider_type='openshift', provider=provider.key, template_type='openshift_pod') as appliances: with appliances[0] as appliance: appliance.openshift_creds = openshift_creds appliance.is_pod = True stack.push(appliance) yield appliance stack.pop()
def pytest_unconfigure(): stack.pop()
def setup_multiregion_env(cfme_version, provider_type, provider, lease, sprout_poolid, desc, remote_nodes, add_prov): lease_time = tot_time(lease) provider_type = None if provider else provider_type """Multi appliance setup with multi region and replication from remote to global""" sprout_client = SproutClient.from_config() required_app_count = 1 # global app required_app_count += remote_nodes if sprout_poolid: if sprout_client.call_method('pool_exists', sprout_poolid): sprout_pool = sprout_client.call_method('request_check', sprout_poolid) if len(sprout_pool['appliances']) >= required_app_count: print("Processing pool...") apps = [] for app in sprout_pool['appliances']: apps.append(IPAppliance(app['ip_address'])) sprout_client.set_pool_description(sprout_poolid, desc) else: sys.exit("Pool does not meet the minimum size requirements!") else: sys.exit("Pool not found!") else: print("Provisioning appliances") apps, request_id = provision_appliances(count=required_app_count, cfme_version=cfme_version, provider_type=provider_type, provider=provider, lease_time=lease_time) print("Appliance pool lease time is {}".format(lease)) sprout_client.set_pool_description(request_id, desc) print("Appliances Provisioned") print("Configuring Replicated Environment") global_app = apps[0] gip = global_app.hostname remote_apps = apps[1:] print("Global Appliance Configuration") app_creds = { "username": credentials["database"]["username"], "password": credentials["database"]["password"], "sshlogin": credentials["ssh"]["username"], "sshpass": credentials["ssh"]["password"], } app_params = dict(region=99, dbhostname='localhost', username=app_creds['username'], password=app_creds['password'], dbname='vmdb_production', dbdisk=global_app.unpartitioned_disks[0]) global_app.appliance_console_cli.configure_appliance_internal(**app_params) global_app.evmserverd.wait_for_running() global_app.wait_for_web_ui() print("Done: Global @ {}".format(gip)) for num, app in enumerate(remote_apps): region_n = str((num + 1) * 10) print("Remote Appliance Configuration") app_params = dict(region=region_n, dbhostname='localhost', username=app_creds['username'], password=app_creds['password'], dbname='vmdb_production', dbdisk=app.unpartitioned_disks[0], fetch_key=gip, sshlogin=app_creds['sshlogin'], sshpass=app_creds['sshpass']) app.appliance_console_cli.configure_appliance_internal_fetch_key( **app_params) app.evmserverd.wait_for_running() app.wait_for_web_ui() print("Done: Remote @ {}, region: {}".format(app.hostname, region_n)) print("Configuring Replication") print("Setup - Replication on remote appliance") app.set_pglogical_replication(replication_type=':remote') print("Setup - Replication on global appliance") global_app.set_pglogical_replication(replication_type=':global') for app in remote_apps: global_app.add_pglogical_replication_subscription(app.hostname) random.shuffle(remote_apps) if add_prov: for app, prov_id in zip(cycle(remote_apps), add_prov): stack.push(app) prov = get_crud(prov_id) print("Adding provider {} to appliance {}".format( prov_id, app.hostname)) prov.create_rest() stack.pop() print("Done!")
def pytest_unconfigure(config): config.hook.pytest_appliance_teardown(config=config) stack.pop()
def setup_multiregion_env(cfme_version, provider_type, provider, lease, sprout_poolid, desc, remote_nodes, add_prov): lease_time = tot_time(lease) provider_type = None if provider else provider_type """Multi appliance setup with multi region and replication from remote to global""" sprout_client = SproutClient.from_config() required_app_count = 1 # global app required_app_count += remote_nodes if sprout_poolid: if sprout_client.call_method('pool_exists', sprout_poolid): sprout_pool = sprout_client.call_method('request_check', sprout_poolid) if len(sprout_pool['appliances']) >= required_app_count: print("Processing pool...") apps = [] for app in sprout_pool['appliances']: apps.append(IPAppliance(app['ip_address'])) sprout_client.set_pool_description(sprout_poolid, desc) else: sys.exit("Pool does not meet the minimum size requirements!") else: sys.exit("Pool not found!") else: print("Provisioning appliances") apps, request_id = provision_appliances(count=required_app_count, cfme_version=cfme_version, provider_type=provider_type, provider=provider, lease_time=lease_time) print("Appliance pool lease time is {}".format(lease)) sprout_client.set_pool_description(request_id, desc) print("Appliances Provisioned") print("Configuring Replicated Environment") global_app = apps[0] gip = global_app.hostname remote_apps = apps[1:] print("Global Appliance Configuration") command_set0 = ('ap', '', '7', '1', '1', '2', 'n', '99', pwd, TimedCommand(pwd, 360), '') global_app.appliance_console.run_commands(command_set0) global_app.evmserverd.wait_for_running() global_app.wait_for_web_ui() print("Done: Global @ {}".format(gip)) for num, app in enumerate(remote_apps): region_n = str(num + 1 * 10) print("Remote Appliance Configuration") command_set1 = ('ap', '', '7', '2', gip, '', pwd, '', '1', '2', 'n', region_n, pwd, TimedCommand(pwd, 360), '') app.appliance_console.run_commands(command_set1) app.evmserverd.wait_for_running() app.wait_for_web_ui() print("Done: Remote @ {}, region: {}".format(app.hostname, region_n)) print("Configuring Replication") print("Setup - Replication on remote appliance") app.set_pglogical_replication(replication_type=':remote') print("Setup - Replication on global appliance") global_app.set_pglogical_replication(replication_type=':global') for app in remote_apps: global_app.add_pglogical_replication_subscription(app.hostname) random.shuffle(remote_apps) if add_prov: for app, prov_id in zip(cycle(remote_apps), add_prov): stack.push(app) prov = get_crud(prov_id) print("Adding provider {} to appliance {}".format( prov_id, app.hostname)) prov.create() stack.pop() print("Done!")