def create(self): sel.force_navigate('catalog_new') web_ui.fill(catalog.form, {'name_text': self.name, 'description_text': self.description, 'button_multiselect': self.items}, action=catalog.form.add_button) flash.assert_no_errors()
def _provisioner(template, provisioning_data, delayed=None): pytest.sel.force_navigate('infrastructure_provision_vms', context={ 'provider': provider, 'template_name': template, }) vm_name = provisioning_data["vm_name"] fill(provisioning_form, provisioning_data, action=provisioning_form.submit_button) flash.assert_no_errors() request.addfinalizer(lambda: cleanup_vm(vm_name, provider)) if delayed is not None: total_seconds = (delayed - datetime.utcnow()).total_seconds() row_description = 'Provision from [{}] to [{}]'.format(template, vm_name) cells = {'Description': row_description} try: row, __ = wait_for(requests.wait_for_request, [cells], fail_func=requests.reload, 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], 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) row_description = 'Provision from [{}] to [{}]'.format(template, vm_name) cells = {'Description': row_description} row, __ = wait_for(requests.wait_for_request, [cells], fail_func=requests.reload, num_sec=900, delay=20) assert row.last_message.text == 'Vm Provisioned Successfully' return VM.factory(vm_name, provider)
def create(self, *element_data): sel.force_navigate('service_dialog_new') fill(label_form, {'label': self.label, 'description_text': self.description, 'submit_button': self.submit, 'cancel_button': self.cancel}) plus_btn({ version.LOWEST: "Add a New Tab to this Dialog", "5.3": "Add a new Tab to this Dialog"}) sel.wait_for_element(tab_form.tab_label) fill(tab_form, {'tab_label': self.tab_label, 'tab_desc': self.tab_desc}) plus_btn({ version.LOWEST: "Add a New Box to this Tab", "5.3": "Add a new Box to this Tab"}) sel.wait_for_element(box_form.box_label) fill(box_form, {'box_label': self.box_label, 'box_desc': self.box_desc}) for each_element in element_data: plus_btn({ version.LOWEST: "Add a New Element to this Box", "5.3": "Add a new Element to this Box"}) sel.wait_for_element(element_form.ele_label) # Workaround to refresh the fields, select other values (text area box and checkbox)and # then select "text box" fill(element_form, {'choose_type': "Text Area Box"}) fill(element_form, {'choose_type': "Check Box"}) fill(element_form, each_element) self.element_type(each_element) sel.click(form_buttons.add) flash.assert_no_errors()
def _submit(self, cancel, submit_button): if cancel: form_buttons.cancel() # sel.wait_for_element(page.configuration_btn) else: submit_button() flash.assert_no_errors()
def queue_canned_report(*path): """Queue report from selection of pre-prepared reports. Args: *path: Path in tree after All Reports Returns: Value of Run At in the table so the run can be then checked. """ sel.force_navigate("report_canned_info", context={"path": path}) toolbar.select("Queue") flash.assert_no_errors() tabstrip.select_tab("Saved Reports") def _get_state(): try: first_row = list(records_table.rows())[0] except IndexError: return False return sel.text(first_row.status).strip().lower() == "finished" wait_for( _get_state, delay=1, message="wait for report generation finished", fail_func=reload_view ) return sel.text(list(records_table.rows())[0].run_at).encode("utf-8")
def test_update_catalog(): cat = Catalog(name=rand.generate_random_string(), description="my catalog") cat.create() with update(cat): cat.description = "my edited description" flash.assert_no_errors()
def queue_canned_report(cls, path): """Queue report from selection of pre-prepared reports. Args: *path: Path in tree after All Reports Returns: Value of Run At in the table so the run can be then checked. """ cls.path = path navigate_to(cls, "Info") toolbar.select("Queue") flash.assert_no_errors() tabstrip.select_tab("Saved Reports") queued_at = sel.text(list(records_table.rows())[0].queued_at) def _get_state(): navigate_to(cls, 'Saved') row = records_table.find_row("queued_at", queued_at) status = sel.text(row.status).strip().lower() assert status != "error", sel.text(row) return status == version.pick({"5.6": "finished", "5.7": "complete"}) wait_for( _get_state, delay=3, message="wait for report generation finished", fail_func=toolbar.refresh() ) return sel.text(list(records_table.rows())[0].run_at).encode("utf-8")
def check_vm_add(self, add_vm_name): sel.force_navigate('service', context={'service_name': self.service_name}) quadicon = Quadicon(add_vm_name, "vm") sel.click(quadicon) flash.assert_no_errors()
def compare(self, *objects, **kwargs): """Compares two or more objects in the genealogy. Args: *objects: :py:class:`Vm` or :py:class:`Template` or :py:class:`str` with name. Keywords: sections: Which sections to compare. attributes: `all`, `different` or `same`. Default: `all`. mode: `exists` or `details`. Default: `exists`.""" sections = kwargs.get("sections", None) attributes = kwargs.get("attributes", "all").lower() mode = kwargs.get("mode", "exists").lower() assert len(objects) >= 2, "You must specify at least two objects" objects = map(lambda o: o.name if isinstance(o, (Vm, Template)) else o, objects) self.navigate() for obj in objects: if not isinstance(obj, list): path = self.genealogy_tree.find_path_to(obj) self.genealogy_tree.check_node(*path) toolbar.select("Compare selected VMs") # COMPARE PAGE flash.assert_no_errors() if sections is not None: map(lambda path: self.section_comparison_tree.check_node(*path), sections) sel.click(self.apply_button) flash.assert_no_errors() # Set requested attributes sets toolbar.select(self.attr_mapping[attributes]) # Set the requested mode toolbar.select(self.mode_mapping[mode])
def depot_configured(request, depot_type, depot_machine, depot_credentials): """ Configure selected depot provider This fixture used the trick that the fixtures are cached for given function. So if placed behind the depot_* stuff on the test function, it can actually take the values from them. It also provides a finalizer to disable the depot after test run. """ if depot_type not in ["nfs"]: credentials = configure.ServerLogDepot.Credentials( depot_type, depot_machine, username=depot_credentials["username"], password=depot_credentials["password"] ) else: credentials = configure.ServerLogDepot.Credentials( depot_type, depot_machine ) # Fails on upstream - BZ1108087 credentials.update() flash.assert_no_errors() request.addfinalizer(configure.ServerLogDepot.Credentials.clear)
def test_modify_host_condition(random_host_condition): with update(random_host_condition): random_host_condition.notes = "Modified!" flash.assert_no_errors() sel.force_navigate("host_condition", context={"condition_name": random_host_condition.description}) assert sel.text(random_host_condition.form.notes).strip() == "Modified!"
def _submit(self, cancel, submit_button): if cancel: sel.click(page_specific_locators.cancel_button) # sel.wait_for_element(page.configuration_btn) else: sel.click(submit_button) flash.assert_no_errors()
def login(username, password, submit_method=_click_on_login): """ Login to CFME with the given username and password. Optionally, submit_method can be press_enter_after_password to use the enter key to login, rather than clicking the button. Args: user: The username to fill in the username field. password: The password to fill in the password field. submit_method: A function to call after the username and password have been input. Raises: RuntimeError: If the login fails, ie. if a flash message appears """ if not logged_in() or username is not current_username(): if logged_in(): logout() # workaround for strange bug where we are logged out # as soon as we click something on the dashboard sel.sleep(1.0) logger.debug('Logging in as user %s' % username) fill(form, {'username': username, 'password': password}) submit_method() flash.assert_no_errors() thread_locals.current_user = User(username, password, _full_name())
def generate(self, wait=True): self.go_to_detail() toolbar.select("Configuration", "Generate Widget content now", invokes_alert=True) sel.handle_alert() flash.assert_no_errors() if wait: wait_for(lambda: self.check_status() == "Complete")
def change_type(self, new_type): """Safely changes type of the dialog. It would normally mess up the navigation""" sel.force_navigate("{}_dialog".format(self.type_nav), context={"dialog": self}) cfg_btn("Edit this Dialog") self.type = new_type fill(self.form, {"type": new_type}, action=form_buttons.save) flash.assert_no_errors()
def _fill_credential(form, cred, validate=None): """How to fill in a credential. Validates the credential if that option is passed in. """ if cred.type == 'amqp': fill(credential_form, {'amqp_principal': cred.principal, 'amqp_secret': cred.secret, 'amqp_verify_secret': cred.verify_secret, 'validate_btn': validate}) elif cred.type == 'candu': fill(credential_form, {'candu_principal': cred.principal, 'candu_secret': cred.secret, 'candu_verify_secret': cred.verify_secret, 'validate_btn': validate}) elif cred.type == 'ssh': fill(credential_form, {'ssh_user': cred.principal, 'ssh_key': cred.secret}) elif cred.type == 'token': fill(credential_form, {'token_secret': cred.token, 'validate_btn': validate}) else: if cred.domain: principal = r'{}\{}'.format(cred.domain, cred.principal) else: principal = cred.principal fill(credential_form, {'default_principal': principal, 'default_secret': cred.secret, 'default_verify_secret': cred.verify_secret, 'validate_btn': validate}) if validate: flash.assert_no_errors()
def login(username, password, submit_method=_click_on_login): """ Login to CFME with the given username and password. Optionally, submit_method can be press_enter_after_password to use the enter key to login, rather than clicking the button. Args: user: The username to fill in the username field. password: The password to fill in the password field. submit_method: A function to call after the username and password have been input. Raises: RuntimeError: If the login fails, ie. if a flash message appears """ # TODO: Should probably do the username check here, but there are pretty usernames to deal with # e.g. 'admin' shows up in the UI as 'Administrator' if not logged_in(): # workaround for strange bug where we are logged out # as soon as we click something on the dashboard sel.sleep(1.0) logger.debug('Logging in as user %s' % username) fill(form, {'username': username, 'password': password}) submit_method() flash.assert_no_errors()
def test_bundles_in_bundle(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_bundle.create([catalog_item.name]) 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) sec_catalog_bundle.create([bundle_name]) 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) third_catalog_bundle.create([bundle_name, sec_bundle_name]) service_catalogs = ServiceCatalogs(third_bundle_name) service_catalogs.order() flash.assert_no_errors() logger.info('Waiting for cfme provision request for service %s', bundle_name) row_description = third_bundle_name cells = {'Description': row_description} row, __ = wait_for(requests.wait_for_request, [cells, True], fail_func=requests.reload, num_sec=900, delay=20) # Success message differs between 5.6 and 5.7 if version.current_version() >= '5.7': assert 'Service [{}] Provisioned Successfully'.format(third_bundle_name)\ in row.last_message.text else: assert row.last_message.text == 'Request complete'
def _fill_credential(form, cred, validate=None): """How to fill in a credential (either candu or default). Validates the credential if that option is passed in. """ if cred.candu: fill( credential_form, { "candu_button": True, "candu_principal": cred.principal, "candu_secret": cred.secret, "candu_verify_secret": cred.verify_secret, "validate_btn": validate, }, ) else: fill( credential_form, { "default_principal": cred.principal, "default_secret": cred.secret, "default_verify_secret": cred.verify_secret, "validate_btn": validate, }, ) if validate: flash.assert_no_errors()
def create(self, *element_data): sel.force_navigate('service_dialog_new') fill(label_form, {'label': self.label, 'description_text': self.description, 'submit_button': self.submit, 'cancel_button': self.cancel}) plus_btn({ version.LOWEST: "Add a New Tab to this Dialog", "5.3": "Add a new Tab to this Dialog"}) sel.wait_for_element(tab_form.tab_label) fill(tab_form, {'tab_label': self.tab_label, 'tab_desc': self.tab_desc}) plus_btn({ version.LOWEST: "Add a New Box to this Tab", "5.3": "Add a new Box to this Tab"}) sel.wait_for_element(box_form.box_label) fill(box_form, {'box_label': self.box_label, 'box_desc': self.box_desc}) for each_element in element_data: plus_btn({ version.LOWEST: "Add a New Element to this Box", "5.3": "Add a new Element to this Box"}) sel.wait_for_element(element_form.ele_label) fill(element_form, each_element) self.element_type(each_element) sel.click(form_buttons.add) flash.assert_no_errors()
def test_modify_host_control_policy(random_host_control_policy): with update(random_host_control_policy): random_host_control_policy.notes = "Modified!" flash.assert_no_errors() sel.force_navigate("host_control_policy", context={"policy_name": random_host_control_policy.description}) assert sel.text(random_host_control_policy.form.notes).strip() == "Modified!"
def test_modify_policy_profile(): global profile with update(profile): profile.notes = "Modified!" flash.assert_no_errors() sel.force_navigate("policy_profile", context={"policy_profile_name": profile.description}) assert sel.text(profile.form.notes).strip() == "Modified!"
def test_ec2_catalog_item(provider_init, provider_key, provider_mgmt, provider_crud, provider_type, provisioning, dialog, catalog, request): # tries to delete the VM that gets created here vm_name = 'test_ec2_servicecatalog-%s' % generate_random_string() image = provisioning['image']['name'] item_name = "ec2_" + generate_random_string() ec2_catalog_item = ec2.Instance( item_type="Amazon", name=item_name, description="my catalog", display_in=True, catalog=catalog.name, dialog=dialog, catalog_name=image, vm_name=vm_name, instance_type=provisioning['instance_type'], availability_zone=provisioning['availability_zone'], security_groups=[provisioning['security_group']], provider_mgmt=provider_mgmt, provider=provider_crud.name, guest_keypair="shared") ec2_catalog_item.create() service_catalogs = ServiceCatalogs("service_name") service_catalogs.order(catalog.name, ec2_catalog_item) flash.assert_no_errors() logger.info('Waiting for cfme provision request for service %s' % item_name) row_description = 'Provisioning [%s] for Service [%s]' % (item_name, item_name) cells = {'Description': row_description} request.addfinalizer(lambda: cleanup_vm(vm_name, provider_key, provider_mgmt)) row, __ = wait_for(requests.wait_for_request, [cells], fail_func=requests.reload, num_sec=600, delay=20) assert row.last_message.text == 'Request complete'
def do_vm_provisioning(template_name, provider_crud, vm_name, provisioning_data, request, provider_mgmt, provider_key, smtp_test, num_sec=1500, wait=True): # generate_tests makes sure these have values sel.force_navigate('infrastructure_provision_vms', context={ 'provider': provider_crud, 'template_name': template_name, }) note = ('template %s to vm %s on provider %s' % (template_name, vm_name, provider_crud.key)) provisioning_data.update({ 'email': '*****@*****.**', 'first_name': 'Template', 'last_name': 'Provisioner', 'notes': note, }) fill(provisioning_form, provisioning_data, action=provisioning_form.submit_button) flash.assert_no_errors() if not wait: return # 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_crud.key) wait_for(provider_mgmt.does_vm_exist, [vm_name], 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) row_description = 'Provision from [%s] to [%s]' % (template_name, vm_name) cells = {'Description': row_description} try: row, __ = wait_for(requests.wait_for_request, [cells], fail_func=requests.reload, num_sec=num_sec, delay=20) except Exception as e: requests.debug_requests() raise e assert row.last_message.text == version.pick( {version.LOWEST: 'VM Provisioned Successfully', "5.3": 'Vm Provisioned Successfully', }) # Wait for e-mails to appear def verify(): if current_version() >= "5.4": approval = dict(subject_like="%%Your Virtual Machine configuration was Approved%%") else: approval = dict(text_like="%%Your Virtual Machine Request was approved%%") return ( len( smtp_test.get_emails(**approval) ) > 0 and len( smtp_test.get_emails( subject_like="Your virtual machine request has Completed - VM:%%%s" % vm_name ) ) > 0 ) wait_for(verify, message="email receive check", delay=5)
def test_vmware_vimapi_hotadd_disk( request, testing_group, provider, testing_vm, domain, cls): """ Tests hot adding a disk to vmware vm. This test exercises the ``VMware_HotAdd_Disk`` method, located in ``/Integration/VMware/VimApi`` Steps: * It creates an instance in ``System/Request`` that can be accessible from eg. a button. * Then it creates a button, that refers to the ``VMware_HotAdd_Disk`` in ``Request``. The button shall belong in the VM and instance button group. * After the button is created, it goes to a VM's summary page, clicks the button. * The test waits until the capacity of disks is raised. Metadata: test_flag: hotdisk, provision """ meth = cls.methods.create( name='load_value_{}'.format(fauxfactory.gen_alpha()), script=dedent('''\ # Sets the capacity of the new disk. $evm.root['size'] = 1 # GB exit MIQ_OK ''')) request.addfinalizer(meth.delete_if_exists) # Instance that calls the method and is accessible from the button instance = cls.instances.create( name="VMware_HotAdd_Disk_{}".format(fauxfactory.gen_alpha()), fields={ "meth4": {'value': meth.name}, # To get the value "rel5": {'value': "/Integration/VMware/VimApi/VMware_HotAdd_Disk"}, }, ) request.addfinalizer(instance.delete_if_exists) # Button that will invoke the dialog and action button_name = fauxfactory.gen_alphanumeric() button = Button(group=testing_group, text=button_name, hover=button_name, system="Request", request=instance.name) request.addfinalizer(button.delete_if_exists) button.create() def _get_disk_capacity(): testing_vm.summary.reload() return testing_vm.summary.datastore_allocation_summary.total_allocation.value original_disk_capacity = _get_disk_capacity() logger.info('Initial disk allocation: %s', original_disk_capacity) toolbar.select(testing_group.text, button.text) flash.assert_no_errors() try: wait_for( lambda: _get_disk_capacity() > original_disk_capacity, num_sec=180, delay=5) finally: logger.info('End disk capacity: %s', _get_disk_capacity())
def create(self, cancel=False): sel.force_navigate("reports_dashboard_add", context={"group": self._group}) fill( self.form, {k: v for k, v in self.__dict__.iteritems() if not k.startswith("_")}, # non-private action=form_buttons.cancel if cancel else form_buttons.add ) flash.assert_no_errors()
def _provisioner(template, provisioning_data, delayed=None): sel.force_navigate('infrastructure_provision_vms', context={ 'provider': provider, 'template_name': template, }) fill(provisioning_form, provisioning_data, action=provisioning_form.submit_button) flash.assert_no_errors()
def generate(self, wait=True, **kwargs): navigate_to(self, 'Details') toolbar.select("Configuration", "Generate Widget content now", invokes_alert=True) sel.handle_alert() flash.assert_message_match("Content generation for this Widget has been initiated") flash.assert_no_errors() if wait: self.wait_generated(**kwargs)
def computeassign(self): sel.force_navigate('chargeback_assignments_compute', context={'chargeback': self}) fill(assign_form, {'assign_to': self.assign_to, 'tag_category': self.tag_category, 'selections': self.selections}, action=assign_form.save_button) flash.assert_no_errors()
def _fill_credential(form, cred, validate=None): """How to fill in a credential. Validates the credential if that option is passed in.""" fill(credential_form, {'principal_text': cred.principal, 'secret_pass': cred.secret, 'verify_secret_pass': cred.verify_secret, 'validate_btn': validate}) if validate: flash.assert_no_errors()
def update(self, updates): sel.force_navigate("automate_explorer_domain_edit", context={"tree_item": self}) fill(self.form, updates, action=form_buttons.save) flash.assert_no_errors()
def add_datasource(self, ds_type, ds_name, jndi_name, ds_url, xa_ds=False, driver_name=None, existing_driver=None, driver_module_name=None, driver_class=None, username=None, password=None, sec_domain=None, cancel=False): """Clicks to "Add Datasource" button, in opened window fills fields by provided parameter by clicking 'Next', and submits the form by clicking 'Finish'. Args: ds_type: Type of database. ds_name: Name of newly created Datasource. jndi_name: JNDI Name of Datasource. driver_name: JDBC Driver name in Datasource. driver_module_name: Module name of JDBC Driver used in datasource. driver_class: JDBC Driver Class. ds_url: Database connection URL in jdbc format. username: Database username. password: Databasae password, optional. sec_domain: Security Domain, optional. cancel: Whether to click Cancel instead of commit. """ self.load_details(refresh=True) datasources_btn("Add Datasource", invokes_alert=True) if self.appliance.version >= '5.8': fill(datasource_form, { "xa_ds": xa_ds }) fill(datasource_form, { "ds_type": ds_type, }) sel.click(datasource_form.cancel_button if cancel else datasource_form.next0_button) fill(datasource_form, { "ds_name": ds_name, "jndi_name": jndi_name }) sel.click(datasource_form.cancel_button if cancel else datasource_form.next1_button) if existing_driver and self.appliance.version >= '5.8': tabstrip.select_tab("Existing Driver") fill(datasource_form, { "existing_driver": existing_driver }) else: fill(datasource_form, { "driver_name": driver_name, "driver_module_name": driver_module_name, "driver_class": driver_class }) sel.click(datasource_form.cancel_button if cancel else datasource_form.next2_button) fill(datasource_form, { "ds_url": ds_url, "username": username, "password": password, "sec_domain": sec_domain }) sel.click(datasource_form.cancel_button if cancel else datasource_form.finish_button) flash.assert_no_errors()
def refresh_status(self): self.navigate() cfg_btn("Refresh Status", invokes_alert=True) sel.handle_alert(cancel=False) flash.assert_no_errors()
def test_import_policies(import_policy_file): import_export.import_file(import_policy_file) flash.assert_no_errors()
def generated_request(provider, provider_data, provisioning, template_name, vm_name): """Creates a provision request, that is not automatically approved, and returns the search data. After finishing the test, request should be automatically deleted. Slightly modified code from :py:module:`cfme.tests.infrastructure.test_provisioning` """ first_name = fauxfactory.gen_alphanumeric() last_name = fauxfactory.gen_alphanumeric() notes = fauxfactory.gen_alphanumeric() e_mail = "{}@{}.test".format(first_name, last_name) host, datastore = map(provisioning.get, ('host', 'datastore')) pytest.sel.force_navigate('infrastructure_provision_vms', context={ 'provider': provider, 'template_name': template_name, }) provisioning_data = { 'email': e_mail, 'first_name': first_name, 'last_name': last_name, 'notes': notes, 'vm_name': vm_name, 'host_name': { 'name': [host] }, 'datastore_name': { 'name': [datastore] }, 'num_vms': "10", # so it won't get auto-approved } # Same thing, different names. :\ if provider_data["type"] == 'rhevm': provisioning_data['provision_type'] = 'Native Clone' elif provider_data["type"] == 'virtualcenter': provisioning_data['provision_type'] = 'VMware' try: provisioning_data['vlan'] = provisioning['vlan'] except KeyError: # provisioning['vlan'] is required for rhevm provisioning if provider_data["type"] == 'rhevm': raise pytest.fail( 'rhevm requires a vlan value in provisioning info') provisioning_form.fill(provisioning_data) pytest.sel.click(provisioning_form.submit_button) flash.assert_no_errors() request_cells = { "Description": "Provision from [{}] to [{}###]".format(template_name, vm_name), } yield request_cells browser().get(store.base_url) login_admin() requests.delete_request(request_cells) flash.assert_no_errors()
def _submit(self, cancel, submit_button): if cancel: form_buttons.cancel() else: submit_button() flash.assert_no_errors()
def create(self, cancel=False): navigate_to(self, 'New') fill(report_form, self, action=form_buttons.cancel if cancel else form_buttons.add) flash.assert_no_errors()
def update(self, updates): navigate_to(self, 'Edit') fill(report_form, updates, action=form_buttons.save) flash.assert_no_errors()
def test_iso_provision_from_template(provider_key, provider_crud, provider_type, provider_mgmt, provisioning, vm_name, smtp_test, request): # generate_tests makes sure these have values iso_template, host, datastore, iso_file, iso_kickstart,\ iso_root_password, iso_image_type, vlan = map(provisioning.get, ('pxe_template', 'host', 'datastore', 'iso_file', 'iso_kickstart', 'iso_root_password', 'iso_image_type', 'vlan')) pytest.sel.force_navigate('infrastructure_provision_vms', context={ 'provider': provider_crud, 'template_name': iso_template, }) note = ('template %s to vm %s on provider %s' % (iso_template, vm_name, provider_crud.key)) provisioning_data = { 'email': '*****@*****.**', 'first_name': 'Template', 'last_name': 'Provisioner', 'notes': note, 'vm_name': vm_name, 'host_name': { 'name': [host] }, 'datastore_name': { 'name': [datastore] }, 'provision_type': 'ISO', 'iso_file': { 'name': [iso_file] }, 'custom_template': { 'name': [iso_kickstart] }, 'root_password': iso_root_password, 'vlan': vlan, } fill(provisioning_form, provisioning_data, action=provisioning_form.submit_button) flash.assert_no_errors() request.addfinalizer( lambda: cleanup_vm(vm_name, provider_key, provider_mgmt)) # 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_crud.key) wait_for(provider_mgmt.does_vm_exist, [vm_name], 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) row_description = 'Provision from [%s] to [%s]' % (iso_template, vm_name) cells = {'Description': row_description} row, __ = wait_for(requests.wait_for_request, [cells], fail_func=requests.reload, num_sec=1800, delay=20) assert row.last_message.text == 'VM Provisioned Successfully' # Wait for e-mails to appear def verify(): return ( len( smtp_test.get_emails( text_like="%%Your Virtual Machine Request was approved%%")) > 0 and len( smtp_test.get_emails( subject_like= "Your virtual machine request has Completed - VM:%%%s" % vm_name)) > 0) wait_for(verify, message="email receive check", delay=5)
def delete(self, cancel=False): self.navigate() cfg_btn("Remove this Storage Manager from the VMDB", invokes_alert=True) sel.handle_alert(cancel) flash.assert_no_errors()
def refresh_inventory(self): self.navigate() cfg_btn("Refresh Inventory", invokes_alert=True) sel.handle_alert(cancel=False) flash.assert_no_errors()
def delete(self, cancel=False): sel.force_navigate("automate_explorer_tree_path", context={'tree_item': self}) cfg_btn('Remove this Instance', invokes_alert=True) sel.handle_alert(cancel) return flash.assert_no_errors()
def import_reports(filename, overwrite=False): sel.force_navigate("import_export") sel.checkbox(form.import_overwrite, overwrite) sel.send_keys(form.import_file, filename) sel.click(form.import_submit) flash.assert_no_errors()
def test_vmware_vimapi_hotadd_disk(request, testing_group, provider, testing_vm, domain, namespace, cls): """ Tests hot adding a disk to vmware vm. This test exercises the ``VMware_HotAdd_Disk`` method, located either in ``/Integration/VimApi/`` (<5.3) or ``/Integration/VMware/VimApi`` (5.3 and up). Steps: * It creates an instance in ``System/Request`` that can be accessible from eg. a button. * Then it creates a service dialog that contains a field with the desired disk size, the text field name should be ``size`` * Then it creates a button, that refers to the ``VMware_HotAdd_Disk`` in ``Request``. The button shall belong in the VM and instance button group. * After the button is created, it goes to a VM's summary page, clicks the button, enters the size of the disk and submits the dialog. * The test waits until the number of disks is raised. Metadata: test_flag: hotdisk, provision """ # Instance that calls the method and is accessible from the button if current_version() < "5.3": rel = "/Integration/VimApi/VMware_HotAdd_Disk" else: rel = "/Integration/VMware/VimApi/VMware_HotAdd_Disk" instance = Instance(name="VMware_HotAdd_Disk", values={ "rel5": rel, }, cls=cls) if not instance.exists(): request.addfinalizer(lambda: instance.delete() if instance.exists() else None) instance.create() # Dialog to put the disk capacity return element_data = { 'ele_label': "Disk size", 'ele_name': "size", 'ele_desc': "Disk size", 'choose_type': "Text Box", 'default_text_box': "Default text" } dialog = ServiceDialog( label=fauxfactory.gen_alphanumeric(), description=fauxfactory.gen_alphanumeric(), submit=True, tab_label=fauxfactory.gen_alphanumeric(), tab_desc=fauxfactory.gen_alphanumeric(), box_label=fauxfactory.gen_alphanumeric(), box_desc=fauxfactory.gen_alphanumeric(), ) dialog.create(element_data) request.addfinalizer(lambda: dialog.delete()) # Button that will invoke the dialog and action button_name = fauxfactory.gen_alphanumeric() button = Button(group=testing_group, text=button_name, hover=button_name, dialog=dialog, system="Request", request="VMware_HotAdd_Disk") request.addfinalizer(button.delete_if_exists) button.create() # Now do the funny stuff def _get_disk_count(): return int( testing_vm.get_detail(properties=("Datastore Allocation Summary", "Number of Disks")).strip()) original_disk_count = _get_disk_count() toolbar.select(testing_group.text, button.text) fill(Input("size"), "1") pytest.sel.click(submit) flash.assert_no_errors() wait_for(lambda: original_disk_count + 1 == _get_disk_count(), num_sec=180, delay=5)
def change_type(self, new_type): """Safely changes type of the dialog. It would normally mess up the navigation""" navigate_to(self, 'Edit') self.type = new_type fill(self.form, {"type": new_type}, action=form_buttons.save) flash.assert_no_errors()
def create(self, cancel=False): navigate_to(self, 'Add') fill(self.form, self.__dict__, action=form_buttons.cancel if cancel else form_buttons.add) flash.assert_no_errors()
def delete(self): sel.force_navigate('chargeback_rates_storage_named', context={'chargeback': self}) tb_select('Remove from the VMDB', invokes_alert=True) sel.handle_alert() flash.assert_no_errors()
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 sel.force_navigate('infrastructure_provision_vms', context={ 'provider': provider, 'template_name': template_name, }) note = ('template {} to vm {} on provider {}'.format( template_name, vm_name, provider.key)) provisioning_data.update({ 'email': '*****@*****.**', 'first_name': 'Template', 'last_name': 'Provisioner', 'notes': note, }) fill(provisioning_form, provisioning_data, action=provisioning_form.submit_button) flash.assert_no_errors() if not wait: return # 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) # nav to requests page happens on successful provision logger.info('Waiting for cfme provision request for vm %s', vm_name) row_description = 'Provision from [{}] to [{}]'.format( template_name, vm_name) cells = {'Description': row_description} try: row, __ = wait_for(requests.wait_for_request, [cells], fail_func=requests.reload, num_sec=num_sec, delay=20) except Exception as e: requests.debug_requests() raise e assert row.last_message.text == 'Vm Provisioned Successfully' if smtp_test: # Wait for e-mails to appear def verify(): if current_version() >= "5.4": approval = dict( subject_like= "%%Your Virtual Machine configuration was Approved%%") else: approval = dict( text_like="%%Your Virtual Machine Request 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=5)