def cleanup_host(): try: logger.info('Cleaning up host %s on provider %s', prov_host_name, provider.key) mgmt_system = provider.mgmt host_list = mgmt_system.list_host() if host_provisioning['ip_addr'] in host_list: wait_for(mgmt_system.is_host_connected, [host_provisioning['ip_addr']]) mgmt_system.remove_host_from_cluster(host_provisioning['ip_addr']) ipmi = test_host.get_ipmi() ipmi.power_off() # During host provisioning,the host name gets changed from what's specified at creation # time.If host provisioning succeeds,the original name is reverted to,otherwise the # changed names are retained upon failure renamed_host_name1 = "{} ({})".format('IPMI', host_provisioning['ipmi_address']) renamed_host_name2 = "{} ({})".format('VMware ESXi', host_provisioning['ip_addr']) host_list_ui = host.get_all_hosts() if host_provisioning['hostname'] in host_list_ui: test_host.delete(cancel=False) host.wait_for_host_delete(test_host) elif renamed_host_name1 in host_list_ui: host_renamed_obj1 = host.Host(name=renamed_host_name1, provider=provider) host_renamed_obj1.delete(cancel=False) host.wait_for_host_delete(host_renamed_obj1) elif renamed_host_name2 in host_list_ui: host_renamed_obj2 = host.Host(name=renamed_host_name2, provider=provider) host_renamed_obj2.delete(cancel=False) host.wait_for_host_delete(host_renamed_obj2) except: # The mgmt_sys classes raise Exception :\ logger.warning('Failed to clean up host %s on provider %s', prov_host_name, provider.key)
def setup_host_creds(provider_key, host_name, ignore_errors=False): try: host_data = get_host_data_by_name(provider_key, host_name) test_host = host.Host(name=host_name) if not test_host.has_valid_credentials: logger.info("Setting up creds for host:" + host_name) # double check ip address (issue around added ipv6 to the test # beds for upcoming support) if test_host.ip_address is None: test_host.ip_address = socket.gethostbyname_ex(host_name)[2][0] test_host.update( updates={'credentials': host.get_credentials_from_config(host_data['credentials']), 'ip_address': test_host.ip_address} ) wait_for( lambda: test_host.has_valid_credentials, delay=10, num_sec=120, fail_func=sel.refresh ) except Exception as e: if not ignore_errors: raise e
def set_host_credentials(request, provider, vm_analysis_data): # Add credentials to host test_host = host.Host(name=vm_analysis_data['host'], provider=provider) wait_for(lambda: test_host.exists, delay=10, num_sec=120) host_list = cfme_data.get('management_systems', {})[provider.key].get('hosts', []) host_data = [x for x in host_list if x.name == vm_analysis_data['host']][0] # has valid creds appears broken if not test_host.has_valid_credentials: test_host.update(updates={ 'credentials': host.get_credentials_from_config(host_data['credentials']) }, validate_credentials=True) # Remove creds after test @request.addfinalizer def _host_remove_creds(): test_host.update(updates={ 'credentials': host.Host.Credential(principal="", secret="", verify_secret="") }, validate_credentials=False)
def test_host_bad_creds(request, setup_provider, provider): """ Tests host credentialing with bad credentials """ test_host = random.choice(provider.get_yaml_data()["hosts"]) host_obj = host.Host(name=test_host.name) with error.expected(msgs[provider.type]): with update(host_obj, validate_credentials=True): host_obj.credentials = host.get_credentials_from_config( 'bad_credentials')
def test_delete_host_appear_after_refresh(setup_provider, provider): """ Tests delete host Metadata: test_flag: delete_object """ host_name = provider.data['remove_test']['host'] test_host = host.Host(name=host_name, provider=provider) test_host.delete(cancel=False) host.wait_for_host_delete(test_host) provider.refresh_provider_relationships() host.wait_for_host_to_appear(test_host)
def test_host_good_creds(request, setup_provider, provider): """ Tests host credentialing with good credentials """ test_host = random.choice(provider.get_yaml_data()["hosts"]) host_data = get_host_data_by_name(provider.key, test_host.name) host_obj = host.Host(name=test_host.name) # Remove creds after test @request.addfinalizer def _host_remove_creds(): with update(host_obj): host_obj.credentials = host.Host.Credential(principal="", secret="", verify_secret="") with update(host_obj, validate_credentials=True): host_obj.credentials = host.get_credentials_from_config( host_data['credentials'])
def setup_host_creds(provider_key, host_name, remove_creds=False, ignore_errors=False): try: host_data = get_host_data_by_name(provider_key, host_name) test_host = host.Host(name=host_name) if not test_host.has_valid_credentials: logger.info("Setting up creds for host: %s", host_name) with update(test_host): if test_host.ip_address is None: test_host.ip_address = socket.gethostbyname_ex( host_name)[2][0] test_host.credentials = host.get_credentials_from_config( host_data['credentials']) elif test_host.has_valid_credentials and remove_creds: with update(test_host): test_host.credentials = host.Host.Credential(principal="", secret="", verify_secret="") except Exception as e: if not ignore_errors: raise e
def set_host_credentials(request, provider, vm): # Add credentials to host host_name = vm.api.host.name test_host = host.Host(name=host_name) host_list = cfme_data.get('management_systems', {})[vm._prov.key].get('hosts', []) host_data = [x for x in host_list if x.name == host_name][0] if not test_host.has_valid_credentials: test_host.update(updates={ 'credentials': host.get_credentials_from_config(host_data['credentials']) }, validate_credentials=True) # Remove creds after test @request.addfinalizer def _host_remove_creds(): test_host.update(updates={ 'credentials': host.Host.Credential(principal="", secret="", verify_secret="") }, validate_credentials=False)
def test_host_drift_analysis(request, setup_provider, provider, host, soft_assert): """Tests host drift analysis Metadata: test_flag: host_drift_analysis """ test_host = host_obj.Host(name=host['name'], provider=provider) wait_for(lambda: test_host.exists, delay=10, num_sec=120, fail_func=sel.refresh, message="hosts_exists") # get drift history num drift_num_orig = int(test_host.get_detail('Relationships', 'Drift History')) # add credentials to host + finalizer to remove them if not test_host.has_valid_credentials: test_host.update(updates={ 'credentials': host_obj.get_credentials_from_config(host['credentials']) }, validate_credentials=True) @request.addfinalizer def test_host_remove_creds(): test_host.update( updates={ 'credentials': host_obj.Host.Credential( principal="", secret="", verify_secret="") }) # clear table view = navigate_to(Tasks, 'AllOtherTasks') view.delete.item_select('Delete All', handle_alert=True) # initiate 1st analysis test_host.run_smartstate_analysis() # Wait for the task to finish def is_host_analysis_finished(): """ Check if analysis is finished - if not, reload page """ finished = False view = navigate_to(Tasks, 'AllOtherTasks') host_analysis_row = view.tabs.allothertasks.table.row( task_name="SmartState Analysis for '{}'".format(test_host.name)) if host_analysis_row.state.text == 'Finished': finished = True # select the row and delete the task host_analysis_row[0].check() view.delete.item_select('Delete', handle_alert=True) else: view.reload.click() return finished wait_for(is_host_analysis_finished, delay=5, timeout="8m") # wait for for drift history num+1 wait_for(lambda: int(test_host.get_detail('Relationships', 'Drift History') ) == drift_num_orig + 1, delay=20, num_sec=120, message="Waiting for Drift History count to increase", fail_func=sel.refresh) # add a tag and a finalizer to remove it tag = ('Department', 'Accounting') test_host.tag(tag, single_value=False) request.addfinalizer(lambda: test_host.untag(tag)) # initiate 2nd analysis test_host.run_smartstate_analysis() # Wait for the task to finish wait_for(is_host_analysis_finished, delay=5, timeout="8m") # wait for for drift history num+2 wait_for(lambda: int(test_host.get_detail('Relationships', 'Drift History') ) == drift_num_orig + 2, delay=20, num_sec=120, message="Waiting for Drift History count to increase", fail_func=sel.refresh) # check drift difference soft_assert( not test_host.equal_drift_results('Department (1)', 'My Company Tags', 0, 1), "Drift analysis results are equal when they shouldn't be") # Test UI features that modify the drift grid d_grid = DriftGrid() # Accounting tag should not be displayed, because it was changed to True tb.select("Attributes with same values") with error.expected(sel.NoSuchElementException): d_grid.get_cell('Accounting', 0) # Accounting tag should be displayed now tb.select("Attributes with different values") d_grid.get_cell('Accounting', 0)
def test_run_host_analysis(request, setup_provider, provider, host_type, host_name, register_event, soft_assert, bug): """ Run host SmartState analysis Metadata: test_flag: host_analysis """ # Add credentials to host host_data = get_host_data_by_name(provider.key, host_name) test_host = host.Host(name=host_name) wait_for(lambda: test_host.exists, delay=10, num_sec=120, fail_func=sel.refresh) if not test_host.has_valid_credentials: test_host.update( updates={ 'credentials': host.get_credentials_from_config(host_data['credentials']) }) wait_for(lambda: test_host.has_valid_credentials, delay=10, num_sec=120, fail_func=sel.refresh) # Remove creds after test def test_host_remove_creds(): test_host.update( updates={ 'credentials': host.Host.Credential( principal="", secret="", verify_secret="") }) request.addfinalizer(test_host_remove_creds) register_event(None, "host", host_name, ["host_analysis_request", "host_analysis_complete"]) # Initiate analysis test_host.run_smartstate_analysis() # Wait for the task to finish def is_host_analysis_finished(): """ Check if analysis is finished - if not, reload page """ if not sel.is_displayed(tasks.tasks_table) or not tabs.is_tab_selected( 'All Other Tasks'): sel.force_navigate('tasks_all_other') host_analysis_finished = tasks.tasks_table.find_row_by_cells({ 'task_name': "SmartState Analysis for '{}'".format(host_name), 'state': 'Finished' }) return host_analysis_finished is not None wait_for(is_host_analysis_finished, delay=15, num_sec=480, fail_func=lambda: tb.select('Reload')) # Delete the task tasks.tasks_table.select_row_by_cells({ 'task_name': "SmartState Analysis for '{}'".format(host_name), 'state': 'Finished' }) tb.select('Delete Tasks', 'Delete', invokes_alert=True) sel.handle_alert() # Check results of the analysis # This is done on purpose; we cannot use the "bug" fixture here as # the bug doesnt block streams other than 5.3 services_bug = BZ(1156028) if provider.type == "rhevm" and (not services_bug.data.is_opened): soft_assert( test_host.get_detail('Configuration', 'Services') != '0', 'No services found in host detail') if host_type in ('rhel', 'rhev'): soft_assert( test_host.get_detail('Security', 'Users') != '0', 'No users found in host detail') soft_assert( test_host.get_detail('Security', 'Groups') != '0', 'No groups found in host detail') soft_assert( test_host.get_detail('Configuration', 'Packages') != '0', 'No packages found in host detail') elif host_type in ('esx', 'esxi'): soft_assert( test_host.get_detail('Configuration', 'Advanced Settings') != '0', 'No advanced settings found in host detail') fw_bug = bug(1055657) if not (fw_bug is not None and provider.type == "virtualcenter" and provider.version < "5"): # If the Firewall Rules are 0, the element can't be found (it's not a link) try: # This fails for vsphere4... https://bugzilla.redhat.com/show_bug.cgi?id=1055657 list_acc.select('Security', 'Show the firewall rules on this Host') except ListAccordionLinkNotFound: # py.test's .fail would wipe the soft_assert data soft_assert( False, "No firewall rules found in host detail accordion")
def test_run_host_analysis(request, provider_key, host_type, host_name, register_event, soft_assert): """ Run host SmartState analysis """ # Add credentials to host host_data = get_host_data_by_name(provider_key, host_name) test_host = host.Host(name=host_name) wait_for(lambda: test_host.exists, delay=10, num_sec=120, fail_func=sel.refresh) if not test_host.has_valid_credentials: test_host.update( updates={ 'credentials': host.get_credentials_from_config(host_data['credentials']) }) wait_for(lambda: test_host.has_valid_credentials, delay=10, num_sec=120, fail_func=sel.refresh) # Remove creds after test def test_host_remove_creds(): test_host.update( updates={ 'credentials': host.Host.Credential( principal="", secret="", verify_secret="") }) request.addfinalizer(test_host_remove_creds) register_event(None, "host", host_name, ["host_analysis_request", "host_analysis_complete"]) # Initiate analysis sel.force_navigate('infrastructure_host', context={'host': test_host}) tb.select('Configuration', 'Perform SmartState Analysis', invokes_alert=True) sel.handle_alert() flash.assert_message_contain( '"{}": Analysis successfully initiated'.format(host_name)) # Wait for the task to finish def is_host_analysis_finished(): """ Check if analysis is finished - if not, reload page """ if not sel.is_displayed(tasks.tasks_table) or not tabs.is_tab_selected( 'All Other Tasks'): sel.force_navigate('tasks_all_other') host_analysis_finished = tasks.tasks_table.find_row_by_cells({ 'task_name': "SmartState Analysis for '{}'".format(host_name), 'state': 'Finished' }) return host_analysis_finished is not None wait_for(is_host_analysis_finished, delay=10, num_sec=120, fail_func=lambda: tb.select('Reload')) # Delete the task tasks.tasks_table.select_row_by_cells({ 'task_name': "SmartState Analysis for '{}'".format(host_name), 'state': 'Finished' }) tb.select('Delete Tasks', 'Delete', invokes_alert=True) sel.handle_alert() # Check results of the analysis soft_assert( test_host.get_detail('Configuration', 'Services') != '0', 'No services found in host detail') if host_type in ('rhel', 'rhev'): soft_assert( test_host.get_detail('Security', 'Users') != '0', 'No users found in host detail') soft_assert( test_host.get_detail('Security', 'Groups') != '0', 'No groups found in host detail') soft_assert( test_host.get_detail('Configuration', 'Packages') != '0', 'No packages found in host detail') elif host_type in ('esx', 'esxi'): soft_assert( test_host.get_detail('Configuration', 'Advanced Settings') != '0', 'No advanced settings found in host detail') # If the Firewall Rules are 0, the element can't be found (it's not a link) try: # This fails for vsphere4... https://bugzilla.redhat.com/show_bug.cgi?id=1055657 list_acc.select('Security', 'Show the firewall rules on this Host') except ListAccordionLinkNotFound: # py.test's .fail would wipe the soft_assert data soft_assert(False, "No firewall rules found in host detail accordion")
def test_run_host_analysis(request, setup_provider, provider, host_type, host_name, register_event, soft_assert, bug): """ Run host SmartState analysis Metadata: test_flag: host_analysis """ # Add credentials to host host_data = get_host_data_by_name(provider.key, host_name) test_host = host.Host(name=host_name) wait_for(lambda: test_host.exists, delay=10, num_sec=120) if not test_host.has_valid_credentials: with update(test_host): test_host.credentials = host.get_credentials_from_config( host_data['credentials']) wait_for(lambda: test_host.has_valid_credentials, delay=10, num_sec=120) # Remove creds after test @request.addfinalizer def _host_remove_creds(): with update(test_host): test_host.credentials = host.Host.Credential(principal="", secret="", verify_secret="") register_event(None, "host", host_name, ["host_analysis_request", "host_analysis_complete"]) # Initiate analysis test_host.run_smartstate_analysis() wait_for(lambda: is_host_analysis_finished(host_name), delay=15, timeout="10m", fail_func=lambda: toolbar.select('Reload')) # Check results of the analysis drift_history = test_host.get_detail('Relationships', 'Drift History') soft_assert(drift_history != '0', 'No drift history change found') if provider.type == "rhevm": soft_assert( test_host.get_detail('Configuration', 'Services') != '0', 'No services found in host detail') if host_type in ('rhel', 'rhev'): soft_assert( InfoBlock.text('Security', 'Users') != '0', 'No users found in host detail') soft_assert( InfoBlock.text('Security', 'Groups') != '0', 'No groups found in host detail') soft_assert( InfoBlock.text('Security', 'SSH Root') != '', 'No packages found in host detail') soft_assert( InfoBlock.text('Configuration', 'Packages') != '0', 'No packages found in host detail') soft_assert( InfoBlock.text('Configuration', 'Files') != '0', 'No files found in host detail') soft_assert( InfoBlock.text('Security', 'Firewall Rules') != '0', 'No firewall rules found in host detail') elif host_type in ('esx', 'esxi'): soft_assert( InfoBlock.text('Configuration', 'Advanced Settings') != '0', 'No advanced settings found in host detail') if not (provider.type == "virtualcenter" and provider.version < "5"): # If the Firewall Rules are 0, the element can't be found (it's not a link) try: # This fails for vsphere4... https://bugzilla.redhat.com/show_bug.cgi?id=1055657 list_acc.select('Security', 'Show the firewall rules on this Host') except ListAccordionLinkNotFound: # py.test's .fail would wipe the soft_assert data soft_assert( False, "No firewall rules found in host detail accordion")
def test_host_drift_analysis(request, setup_provider, provider, host_type, host_name, soft_assert): """Tests host drift analysis Metadata: test_flag: host_drift_analysis """ host_data = get_host_data_by_name(provider.key, host_name) test_host = host.Host(name=host_name) wait_for(lambda: test_host.exists, delay=10, num_sec=120, fail_func=sel.refresh, message="hosts_exists") # get drift history num drift_num_orig = int(test_host.get_detail('Relationships', 'Drift History')) # add credentials to host + finalizer to remove them if not test_host.has_valid_credentials: test_host.update( updates={'credentials': host.get_credentials_from_config(host_data['credentials'])} ) wait_for( lambda: test_host.has_valid_credentials, delay=10, num_sec=120, fail_func=sel.refresh, message="has_valid_credentials" ) def test_host_remove_creds(): test_host.update( updates={ 'credentials': host.Host.Credential( principal="", secret="", verify_secret="" ) } ) request.addfinalizer(test_host_remove_creds) # initiate 1st analysis test_host.run_smartstate_analysis() # wait for for drift history num+1 wait_for( lambda: int(test_host.get_detail('Relationships', 'Drift History')) == drift_num_orig + 1, delay=20, num_sec=120, message="Waiting for Drift History count to increase", fail_func=sel.refresh ) # add a tag and a finalizer to remove it tag = ('Department', 'Accounting') test_host.tag(tag, single_value=False) request.addfinalizer(lambda: test_host.untag(tag)) # initiate 2nd analysis test_host.run_smartstate_analysis() # wait for for drift history num+2 wait_for( lambda: int(test_host.get_detail('Relationships', 'Drift History')) == drift_num_orig + 2, delay=20, num_sec=120, message="Waiting for Drift History count to increase", fail_func=sel.refresh ) # check drift difference soft_assert(not test_host.equal_drift_results('Department (1)', 'My Company Tags', 0, 1), "Drift analysis results are equal when they shouldn't be") # Test UI features that modify the drift grid d_grid = DriftGrid() # Accounting tag should not be displayed, because it was changed to True tb.select("Attributes with same values") with error.expected(sel.NoSuchElementException): d_grid.get_cell('Accounting', 0) # Accounting tag should be displayed now tb.select("Attributes with different values") d_grid.get_cell('Accounting', 0)
def test_ssa_template(request, local_setup_provider, provider, soft_assert, vm_analysis_data): """ Tests SSA can be performed on a template Metadata: test_flag: vm_analysis """ template_name = vm_analysis_data['image'] template = Template.factory(template_name, provider, template=True) # Set credentials to all hosts set for this datastore if provider.type in ['virtualcenter', 'rhevm']: datastore_name = vm_analysis_data['datastore'] test_datastore = datastore.Datastore(datastore_name, provider.key) host_list = cfme_data.get('management_systems', {})[provider.key].get('hosts', []) host_names = test_datastore.get_hosts() for host_name in host_names: test_host = host.Host(name=host_name, provider=provider) hosts_data = [x for x in host_list if x.name == host_name] if len(hosts_data) > 0: host_data = hosts_data[0] if not test_host.has_valid_credentials: creds = host.get_credentials_from_config( host_data['credentials']) test_host.update(updates={'credentials': creds}, validate_credentials=True) template.smartstate_scan() wait_for(lambda: is_vm_analysis_finished(template_name), delay=15, timeout="35m", fail_func=lambda: toolbar.select('Reload')) # Check release and quadricon quadicon_os_icon = template.find_quadicon().os details_os_icon = template.get_detail(properties=('Properties', 'Operating System'), icon_href=True) logger.info("Icons: {}, {}".format(details_os_icon, quadicon_os_icon)) # We shouldn't use get_detail anymore - it takes too much time c_users = InfoBlock.text('Security', 'Users') c_groups = InfoBlock.text('Security', 'Groups') c_packages = 0 if vm_analysis_data['fs-type'] not in ['ntfs', 'fat32']: c_packages = InfoBlock.text('Configuration', 'Packages') logger.info("SSA shows {} users, {} groups and {} packages".format( c_users, c_groups, c_packages)) if vm_analysis_data['fs-type'] not in ['ntfs', 'fat32']: soft_assert(c_users != '0', "users: '{}' != '0'".format(c_users)) soft_assert(c_groups != '0', "groups: '{}' != '0'".format(c_groups)) soft_assert(c_packages != '0', "packages: '{}' != '0'".format(c_packages)) else: # Make sure windows-specific data is not empty c_patches = InfoBlock.text('Security', 'Patches') c_applications = InfoBlock.text('Configuration', 'Applications') c_win32_services = InfoBlock.text('Configuration', 'Win32 Services') c_kernel_drivers = InfoBlock.text('Configuration', 'Kernel Drivers') c_fs_drivers = InfoBlock.text('Configuration', 'File System Drivers') soft_assert(c_patches != '0', "patches: '{}' != '0'".format(c_patches)) soft_assert(c_applications != '0', "applications: '{}' != '0'".format(c_applications)) soft_assert(c_win32_services != '0', "win32 services: '{}' != '0'".format(c_win32_services)) soft_assert(c_kernel_drivers != '0', "kernel drivers: '{}' != '0'".format(c_kernel_drivers)) soft_assert(c_fs_drivers != '0', "fs drivers: '{}' != '0'".format(c_fs_drivers))
def test_run_datastore_analysis(request, setup_provider, provider, datastore, soft_assert): """Tests smarthost analysis Metadata: test_flag: datastore_analysis """ # Check if there is a host with valid credentials host_names = datastore.get_hosts() assert len(host_names) != 0, "No hosts attached to this datastore found" for host_name in host_names: host_qi = Quadicon(host_name, 'host') if 'checkmark' in host_qi.creds: break else: # If not, get credentials for one of the present hosts found_host = False for host_name in host_names: host_data = get_host_data_by_name(provider.key, host_name) if host_data is None: continue found_host = True test_host = host.Host(name=host_name) # Add them to the host wait_for(lambda: test_host.exists, delay=10, num_sec=120, fail_func=sel.refresh) if not test_host.has_valid_credentials: test_host.update( updates={ 'credentials': host.get_credentials_from_config( host_data['credentials']) }) wait_for(lambda: test_host.has_valid_credentials, delay=10, num_sec=120, fail_func=sel.refresh) # And remove them again when the test is finished def test_host_remove_creds(): test_host.update( updates={ 'credentials': host.Host.Credential( principal="", secret="", verify_secret="") }) request.addfinalizer(test_host_remove_creds) break assert found_host,\ "No credentials found for any of the hosts attached to datastore {}"\ .format(datastore.name) # TODO add support for events # register_event( # None, # "datastore", # datastore_name, # ["datastore_analysis_request_req", "datastore_analysis_complete_req"] # ) # Initiate analysis datastore.run_smartstate_analysis() wait_for(lambda: is_datastore_analysis_finished(datastore.name), delay=15, timeout="10m", fail_func=lambda: toolbar.select('Reload')) c_datastore = datastore.get_detail('Properties', 'Datastore Type') # Check results of the analysis and the datastore type soft_assert( c_datastore == datastore.type.upper(), 'Datastore type does not match the type defined in yaml:' + 'expected "{}" but was "{}"'.format(datastore.type.upper(), c_datastore)) for row_name in CONTENT_ROWS_TO_CHECK: value = InfoBlock('Content', row_name).text soft_assert(value != '0', 'Expected value for {} to be non-empty'.format(row_name))
def test_workload_smartstate_analysis(appliance, request, scenario): """Runs through provider based scenarios initiating smart state analysis against VMs, Hosts, and Datastores""" from_ts = int(time.time() * 1000) logger.debug('Scenario: {}'.format(scenario['name'])) appliance.install_vddk() appliance.clean_appliance() quantifiers = {} scenario_data = {'appliance_ip': appliance.hostname, 'appliance_name': cfme_performance['appliance']['appliance_name'], 'test_dir': 'workload-ssa', 'test_name': 'SmartState Analysis', 'appliance_roles': ', '.join(roles_smartstate), 'scenario': scenario} monitor_thread = SmemMemoryMonitor(appliance.ssh_client(), scenario_data) def cleanup_workload(scenario, from_ts, quantifiers, scenario_data): starttime = time.time() to_ts = int(starttime * 1000) g_urls = get_scenario_dashboard_urls(scenario, from_ts, to_ts) logger.debug('Started cleaning up monitoring thread.') monitor_thread.grafana_urls = g_urls monitor_thread.signal = False monitor_thread.join() add_workload_quantifiers(quantifiers, scenario_data) timediff = time.time() - starttime logger.info('Finished cleaning up monitoring thread in {}'.format(timediff)) request.addfinalizer(lambda: cleanup_workload(scenario, from_ts, quantifiers, scenario_data)) monitor_thread.start() appliance.wait_for_miq_server_workers_started(poll_interval=2) appliance.update_server_roles({role: True for role in roles_smartstate}) for provider in scenario['providers']: get_crud(provider).create_rest() logger.info('Sleeping for Refresh: {}s'.format(scenario['refresh_sleep_time'])) time.sleep(scenario['refresh_sleep_time']) # Add host credentials and set CFME relationship for RHEVM SSA for provider in scenario['providers']: for api_host in appliance.rest_api.collections.hosts.all: test_host = host.Host(name=api_host.name, provider=provider) host_data = get_host_data_by_name(get_crud(provider), api_host.name) credentials = host.get_credentials_from_config(host_data['credentials']) test_host.update_credentials_rest(credentials) appliance.set_cfme_server_relationship(cfme_performance['appliance']['appliance_name']) # Variable amount of time for SmartState Analysis workload total_time = scenario['total_time'] starttime = time.time() time_between_analyses = scenario['time_between_analyses'] total_scanned_vms = 0 while ((time.time() - starttime) < total_time): start_ssa_time = time.time() for vm in scenario['vms_to_scan'].values()[0]: vm_api = appliance.rest_api.collections.vms.get(name=vm) vm_api.action.scan() total_scanned_vms += 1 iteration_time = time.time() ssa_time = round(iteration_time - start_ssa_time, 2) elapsed_time = iteration_time - starttime logger.debug('Time to Queue SmartState Analyses: {}'.format(ssa_time)) logger.info('Time elapsed: {}/{}'.format(round(elapsed_time, 2), total_time)) if ssa_time < time_between_analyses: wait_diff = time_between_analyses - ssa_time time_remaining = total_time - elapsed_time if (time_remaining > 0 and time_remaining < time_between_analyses): time.sleep(time_remaining) elif time_remaining > 0: time.sleep(wait_diff) else: logger.warn('Time to Queue SmartState Analyses ({}) exceeded time between ' '({})'.format(ssa_time, time_between_analyses)) quantifiers['Elapsed_Time'] = round(time.time() - starttime, 2) quantifiers['Queued_VM_Scans'] = total_scanned_vms logger.info('Test Ending...')
def test_run_datastore_analysis(request, provider_key, datastore_type, datastore_name): """ Run host SmartState analysis """ test_datastore = datastore.Datastore(datastore_name, provider_key) # Check if there is a host with valid credentials host_qis = test_datastore.get_hosts() assert len(host_qis) != 0, "No hosts attached to this datastore found" for host_qi in host_qis: if host_qi.creds == 'checkmark': break else: # If not, get credentials for one of the present hosts found_host = False for host_qi in host_qis: host_data = get_host_data_by_name(provider_key, host_qi._name) if host_data is None: continue found_host = True test_host = host.Host(name=host_qi._name) # Add them to the host wait_for(lambda: test_host.exists, delay=10, num_sec=120, fail_func=sel.refresh) if not test_host.has_valid_credentials: test_host.update( updates={ 'credentials': host.get_credentials_from_config( host_data['credentials']) }) wait_for(lambda: test_host.has_valid_credentials, delay=10, num_sec=120, fail_func=sel.refresh) # And remove them again when the test is finished def test_host_remove_creds(): test_host.update( updates={ 'credentials': host.Host.Credential( principal="", secret="", verify_secret="") }) request.addfinalizer(test_host_remove_creds) break assert found_host,\ "No credentials found for any of the hosts attached to datastore {}"\ .format(datastore_name) # TODO add support for events # register_event( # None, # "datastore", # datastore_name, # ["datastore_analysis_request_req", "datastore_analysis_complete_req"] # ) # Initiate analysis sel.force_navigate('infrastructure_datastore', context={ 'datastore': test_datastore, 'provider': test_datastore.provider }) tb.select('Configuration', 'Perform SmartState Analysis', invokes_alert=True) sel.handle_alert() flash.assert_message_contain( '"{}": scan successfully initiated'.format(datastore_name)) # Wait for the task to finish def is_datastore_analysis_finished(): """ Check if analysis is finished - if not, reload page """ if not sel.is_displayed(tasks.tasks_table) or not tabs.is_tab_selected( 'All Other Tasks'): sel.force_navigate('tasks_all_other') host_analysis_finished = tasks.tasks_table.find_row_by_cells({ 'task_name': "SmartState Analysis for [{}]".format(datastore_name), 'state': 'Finished' }) return host_analysis_finished is not None wait_for(is_datastore_analysis_finished, delay=10, num_sec=300, fail_func=lambda: tb.select('Reload')) # Delete the task tasks.tasks_table.select_row_by_cells({ 'task_name': "SmartState Analysis for [{}]".format(datastore_name), 'state': 'Finished' }) tb.select('Delete Tasks', 'Delete', invokes_alert=True) sel.handle_alert() # Check results of the analysis and the datastore type assert test_datastore.get_detail('Properties', 'Datastore Type') == datastore_type.upper(),\ 'Datastore type does not match the type defined in yaml' for row_name in CONTENT_ROWS_TO_CHECK: assert test_datastore.get_detail('Content', row_name) != '0',\ '{} in Content infoblock should not be 0'.format(row_name)
def test_host_drift_analysis(request, setup_provider, provider, host_type, host_name, soft_assert): """Tests host drift analysis Metadata: test_flag: host_drift_analysis """ host_data = get_host_data_by_name(provider.key, host_name) test_host = host.Host(name=host_name) wait_for(lambda: test_host.exists, delay=10, num_sec=120, fail_func=sel.refresh, message="hosts_exists") # get drift history num drift_num_orig = int(test_host.get_detail('Relationships', 'Drift History')) # add credentials to host + finalizer to remove them if not test_host.has_valid_credentials: test_host.update(updates={ 'credentials': host.get_credentials_from_config(host_data['credentials']) }, validate_credentials=True) @request.addfinalizer def test_host_remove_creds(): test_host.update( updates={ 'credentials': host.Host.Credential( principal="", secret="", verify_secret="") }) # initiate 1st analysis test_host.run_smartstate_analysis() # Wait for the task to finish def is_host_analysis_finished(): """ Check if analysis is finished - if not, reload page """ if not sel.is_displayed(tasks.tasks_table) or not tabs.is_tab_selected( 'All Other Tasks'): sel.force_navigate('tasks_all_other') host_analysis_finished = tasks.tasks_table.find_row_by_cells({ 'task_name': "SmartState Analysis for '{}'".format(host_name), 'state': 'Finished' }) if host_analysis_finished: # Delete the task tasks.tasks_table.select_row_by_cells({ 'task_name': "SmartState Analysis for '{}'".format(host_name), 'state': 'Finished' }) tb.select('Delete Tasks', 'Delete', invokes_alert=True) sel.handle_alert() return host_analysis_finished is not None wait_for(is_host_analysis_finished, delay=15, timeout="8m", fail_func=lambda: tb.select('Reload')) # wait for for drift history num+1 wait_for(lambda: int(test_host.get_detail('Relationships', 'Drift History') ) == drift_num_orig + 1, delay=20, num_sec=120, message="Waiting for Drift History count to increase", fail_func=sel.refresh) # add a tag and a finalizer to remove it tag = ('Department', 'Accounting') test_host.tag(tag, single_value=False) request.addfinalizer(lambda: test_host.untag(tag)) # initiate 2nd analysis test_host.run_smartstate_analysis() # Wait for the task to finish wait_for(is_host_analysis_finished, delay=15, timeout="8m", fail_func=lambda: tb.select('Reload')) # wait for for drift history num+2 wait_for(lambda: int(test_host.get_detail('Relationships', 'Drift History') ) == drift_num_orig + 2, delay=20, num_sec=120, message="Waiting for Drift History count to increase", fail_func=sel.refresh) # check drift difference soft_assert( not test_host.equal_drift_results('Department (1)', 'My Company Tags', 0, 1), "Drift analysis results are equal when they shouldn't be") # Test UI features that modify the drift grid d_grid = DriftGrid() # Accounting tag should not be displayed, because it was changed to True tb.select("Attributes with same values") with error.expected(sel.NoSuchElementException): d_grid.get_cell('Accounting', 0) # Accounting tag should be displayed now tb.select("Attributes with different values") d_grid.get_cell('Accounting', 0)