def provisioned_instance(provider, testing_instance, appliance): """ Checks provisioning status for instance """ 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 = RequestCollection(appliance).instantiate( request_description) try: provision_request.wait_for_request(method='ui') except Exception as e: logger.info("Provision failed {}: {}".format( e, provision_request.request_state)) 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) return instance
def myservice(appliance, 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(appliance, 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 = RequestCollection(appliance).instantiate( request_description, partial_check=True) service_request.wait_for_request() assert service_request.is_succeeded() yield catalog_item.name, vm_name cleanup_vm(vm_name, provider)
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 = RequestCollection(self.appliance).instantiate(cells=cells) provision_request.wait_for_request() return Template(template_name, self.provider)
def test_retire_stack(appliance, 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 = RequestCollection(appliance).instantiate(request_description, partial_check=True) provision_request.wait_for_request() assert provision_request.is_succeeded() stack = StackCollection(appliance).instantiate(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_order_catalog_bundle(appliance, 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 = RequestCollection(appliance).instantiate( request_description, partial_check=True) provision_request.wait_for_request() assert provision_request.is_succeeded()
def test_provision_from_template(appliance, 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 = RequestCollection(appliance).instantiate( 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_action_cancel_clone(appliance, 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 = RequestCollection(appliance).instantiate( description=request_description, partial_check=True) clone_request.wait_for_request(method='ui') assert clone_request.status == "Error"
def do_vm_provisioning(appliance, 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 = RequestCollection(appliance).instantiate( 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 create_vm(appliance, 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() logger.info('Waiting for cfme provision request for service %s', catalog_item.name) request_description = catalog_item.name request_row = RequestCollection(appliance).instantiate(request_description, partial_check=True) request_row.wait_for_request() assert request_row.is_succeeded() return vm_name
def test_copy_request(appliance, 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 = RequestCollection(appliance).instantiate( request_description, partial_check=True) service_request.wait_for_request() assert navigate_to(service_request, 'Details')
def test_vm_clone(appliance, 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 = RequestCollection(appliance).instantiate(request_description, partial_check=True) request_row.wait_for_request(method='ui') assert request_row.is_succeeded(method='ui')
def test_service_generic_catalog_bundle(appliance, 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() logger.info('Waiting for cfme provision request for service %s', bundle_name) request_description = bundle_name provision_request = RequestCollection(appliance).instantiate(request_description, partial_check=True) provision_request.wait_for_request() assert provision_request.is_succeeded()
def test_cloud_catalog_item(appliance, 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(appliance, catalog_item.catalog, catalog_item.name) service_catalogs.order() logger.info('Waiting for cfme provision request for service %s', item_name) request_description = item_name provision_request = RequestCollection(appliance).instantiate( request_description, partial_check=True) provision_request.wait_for_request() assert provision_request.is_succeeded()
def test_retire_ansible_service(appliance, 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 = RequestCollection(appliance).instantiate( cells=cells, partial_check=True) order_request.wait_for_request(method='ui') assert order_request.is_succeeded(method='ui') myservice = MyService(appliance, catalog_item.name) myservice.retire()
def test_order_tower_catalog_item(appliance, 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 = RequestCollection(appliance).instantiate( cells=cells, partial_check=True) order_request.wait_for_request(method='ui') assert order_request.is_succeeded(method='ui') DefaultView.set_default_view("Configuration Management Providers", "List View")
def test_request_with_orphaned_template(appliance, 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 = RequestCollection(appliance).instantiate( 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'
def test_remove_template_provisioning(appliance, 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 = RequestCollection(appliance).instantiate(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 test_vm_migrate(appliance, 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) request_description = new_vm.name cells = {'Description': request_description, 'Request Type': 'Migrate'} migrate_request = RequestCollection(appliance).instantiate( request_description, cells=cells, partial_check=True) migrate_request.wait_for_request(method='ui') assert migrate_request.is_succeeded(method='ui')
def test_tenant_quota_max_cpu_check(appliance, 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 """ prov_data = { 'catalog': { 'vm_name': vm_name }, 'environment': { 'automatic_placement': True }, 'hardware': { 'num_sockets': '8' } } provisioner(appliance, template_name, prov_data, vm_name) # nav to requests page to check quota validation request_description = 'Provision from [{}] to [{}]'.format( template_name, vm_name) provision_request = RequestCollection(appliance).instantiate( 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"
def myservice(appliance, 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 = RequestCollection(appliance).instantiate(request_description, partial_check=True) provision_request.wait_for_request() assert provision_request.is_finished() service = MyService(appliance, catalog_item.name, vm_name) yield service try: service.delete() except Exception as ex: logger.warning('Exception while deleting MyService, continuing: {}'.format(ex.message))
def order_catalog_item_in_ops_ui(appliance, provider, catalog_item, request): """ Fixture for SSUI tests. Orders catalog item in OPS UI. """ vm_name = catalog_item.provisioning_data["vm_name"] request.addfinalizer( lambda: cleanup_vm("{}_0001".format(vm_name), 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 provision_request = RequestCollection(appliance).instantiate( request_description, partial_check=True) provision_request.wait_for_request() assert provision_request.is_finished() return catalog_item.name
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(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 test_rhev_iso_servicecatalog(appliance, setup_provider, provider, catalog_item, request): """Tests RHEV ISO service catalog Metadata: test_flag: iso, 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 = RequestCollection(appliance).instantiate( request_description, partial_check=True) provision_request.wait_for_request() assert provision_request.is_succeeded()
def test_tenant_quota_max_num_vms_check(appliance, provisioner, prov_data, template_name, provider, request, vm_name, set_tenant_vm, bug): """Test Tenant Quota-Max number of vms 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 num of vms greater then tenant quota vm. * Submit the provisioning request. * Approve the request and wait for it to finish. * Visit the requests page. The last message should state quota validation message. Metadata: test_flag: provision """ prov_data = { 'catalog': { 'vm_name': vm_name, 'num_vms': '4' }, 'environment': { 'automatic_placement': True } } provisioner(appliance, template_name, prov_data, vm_name) # nav to requests page to check quota validation request_description = 'Provision from [{}] to [{}###]'.format( template_name, vm_name) provision_request = RequestCollection(appliance).instantiate( request_description) provision_request.approve_request(method='ui', reason="Approved") provision_request.wait_for_request(method='ui') assert provision_request.row.reason.text == "Quota Exceeded"
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
def order_catalog_item_in_ops_ui(appliance, provider, provisioning, vm_name, dialog, catalog, console_template, request): """ Fixture for SSUI tests. Orders catalog item in OPS UI. """ if hasattr(request, 'param'): catalog_item = create_catalog_item(provider, provisioning, vm_name, dialog, catalog, console_template if 'console_test' in request.param else None) else: catalog_item = create_catalog_item(provider, provisioning, vm_name, dialog, catalog) vm_name = catalog_item.provisioning_data["vm_name"] request.addfinalizer(lambda: cleanup_vm("{}0001".format(vm_name), provider)) catalog_item.create() service_catalogs = ServiceCatalogs(appliance, 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_finished() return catalog_item.name
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()
def test_reconfigure_service(appliance, 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() myservice = MyService(appliance, catalog_item.name) myservice.reconfigure_service()
def test_group_quota_max_cpu_check_by_tagging(appliance, 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 = RequestCollection(appliance).instantiate( 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 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)