Пример #1
0
def test_name_max_character_validation(request):
    """Test to validate max character for name field"""
    prov = EC2Provider(name=fauxfactory.gen_alphanumeric(255),
                       region='us-east-1')

    request.addfinalizer(prov.delete_if_exists)
    prov.create()
Пример #2
0
def test_add_cancelled_validation(request):
    """Tests that the flash message is correct when add is cancelled."""
    prov = EC2Provider()
    request.addfinalizer(prov.delete_if_exists)
    prov.create(cancel=True)
    flash.assert_message_match(
        'Add of new Cloud Provider was cancelled by the user')
Пример #3
0
def test_region_required_validation(request):
    """Tests to validate the region while adding a provider"""
    prov = EC2Provider(name=fauxfactory.gen_alphanumeric(5), region=None)

    request.addfinalizer(prov.delete_if_exists)
    with error.expected('Region is not included in the list'):
        prov.create()
Пример #4
0
def test_name_required_validation(request):
    """Tests to validate the name while adding a provider"""
    prov = EC2Provider(name=None, region='us-east-1')

    request.addfinalizer(prov.delete_if_exists)
    with error.expected("Name can't be blank"):
        prov.create()
Пример #5
0
def test_region_required_validation(request, soft_assert):
    """Tests to validate the region while adding a provider"""
    prov = EC2Provider(name=fauxfactory.gen_alphanumeric(5), region=None)

    request.addfinalizer(prov.delete_if_exists)
    if version.current_version() < "5.5":
        with error.expected('Region is not included in the list'):
            prov.create()
    else:
        with error.expected(FlashMessageException):
            prov.create()
        soft_assert("ng-invalid-required" in
                    properties_form.amazon_region_select.classes)
Пример #6
0
def test_name_required_validation(request):
    """Tests to validate the name while adding a provider"""
    prov = EC2Provider(name=None, region='us-east-1')

    request.addfinalizer(prov.delete_if_exists)
    if version.current_version() < "5.5":
        with error.expected("Name can't be blank"):
            prov.create()
    else:
        # It must raise an exception because it keeps on the form
        with error.expected(FlashMessageException):
            prov.create()
        assert properties_form.name_text.angular_help_block == "Required"
Пример #7
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))
Пример #8
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))