def custom_prov_data(request, provisioning):
    prov_data = {
        "catalog": {
            'vm_name': random_name(prefix="test_")
        },
        "environment": {
            'automatic_placement': True
        },
        "network": {
            'vlan': partial_match(provisioning['vlan'])
        }
    }
    prov_data.update(request.param)
    prov_data['catalog']['catalog_name'] = {'name': provisioning["template"]}
    return prov_data
예제 #2
0
def custom_ae_domain(request, appliance):
    """
    Create a new AE Domain.

    By default, a random name is generated for the Domain, but you can specify it explicitly with
    @pytest.mark.parametrize decorator on your test function.

    Example:
    @pytest.mark.parametrize('domain', ['TestDomain'], indirect=True)
    def test_my_automation(domain):
      ...
    """
    domains_collection = appliance.collections.domains
    domain = domains_collection.create(
        name=getattr(request, 'param', random_name()),
        enabled=True)
    yield domain
    domain.delete()
예제 #3
0
def custom_ae_domain(request, appliance):
    """
    Create a new AE Domain.

    By default, a random name is generated for the Domain, but you can specify it explicitly with
    @pytest.mark.parametrize decorator on your test function.

    Example:
    @pytest.mark.parametrize('domain', ['TestDomain'], indirect=True)
    def test_my_automation(domain):
      ...
    """
    domains_collection = appliance.collections.domains
    domain = domains_collection.create(name=getattr(request, 'param',
                                                    random_name()),
                                       enabled=True)
    yield domain
    domain.delete()
예제 #4
0
def create_basic_sandbox(nuage):
    box = {}

    # Create empty enterprise aka 'sandbox'.
    enterprise = box['enterprise'] = nuage.create_enterprise()
    logger.info('Created sandbox enterprise %s (%s)', enterprise.name,
                enterprise.id)

    # Fill the sandbox with some entities.
    # Method `create_child` returns a tuple (object, connection) and we only need object.
    box['template'] = enterprise.create_child(
        nuage.vspk.NUDomainTemplate(name=random_name()))[0]
    box['domain'] = enterprise.create_child(
        nuage.vspk.NUDomain(name=random_name(),
                            template_id=box['template'].id))[0]
    box['zone'] = box['domain'].create_child(
        nuage.vspk.NUZone(name=random_name()))[0]
    box['subnet'] = box['zone'].create_child(
        nuage.vspk.NUSubnet(name=random_name(),
                            address='192.168.0.0',
                            netmask='255.255.255.0',
                            gateway='192.168.0.1'))[0]
    box['cont_vport'] = box['subnet'].create_child(
        nuage.vspk.NUVPort(name=random_name(), type='CONTAINER'))[0]
    box['vm_vport'] = box['subnet'].create_child(
        nuage.vspk.NUVPort(name=random_name(), type='VM'))[0]
    box['l2_template'] = enterprise.create_child(
        nuage.vspk.NUL2DomainTemplate(name=random_name()))[0]
    box['l2_domain'] = enterprise.create_child(
        nuage.vspk.NUL2Domain(name=random_name(),
                              template_id=box['l2_template'].id))[0]
    box['l2_cont_vport'] = box['l2_domain'].create_child(
        nuage.vspk.NUVPort(name=random_name(), type='CONTAINER'))[0]
    box['l2_vm_vport'] = box['l2_domain'].create_child(
        nuage.vspk.NUVPort(name=random_name(), type='VM'))[0]
    box['group'] = box['domain'].create_child(
        nuage.vspk.NUPolicyGroup(name=random_name()))[0]
    box['l2_group'] = box['l2_domain'].create_child(
        nuage.vspk.NUPolicyGroup(name=random_name()))[0]

    return box
예제 #5
0
def test_embedded_ansible_executed_with_data_upon_event(
        request, ansible_repository, copy_ae_instance_to_new_domain,
        networks_provider):
    """
    Test that Nuage events trigger Embedded Ansible automation and that playbook has access to
    authentication attributes and event data.

    Specifically, we copy AE Instance 'ManageIQ/System/Event/EmsEvent/Nuage/nuage_enterprise_create'
    from default domain into our own domain and customize it's 'meth5' attribute to invoke
    Embedded Ansible playbook which prints authentication attributes and event data into evm.log.
    This test then triggers a 'nuage_enterprise_create' event and waits for appropriate line
    to appear in evm.log.

    Prerequisites:
    Following content needs to be present in cfme_data.yaml in order to fetch correct
    Ansible repository:

    ansible_links:
      playbook_repositories:
        embedded_ansible: https://github.com/xlab-si/integration-tests-nuage-automation.git

    """
    ae_instance = copy_ae_instance_to_new_domain
    ae_class = ae_instance.klass
    ae_method = ae_class.methods.create(
        name='printout',
        location='playbook',
        repository=ansible_repository.name,
        playbook='printout.yaml',
        machine_credential='CFME Default Credential',
        logging_output='Always')

    username = random_name()
    with update(ae_instance):
        ae_instance.fields = {
            'nuage_username': {
                'value': username
            },
            'nuage_enterprise': {
                'value': 'csp'
            },
            'nuage_url': {
                'value': 'https://nuage:8443'
            },
            'nuage_api_version': {
                'value': 'v5_0'
            },
            'meth5': {
                'value': ae_method.name
            }
        }

    enterprise = networks_provider.mgmt.create_enterprise()
    request.addfinalizer(
        lambda: networks_provider.mgmt.delete_enterprise(enterprise))
    evm_tail = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=[
            r'.*I confirm that username is {} and event is raised for {}.*'.
            format(username, enterprise.id)
        ])
    evm_tail.start_monitoring()
    # search logs and wait for validation
    assert evm_tail.validate(wait="300s")
예제 #6
0
파일: nuage.py 프로젝트: mkoura/cfme_tests
def create_basic_sandbox(nuage):
    box = {}

    # Create empty enterprise aka 'sandbox'.
    enterprise = box['enterprise'] = nuage.create_enterprise()
    logger.info('Created sandbox enterprise %s (%s)', enterprise.name, enterprise.id)

    # Fill the sandbox with some entities.
    # Method `create_child` returns a tuple (object, connection) and we only need object.
    box['template'] = enterprise.create_child(
        nuage.vspk.NUDomainTemplate(name=random_name()))[0]
    box['domain'] = enterprise.create_child(
        nuage.vspk.NUDomain(name=random_name(), template_id=box['template'].id))[0]
    box['zone'] = box['domain'].create_child(
        nuage.vspk.NUZone(name=random_name()))[0]
    box['subnet'] = box['zone'].create_child(
        nuage.vspk.NUSubnet(
            name=random_name(),
            address='192.168.0.0',
            netmask='255.255.255.0',
            gateway='192.168.0.1'))[0]
    box['cont_vport'] = box['subnet'].create_child(
        nuage.vspk.NUVPort(name=random_name(), type='CONTAINER'))[0]
    box['vm_vport'] = box['subnet'].create_child(
        nuage.vspk.NUVPort(name=random_name(), type='VM'))[0]
    box['l2_template'] = enterprise.create_child(
        nuage.vspk.NUL2DomainTemplate(name=random_name()))[0]
    box['l2_domain'] = enterprise.create_child(
        nuage.vspk.NUL2Domain(name=random_name(), template_id=box['l2_template'].id))[0]
    box['l2_cont_vport'] = box['l2_domain'].create_child(
        nuage.vspk.NUVPort(name=random_name(), type='CONTAINER'))[0]
    box['l2_vm_vport'] = box['l2_domain'].create_child(
        nuage.vspk.NUVPort(name=random_name(), type='VM'))[0]
    box['group'] = box['domain'].create_child(
        nuage.vspk.NUPolicyGroup(name=random_name()))[0]
    box['l2_group'] = box['l2_domain'].create_child(
        nuage.vspk.NUPolicyGroup(name=random_name()))[0]

    return box
예제 #7
0
 def create_enterprise(self, name=None):
     enterprise, _ = self.api.create_child(
         self.vspk.NUEnterprise(name=name or random_name()))
     return enterprise
예제 #8
0
def test_embedded_ansible_executed_with_data_upon_event(request,
                                                        ansible_repository,
                                                        copy_ae_instance_to_new_domain,
                                                        networks_provider):
    """
    Test that Nuage events trigger Embedded Ansible automation and that playbook has access to
    authentication attributes and event data.

    Specifically, we copy AE Instance 'ManageIQ/System/Event/EmsEvent/Nuage/nuage_enterprise_create'
    from default domain into our own domain and customize it's 'meth5' attribute to invoke
    Embedded Ansible playbook which prints authentication attributes and event data into evm.log.
    This test then triggers a 'nuage_enterprise_create' event and waits for appropriate line
    to appear in evm.log.

    Prerequisites:
    Following content needs to be present in cfme_data.yaml in order to fetch correct
    Ansible repository:

    ansible_links:
      playbook_repositories:
        embedded_ansible: https://github.com/xlab-si/integration-tests-nuage-automation.git
    """
    ae_instance = copy_ae_instance_to_new_domain
    ae_class = ae_instance.klass
    ae_method = ae_class.methods.create(
        name='printout',
        location='playbook',
        repository=ansible_repository.name,
        playbook='printout.yaml',
        machine_credential='CFME Default Credential',
        logging_output='Always')

    username = random_name()
    with update(ae_instance):
        ae_instance.fields = {
            'nuage_username': {'value': username},
            'nuage_enterprise': {'value': 'csp'},
            'nuage_url': {'value': 'https://nuage:8443'},
            'nuage_api_version': {'value': 'v5_0'},
            'meth5': {'value': ae_method.name}
        }

    enterprise = networks_provider.mgmt.create_enterprise()
    request.addfinalizer(lambda: networks_provider.mgmt.delete_enterprise(enterprise))
    evm_tail = LogValidator(
        '/var/www/miq/vmdb/log/evm.log',
        matched_patterns=[
            r'.*I confirm that username is {} and event is raised for {}.*'.format(username,
                                                                                   enterprise.id)
        ]
    )
    evm_tail.fix_before_start()

    # LogValidator.validate_logs throws `Failed` exception which inherits `BaseException`.
    # wait_for function checks for `Exception` which inherits `BaseException` when
    # 'handle_exception' parameter is used. We can't make use of this functionality because
    # `Failed` exception is not caught with `Exception` class, hence the helper function.
    def validate_logs():
        try:
            evm_tail.validate_logs()
            return True
        except Failed:
            return False

    wait_for(validate_logs, timeout=300, delay=10, fail_condition=False)
def with_nuage_sandbox(networks_provider):
    nuage = networks_provider.mgmt
    sandbox = box = {}

    # Create empty enterprise aka 'sandbox'.
    enterprise = box['enterprise'] = nuage.create_enterprise()
    logger.info('Created sandbox enterprise {} ({})'.format(
        enterprise.name, enterprise.id))

    # Fill the sandbox with some entities.
    # Method `create_child` returns a tuple (object, connection) and we only need object.
    box['template'] = enterprise.create_child(
        nuage.vspk.NUDomainTemplate(name=random_name()))[0]
    box['domain'] = enterprise.create_child(
        nuage.vspk.NUDomain(name=random_name(),
                            template_id=box['template'].id))[0]
    box['zone'] = box['domain'].create_child(
        nuage.vspk.NUZone(name=random_name()))[0]
    box['subnet'] = box['zone'].create_child(
        nuage.vspk.NUSubnet(name=random_name(),
                            address='192.168.0.0',
                            netmask='255.255.255.0',
                            gateway='192.168.0.1'))[0]
    box['cont_vport'] = box['subnet'].create_child(
        nuage.vspk.NUVPort(name=random_name(), type='CONTAINER'))[0]
    box['vm_vport'] = box['subnet'].create_child(
        nuage.vspk.NUVPort(name=random_name(), type='VM'))[0]
    box['l2_template'] = enterprise.create_child(
        nuage.vspk.NUL2DomainTemplate(name=random_name()))[0]
    box['l2_domain'] = enterprise.create_child(
        nuage.vspk.NUL2Domain(name=random_name(),
                              template_id=box['l2_template'].id))[0]
    box['l2_cont_vport'] = box['l2_domain'].create_child(
        nuage.vspk.NUVPort(name=random_name(), type='CONTAINER'))[0]
    box['l2_vm_vport'] = box['l2_domain'].create_child(
        nuage.vspk.NUVPort(name=random_name(), type='VM'))[0]
    box['group'] = box['domain'].create_child(
        nuage.vspk.NUPolicyGroup(name=random_name()))[0]
    box['l2_group'] = box['l2_domain'].create_child(
        nuage.vspk.NUPolicyGroup(name=random_name()))[0]

    # Let integration test do whatever it needs to do.
    yield sandbox

    # Destroy the sandbox.
    nuage.delete_enterprise(enterprise)
    logger.info('Destroyed sandbox enterprise {} ({})'.format(
        enterprise.name, enterprise.id))