def test_group_quota_max_cpu_check_by_tagging(provisioner, prov_data,
                                              template_name, provider, request,
                                              vm_name, set_group_cpu, bug):
    """ Test group Quota-Max CPU by tagging.

    Prerequisities:
        * A provider set up, supporting provisioning in CFME

    Steps:
        * Set the group quota for cpu by tagging
        * Open the provisioning dialog.
        * Apart from the usual provisioning settings, set CPU greater then group quota cpu.
        * Submit the provisioning request and wait for it to finish.
        * Visit the requests page. The last message should state quota validation message.

    Metadata:
        test_flag: provision
    """
    note = ('template {} to vm {} on provider {}'.format(
        template_name, vm_name, provider.key))
    prov_data["vm_name"] = vm_name
    prov_data["num_sockets"] = "8"
    prov_data["notes"] = note

    provisioner(template_name, prov_data)

    # nav to requests page to check quota validation
    request_description = 'Provision from [{}] to [{}]'.format(
        template_name, vm_name)
    provision_request = Request(request_description)
    provision_request.wait_for_request(method='ui')
    assert provision_request.row.last_message.text == \
        'Request denied due to the following quota limits:' \
        '(Group Allocated vCPUs 0 + Requested 8 > Quota 2)'
    def _provisioner(template, provisioning_data, delayed=None):
        vm = Vm(name=vm_name, provider=provider, template_name=template)
        view = navigate_to(vm, 'Provision')
        view.form.before_fill(provisioning_data)

        fill(provisioning_form, provisioning_data, action=provisioning_form.submit_button)
        flash.assert_no_errors()

        request.addfinalizer(lambda: cleanup_vm(vm_name, provider))
        request_description = 'Provision from [{}] to [{}]'.format(template, vm_name)
        provision_request = Request(description=request_description)
        if delayed is not None:
            total_seconds = (delayed - datetime.utcnow()).total_seconds()
            try:
                wait_for(provision_request.is_finished,
                         fail_func=provision_request.update, num_sec=total_seconds, delay=5)
                pytest.fail("The provisioning was not postponed")
            except TimedOutError:
                pass

        logger.info('Waiting for vm %s to appear on provider %s', vm_name, provider.key)
        wait_for(
            provider.mgmt.does_vm_exist, [vm_name],
            fail_func=provider.refresh_provider_relationships,
            handle_exception=True, num_sec=600
        )

        # nav to requests page happens on successful provision
        logger.info('Waiting for cfme provision request for vm %s', vm_name)
        provision_request.wait_for_request()
        assert provision_request.is_succeeded(method='ui')
        return vm
def test_tenant_quota_max_storage_check(provisioner, prov_data, template_name,
                                        provider, request, vm_name,
                                        set_tenant_storage, bug):
    """Test Tenant Quota-Max Storage by UI.

    Prerequisities:
        * A provider set up, supporting provisioning in CFME

    Steps:
        * Set the tenant quota for storage by UI enforcement
        * Open the provisioning dialog.
        * Apart from the usual provisioning settings, set storage greater then tenant quota storage.
        * Submit the provisioning request and wait for it to finish.
        * Visit the requests page. The last message should state quota validation message.

    Metadata:
        test_flag: provision
    """
    note = ('template {} to vm {} on provider {}'.format(
        template_name, vm_name, provider.key))
    prov_data["vm_name"] = vm_name
    prov_data["notes"] = note

    provisioner(template_name, prov_data)

    # nav to requests page to check quota validation
    request_description = 'Provision from [{}] to [{}]'.format(
        template_name, vm_name)
    provision_request = Request(request_description)
    provision_request.wait_for_request(method='ui')
    assert provision_request.row.reason.text == "Quota Exceeded"
def myservice(setup_provider, provider, catalog_item, request):
    """Tests my service

    Metadata:
        test_flag: provision
    """
    vm_name = version.pick({
        version.LOWEST:
        catalog_item.provisioning_data["vm_name"] + '_0001',
        '5.7':
        catalog_item.provisioning_data["vm_name"] + '0001'
    })
    catalog_item.create()
    service_catalogs = ServiceCatalogs(catalog_item.catalog, catalog_item.name)
    service_catalogs.order()
    logger.info('Waiting for cfme provision request for service %s',
                catalog_item.name)
    request_description = catalog_item.name
    service_request = Request(request_description, partial_check=True)
    service_request.wait_for_request()
    assert service_request.is_succeeded()

    yield MyService(catalog_item.name, vm_name)

    cleanup_vm(vm_name, provider)
def test_order_catalog_bundle(provider, setup_provider, catalog_item, request):
    """Tests ordering a catalog bundle
    Metadata:
        test_flag: provision
    """

    vm_name = catalog_item.provisioning_data["vm_name"]
    request.addfinalizer(lambda: cleanup_vm(vm_name + "_0001", provider))
    catalog_item.create()
    bundle_name = fauxfactory.gen_alphanumeric()
    catalog_bundle = CatalogBundle(name=bundle_name,
                                   description="catalog_bundle",
                                   display_in=True,
                                   catalog=catalog_item.catalog,
                                   dialog=catalog_item.dialog,
                                   catalog_items=[catalog_item.name])
    catalog_bundle.create()
    service_catalogs = ServiceCatalogs(catalog_item.catalog,
                                       catalog_bundle.name)
    service_catalogs.order()
    logger.info("Waiting for cfme provision request for service {}".format(
        bundle_name))
    request_description = bundle_name
    provision_request = Request(request_description, partial_check=True)
    provision_request.wait_for_request()
    assert provision_request.is_succeeded()
Exemple #6
0
def test_retire_stack(provider, provisioning, catalog, catalog_item, request):
    """Tests stack provisioning

    Metadata:
        test_flag: provision
    """
    catalog_item, template = catalog_item
    DefaultView.set_default_view("Stacks", "Grid View")

    stack_data = prepare_stack_data(provider, provisioning)
    service_catalogs = ServiceCatalogs(catalog_item.catalog, catalog_item.name,
                                       stack_data)
    service_catalogs.order()
    logger.info('Waiting for cfme provision request for service {}'.format(
        catalog_item.name))
    request_description = catalog_item.name
    provision_request = Request(request_description, partial_check=True)
    provision_request.wait_for_request()
    assert provision_request.is_succeeded()
    stack = Stack(stack_data['stack_name'], provider=provider)
    stack.wait_for_exists()
    stack.retire_stack()

    @request.addfinalizer
    def _cleanup_vms():
        clean_up(stack_data, provider)
def test_action_cancel_clone(request, provider, vm_name, vm_big,
                             policy_for_testing):
    """This test checks if 'Cancel vCenter task' action works.
    For this test we need big template otherwise CFME won't have enough time
    to cancel the task https://bugzilla.redhat.com/show_bug.cgi?id=1383372#c9
    """
    with update(policy_for_testing):
        policy_for_testing.scope = (
            "fill_field(VM and Instance : Name, INCLUDES, {})".format(
                vm_big.name))
    policy_for_testing.assign_events("VM Clone Start")
    policy_for_testing.assign_actions_to_event("VM Clone Start",
                                               ["Cancel vCenter Task"])
    clone_vm_name = "{}-clone".format(vm_big.name)

    @request.addfinalizer
    def finalize():
        policy_for_testing.assign_events()
        with update(policy_for_testing):
            policy_for_testing.scope = (
                "fill_field(VM and Instance : Name, INCLUDES, {})".format(
                    vm_name))
        cleanup_vm(clone_vm_name, provider)

    vm_big.crud.clone_vm(fauxfactory.gen_email(), "first", "last",
                         clone_vm_name, "VMware")
    request_description = clone_vm_name
    clone_request = Request(description=request_description,
                            partial_check=True)
    clone_request.wait_for_request(method='ui')
    assert clone_request.status == "Error"
Exemple #8
0
def test_reconfigure_service(provider, provisioning, catalog, catalog_item,
                             request):
    """Tests stack provisioning

    Metadata:
        test_flag: provision
    """
    catalog_item, template = catalog_item
    stack_data = prepare_stack_data(provider, provisioning)

    @request.addfinalizer
    def _cleanup_vms():
        clean_up(stack_data, provider)

    service_catalogs = ServiceCatalogs(catalog_item.catalog, catalog_item.name,
                                       stack_data)
    service_catalogs.order()
    logger.info('Waiting for cfme provision request for service {}'.format(
        catalog_item.name))
    request_description = catalog_item.name
    provision_request = Request(request_description, partial_check=True)
    provision_request.wait_for_request()
    assert provision_request.is_succeeded()

    myservice = MyService(catalog_item.name)
    myservice.reconfigure_service()
def test_provision_from_template(provider, testing_instance, soft_assert):
    """ Tests instance provision from template

    Metadata:
        test_flag: provision
    """
    instance, inst_args, image = testing_instance
    instance.create(**inst_args)
    logger.info('Waiting for cfme provision request for vm %s', instance.name)
    request_description = 'Provision from [{}] to [{}]'.format(
        image, instance.name)
    provision_request = Request(request_description)
    try:
        provision_request.wait_for_request(method='ui')
    except Exception as e:
        logger.info("Provision failed {}: {}".format(
            e, provision_request.row.last_message.text()))
        raise e
    assert provision_request.is_succeeded(method='ui'), \
        "Provisioning failed with the message {}".format(provision_request.row.last_message.text)
    instance.wait_to_appear(timeout=800)
    provider.refresh_provider_relationships()
    logger.info("Refreshing provider relationships and power states")
    refresh_timer = RefreshTimer(time_for_refresh=300)
    wait_for(provider.is_refreshed, [refresh_timer],
             message="is_refreshed",
             num_sec=1000,
             delay=60,
             handle_exception=True)
    soft_assert(instance.does_vm_exist_on_provider(),
                "Instance wasn't provisioned")
def test_service_ansible_playbook_provision_in_requests(
        ansible_catalog_item, service_catalog):
    """Tests if ansible playbook service provisioning is shown in service requests."""
    service_catalog.order()
    cat_item_name = ansible_catalog_item.name
    request_descr = "Provisioning Service [{0}] from [{0}]".format(
        cat_item_name)
    service_request = Request(request_descr)
    assert service_request.exists()
def do_vm_provisioning(template_name,
                       provider,
                       vm_name,
                       provisioning_data,
                       request,
                       smtp_test,
                       num_sec=1500,
                       wait=True):
    # generate_tests makes sure these have values
    vm = Vm(name=vm_name, provider=provider, template_name=template_name)
    note = ('template {} to vm {} on provider {}'.format(
        template_name, vm_name, provider.key))
    provisioning_data.update({
        'request': {
            'email': '*****@*****.**',
            'first_name': 'Template',
            'last_name': 'Provisioner',
            'notes': note
        }
    })
    view = navigate_to(vm, 'Provision')
    view.form.fill_with(provisioning_data, on_change=view.form.submit_button)
    flash.assert_no_errors()
    if not wait:
        return

    # Provision Re important in this test
    logger.info('Waiting for cfme provision request for vm %s', vm_name)
    request_description = 'Provision from [{}] to [{}]'.format(
        template_name, vm_name)
    provision_request = Request(request_description)
    provision_request.wait_for_request(method='ui')
    assert provision_request.is_succeeded(method='ui'), \
        "Provisioning failed with the message {}".format(provision_request.row.last_message.text)

    # Wait for the VM to appear on the provider backend before proceeding to ensure proper cleanup
    logger.info('Waiting for vm %s to appear on provider %s', vm_name,
                provider.key)
    wait_for(provider.mgmt.does_vm_exist, [vm_name],
             handle_exception=True,
             num_sec=600)

    if smtp_test:
        # Wait for e-mails to appear
        def verify():
            approval = dict(
                subject_like=
                "%%Your Virtual Machine configuration was Approved%%")
            expected_text = "Your virtual machine request has Completed - VM:%%{}".format(
                vm_name)
            return (len(smtp_test.get_emails(**approval)) > 0 and
                    len(smtp_test.get_emails(subject_like=expected_text)) > 0)

        wait_for(verify, message="email receive check", delay=30)
def test_copy_request(setup_provider, provider, catalog_item, request):
    """Automate BZ 1194479"""
    vm_name = catalog_item.provisioning_data["vm_name"]
    request.addfinalizer(lambda: cleanup_vm(vm_name + "_0001", provider))
    catalog_item.create()
    service_catalogs = ServiceCatalogs(catalog_item.catalog, catalog_item.name)
    service_catalogs.order()
    request_description = catalog_item.name
    service_request = Request(request_description, partial_check=True)
    service_request.wait_for_request()
    assert navigate_to(service_request, 'Details')
Exemple #13
0
def create_vm(provider, setup_provider, catalog_item, request):
    vm_name = catalog_item.provisioning_data["vm_name"]
    catalog_item.create()
    service_catalogs = ServiceCatalogs(catalog_item.name)
    service_catalogs.order()
    flash.assert_no_errors()
    logger.info('Waiting for cfme provision request for service %s',
                catalog_item.name)
    request_description = catalog_item.name
    request_row = Request(request_description, partial_check=True)
    request_row.wait_for_request()
    assert request_row.is_succeeded()
    return vm_name
Exemple #14
0
def test_order_tower_catalog_item(catalog_item, request):
    """Tests order catalog item
    Metadata:
        test_flag: provision
    """
    catalog_item.create()
    service_catalogs = ServiceCatalogs(catalog_item.catalog, catalog_item.name)
    service_catalogs.order()
    logger.info('Waiting for cfme provision request for service %s', catalog_item.name)
    cells = {'Description': catalog_item.name}
    order_request = Request(cells=cells, partial_check=True)
    order_request.wait_for_request(method='ui')
    assert order_request.is_succeeded()
    DefaultView.set_default_view("Configuration Management Providers", "List View")
Exemple #15
0
def test_cloud_catalog_item(setup_provider, provider, dialog, catalog, request,
                            provisioning):
    """Tests cloud catalog item

    Metadata:
        test_flag: provision
    """
    vm_name = 'test{}'.format(fauxfactory.gen_alphanumeric())
    # GCE accepts only lowercase letters in VM name
    vm_name = vm_name.lower()
    request.addfinalizer(lambda: cleanup_vm(vm_name + "_0001", provider))
    image = provisioning['image']['name']
    item_name = fauxfactory.gen_alphanumeric()
    provisioning_data = dict(
        vm_name=vm_name,
        instance_type=provisioning['instance_type'],
        security_groups=[provisioning['security_group']],
    )
    if provider.type == "azure":
        updates = dict(
            virtual_private_cloud=provisioning['virtual_private_cloud'],
            cloud_subnet=provisioning['cloud_subnet'],
            resource_group=[provisioning['resource_group']],
        )
    else:
        updates = dict(availability_zone=provisioning['availability_zone'],
                       cloud_tenant=provisioning['cloud_tenant'],
                       cloud_network=provisioning['cloud_network'],
                       guest_keypair=provisioning['guest_keypair'],
                       boot_disk_size=provisioning['boot_disk_size'])
    provisioning_data.update(updates)
    catalog_item = CatalogItem(item_type=provisioning['item_type'],
                               name=item_name,
                               description="my catalog",
                               display_in=True,
                               catalog=catalog,
                               dialog=dialog,
                               catalog_name=image,
                               provider=provider,
                               prov_data=provisioning_data)
    catalog_item.create()
    service_catalogs = ServiceCatalogs(catalog_item.catalog, catalog_item.name)
    service_catalogs.order()
    flash.assert_no_errors()
    logger.info('Waiting for cfme provision request for service %s', item_name)
    request_description = item_name
    provision_request = Request(request_description, partial_check=True)
    provision_request.wait_for_request()
    assert provision_request.if_succeeded()
Exemple #16
0
def test_retire_ansible_service(catalog_item, request):
    """Tests order catalog item
    Metadata:
        test_flag: provision
    """
    catalog_item.create()
    service_catalogs = ServiceCatalogs(catalog_item.catalog, catalog_item.name)
    service_catalogs.order()
    logger.info('Waiting for cfme provision request for service %s', catalog_item.name)
    cells = {'Description': catalog_item.name}
    order_request = Request(cells=cells, partial_check=True)
    order_request.wait_for_request(method='ui')
    assert order_request.is_succeeded()
    myservice = MyService(catalog_item.name)
    myservice.retire()
Exemple #17
0
def test_vm_clone(provider, clone_vm_name, request, create_vm):
    vm_name = create_vm + "_0001"
    request.addfinalizer(lambda: cleanup_vm(vm_name, provider))
    request.addfinalizer(lambda: cleanup_vm(clone_vm_name, provider))
    vm = VM.factory(vm_name, provider)
    if provider.one_of(RHEVMProvider):
        provision_type = 'Native Clone'
    elif provider.one_of(VMwareProvider):
        provision_type = 'VMware'
    vm.clone_vm("*****@*****.**", "first", "last", clone_vm_name,
                provision_type)
    request_description = clone_vm_name
    request_row = Request(request_description, partial_check=True)
    request_row.wait_for_request(method='ui')
    assert request_row.is_succeeded(method='ui')
def test_request_with_orphaned_template(provider, setup_provider,
                                        catalog_item):
    """Tests edit catalog item after deleting provider
    Metadata:
        test_flag: provision
    """
    catalog_item.create()
    service_catalogs = ServiceCatalogs(catalog_item.catalog, catalog_item.name)
    service_catalogs.order()
    logger.info("Waiting for cfme provision request for service {}".format(
        catalog_item.name))
    request_description = catalog_item.name
    provision_request = Request(request_description, partial_check=True)
    provider.delete(cancel=False)
    provider.wait_for_delete()
    provision_request.wait_for_request(method='ui')
    assert provision_request.row.status.text == 'Error'
Exemple #19
0
def test_service_generic_catalog_bundle(catalog_item):
    bundle_name = "generic_" + fauxfactory.gen_alphanumeric()
    catalog_bundle = CatalogBundle(name=bundle_name,
                                   description="catalog_bundle",
                                   display_in=True,
                                   catalog=catalog_item.catalog,
                                   dialog=catalog_item.dialog,
                                   catalog_items=[catalog_item.name])
    catalog_bundle.create()
    service_catalogs = ServiceCatalogs(catalog_item.catalog, bundle_name)
    service_catalogs.order()
    flash.assert_no_errors()
    logger.info('Waiting for cfme provision request for service %s',
                bundle_name)
    request_description = bundle_name
    provision_request = Request(request_description, partial_check=True)
    provision_request.wait_for_request()
    assert provision_request.is_succeeded()
Exemple #20
0
def test_pxe_servicecatalog(setup_provider, provider, catalog_item, request):
    """Tests RHEV PXE service catalog

    Metadata:
        test_flag: pxe, provision
    """
    vm_name = catalog_item.provisioning_data["vm_name"]
    request.addfinalizer(lambda: cleanup_vm(vm_name + "_0001", provider))
    catalog_item.create()
    service_catalogs = ServiceCatalogs(catalog_item.catalog, catalog_item.name)
    service_catalogs.order()
    # nav to requests page happens on successful provision
    logger.info('Waiting for cfme provision request for service %s',
                catalog_item.name)
    request_description = catalog_item.name
    provision_request = Request(request_description, partial_check=True)
    provision_request.wait_for_request()
    assert provision_request.is_succeeded()
def test_service_manual_approval(provider, setup_provider, modify_instance,
                                 catalog_item, request):
    """Tests order catalog item
    Metadata:
        test_flag: provision
    """
    vm_name = catalog_item.provisioning_data["vm_name"]
    request.addfinalizer(lambda: cleanup_vm(vm_name + "_0001", provider))
    catalog_item.create()

    service_catalogs = ServiceCatalogs(catalog_item.catalog, catalog_item.name)
    service_catalogs.order()
    logger.info("Waiting for cfme provision request for service {}".format(
        catalog_item.name))
    request_description = catalog_item.name
    service_request = Request(description=request_description,
                              partial_check=True)
    service_request.update(method='ui')
    assert service_request.row.approval_state.text == 'Pending Approval'
def test_vm_migrate(new_vm, provider):
    """Tests migration of a vm

    Metadata:
        test_flag: migrate, provision
    """
    # auto_test_services should exist to test migrate VM
    vm_host = new_vm.get_detail(properties=('Relationships', 'Host'))
    migrate_to = [
        vds.name for vds in provider.hosts if vds.name not in vm_host
    ][0]
    new_vm.migrate_vm("*****@*****.**", "first", "last", host_name=migrate_to)
    flash.assert_no_errors()
    request_description = new_vm.name
    cells = {'Description': request_description, 'Request Type': 'Migrate'}
    migrate_request = Request(request_description,
                              cells=cells,
                              partial_check=True)
    migrate_request.wait_for_request(method='ui')
    assert migrate_request.is_succeeded(method='ui')
Exemple #23
0
def test_remove_template_provisioning(provider, provisioning, catalog,
                                      catalog_item):
    """Tests stack provisioning

    Metadata:
        test_flag: provision
    """
    catalog_item, template = catalog_item
    stack_data = prepare_stack_data(provider, provisioning)
    service_catalogs = ServiceCatalogs(catalog_item.catalog, catalog_item.name,
                                       stack_data)
    service_catalogs.order()
    # This is part of test - remove template and see if provision fails , so not added as finalizer
    template.delete()
    request_description = 'Provisioning Service [{}] from [{}]'.format(
        catalog_item.name, catalog_item.name)
    provision_request = Request(request_description)
    provision_request.wait_for_request(method='ui')
    assert (provision_request.row.last_message.text
            == 'Service_Template_Provisioning failed'
            or provision_request.row.status.text == "Error")
def myservice(setup_provider, provider, catalog_item, request):
    vm_name = catalog_item.provisioning_data["vm_name"]
    request.addfinalizer(lambda: cleanup_vm(vm_name + "_0001", provider))
    catalog_item.create()
    service_catalogs = ServiceCatalogs(catalog_item.catalog, catalog_item.name)
    service_catalogs.order()
    logger.info('Waiting for cfme provision request for service %s',
                catalog_item.name)
    request_description = catalog_item.name
    provision_request = Request(request_description, partial_check=True)
    provision_request.wait_for_request()
    assert provision_request.is_finished()
    service = MyService(catalog_item.name, vm_name)
    yield service

    try:
        service.delete()
    except Exception as ex:
        logger.warning(
            'Exception while deleting MyService, continuing: {}'.format(
                ex.message))
Exemple #25
0
    def publish_to_template(self,
                            template_name,
                            email=None,
                            first_name=None,
                            last_name=None):
        self.load_details()
        lcl_btn("Publish this VM to a Template")
        first_name = first_name or fauxfactory.gen_alphanumeric()
        last_name = last_name or fauxfactory.gen_alphanumeric()
        email = email or "{}@{}.test".format(first_name, last_name)
        try:
            prov_data = cfme_data["management_systems"][
                self.provider.key]["provisioning"]
        except (KeyError, IndexError):
            raise ValueError(
                "You have to specify the correct options in cfme_data.yaml")

        provisioning_data = {
            "first_name": first_name,
            "last_name": last_name,
            "email": email,
            "vm_name": template_name,
            "host_name": {
                "name": prov_data.get("host")
            },
            "datastore_name": {
                "name": prov_data.get("datastore")
            },
        }
        from cfme.provisioning import provisioning_form
        fill(provisioning_form,
             provisioning_data,
             action=provisioning_form.submit_button)
        cells = {
            'Description':
            'Publish from [{}] to [{}]'.format(self.name, template_name)
        }
        provision_request = Request(cells=cells)
        provision_request.wait_for_request()
        return Template(template_name, self.provider)
def test_order_catalog_item(provider, setup_provider, catalog_item, request,
                            register_event):
    """Tests order catalog item
    Metadata:
        test_flag: provision
    """
    vm_name = catalog_item.provisioning_data["vm_name"]
    request.addfinalizer(lambda: cleanup_vm(vm_name + "_0001", provider))
    catalog_item.create()

    register_event(target_type='Service',
                   target_name=catalog_item.name,
                   event_type='service_provisioned')

    service_catalogs = ServiceCatalogs(catalog_item.catalog, catalog_item.name)
    service_catalogs.order()
    logger.info("Waiting for cfme provision request for service {}".format(
        catalog_item.name))
    request_description = catalog_item.name
    provision_request = Request(request_description, partial_check=True)
    provision_request.wait_for_request()
    assert provision_request.is_succeeded()
def test_tenant_quota_max_cpu_check(provisioner, prov_data, template_name,
                                    provider, request, vm_name, set_tenant_cpu,
                                    bug):
    """Test Tenant Quota-Max CPU by UI.

    Prerequisities:
        * A provider set up, supporting provisioning in CFME

    Steps:
        * Set the tenant quota for cpu by UI enforcement
        * Open the provisioning dialog.
        * Apart from the usual provisioning settings, set CPU greater then tenant quota cpu.
        * Submit the provisioning request and wait for it to finish.
        * Visit the requests page. The last message should state quota validation message.

    Metadata:
        test_flag: provision
    """
    note = ('template {} to vm {} on provider {}'.format(
        template_name, vm_name, provider.key))
    prov_data["vm_name"] = vm_name
    prov_data["num_sockets"] = "8"
    prov_data["notes"] = note

    provisioner(template_name, prov_data)

    # nav to requests page to check quota validation
    request_description = 'Provision from [{}] to [{}]'.format(
        template_name, vm_name)
    provision_request = Request(request_description)
    provision_request.wait_for_request(method='ui')
    # BUG - https://bugzilla.redhat.com/show_bug.cgi?id=1364381
    # TODO: update assert message once the above bug is fixed.
    # assert row.last_message.text == 'Request exceeds maximum allowed for the following: \
    # (cpu - Used: 526 plus requested: 8 exceeds quota: 3))'
    assert provision_request.row.reason.text == "Quota Exceeded"
Exemple #28
0
def test_host_provisioning(setup_provider, cfme_data, host_provisioning,
                           provider, smtp_test, request):
    """Tests host provisioning

    Metadata:
        test_flag: host_provision
    """

    # Add host before provisioning
    test_host = host.get_from_config('esx')
    test_host.create()

    # Populate provisioning_data before submitting host provisioning form
    pxe_server, pxe_image, pxe_image_type, pxe_kickstart, datacenter, cluster, datastores,\
        prov_host_name, root_password, ip_addr, subnet_mask, gateway, dns = map(
            host_provisioning.get,
            ('pxe_server', 'pxe_image', 'pxe_image_type', 'pxe_kickstart', 'datacenter', 'cluster',
             'datastores', 'hostname', 'root_password', 'ip_addr', 'subnet_mask', 'gateway', 'dns'))

    def cleanup_host():
        try:
            logger.info('Cleaning up host %s on provider %s', prov_host_name,
                        provider.key)
            mgmt_system = provider.mgmt
            host_list = mgmt_system.list_host()
            if host_provisioning['ip_addr'] in host_list:
                wait_for(mgmt_system.is_host_connected,
                         [host_provisioning['ip_addr']])
                mgmt_system.remove_host_from_cluster(
                    host_provisioning['ip_addr'])

            ipmi = test_host.get_ipmi()
            ipmi.power_off()

            # During host provisioning,the host name gets changed from what's specified at creation
            # time.If host provisioning succeeds,the original name is reverted to,otherwise the
            # changed names are retained upon failure
            renamed_host_name1 = "{} ({})".format(
                'IPMI', host_provisioning['ipmi_address'])
            renamed_host_name2 = "{} ({})".format('VMware ESXi',
                                                  host_provisioning['ip_addr'])

            host_list_ui = host.get_all_hosts()
            if host_provisioning['hostname'] in host_list_ui:
                test_host.delete(cancel=False)
                host.wait_for_host_delete(test_host)
            elif renamed_host_name1 in host_list_ui:
                host_renamed_obj1 = host.Host(name=renamed_host_name1,
                                              provider=provider)
                host_renamed_obj1.delete(cancel=False)
                host.wait_for_host_delete(host_renamed_obj1)
            elif renamed_host_name2 in host_list_ui:
                host_renamed_obj2 = host.Host(name=renamed_host_name2,
                                              provider=provider)
                host_renamed_obj2.delete(cancel=False)
                host.wait_for_host_delete(host_renamed_obj2)
        except:
            # The mgmt_sys classes raise Exception :\
            logger.warning('Failed to clean up host %s on provider %s',
                           prov_host_name, provider.key)

    request.addfinalizer(cleanup_host)

    navigate_to(test_host, 'Provision')

    note = ('Provisioning host {} on provider {}'.format(
        prov_host_name, provider.key))
    provisioning_data = {
        'email': '*****@*****.**',
        'first_name': 'Template',
        'last_name': 'Provisioner',
        'notes': note,
        'pxe_server': pxe_server,
        'pxe_image': {
            'name': [pxe_image]
        },
        'provider_name': provider.name,
        'cluster': "{} / {}".format(datacenter, cluster),
        'datastore_name': {
            'name': datastores
        },
        'root_password': root_password,
        'prov_host_name': prov_host_name,
        'ip_address': ip_addr,
        'subnet_mask': subnet_mask,
        'gateway': gateway,
        'dns_servers': dns,
        'custom_template': {
            'name': [pxe_kickstart]
        },
    }

    fill(provisioning_form,
         provisioning_data,
         action=provisioning_form.host_submit_button)
    flash.assert_success_message(
        "Host Request was Submitted, you will be notified when your Hosts are ready"
    )

    request_description = 'PXE install on [{}] from image [{}]'.format(
        prov_host_name, pxe_image)
    host_request = Request(request_description)
    host_request.wait_for_request(method='ui')
    assert host_request.row.last_message.text == 'Host Provisioned Successfully'
    assert host_request.row.status.text != 'Error'

    # Navigate to host details page and verify Provider and cluster names
    assert test_host.get_detail('Relationships', 'Infrastructure Provider') ==\
        provider.name, 'Provider name does not match'

    assert test_host.get_detail('Relationships', 'Cluster') ==\
        host_provisioning['cluster'], 'Cluster does not match'

    # Navigate to host datastore page and verify that the requested datastore has been assigned
    # to the host
    requested_ds = host_provisioning['datastores']
    datastores = test_host.get_datastores()
    assert set(requested_ds).issubset(
        datastores), 'Datastores are missing some members'

    # Wait for e-mails to appear
    def verify():
        return len(
            smtp_test.get_emails(
                subject_like=
                "Your host provisioning request has Completed - Host:%%".
                format(prov_host_name))) > 0

    wait_for(verify, message="email receive check", delay=5)
Exemple #29
0
def test_provision_approval(
        setup_provider, provider, vm_name, smtp_test, request, edit, provisioning):
    """ Tests provisioning approval. Tests couple of things.

    * Approve manually
    * Approve by editing the request to conform

    Prerequisities:
        * A provider that can provision.
        * Automate role enabled
        * User with e-mail set so you can receive and view them

    Steps:
        * Create a provisioning request that does not get automatically approved (eg. ``num_vms``
            bigger than 1)
        * Wait for an e-mail to come, informing you that the auto-approval was unsuccessful.
        * Depending on whether you want to do manual approval or edit approval, do:
            * MANUAL: manually approve the request in UI
            * EDIT: Edit the request in UI so it conforms the rules for auto-approval.
        * Wait for an e-mail with approval
        * Wait until the request finishes
        * Wait until an email, informing about finished provisioning, comes.

    Metadata:
        test_flag: provision
        suite: infra_provisioning
    """
    # generate_tests makes sure these have values
    template, host, datastore = map(provisioning.get, ('template', 'host', 'datastore'))

    # It will provision two of them
    vm_names = [vm_name + "001", vm_name + "002"]
    request.addfinalizer(
        lambda: [cleanup_vm(vmname, provider) for vmname in vm_names])

    provisioning_data = {
        'catalog': {
            'vm_name': vm_name,
            'num_vms': '2'},
        'environment':
            {'host_name': {'name': provisioning['host']},
            'datastore_name': {'name': provisioning['datastore']}},
        'network':
            {'vlan': provisioning['vlan']}}

    do_vm_provisioning(template, provider, vm_name, provisioning_data, request, smtp_test,
                       wait=False)
    wait_for(
        lambda:
        len(filter(
            lambda mail:
            "your request for a new vms was not autoapproved" in normalize_text(mail["subject"]),
            smtp_test.get_emails())) > 0,
        num_sec=90, delay=5)
    wait_for(
        lambda:
        len(filter(
            lambda mail:
            "virtual machine request was not approved" in normalize_text(mail["subject"]),
            smtp_test.get_emails())) > 0,
        num_sec=90, delay=5)

    cells = {'Description': 'Provision from [{}] to [{}###]'.format(template, vm_name)}
    provision_request = Request(cells=cells)
    navigate_to(provision_request, 'Details')
    if edit:
        # Automatic approval after editing the request to conform
        new_vm_name = vm_name + "-xx"
        modifications = {'catalog': {'num_vms': "1", 'vm_name': new_vm_name}}
        provision_request.edit_request(values=modifications)
        vm_names = [new_vm_name]  # Will be just one now
        request.addfinalizer(
            lambda: cleanup_vm(new_vm_name, provider))
    else:
        # Manual approval
        provision_request.approve_request(method='ui', reason="Approved")
        vm_names = [vm_name + "001", vm_name + "002"]  # There will be two VMs
        request.addfinalizer(
            lambda: [cleanup_vm(vmname, provider) for vmname in vm_names])
    wait_for(
        lambda:
        len(filter(
            lambda mail:
            "your virtual machine configuration was approved" in normalize_text(mail["subject"]),
            smtp_test.get_emails())) > 0,
        num_sec=120, delay=5)

    # Wait for the VM to appear on the provider backend before proceeding to ensure proper cleanup
    logger.info('Waiting for vms %s to appear on provider %s', ", ".join(vm_names), provider.key)
    wait_for(
        lambda: all(map(provider.mgmt.does_vm_exist, vm_names)),
        handle_exception=True, num_sec=600)

    provision_request.wait_for_request(method='ui')
    assert provision_request.is_succeeded(method='ui')

    # Wait for e-mails to appear
    def verify():
        return (
            len(filter(
                lambda mail:
                "your virtual machine request has completed vm {}".format(normalize_text(vm_name))
                in normalize_text(mail["subject"]),
                smtp_test.get_emails())) == len(vm_names)
        )

    wait_for(verify, message="email receive check", delay=5)
def service_request(ansible_catalog_item):
    request_desc = "Provisioning Service [{0}] from [{0}]".format(
        ansible_catalog_item.name)
    service_request_ = Request(request_desc)
    yield service_request_
    service_request_.remove_request()