def run_smartstate_analysis(self, wait_for_task_result=False): """ Runs smartstate analysis on this host Note: The host must have valid credentials already set up for this to work. """ view = navigate_to(self, 'DetailsFromProvider') try: wait_for(lambda: view.toolbar.configuration.item_enabled( 'Perform SmartState Analysis'), fail_condition=False, num_sec=10) except TimedOutError: raise MenuItemNotFound( 'Smart State analysis is disabled for this datastore') view.toolbar.configuration.item_select('Perform SmartState Analysis', handle_alert=True) view.flash.assert_success_message(('"{}": scan successfully ' 'initiated'.format(self.name))) if wait_for_task_result: view = self.appliance.browser.create_view(TasksView) wait_for(lambda: is_datastore_analysis_finished(self.name), delay=15, timeout="15m", fail_func=view.reload.click)
def run_smartstate_analysis(self, wait_for_task_result=False): """ Runs smartstate analysis on this host Note: The host must have valid credentials already set up for this to work. """ view = navigate_to(self, 'DetailsFromProvider') try: wait_for(lambda: view.toolbar.configuration.item_enabled('Perform SmartState Analysis'), fail_condition=False, num_sec=10) except TimedOutError: raise MenuItemNotFound('Smart State analysis is disabled for this datastore') view.toolbar.configuration.item_select('Perform SmartState Analysis', handle_alert=True) view.flash.assert_success_message(('"{}": scan successfully ' 'initiated'.format(self.name))) if wait_for_task_result: view = self.appliance.browser.create_view(TasksView) wait_for(lambda: is_datastore_analysis_finished(self.name), delay=15, timeout="15m", fail_func=view.reload.click)
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_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_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))