Ejemplo n.º 1
0
def pytest_generate_tests(metafunc):
    argnames, argvalues, idlist = testgen.provider_by_type(
        metafunc, ['virtualcenter'])
    argnames = argnames + ["_host_provider"]

    new_idlist = []
    new_argvalues = []

    for i, argvalue_tuple in enumerate(argvalues):
        args = dict(zip(argnames, argvalue_tuple))
        if args['provider'].type != "virtualcenter":
            continue
        hosts = args['provider'].data.get("hosts", [])
        if not hosts:
            continue

        version = args['provider'].data.get("version", None)
        if version is None:
            # No version, no test
            continue
        if Version(version) < "5.0":
            # Ignore lesser than 5
            continue

        host = hosts[0]
        creds = credentials[host["credentials"]]
        ip_address = resolve_hostname(host["name"])
        cred = VMwareProvider.Credential(principal=creds["username"],
                                         secret=creds["password"],
                                         verify_secret=creds["password"])
        # Mock provider data
        provider_data = {}
        provider_data.update(args['provider'].data)
        provider_data["name"] = host["name"]
        provider_data["hostname"] = host["name"]
        provider_data["ipaddress"] = ip_address
        provider_data["credentials"] = host["credentials"]
        provider_data.pop("host_provisioning", None)
        provider_data["hosts"] = [host]
        provider_data["discovery_range"] = {}
        provider_data["discovery_range"]["start"] = ip_address
        provider_data["discovery_range"]["end"] = ip_address
        host_provider = VMwareProvider(
            name=host["name"],
            hostname=host["name"],
            ip_address=ip_address,
            credentials={'default': cred},
            provider_data=provider_data,
        )
        argvalues[i].append(host_provider)
        idlist[i] = "{}/{}".format(args['provider'].key, host["name"])
        new_idlist.append(idlist[i])
        new_argvalues.append(argvalues[i])

    testgen.parametrize(metafunc,
                        argnames,
                        new_argvalues,
                        ids=new_idlist,
                        scope="module")
Ejemplo n.º 2
0
def test_host_name_max_character_validation():
    """Test to validate max character for host name field"""
    prov = VMwareProvider(
        name=fauxfactory.gen_alphanumeric(5),
        hostname=fauxfactory.gen_alphanumeric(256),
        ip_address='10.10.10.13')
    prov.create()
    prov.delete(cancel=False)
Ejemplo n.º 3
0
def test_ip_required_validation():
    """Test to validate the ip address while adding a provider"""
    prov = VMwareProvider(name=fauxfactory.gen_alphanumeric(5),
                          hostname=fauxfactory.gen_alphanumeric(5),
                          ip_address=None)

    with error.expected("IP Address can't be blank"):
        prov.create()
Ejemplo n.º 4
0
def test_host_name_required_validation():
    """Test to validate the hostname while adding a provider"""
    prov = VMwareProvider(name=fauxfactory.gen_alphanumeric(5),
                          hostname=None,
                          ip_address='10.10.10.11')

    with error.expected("Host Name can't be blank"):
        prov.create()
Ejemplo n.º 5
0
def test_ip_required_validation():
    """Test to validate the ip address while adding a provider"""
    prov = VMwareProvider(
        name=fauxfactory.gen_alphanumeric(5),
        hostname=fauxfactory.gen_alphanumeric(5),
        ip_address=None)

    with error.expected("IP Address can't be blank"):
        prov.create()
Ejemplo n.º 6
0
def test_host_name_required_validation():
    """Test to validate the hostname while adding a provider"""
    prov = VMwareProvider(
        name=fauxfactory.gen_alphanumeric(5),
        hostname=None,
        ip_address='10.10.10.11')

    with error.expected("Host Name can't be blank"):
        prov.create()
Ejemplo n.º 7
0
def test_add_cancelled_validation():
    """Tests that the flash message is correct when add is cancelled."""
    prov = VMwareProvider()
    prov.create(cancel=True)
    if version.current_version() >= 5.6:
        msg = 'Add of Infrastructure Provider was cancelled by the user'
    else:
        msg = 'Add of new Infrastructure Provider was cancelled by the user'
    flash.assert_message_match(msg)
Ejemplo n.º 8
0
def test_add_cancelled_validation():
    """Tests that the flash message is correct when add is cancelled."""
    prov = VMwareProvider()
    prov.create(cancel=True)
    if version.current_version() >= 5.6:
        msg = 'Add of Infrastructure Provider was cancelled by the user'
    else:
        msg = 'Add of new Infrastructure Provider was cancelled by the user'
    flash.assert_message_match(msg)
Ejemplo n.º 9
0
def pytest_generate_tests(metafunc):
    arg_names = "provider", "provider_data", "original_provider_key"
    arg_values = []
    arg_ids = []
    for provider_key, provider in cfme_data.get("management_systems", {}).iteritems():
        if provider["type"] != "virtualcenter":
            continue
        hosts = provider.get("hosts", [])
        if not hosts:
            continue

        version = provider.get("version", None)
        if version is None:
            # No version, no test
            continue
        if Version(version) < "5.0":
            # Ignore lesser than 5
            continue

        host = random.choice(hosts)
        creds = credentials[host["credentials"]]
        ip_address = resolve_hostname(host["name"])
        cred = VMwareProvider.Credential(
            principal=creds["username"],
            secret=creds["password"],
            verify_secret=creds["password"]
        )
        # Mock provider data
        provider_data = {}
        provider_data.update(provider)
        provider_data["name"] = host["name"]
        provider_data["hostname"] = host["name"]
        provider_data["ipaddress"] = ip_address
        provider_data["credentials"] = host["credentials"]
        provider_data.pop("host_provisioning", None)
        provider_data["hosts"] = [host]
        provider_data["discovery_range"] = {}
        provider_data["discovery_range"]["start"] = ip_address
        provider_data["discovery_range"]["end"] = ip_address
        host_provider = VMwareProvider(
            name=host["name"],
            hostname=host["name"],
            ip_address=ip_address,
            credentials={'default': cred},
            provider_data=provider_data,
        )
        arg_values.append([host_provider, provider_data, provider_key])
        arg_ids.append("{}/random_host".format(provider_key))
    metafunc.parametrize(arg_names, arg_values, ids=arg_ids, scope="module")
Ejemplo n.º 10
0
def test_host_name_required_validation():
    """Test to validate the hostname while adding a provider"""
    prov = VMwareProvider(
        name=fauxfactory.gen_alphanumeric(5),
        hostname=None,
        ip_address='10.10.10.11')

    err = version.pick(
        {version.LOWEST: "Host Name can't be blank",
         '5.6': FlashMessageException})

    with error.expected(err):
        prov.create()

    if version.current_version() >= 5.6:
        assert prov.properties_form.hostname_text.angular_help_block == "Required"
        assert prov.add_provider_button.is_dimmed
Ejemplo n.º 11
0
def test_host_name_max_character_validation():
    """Test to validate max character for host name field"""
    prov = VMwareProvider(name=fauxfactory.gen_alphanumeric(5),
                          hostname=fauxfactory.gen_alphanumeric(256),
                          ip_address='10.10.10.13')
    prov.create()
    prov.delete(cancel=False)
Ejemplo n.º 12
0
def test_add_cancelled_validation():
    """Tests that the flash message is correct when add is cancelled."""
    prov = VMwareProvider()
    prov.create(cancel=True)
    flash.assert_message_match('Add of new Infrastructure Provider was cancelled by the user')
Ejemplo n.º 13
0
def get_crud(provider_config_name):
    """
    Creates a Provider object given a yaml entry in cfme_data.

    Usage:
        get_crud('ec2east')

    Returns: A Provider object that has methods that operate on CFME
    """

    prov_config = conf.cfme_data.get('management_systems', {})[provider_config_name]
    credentials_key = prov_config['credentials']
    credentials = process_credential_yaml_key(credentials_key)
    prov_type = prov_config.get('type')

    if prov_type != 'ec2':
        if prov_config.get('discovery_range', None):
            start_ip = prov_config['discovery_range']['start']
            end_ip = prov_config['discovery_range']['end']
        else:
            start_ip = end_ip = prov_config.get('ipaddress')

    if prov_type == 'ec2':
        from cfme.cloud.provider import EC2Provider
        return EC2Provider(name=prov_config['name'],
            region=prov_config['region'],
            credentials={'default': credentials},
            zone=prov_config['server_zone'],
            key=provider_config_name)
    if prov_type == 'gce':
        from cfme.cloud.provider import GCEProvider
        ser_acc_creds = get_credentials_from_config(
            prov_config['credentials'], cred_type='service_account')
        return GCEProvider(name=prov_config['name'],
            project=prov_config['project'],
            zone=prov_config['zone'],
            region=prov_config['region'],
            credentials={'default': ser_acc_creds},
            key=provider_config_name)
    elif prov_type == 'azure':
        from cfme.cloud.provider import AzureProvider
        return AzureProvider(name=prov_config['name'],
            region=prov_config['region'],
            tenant_id=prov_config['tenant_id'],
            credentials={'default': credentials},
            key=provider_config_name)
    elif prov_type == 'openstack':
        from cfme.cloud.provider import OpenStackProvider
        if 'amqp_credentials' in prov_config:
            amqp_credentials = process_credential_yaml_key(
                prov_config['amqp_credentials'], cred_type='amqp')
        return OpenStackProvider(name=prov_config['name'],
            hostname=prov_config['hostname'],
            ip_address=prov_config['ipaddress'],
            api_port=prov_config['port'],
            credentials={
                'default': credentials,
                'amqp': amqp_credentials},
            zone=prov_config['server_zone'],
            key=provider_config_name,
            sec_protocol=prov_config.get('sec_protocol', "Non-SSL"),
            infra_provider=prov_config.get('infra_provider'))
    elif prov_type == 'virtualcenter':
        return VMwareProvider(name=prov_config['name'],
            hostname=prov_config['hostname'],
            ip_address=prov_config['ipaddress'],
            credentials={'default': credentials},
            zone=prov_config['server_zone'],
            key=provider_config_name,
            start_ip=start_ip,
            end_ip=end_ip)
    elif prov_type == 'scvmm':
        return SCVMMProvider(
            name=prov_config['name'],
            hostname=prov_config['hostname'],
            ip_address=prov_config['ipaddress'],
            credentials={'default': credentials},
            key=provider_config_name,
            start_ip=start_ip,
            end_ip=end_ip,
            sec_protocol=prov_config['sec_protocol'],
            sec_realm=prov_config['sec_realm'])
    elif prov_type == 'rhevm':
        credential_dict = {'default': credentials}
        if prov_config.get('candu_credentials', None):
            credential_dict['candu'] = process_credential_yaml_key(
                prov_config['candu_credentials'], cred_type='candu')
        return RHEVMProvider(name=prov_config['name'],
            hostname=prov_config['hostname'],
            ip_address=prov_config['ipaddress'],
            api_port='',
            credentials=credential_dict,
            zone=prov_config['server_zone'],
            key=provider_config_name,
            start_ip=start_ip,
            end_ip=end_ip)
    elif prov_type == "openstack-infra":
        credential_dict = {'default': credentials}
        if 'ssh_credentials' in prov_config:
            credential_dict['ssh'] = process_credential_yaml_key(
                prov_config['ssh_credentials'], cred_type='ssh')
        if 'amqp_credentials' in prov_config:
            credential_dict['amqp'] = process_credential_yaml_key(
                prov_config['amqp_credentials'], cred_type='amqp')
        return OpenstackInfraProvider(
            name=prov_config['name'],
            sec_protocol=prov_config.get('sec_protocol', "Non-SSL"),
            hostname=prov_config['hostname'],
            ip_address=prov_config['ipaddress'],
            credentials=credential_dict,
            key=provider_config_name,
            start_ip=start_ip,
            end_ip=end_ip)
    elif prov_type == 'kubernetes':
        token_creds = process_credential_yaml_key(prov_config['credentials'], cred_type='token')
        return KubernetesProvider(
            name=prov_config['name'],
            credentials={'token': token_creds},
            key=provider_config_name,
            zone=prov_config['server_zone'],
            hostname=prov_config.get('hostname', None) or prov_config['ip_address'],
            port=prov_config['port'],
            provider_data=prov_config)
    elif prov_type == 'openshift':
        token_creds = process_credential_yaml_key(prov_config['credentials'], cred_type='token')
        return OpenshiftProvider(
            name=prov_config['name'],
            credentials={'token': token_creds},
            key=provider_config_name,
            zone=prov_config['server_zone'],
            hostname=prov_config.get('hostname', None) or prov_config['ip_address'],
            port=prov_config['port'],
            provider_data=prov_config)
    elif prov_type == 'hawkular':
        return HawkularProvider(
            name=prov_config['name'],
            key=provider_config_name,
            hostname=prov_config['hostname'],
            port=prov_config['port'],
            credentials={'default': credentials})
    else:
        raise UnknownProviderType('{} is not a known provider type'.format(prov_type))
Ejemplo n.º 14
0
def get_crud(provider_config_name):
    """
    Creates a Provider object given a yaml entry in cfme_data.

    Usage:
        get_crud('ec2east')

    Returns: A Provider object that has methods that operate on CFME
    """

    prov_config = conf.cfme_data.get('management_systems',
                                     {})[provider_config_name]
    credentials = get_credentials_from_config(prov_config['credentials'])
    prov_type = prov_config.get('type')

    if prov_type != 'ec2':
        if prov_config.get('discovery_range', None):
            start_ip = prov_config['discovery_range']['start']
            end_ip = prov_config['discovery_range']['end']
        else:
            start_ip = end_ip = prov_config.get('ipaddress')

    if prov_type == 'ec2':
        return EC2Provider(name=prov_config['name'],
                           region=prov_config['region'],
                           credentials={'default': credentials},
                           zone=prov_config['server_zone'],
                           key=provider_config_name)
    elif prov_type == 'openstack':
        return OpenStackProvider(name=prov_config['name'],
                                 hostname=prov_config['hostname'],
                                 ip_address=prov_config['ipaddress'],
                                 api_port=prov_config['port'],
                                 credentials={'default': credentials},
                                 zone=prov_config['server_zone'],
                                 key=provider_config_name)
    elif prov_type == 'virtualcenter':
        return VMwareProvider(name=prov_config['name'],
                              hostname=prov_config['hostname'],
                              ip_address=prov_config['ipaddress'],
                              credentials={'default': credentials},
                              zone=prov_config['server_zone'],
                              key=provider_config_name,
                              start_ip=start_ip,
                              end_ip=end_ip)
    elif prov_type == 'scvmm':
        return SCVMMProvider(name=prov_config['name'],
                             hostname=prov_config['hostname'],
                             ip_address=prov_config['ipaddress'],
                             credentials={'default': credentials},
                             key=provider_config_name,
                             start_ip=start_ip,
                             end_ip=end_ip,
                             sec_protocol=prov_config['sec_protocol'],
                             sec_realm=prov_config['sec_realm'])
    elif prov_type == 'rhevm':
        if prov_config.get('candu_credentials', None):
            candu_credentials = get_credentials_from_config(
                prov_config['candu_credentials'])
            candu_credentials.candu = True
        else:
            candu_credentials = None
        return RHEVMProvider(name=prov_config['name'],
                             hostname=prov_config['hostname'],
                             ip_address=prov_config['ipaddress'],
                             api_port='',
                             credentials={
                                 'default': credentials,
                                 'candu': candu_credentials
                             },
                             zone=prov_config['server_zone'],
                             key=provider_config_name,
                             start_ip=start_ip,
                             end_ip=end_ip)
    else:
        raise UnknownProviderType(
            '{} is not a known infra provider type'.format(prov_type))
Ejemplo n.º 15
0
def test_add_cancelled_validation():
    """Tests that the flash message is correct when add is cancelled."""
    prov = VMwareProvider()
    prov.create(cancel=True)
    flash.assert_message_match(
        'Add of new Infrastructure Provider was cancelled by the user')