def test_A_create_new_email_action(self): u""" Create a new alert action using eMail command and check that create ok """ logging.basicConfig(filename="Alerts.log", level=logging.INFO, filemode='w') action_name = gen_random_string(6) driver = self.driver self.login() detect_and_pass_all_wizards(driver) create_new_action_to_alert(driver, action_name, "Applications", "eMail", field1="*****@*****.**", field2="Test", field3="This is a test") element = driver.find_element_by_xpath( '//td[contains(.,"Successfully created")]') self.assertIsInstance(element, WebElement) click_menu_element(driver, "Actions") element = driver.find_element_by_xpath('//a[contains(.,"' + action_name + '")]') self.assertIsInstance(element, WebElement) logging.info("test_A_create_new_email_action is correct")
def test_create_ICMP_module(self): u""" Creates a simple ICMP check against localhost and checks the result is 1 """ driver = self.driver self.login() detect_and_pass_all_wizards(driver) create_agent(driver,"PAN3_agent",ip="127.0.0.1") create_module("network_server",driver,agent_name="PAN3_agent",module_name="PAN3_module",component_group="Network Management",network_component="Host Alive",ip="127.0.0.1") driver.find_element_by_xpath('//*[@id="menu_tab"]//a[contains(@href,"ver_agente")]').click() max_retries = 3 i = 1 element_text = "" while (i <= max_retries): # Temporary workaround to weird StaleElementReferenceException exceptions due Javascript altering the DOM try: element_text = refresh_N_times_until_find_element(driver,5,"table1-1-7",how=By.ID).text self.assertEqual("1", element_text.lstrip().rstrip()) # The lstrip.rstrip is done because if not, this error is raised: "'1' != u'1 '" break except StaleElementReferenceException as e_stale: i = i+1 if i > max_retries: self.verificationErrors.append(str(e_stale)) break else: next except AssertionError as e: self.verificationErrors.append(str(e)) break
def atest_A_create_planned_downtime_Quiet(self): u""" Create and search planned downtime quiet """ logging.basicConfig(filename="Planned_downtime.log", level=logging.INFO, filemode='w') driver = self.driver self.login() detect_and_pass_all_wizards(driver) planned_name = gen_random_string(6) create_planned_downtime(driver, planned_name, "Applications", "Quiet", "Once", description=planned_name) time.sleep(10) search_planned_downtime(driver, planned_name) element = driver.find_element_by_xpath('//img[@data-title="Running"]') self.assertIsInstance(element, WebElement) logging.info("atest_A_create_planned_downtime_Quiet is correct")
def test_A_home_screen(self): u""" Modify home screen, and check that change is correct. Return this change """ logging.basicConfig(filename="Users.log", level=logging.INFO, filemode='w') driver = self.driver self.login() detect_and_pass_all_wizards(driver) activate_home_screen(driver, "Event list") self.logout() self.login() element = driver.find_element_by_xpath( '//a[contains(.,"Event control filter")]') self.assertIsInstance(element, WebElement) #Return this change activate_home_screen(driver, "Default") logging.info("test_A_home_screen is correct")
def test_japanese_characters(self): u""" Creates an agent and a module with japanese characters and test if the event list show the characters properly """ driver = self.driver self.login() detect_and_pass_all_wizards(driver) create_agent(driver, u"次のライセンスに基づいていま") #Create module create_module("network_server", driver, agent_name=u"次のライセンスに基づいていま", module_name=u"管理者ガイド", component_group="Network Management", network_component="Host Alive", ip="192.168.50.50") #Create alert driver.find_element_by_xpath( '//ul[@class="mn"]/li/a/img[@data-title="Alerts"]').click() Select(driver.find_element_by_id( "id_agent_module")).select_by_visible_text(u"管理者ガイド") Select(driver.find_element_by_id("template")).select_by_visible_text( "Critical condition") Select(driver.find_element_by_id( "action_select")).select_by_visible_text("Default action") driver.find_element_by_id("submit-add").click() #Force alert click_menu_element(driver, "Agent detail") driver.find_element_by_id("text-search").clear() driver.find_element_by_id("text-search").send_keys(u"次のライセンスに基づいていま") driver.find_element_by_id("submit-srcbutton").click() driver.find_element_by_css_selector("b").click() driver.find_element_by_xpath( '//ul[@class="mn"]/li/a/img[@data-title="Alerts"]').click() driver.find_element_by_xpath( '//tr[@id="table2-0"]/td/a/img[@data-title="Force"]').click() time.sleep(10) #Search events of our agent search_events(driver, agent_name=u"次のライセンスに基づいていま", module_name=u"管理者ガイド") #Check that there are japanese characters present on the event element = driver.find_element_by_xpath( u'//a[contains(.,"Alert fired (Critical condition) assigned to (管理者ガイド)")]' ) self.assertIsInstance(element, WebElement)
def test_A_create_network_component(self): u""" Create and search new network component module """ logging.basicConfig(filename="Network_components.log", level=logging.INFO, filemode='w') driver = self.driver self.login() detect_and_pass_all_wizards(driver) agent_name = gen_random_string(6) network_component_name = gen_random_string(6) activate_api(driver,"1234") params = [agent_name,"127.0.0.1","0","4","0","300","2","pandorafms","2","0","0","pruebas"] create_agent_api(driver,params,user="******",pwd="pandora") lista = driver.current_url.split('/') url = lista[0]+'//'+lista[2]+'/pandora_console' driver.get(url) create_network_component(driver,network_component_name,"Remote TCP network agent, boolean data","Network Management","Application",min_warning=10,max_critical=100,description="New network component by test") search_agent(driver,agent_name,go_to_agent=True) driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Manage"]').click() driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Modules"]').click() Select(driver.find_element_by_id("moduletype")).select_by_visible_text("Create a new network server module") driver.find_element_by_xpath('//*[@id="main"]/form/table/tbody/tr/td[5]/input').click() driver.find_element_by_xpath('//a[contains(.,"Advanced options")]').click() Select(driver.find_element_by_id("network_component_group")).select_by_visible_text("Network Management") time.sleep(3) Select(driver.find_element_by_id("network_component")).select_by_visible_text(network_component_name) driver.find_element_by_id("submit-crtbutton").click() search_module (driver,agent_name,network_component_name,go_to_module=False) self.assertEqual(network_component_name in driver.page_source,True) logging.info("test_A_create_network_component is correct")
def test_A_create_policy(self): u""" Create a policy and verify that it is created """ driver = self.driver self.login() detect_and_pass_all_wizards(driver) create_policy(driver,self.policy_name,"Applications",description="Policy for test") search_policy(driver,self.policy_name,go_to_policy=False) element = driver.find_element_by_xpath('//a[contains(.,"'+self.policy_name+'")]') self.assertIsInstance(element,WebElement)
def test_A_create_collection(self): logging.basicConfig(filename="Collections.log", level=logging.INFO, filemode='w') driver = self.driver self.login() detect_and_pass_all_wizards(driver) create_collection(driver,self.collection_name,"PAN11",group="All",description="Collection with PAN11") search_collection(driver,self.collection_name,go_to_collection=False) element = driver.find_element_by_xpath('//a[contains(.,self.collection_name)]') self.assertIsInstance(element,WebElement) logging.info("test_A_create_collection is correct")
def test_A_create_collection(self): driver = self.driver self.login() detect_and_pass_all_wizards(driver) create_collection(driver, self.collection_name, "PAN11", group="All", description="Collection with PAN11") search_collection(driver, self.collection_name, go_to_collection=False) element = driver.find_element_by_xpath( '//a[contains(.,self.collection_name)]') self.assertIsInstance(element, WebElement)
def test_A_home_screen(self): u""" Modify home screen, and check that change is correct. Return this change """ driver = self.driver self.login() detect_and_pass_all_wizards(driver) activate_home_screen(driver,"Event list") self.logout() self.login() element = driver.find_element_by_xpath('//a[contains(.,"Event control filter")]') self.assertIsInstance(element,WebElement) #Return this change activate_home_screen(driver,"Default")
def avoid_test_A_create_planned_downtime_Quiet(self): u""" Create and search planned downtime quiet """ driver = self.driver self.login() detect_and_pass_all_wizards(driver) planned_name = gen_random_string(6) create_planned_downtime(driver, planned_name, "Applications", "Quiet", "Once", description=planned_name) time.sleep(10) search_planned_downtime(driver, planned_name) element = driver.find_element_by_xpath('//img[@data-title="Running"]') self.assertIsInstance(element, WebElement)
def test_ACL_propagation(self): u""" ACL Propagation test: Creates one group "A" with ACL propagation, then a group "B" son of "A" with no ACL propagation, and finally group "C". The test asserts if a user with privileges to "A" can see the agent of "B" but no agents of "C". """ group_name_A = gen_random_string(6) group_name_B = gen_random_string(6) group_name_C = gen_random_string(6) agent_name_A = gen_random_string(6) agent_name_B = gen_random_string(6) user_name = gen_random_string(6) driver = self.driver self.login() detect_and_pass_all_wizards(driver) create_agent_group( driver, group_name_A, propagate_acl=True, description="Group A, with propagate ACL, son of ALL") create_agent_group(driver, group_name_B, parent_group=group_name_A, description="Group B, son of A") create_agent_group(driver, group_name_C, parent_group=group_name_B, description="Group C, son of B") create_agent(driver, agent_name_A, description="Agent in group B", group=group_name_B) create_agent(driver, agent_name_B, description="Agent in group C", group=group_name_C) l = [("Chief Operator", group_name_A, [])] create_user(driver, user_name, "pandora", profile_list=l) self.logout() self.login(user=user_name) detect_and_pass_all_wizards(driver) #Is the agent listed in the agent list? search_agent(driver, agent_name_A, go_to_agent=False) element = driver.find_element_by_xpath('//a[contains(.,"' + agent_name_A + '")]') self.assertIsInstance(element, WebElement) #Is the agent accesible for the user? search_agent(driver, agent_name_A, go_to_agent=True) element = driver.find_element_by_xpath( '//*[@id="agent_contact_main"]/thead/tr/th') self.assertIsInstance(element, WebElement) #Is the agent invisible to the user? (It should be invisible) search_agent(driver, agent_name_B, go_to_agent=False) element = driver.find_elements_by_xpath('//a[contains(.,"' + agent_name_B + '")]') self.assertEqual(element, [])
def test_ACL_tag(self): u"""Create agent and two modules, one without tag and with tag, create a user with tag and check this user can view module with tag and user can´t view module without tag""" agent_name = gen_random_string(6) module_name_A = gen_random_string(6) module_name_B = gen_random_string(6) user_name = gen_random_string(6) driver = self.driver self.login() detect_and_pass_all_wizards(driver) create_agent(driver, agent_name, group="Applications", ip="192.168.50.50") #We create a module without a tag create_module("network_server", driver, agent_name=agent_name, module_name=module_name_A, component_group="Network Management", network_component="Host Alive", ip="192.168.50.50") #We now create a modulo with tag "critical" create_module("network_server", driver, agent_name=agent_name, module_name=module_name_B, component_group="Network Management", network_component="Host Alive", ip="192.168.50.50", tag_name="critical") l = [("Operator (Read)", "All", ["critical"])] create_user(driver, user_name, "pandora", profile_list=l) self.logout() self.login(user=user_name) detect_and_pass_all_wizards(driver) search_agent(driver, agent_name) time.sleep(6) #The user should be able to see the module with Tag module = driver.find_element_by_xpath('//td[contains(.,"' + module_name_B + '")]') self.assertIsInstance(module, WebElement) #The user should NOT be able to see the module without tag modules = driver.find_elements_by_xpath('//td[contains(.,"' + module_name_A + '")]') self.assertEqual(modules, [])
def test_A_simple_service(self): u""" Add 3 modules in Simple service, two critical and one in warning, force service and check that service is warning. """ service_name = gen_random_string(6) driver = self.driver self.login() detect_and_pass_all_wizards(driver) activate_api(driver, "1234") params = [ self.agent_name, "127.0.0.1", "0", "4", "0", "300", "2", "pandorafms", "2", "0", "0", "pruebas" ] create_agent_api(driver, params, user="******", pwd="pandora") # creamos 3 modulos uno que este router ping (127.0.0.3) y otro ping printer (127.0.0.1) y Apache server -> Host latency min_warning 0.01 time.sleep(3) params = [ self.agent_name, self.module_critical_1_name, "0", "6", "1", "0", "0", "0", "0", "0", "0", "0", "0", "129.99.40.1", "0", "0", "180", "0", "0", "0", "0", "Host_Alive" ] add_network_module_to_agent_api(driver, params, user="******", pwd="pandora", apipwd="1234") time.sleep(3) params = [ self.agent_name, self.module_critical_2_name, "0", "6", "1", "0", "0", "0", "0", "0", "0", "0", "0", "129.99.40.1", "0", "0", "180", "0", "0", "0", "0", "Host_Alive" ] add_network_module_to_agent_api(driver, params, user="******", pwd="pandora", apipwd="1234") time.sleep(3) params = [ self.agent_name, self.module_critical_3_name, "0", "6", "1", "0", "0", "0", "0", "0", "0", "0", "0", "129.99.40.1", "0", "0", "180", "0", "0", "0", "0", "Host_Alive" ] add_network_module_to_agent_api(driver, params, user="******", pwd="pandora", apipwd="1234") time.sleep(3) params = [ self.agent_name, self.module_normal_1_name, "0", "6", "1", "0", "0", "0", "0", "0", "0", "0", "0", "127.0.0.1", "0", "0", "180", "0", "0", "0", "0", "Host_Alive" ] add_network_module_to_agent_api(driver, params, user="******", pwd="pandora", apipwd="1234") time.sleep(3) params = [ self.agent_name, self.module_normal_2_name, "0", "6", "1", "0", "0", "0", "0", "0", "0", "0", "0", "127.0.0.1", "0", "0", "180", "0", "0", "0", "0", "Host_Alive" ] add_network_module_to_agent_api(driver, params, user="******", pwd="pandora", apipwd="1234") time.sleep(3) params = [ self.agent_name, self.module_warning_1_name, "0", "7", "1", "-10", "9999", "0", "0", "0", "0", "0", "0", "127.0.0.1", "0", "0", "180", "0", "0", "0", "0", "Host_Latency" ] add_network_module_to_agent_api(driver, params, user="******", pwd="pandora", apipwd="1234") lista = driver.current_url.split('/') url = lista[0] + '//' + lista[2] + '/pandora_console' driver.get(url) #Creamos servicio en modo simple create_service(driver, service_name, "Applications", self.agent_name, description=service_name, mode="simple") # añadimos los 3 modulos al servicio un router y el warning router critico printer no critico y apache critico add_elements_to_service(driver, service_name, "Module", agent_name=self.agent_name, module=self.module_critical_1_name, description=self.module_critical_1_name, is_critical=True) add_elements_to_service(driver, service_name, "Module", agent_name=self.agent_name, module=self.module_critical_2_name, description=self.module_critical_2_name) add_elements_to_service(driver, service_name, "Module", agent_name=self.agent_name, module=self.module_warning_1_name, description=self.module_warning_1_name, is_critical=True) # Forzamos el servicio y comprobamos que el estado es warning force_service(driver, service_name) search_service(driver, service_name, go_to_service=False) element = driver.find_element_by_xpath( '//td/img[@data-title="Warning"]') self.assertIsInstance(element, WebElement)
def test_A_manual_service_ok(self): u""" Creamos agente y modulos necesarios, creamos un servicio de tipo manual para añadirle el modulo OK y al dar valor menor de 0.5 tener el servicio en Ok """ service_name = gen_random_string(6) driver = self.driver self.login() detect_and_pass_all_wizards(driver) activate_api(driver, "1234") #Creamos agentes y modulos warning, critical y ok que usaremos en los 3 test de servicios tipo manual params = [ self.agent_name, "127.0.0.1", "0", "4", "0", "300", "2", "pandorafms", "2", "0", "0", "pruebas" ] create_agent_api(driver, params, user="******", pwd="pandora") params = [ self.agent_name, self.module_critical_1_name, "0", "6", "1", "0", "0", "0", "0", "0", "0", "0", "0", "129.99.40.1", "0", "0", "180", "0", "0", "0", "0", "Host_Alive" ] add_network_module_to_agent_api(driver, params, user="******", pwd="pandora", apipwd="1234") params = [ self.agent_name, self.module_warning_1_name, "0", "7", "1", "-10", "9999", "0", "0", "0", "0", "0", "0", "127.0.0.1", "0", "0", "180", "0", "0", "0", "0", "Host_Latency" ] add_network_module_to_agent_api(driver, params, user="******", pwd="pandora", apipwd="1234") params = [ self.agent_name, self.module_ok_1_name, "0", "6", "1", "0", "0", "0", "0", "0", "0", "0", "0", "127.0.0.1", "0", "0", "180", "0", "0", "0", "0", "Host_Alive" ] add_network_module_to_agent_api(driver, params, user="******", pwd="pandora", apipwd="1234") lista = driver.current_url.split('/') url = lista[0] + '//' + lista[2] + '/pandora_console' driver.get(url) #Creamos el servicio añadiendo modulo en warnining y el servicio será OK create_service(driver, service_name, "Applications", self.agent_name, description=service_name, mode="manual", critical="1", warning="0.5") add_elements_to_service(driver, service_name, "Module", agent_name=self.agent_name, module=self.module_ok_1_name, description=self.module_ok_1_name, ok_weight="0.2") add_elements_to_service(driver, service_name, "Module", agent_name=self.agent_name, module=self.module_warning_1_name, description=self.module_warning_1_name, warning_weight="0.2") force_service(driver, service_name) search_service(driver, service_name, go_to_service=False) element = driver.find_element_by_xpath('//td/img[@data-title="Ok"]') self.assertIsInstance(element, WebElement)
def test_views_metaconsole(self): u""" This test do login in metaconsole and check one by one that all views appear. """ """ logging.basicConfig(filename="ViewsMetaconsole.log", level=logging.INFO, filemode='w') driver = self.driver self.login() detect_and_pass_all_wizards(driver) click_menu_element(driver,"Tree view") time.sleep(2) self.assertEqual("Show Options" in driver.page_source,True) click_menu_element(driver,"Tactical view") time.sleep(2) self.assertEqual("Report of events (1 hours)" in driver.page_source,True) click_menu_element(driver,"Group view") time.sleep(2) self.assertEqual("Summary by status" in driver.page_source,True) click_menu_element(driver,"Alerts view") time.sleep(2) self.assertEqual("Show Options" in driver.page_source,True) click_menu_element(driver,"Monitors view") time.sleep(2) self.assertEqual("Show Options" in driver.page_source,True) click_menu_element(driver,"Wizard") time.sleep(2) click_menu_element(driver,"Events") time.sleep(2) self.assertEqual("Show Options" in driver.page_source,True) click_menu_element(driver,"Create new report") time.sleep(2) self.assertEqual("Main data" in driver.page_source,True) click_menu_element(driver,"Reports") time.sleep(2) self.assertEqual("Show Options" in driver.page_source,True) click_menu_element(driver,"Report templates") time.sleep(2) self.assertEqual("Template name" in driver.page_source,True) click_menu_element(driver,"Templates wizard") time.sleep(2) self.assertEqual("Create template report wizard" in driver.page_source,True) click_menu_element(driver,"Services") time.sleep(2) self.assertEqual("Filter" in driver.page_source,True) click_menu_element(driver,"Network map") time.sleep(2) self.assertEqual("Show Options" in driver.page_source,True) click_menu_element(driver,"Visual Console") time.sleep(2) self.assertEqual("Map name" in driver.page_source,True) click_menu_element(driver,"Live view") time.sleep(2) self.assertEqual("Draw live filter" in driver.page_source,True) click_menu_element(driver,"Live view") time.sleep(2) self.assertEqual("Draw live filter" in driver.page_source,True) click_menu_element(driver,"Filters") time.sleep(2) click_menu_element(driver,"Synchronising") time.sleep(2) self.assertEqual("Synchronizing Users" in driver.page_source,True) click_menu_element(driver,"User management") time.sleep(2) self.assertEqual("Show Options" in driver.page_source,True) click_menu_element(driver,"Agent management") time.sleep(2) self.assertEqual("Source Server" in driver.page_source,True) click_menu_element(driver,"Module management") time.sleep(2) self.assertEqual("Name" in driver.page_source,True) click_menu_element(driver,"Alert management") time.sleep(2) self.assertEqual("Show Options" in driver.page_source,True) click_menu_element(driver,"Event alerts") time.sleep(2) self.assertEqual("Show Options" in driver.page_source,True) click_menu_element(driver,"Component management") time.sleep(2) self.assertEqual("Show Options" in driver.page_source,True) click_menu_element(driver,"Policy management") time.sleep(2) self.assertEqual("Show Options" in driver.page_source,True) click_menu_element(driver,"Cron jobs") time.sleep(2) self.assertEqual("ADD NEW JOB" in driver.page_source,True) logging.info("test_views_appear_metaconsole is correct")