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 setup_host_creds(provider, host_name, remove_creds=False, ignore_errors=False): try: appliance = provider.appliance host_data = get_host_data_by_name(provider.key, host_name) if host_data is None: raise ValueError( 'There is no {} host entry for provider {}!'.format( host_name, provider.key)) test_host_collection = appliance.collections.hosts test_host = test_host_collection.instantiate(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: if not ignore_errors: raise
def set_host_credentials(appliance, request, provider, vm_analysis_data): # Add credentials to host host_collection = appliance.collections.hosts test_host = host_collection.instantiate(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 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: %s", 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 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_host_bad_creds(appliance, request, setup_provider, provider, creds): """ Tests host credentialing with bad credentials Steps: 1) Add Host credentials 2) Validate + Save bad credentials 3) Verify invalid creds on Host Details page Metadata: test_flag: inventory """ test_host = random.choice(provider.data["hosts"]) host_data = get_host_data_by_name(provider.key, test_host.name) host_collection = appliance.collections.hosts host_obj = host_collection.instantiate(name=test_host.name, provider=provider) flash_msg = msgs.get(provider.type) with pytest.raises(Exception, match=flash_msg): with update(host_obj, validate_credentials=True): host_obj.credentials = { creds: host.get_credentials_from_config('bad_credentials') } # TODO Remove this workaround once our SCVMM env will work with common DNS if provider.one_of(SCVMMProvider): host_obj.hostname = host_data['ipaddress'] # Checking that we can save invalid creds and get proper credentials state in Host Details page edit_view = appliance.browser.create_view(HostEditView) edit_view.save_button.click() # Remove creds after test @request.addfinalizer def _host_remove_creds(): with update(host_obj): host_obj.credentials = { creds: host.Host.Credential(principal="", secret="", verify_secret="") } def _refresh(): view = appliance.browser.create_view(HostDetailsView) view.browser.refresh() try: creds_value = view.entities.summary( 'Authentication Status').get_text_of(credentials_type[creds]) except NameError: return 'None' return creds_value wait_for(lambda: _refresh() in ['Error', 'Invalid'], num_sec=180, delay=15, message='Waiting for \'{}\' state change'.format( credentials_type[creds]))
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_host_bad_creds(appliance, request, setup_provider, provider): """ Tests host credentialing with bad credentials """ test_host = random.choice(provider.data["hosts"]) host_collection = appliance.collections.hosts host_obj = host_collection.instantiate(name=test_host.name, provider=provider) 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_host_good_creds(appliance, request, setup_provider, provider, creds): """ Tests host credentialing with good credentials Steps: 1) Add Host credentials 2) Validate + Save 3) Verify Valid creds on Host Details page Metadata: test_flag: inventory """ test_host = random.choice(provider.data["hosts"]) host_data = get_host_data_by_name(provider.key, test_host.name) host_collection = appliance.collections.hosts host_obj = host_collection.instantiate(name=test_host.name, provider=provider) # Remove creds after test @request.addfinalizer def _host_remove_creds(): with update(host_obj): host_obj.credentials = { creds: host.Host.Credential(principal="", secret="", verify_secret="") } with update(host_obj, validate_credentials=True): host_obj.credentials = { creds: host.get_credentials_from_config(host_data['credentials']) } # TODO Remove this workaround once our SCVMM env will work with common DNS if provider.one_of(SCVMMProvider): host_obj.hostname = host_data['ipaddress'] def _refresh(): view = appliance.browser.create_view(HostDetailsView) view.browser.refresh() try: creds_value = view.entities.summary( 'Authentication Status').get_text_of(credentials_type[creds]) except NameError: return 'None' return creds_value wait_for(lambda: _refresh() == 'Valid', num_sec=180, delay=15, message='Waiting for \'{}\' state change'.format( credentials_type[creds]))
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 test_host_bad_creds(appliance, request, setup_provider, provider): """ Tests host credentialing with bad credentials Metadata: test_flag: inventory """ test_host = random.choice(provider.data["hosts"]) host_collection = appliance.collections.hosts host_obj = host_collection.instantiate(name=test_host.name, provider=provider) with pytest.raises(Exception, match=msgs[provider.type]): with update(host_obj, validate_credentials=True): host_obj.credentials = host.get_credentials_from_config( 'bad_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 datastores_hosts_setup(provider, datastore, request, appliance): # Check if there is a host with valid credentials host_entities = datastore.get_hosts() assert len(host_entities) != 0, "No hosts attached to this datastore found" for host_entity in host_entities: if 'checkmark' in host_entity.data['creds']: continue # If not, get credentials for one of the present hosts host_data = hosts.get_host_data_by_name(provider.key, host_entity.name) if host_data is None: continue host_collection = appliance.collections.hosts test_host = host_collection.instantiate(name=host_entity.name, provider=provider) test_host.update_credentials_rest( credentials=get_credentials_from_config(host_data.credentials)) request.addfinalizer(lambda: test_host.update_credentials_rest( credentials=Host.Credential(principal="", secret="")))
def test_host_good_creds(appliance, request, setup_provider, provider): """ Tests host credentialing with good credentials """ test_host = random.choice(provider.data["hosts"]) host_data = get_host_data_by_name(provider.key, test_host.name) host_collection = appliance.collections.hosts host_obj = host_collection.instantiate(name=test_host.name, provider=provider) # 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 set_host_credentials(request, provider, vm_analysis_data): # Add credentials to host test_host = host.Host(name=vm_analysis_data["host"]) 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] 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 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 setup_host_creds(provider, host_name, remove_creds=False, ignore_errors=False): try: appliance = provider.appliance host_data = get_host_data_by_name(provider.key, host_name) if host_data is None: raise ValueError( 'There is no {} host entry for provider {}!'.format(host_name, provider.key)) test_host_collection = appliance.collections.hosts test_host = test_host_collection.instantiate(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: if not ignore_errors: raise
def set_host_credentials(request, provider): # Add credentials to host vm_analysis_new = provider.data['vm_analysis_new'] test_host = host.Host(name=vm_analysis_new['host']) 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_new['host']][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 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, vm_analysis_new, provider): # Add credentials to host test_host = host.Host(name=vm_analysis_new['host']) 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_new['host']][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 set_host_credentials(appliance, request, provider, vm_analysis_data): # Add credentials to host host_collection = appliance.collections.hosts test_host = host_collection.instantiate(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 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(appliance, request, setup_provider, provider, host, soft_assert): """Tests host drift analysis Metadata: test_flag: host_drift_analysis """ host_collection = appliance.collections.hosts test_host = host_collection.instantiate(name=host['name'], provider=provider) wait_for(lambda: test_host.exists, delay=20, num_sec=120, fail_func=appliance.server.browser.refresh, message="hosts_exists") # tabs changed, hack until configure.tasks is refactored for collections and versioned widgets destination = 'AllTasks' if appliance.version >= '5.9' else 'AllOtherTasks' # 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 delete_all_tasks(destination) # 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, destination) host_analysis_row = getattr(view.tabs, destination.lower()).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: test_host.get_detail('Relationships', 'Drift History') == str(drift_num_orig + 1), delay=20, num_sec=120, message="Waiting for Drift History count to increase", fail_func=appliance.server.browser.refresh ) # add a tag and a finalizer to remove it test_host.add_tag(category='Department', tag='Accounting') request.addfinalizer(lambda: test_host.remove_tag(category='Department', tag='Accounting')) # 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: test_host.get_detail('Relationships', 'Drift History') == str(drift_num_orig + 2), delay=20, num_sec=120, message="Waiting for Drift History count to increase", fail_func=appliance.server.browser.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 drift_analysys_view = appliance.browser.create_view(DriftAnalysis) drift_history_view = appliance.browser.create_view(DriftHistory) # Accounting tag should not be displayed, because it was changed to True drift_analysys_view.toolbar.different_values_attributes.click() with error.expected(NoSuchElementException): drift_history_view.history_table.row((0, 'Accounting')) # Accounting tag should be displayed now drift_analysys_view.toolbar.different_values_attributes.click() drift_history_view.history_table.row((0, 'Accounting'))
def test_run_host_analysis( request, setup_provider, provider_key, provider_type, provider_ver, 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 services_bug = bug(1156028) if not (services_bug is not None and provider_type == "rhevm" and provider_ver >= "3.3"): 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_ver < "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'])}, 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)
def test_run_host_analysis(appliance, 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) host_collection = appliance.collections.hosts test_host = host_collection.instantiate(name=host_name, provider=provider) 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(target_type='Host', target_name=host_name, event_type='request_host_scan') register_event(target_type='Host', target_name=host_name, event_type='host_scan_complete') # Initiate analysis test_host.run_smartstate_analysis() wait_for(lambda: is_host_analysis_finished(host_name), delay=15, timeout="10m", fail_func=lambda: reload_tasks_page(appliance)) # 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'): view = navigate_to(test_host, 'Details') # will return list of values if some of them are active accordion_info = view.security_accordion.navigation.read() soft_assert(not accordion_info) soft_assert(test_host.get_detail('Configuration', 'Packages') != '0', 'No packages found in host detail') soft_assert(test_host.get_detail('Configuration', 'Files') != '0', 'No files 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 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 view = navigate_to(test_host, 'Details') view.security_accordion.navigation.select('Firewall Rules') except NoSuchElementException: # 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_key, 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, ) # change host name + finalizer to change it back orig_host_name = test_host.name with update(test_host): test_host.name = "{}_tmp_drift_rename".format(test_host.name) def host_reset_name(): with update(test_host): test_host.name = orig_host_name request.addfinalizer(host_reset_name) # 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("All Sections", 0, 1), "Drift analysis results are equal when they shouldn't be", ) # Test UI features that modify the drift grid d_grid = DriftGrid() # Name should not be displayed, because it was changed tb.select("Attributes with same values") with error.expected(sel.NoSuchElementException): d_grid.get_cell("Name", 0) # Name should be displayed now tb.select("Attributes with different values") d_grid.get_cell("Name", 0)
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_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)
def test_run_datastore_analysis(appliance, request, setup_provider, provider, datastore, soft_assert, has_no_providers): """Tests smarthost analysis Metadata: test_flag: datastore_analysis """ # Check if there is a host with valid credentials host_entities = datastore.get_hosts() assert len(host_entities) != 0, "No hosts attached to this datastore found" for host_entity in host_entities: if 'checkmark' in host_entity.data['creds']: break else: # If not, get credentials for one of the present hosts found_host = False for host_entity in host_entities: host_data = get_host_data_by_name(provider.key, host_entity.name) if host_data is None: continue found_host = True host_collection = appliance.collections.hosts test_host = host_collection.instantiate(name=host_entity.name, provider=provider) # 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="15m", fail_func=lambda: tb.select('Reload the current display')) details_view = navigate_to(datastore, 'Details') c_datastore = details_view.entities.properties.get_text_of( "Datastores 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_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_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, setup_provider, provider, datastore_type, datastore_name, soft_assert): """Tests smarthost analysis Metadata: test_flag: datastore_analysis """ test_datastore = datastore.Datastore(datastore_name, provider.key) # Check if there is a host with valid credentials host_names = test_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 host_qi.creds == 'checkmark': 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 test_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 = test_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_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_run_host_analysis(request, setup_provider, provider_key, provider_type, provider_ver, host_type, host_name, register_event, soft_assert): """ 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 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_datastore_analysis(request, setup_provider, provider_key, provider_type, datastore_type, datastore_name): """Tests smarthost analysis Metadata: test_flag: datastore_analysis """ test_datastore = datastore.Datastore(datastore_name, provider_key) # Check if there is a host with valid credentials host_names = test_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 host_qi.creds == 'checkmark': 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 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_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, 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 the task to finish @pytest.wait_for(delay=15, timeout="8m", fail_func=lambda: tb.select('Reload')) 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 # 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 drift_history = test_host.get_detail('Relationships', 'Drift History') soft_assert(drift_history != '0', 'No drift history change found') # 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, forced_streams=["5.3", "5.4", "5.5", "upstream"]) if provider.type == "rhevm" and (not services_bug.blocks): 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') if not BZ(1055657, forced_streams=["5.4", "5.5", "upstream"]).blocks: 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') 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_ssa_template(request, local_setup_provider, provider, soft_assert, vm_analysis_data, appliance): """ 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'] datastore_collection = appliance.collections.datastores test_datastore = datastore_collection.instantiate(name=datastore_name, provider=provider) host_list = cfme_data.get('management_systems', {})[provider.key].get('hosts', []) host_names = [h.name for h in test_datastore.get_hosts()] for host_name in host_names: host_collection = appliance.collections.hosts test_host = host_collection.instantiate(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().data['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_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_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_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, provider=provider) 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="") builder = EventBuilder(get_or_create_current_appliance()) base_evt = partial(builder.new_event, target_type='Host', target_name=host_name) register_event(base_evt(event_type='request_host_scan'), base_evt(event_type='host_scan_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 != 'openstack': 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) 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="10m", 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_workload_smartstate_analysis(appliance, request, scenario): """Runs through provider based scenarios initiating smart state analysis against VMs, Hosts, and Datastores Polarion: assignee: rhcf3_machine initialEstimate: 1/4h """ 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: host_collection = appliance.collections.hosts test_host = host_collection.instantiate(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...')