def test_copy_request(setup_provider, provider_key, provider_mgmt, catalog_item, request): """Automate BZ 1194479""" vm_name = catalog_item.provisioning_data["vm_name"] request.addfinalizer(lambda: cleanup_vm(vm_name, provider_key, provider_mgmt)) catalog_item.create() service_catalogs = ServiceCatalogs("service_name") service_catalogs.order(catalog_item.catalog, catalog_item) row_description = catalog_item.name cells = {"Description": row_description} row, __ = wait_for(requests.wait_for_request, [cells, True], fail_func=requests.reload, num_sec=1800, delay=20) requests.go_to_request(cells)
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("service_name") service_catalogs.order(catalog_item.catalog, catalog_item) row_description = catalog_item.name cells = {'Description': row_description} row, __ = wait_for(requests.wait_for_request, [cells, True], fail_func=requests.reload, num_sec=1800, delay=20) requests.go_to_request(cells)
def test_tenant_quota_max_num_vms_check( 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 """ note = ('template {} to vm {} on provider {}'.format(template_name, vm_name, provider.key)) prov_data["num_vms"] = "4" prov_data["vm_name"] = vm_name prov_data["notes"] = note provisioner(template_name, prov_data) # nav to requests page to check quota validation row_description = 'Provision from [{}] to [{}###]'.format(template_name, vm_name) cells = {'Description': row_description} wait_for(lambda: requests.go_to_request(cells), num_sec=80, delay=5) requests.approve_request(cells, "Approved") row, __ = wait_for(requests.wait_for_request, [cells, True], fail_func=requests.reload, num_sec=500, delay=20) assert row.reason.text == "Quota Exceeded"
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.name) service_catalogs.order() logger.info('Waiting for cfme provision request for service %s', catalog_item.name) row_description = catalog_item.name cells = {'Description': row_description} provider.delete(cancel=False) provider.wait_for_delete() requests.go_to_request(cells) row, __ = wait_for(requests.wait_for_request, [cells, True], fail_func=requests.reload, num_sec=1800, delay=20) assert row.status.text == 'Error'
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("service_name") service_catalogs.order(catalog_item.catalog, catalog_item) logger.info('Waiting for cfme provision request for service %s', catalog_item.name) row_description = catalog_item.name cells = {'Description': row_description} provider.delete(cancel=False) provider.wait_for_delete() requests.go_to_request(cells) row, __ = wait_for(requests.wait_for_request, [cells, True], fail_func=requests.reload, num_sec=1800, delay=20) assert row.status.text == 'Error'
def test_services_request_direct_url(generated_request): """Go to the request page, save the url and try to access it directly.""" assert requests.go_to_request(generated_request), "could not find the request!" request_url = sel.current_url() sel.get(sel.base_url()) # I need to flip it with something different here sel.get(request_url) # Ok, direct access now. wait_for( lambda: sel.is_displayed("//body[contains(@onload, 'miqOnLoad')]"), num_sec=20, message="wait for a CFME page appear", delay=0.5 )
def test_services_request_direct_url(generated_request): """Go to the request page, save the url and try to access it directly.""" assert requests.go_to_request( generated_request), "could not find the request!" request_url = sel.current_url() sel.get(sel.base_url()) # I need to flip it with something different here sel.get(request_url) # Ok, direct access now. wait_for( lambda: sel.is_displayed("//body[contains(@onload, 'miqOnLoad')]"), num_sec=20, message="wait for a CFME page appear", delay=0.5)
def test_services_request_direct_url(generated_request): """Go to the request page, save the url and try to access it directly.""" assert requests.go_to_request( generated_request), "could not find the request!" request_url = sel.current_url() sel.get(env["base_url"]) # I need to flip it with something different here sel.get(request_url) # Ok, direct access now. # This is a bit tricky. We have to wait IF the blank page appeared, because checking # if we are STILL IN CFME is unreliable as the transition is not guarded by JS or stuff. # btw. when the on_cfme_page returns true because of being on login screen, it will work. # After logging in, user is redirected for a correct link. Tested. try: wait_for(lambda: not sel.on_cfme_page(), num_sec=20, message="wait for blank page appear") pytest.fail("Blank screen appeared!") except TimedOutError: pass # Success!
def test_remove_template_provisioning(setup_provider, provider, provisioning, catalog, request): """Tests stack provisioning Metadata: test_flag: provision """ dialog_name_new = "dialog_" + fauxfactory.gen_alphanumeric() template_type = provisioning['stack_provisioning']['template_type'] template = OrchestrationTemplate( template_type=template_type, template_name=fauxfactory.gen_alphanumeric()) template.create(METHOD_TORSO) template.create_service_dialog_from_template(dialog_name_new, template.template_name) item_name = fauxfactory.gen_alphanumeric() catalog_item = CatalogItem(item_type="Orchestration", name=item_name, description="my catalog", display_in=True, catalog=catalog.name, dialog=dialog_name_new, orch_template=template.template_name, provider_type=provider.name) catalog_item.create() if provider.type == 'ec2': stack_data = {'stack_name': "stack" + fauxfactory.gen_alphanumeric()} elif provider.type == 'openstack': stack_data = {'stack_name': "stack" + fauxfactory.gen_alphanumeric()} service_catalogs = ServiceCatalogs("service_name", stack_data) service_catalogs.order_stack_item(catalog.name, catalog_item) flash.assert_no_errors() template.delete() row_description = 'Provisioning Service [{}] from [{}]'.format( item_name, item_name) cells = {'Description': row_description} wait_for(lambda: requests.go_to_request(cells), num_sec=500, delay=20) row, __ = wait_for(requests.wait_for_request, [cells, True], fail_func=requests.reload, num_sec=1000, delay=20) assert row.last_message.text == 'Service_Template_Provisioning failed'
def test_services_request_direct_url(generated_request): """Go to the request page, save the url and try to access it directly.""" assert requests.go_to_request(generated_request), "could not find the request!" request_url = sel.current_url() sel.get(env["base_url"]) # I need to flip it with something different here sel.get(request_url) # Ok, direct access now. # This is a bit tricky. We have to wait IF the blank page appeared, because checking # if we are STILL IN CFME is unreliable as the transition is not guarded by JS or stuff. # btw. when the on_cfme_page returns true because of being on login screen, it will work. # After logging in, user is redirected for a correct link. Tested. try: wait_for( lambda: not sel.on_cfme_page(), num_sec=20, message="wait for blank page appear" ) pytest.fail("Blank screen appeared!") except TimedOutError: pass # Success!
def test_remove_template_provisioning(setup_provider, provider, provisioning, catalog, request): """Tests stack provisioning Metadata: test_flag: provision """ dialog_name_new = "dialog_" + fauxfactory.gen_alphanumeric() template_type = provisioning['stack_provisioning']['template_type'] template = OrchestrationTemplate(template_type=template_type, template_name=fauxfactory.gen_alphanumeric()) template.create(METHOD_TORSO) template.create_service_dialog_from_template(dialog_name_new, template.template_name) item_name = fauxfactory.gen_alphanumeric() catalog_item = CatalogItem(item_type="Orchestration", name=item_name, description="my catalog", display_in=True, catalog=catalog.name, dialog=dialog_name_new, orch_template=template.template_name, provider_type=provider.name) catalog_item.create() if provider.type == 'ec2': stack_data = { 'stack_name': "stack" + fauxfactory.gen_alphanumeric() } elif provider.type == 'openstack': stack_data = { 'stack_name': "stack" + fauxfactory.gen_alphanumeric() } service_catalogs = ServiceCatalogs("service_name", stack_data) service_catalogs.order_stack_item(catalog.name, catalog_item) flash.assert_no_errors() template.delete() row_description = 'Provisioning Service [{}] from [{}]'.format(item_name, item_name) cells = {'Description': row_description} wait_for(lambda: requests.go_to_request(cells), num_sec=500, delay=20) row, __ = wait_for(requests.wait_for_request, [cells, True], fail_func=requests.reload, num_sec=1000, delay=20) assert row.last_message.text == 'Service_Template_Provisioning failed'
def test_provision_approval( setup_provider, provider, provisioning, vm_name, smtp_test, request, edit): """ 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 = { 'vm_name': vm_name, 'host_name': {'name': [host]}, 'datastore_name': {'name': [datastore]}, 'num_vms': "2", } # Same thing, different names. :\ if provider.type == 'rhevm': provisioning_data['provision_type'] = 'Native Clone' elif provider.type == 'virtualcenter': provisioning_data['provision_type'] = 'VMware' try: provisioning_data['vlan'] = provisioning['vlan'] except KeyError: # provisioning['vlan'] is required for rhevm provisioning if provider.type == 'rhevm': raise pytest.fail('rhevm requires a vlan value in provisioning info') 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)} wait_for(lambda: requests.go_to_request(cells), num_sec=80, delay=5) if edit: # Automatic approval after editing the request to conform with requests.edit_request(cells) as form: fill(form.num_vms, "1") new_vm_name = vm_name + "_xx" fill(form.vm_name, new_vm_name) vm_names = [new_vm_name] # Will be just one now cells = {'Description': 'Provision from [{}] to [{}]'.format(template, new_vm_name)} check = "vm provisioned successfully" request.addfinalizer( lambda: cleanup_vm(new_vm_name, provider)) else: # Manual approval requests.approve_request(cells, "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]) check = "request complete" 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 "{}" to appear on provider {}'.format( ", ".join(vm_names), provider.key)) wait_for( lambda: all(map(provider.mgmt.does_vm_exist, vm_names)), handle_exception=True, num_sec=600) row, __ = wait_for(requests.wait_for_request, [cells], fail_func=requests.reload, num_sec=1500, delay=20) assert normalize_text(row.last_message.text) == check # 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 go_to_request_by_vm_and_template_name(vm_name, template_name, multi=False): multistr = "###" if multi else "" row_description = "Provision from [{}] to [{}{}]".format(template_name, vm_name, multistr) return requests.go_to_request({'Description': row_description})
def go_to_request_by_vm_and_template_name(vm_name, template_name, multi=False): multistr = "###" if multi else "" row_description = "Provision from [{}] to [{}{}]".format( template_name, vm_name, multistr) return requests.go_to_request({'Description': row_description})
def test_provision_approval(provider_init, provider_key, provider_crud, provider_type, provider_mgmt, provisioning, vm_name, smtp_test, request): """ Tests provisioning approval 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_key, provider_mgmt) for vmname in vm_names]) provisioning_data = { 'vm_name': vm_name, 'host_name': {'name': [host]}, 'datastore_name': {'name': [datastore]}, 'num_vms': "2", } # Same thing, different names. :\ if provider_type == 'rhevm': provisioning_data['provision_type'] = 'Native Clone' elif provider_type == 'virtualcenter': provisioning_data['provision_type'] = 'VMware' try: provisioning_data['vlan'] = provisioning['vlan'] except KeyError: # provisioning['vlan'] is required for rhevm provisioning if provider_type == 'rhevm': raise pytest.fail('rhevm requires a vlan value in provisioning info') do_vm_provisioning(template, provider_crud, vm_name, provisioning_data, request, provider_mgmt, provider_key, 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)} wait_for(lambda: requests.go_to_request(cells), num_sec=80, delay=5) requests.approve_request(cells, "Approved") 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=90, delay=5) # Wait for the VM to appear on the provider backend before proceeding to ensure proper cleanup logger.info( 'Waiting for vms "{}" to appear on provider {}'.format( ", ".join(vm_names), provider_crud.key)) wait_for( lambda: all(map(provider_mgmt.does_vm_exist, vm_names)), handle_exception=True, num_sec=600) row, __ = wait_for(requests.wait_for_request, [cells], fail_func=requests.reload, num_sec=1500, delay=20) assert normalize_text(row.last_message.text) == "request complete" # 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())) == 2 ) wait_for(verify, message="email receive check", delay=5)