Ejemplo n.º 1
0
def pytest_configure(config):

    reporter = terminalreporter.reporter()
    if config.getoption('--dummy-appliance'):
        appliances = [DummyAppliance.from_config(config)]
        reporter.write_line('Retrieved Dummy Appliance', red=True)
    elif stack.top:
        appliances = [stack.top]
    elif config.option.appliances:
        appliances = appliances_from_cli(config.option.appliances, config.option.appliance_version)
        reporter.write_line('Retrieved these appliances from the --appliance parameters', red=True)
    elif config.getoption('--use-sprout'):
        from .sprout.plugin import mangle_in_sprout_appliances

        mangle_in_sprout_appliances(config)
        # TODO : handle direct sprout pass on?
        appliances = appliances_from_cli(config.option.appliances, None)
        reporter.write_line('Retrieved these appliances from the --sprout-* parameters', red=True)
    else:
        appliances = load_appliances_from_config(conf.env)
        reporter.write_line('Retrieved these appliances from the conf.env', red=True)

    if not stack.top:
        for appliance in appliances:
            reporter.write_line('* {!r}'.format(appliance), cyan=True)
    appliance = appliances[0]
    if not appliance.is_dev:
        appliance.set_session_timeout(86400)
    stack.push(appliance)
    plugin = ApplianceHolderPlugin(appliance, appliances)
    config.pluginmanager.register(plugin, PLUGIN_KEY)
Ejemplo n.º 2
0
def pytest_configure(config):

    reporter = terminalreporter.reporter()
    if config.getoption('--dummy-appliance'):
        appliances = [DummyAppliance.from_config(config)]
        reporter.write_line('Retrieved Dummy Appliance', red=True)
    elif stack.top:
        appliances = [stack.top]
    elif config.option.appliances:
        appliances = appliances_from_cli(config.option.appliances)
        reporter.write_line('Retrieved these appliances from the --appliance parameters', red=True)
    elif config.getoption('--use-sprout'):
        from .sprout.plugin import mangle_in_sprout_appliances
        mangle_in_sprout_appliances(config)
        appliances = appliances_from_cli(config.option.appliances)
        reporter.write_line('Retrieved these appliances from the --sprout-* parameters', red=True)
    else:
        appliances = load_appliances_from_config(conf.env)
        reporter.write_line('Retrieved these appliances from the conf.env', red=True)

    if not stack.top:
        for appliance in appliances:
            reporter.write_line('* {!r}'.format(appliance), cyan=True)
    appliance = appliances[0]
    appliance.set_session_timeout(86400)
    stack.push(appliance)
    plugin = ApplianceHolderPlugin(appliance, appliances)
    config.pluginmanager.register(plugin, "appliance-holder")
Ejemplo n.º 3
0
def pytest_configure(config):

    if config.getoption('--help'):
        return
    reporter = terminalreporter.reporter()
    if config.getoption('--dummy-appliance'):
        appliances = [DummyAppliance.from_config(config)]
        reporter.write_line('Retrieved Dummy Appliance', red=True)
    elif stack.top:
        appliances = [stack.top]
    elif config.option.appliances:
        appliances = appliances_from_cli(config.option.appliances, config.option.appliance_version)
        reporter.write_line('Retrieved these appliances from the --appliance parameters', red=True)
    elif config.getoption('--use-sprout'):
        from cfme.test_framework.sprout.plugin import mangle_in_sprout_appliances

        mangle_in_sprout_appliances(config)
        # TODO : handle direct sprout pass on?
        appliances = appliances_from_cli(config.option.appliances, None)
        reporter.write_line('Retrieved these appliances from the --sprout-* parameters', red=True)
    else:
        appliances = load_appliances_from_config(conf.env)
        reporter.write_line('Retrieved these appliances from the conf.env', red=True)

    if not stack.top:
        for appliance in appliances:
            reporter.write_line('* {!r}'.format(appliance), cyan=True)
    appliance = appliances[0]
    if not appliance.is_dev:
        appliance.set_session_timeout(86400)
    stack.push(appliance)
    plugin = ApplianceHolderPlugin(appliance, appliances)
    config.pluginmanager.register(plugin, PLUGIN_KEY)
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
def get_appliance(appliance_ip):
    """Checks an appliance is not None and if so, loads the appropriate things"""
    from cfme.utils.appliance import IPAppliance, load_appliances_from_config, stack
    if not appliance_ip:
        app = load_appliances_from_config(env)[0]
    else:
        app = IPAppliance(hostname=appliance_ip)
    stack.push(app)  # ensure safety from bad code, phase out later
    return app
Ejemplo n.º 6
0
def get_appliance(appliance_ip):
    """Checks an appliance is not None and if so, loads the appropriate things"""
    from cfme.utils.appliance import IPAppliance, load_appliances_from_config, stack
    if not appliance_ip:
        app = load_appliances_from_config(env)[0]
    else:
        app = IPAppliance(hostname=appliance_ip)
    stack.push(app)  # ensure safety from bad code, phase out later
    return app
Ejemplo n.º 7
0
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()
Ejemplo n.º 8
0
def pytest_configure(config):

    if config.getoption('--help'):
        return
    reporter = terminalreporter.reporter()
    if config.getoption('--dummy-appliance'):
        appliances = [
            DummyAppliance.from_config(config)
            for _ in range(config.getoption('--num-dummies'))
        ]
        if not config.option.collectonly:
            config.option.collectonly = True

        reporter.write_line('Retrieved Dummy Appliance', red=True)
    elif stack.top:
        appliances = [stack.top]
    elif config.option.appliances:
        appliances = appliances_from_cli(config.option.appliances,
                                         config.option.appliance_version)
        reporter.write_line(
            'Retrieved these appliances from the --appliance parameters',
            red=True)
    elif config.getoption('--use-sprout'):
        from cfme.test_framework.sprout.plugin import mangle_in_sprout_appliances

        mangle_in_sprout_appliances(config)
        # TODO : handle direct sprout pass on?
        appliances = appliances_from_cli(config.option.appliances, None)
        reporter.write_line(
            'Retrieved these appliances from the --sprout-* parameters',
            red=True)
    else:
        appliances = load_appliances_from_config(conf.env)
        reporter.write_line('Retrieved these appliances from the conf.env',
                            red=True)

    if not stack.top:
        for appliance in appliances:
            reporter.write_line(f'* {appliance!r}', cyan=True)
    appliance = appliances[0]

    stack.push(appliance)
    plugin = ApplianceHolderPlugin(appliance, appliances)
    config.pluginmanager.register(plugin, PLUGIN_KEY)

    if not any((isinstance(appliance, DummyAppliance), appliance.is_dev)):
        config.hook.pytest_appliance_setup(config=config)
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()
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
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()
Ejemplo n.º 12
0
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()
Ejemplo n.º 14
0
def pytest_configure(config):
    if config.getoption("appliances"):
        return
    if not config.getoption('--use-sprout'):
        return

    provision_request = SproutProvisioningRequest.from_config(config)

    mgr = config._sprout_mgr = SproutManager()
    requested_appliances = mgr.request_appliances(provision_request)
    config.option.appliances[:] = []
    appliances = config.option.appliances
    # Push an appliance to the stack to have proper reference for test collection
    # FIXME: this is a bad hack based on the need for controll of collection partitioning
    appliance_stack.push(
        IPAppliance(address=requested_appliances[0]["ip_address"]))
    log.info("Appliances were provided:")
    for appliance in requested_appliances:
        url = "https://{}/".format(appliance["ip_address"])
        appliances.append(url)
        log.info("- %s is %s", url, appliance['name'])

    mgr.reset_timer()
    # Set the base_url for collection purposes on the first appliance
    conf.runtime["env"]["base_url"] = appliances[0]
    # Retrieve and print the template_name for Jenkins to pick up
    template_name = requested_appliances[0]["template_name"]
    conf.runtime["cfme_data"]["basic_info"][
        "appliance_template"] = template_name
    log.info("appliance_template: %s", template_name)
    with project_path.join('.appliance_template').open('w') as template_file:
        template_file.write(
            'export appliance_template="{}"'.format(template_name))
    log.info("Sprout setup finished.")

    config.pluginmanager.register(ShutdownPlugin())
Ejemplo n.º 15
0
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!")
Ejemplo n.º 16
0
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!")
Ejemplo n.º 17
0
        config.pluginmanager.consider_pluginarg(pluginarg)
    return config


if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('slaveid', help='The name of this slave')
    parser.add_argument('appliance_json',
                        help='The json data about the used appliance')
    parser.add_argument('ts', help='The timestap to use for collections')
    args = parser.parse_args()

    from cfme.utils.appliance import IPAppliance, stack
    appliance = IPAppliance.from_json(args.appliance_json)
    stack.push(appliance)

    # overwrite the default logger before anything else is imported,
    # to get our best chance at having everything import the replaced logger
    import cfme.utils.log
    cfme.utils.log.setup_for_worker(args.slaveid)

    from fixtures import terminalreporter
    from fixtures.pytest_store import store
    from cfme.utils import conf

    conf.runtime['env']['slaveid'] = args.slaveid
    conf.runtime['env']['ts'] = args.ts
    store.parallelizer_role = 'slave'

    slave_args = conf.slave_config.pop('args')
Ejemplo n.º 18
0
    for pluginarg in config.option.plugins:
        config.pluginmanager.consider_pluginarg(pluginarg)
    return config


if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('slaveid', help='The name of this slave')
    parser.add_argument('appliance_json', help='The json data about the used appliance')
    parser.add_argument('ts', help='The timestap to use for collections')
    args = parser.parse_args()

    from cfme.utils.appliance import IPAppliance, stack
    appliance = IPAppliance.from_json(args.appliance_json)
    stack.push(appliance)

    # overwrite the default logger before anything else is imported,
    # to get our best chance at having everything import the replaced logger
    import cfme.utils.log
    cfme.utils.log.setup_for_worker(args.slaveid)

    from fixtures import terminalreporter
    from fixtures.pytest_store import store
    from cfme.utils import conf

    conf.runtime['env']['slaveid'] = args.slaveid
    conf.runtime['env']['ts'] = args.ts
    store.parallelizer_role = 'slave'

    slave_args = conf.slave_config.pop('args')