def test_provision_stack(appliance, setup_provider, 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 = RequestCollection(appliance).instantiate(request_description,
                                                                 partial_check=True)
    provision_request.wait_for_request()
    assert provision_request.is_succeeded()
예제 #2
0
def test_tagdialog_catalog_item(appliance, provider, setup_provider,
                                catalog_item, request):
    """Tests tag dialog 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()
    dialog_values = {'default_select_value': "Gold"}
    service_catalogs = ServiceCatalogs(appliance,
                                       catalog=catalog_item.catalog,
                                       name=catalog_item.name,
                                       dialog_values=dialog_values)
    service_catalogs.order()
    logger.info('Waiting for cfme provision request for service {}'.format(
        catalog_item.name))
    request_description = catalog_item.name
    provision_request = RequestCollection(appliance).instantiate(
        request_description, partial_check=True)
    provision_request.wait_for_request()
    assert provision_request.is_succeeded()
    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 = RequestCollection(appliance).instantiate(
            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
예제 #4
0
def test_order_catalog_item(appliance, 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 = RequestCollection(appliance).instantiate(
        request_description, partial_check=True)
    provision_request.wait_for_request()
    assert provision_request.is_succeeded()
예제 #5
0
def test_bundles_in_bundle(appliance, catalog_item):
    bundle_name = "first_" + 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()
    sec_bundle_name = "sec_" + fauxfactory.gen_alphanumeric()
    sec_catalog_bundle = CatalogBundle(name=sec_bundle_name,
                                       description="catalog_bundle",
                                       display_in=True,
                                       catalog=catalog_item.catalog,
                                       dialog=catalog_item.dialog,
                                       catalog_items=[bundle_name])
    sec_catalog_bundle.create()
    third_bundle_name = "third_" + fauxfactory.gen_alphanumeric()
    third_catalog_bundle = CatalogBundle(
        name=third_bundle_name,
        description="catalog_bundle",
        display_in=True,
        catalog=catalog_item.catalog,
        dialog=catalog_item.dialog,
        catalog_items=[bundle_name, sec_bundle_name])
    third_catalog_bundle.create()
    service_catalogs = ServiceCatalogs(appliance, third_catalog_bundle.catalog,
                                       third_bundle_name)
    service_catalogs.order()
    logger.info('Waiting for cfme provision request for service %s',
                bundle_name)
    request_description = third_bundle_name
    provision_request = RequestCollection(appliance).instantiate(
        request_description, partial_check=True)
    provision_request.wait_for_request()
    assert provision_request.is_succeeded()
def test_provision_approval(appliance, 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(appliance,
                       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 = RequestCollection(appliance).instantiate(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)