Added downtime tests

This commit is contained in:
cesar991 2016-08-17 17:14:25 +02:00
parent db94436477
commit c5e0e09e9e
6 changed files with 214 additions and 55 deletions

View File

@ -53,14 +53,8 @@ class Miscellaneous (PandoraWebDriverTestCase):
time.sleep(10)
#Search events of our agent
click_menu_element(driver,"View events")
driver.find_element_by_xpath('//a[contains(.,"Event control filter")]').click()
driver.find_element_by_xpath('//a[contains(.,"Advanced options")]').click()
driver.find_element_by_id("text-text_agent").clear()
driver.find_element_by_id("text-text_agent").send_keys(u"次のライセンスに基づいていま")
driver.find_element_by_id("text-module_search").clear()
driver.find_element_by_id("text-module_search").send_keys(u"管理者ガイド")
driver.find_element_by_id("submit-update").click()
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 (管理者ガイド)")]')

View File

@ -1,7 +1,11 @@
# -*- coding: utf-8 -*-
from include.common_classes_60 import PandoraWebDriverTestCase
from include.common_functions_60 import login, click_menu_element, detect_and_pass_all_wizards, logout, is_enterprise, gen_random_string
from include.common_functions_60 import login, click_menu_element, detect_and_pass_all_wizards, logout, gen_random_string
from include.planned_downtime_functions import *
from include.alert_functions import *
from include.module_functions import *
from include.agent_functions import *
from include.event_functions import *
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
@ -9,7 +13,7 @@ from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.remote.webelement import WebElement
import unittest, time, re
import unittest, time, re, datetime
class PAN13(PandoraWebDriverTestCase):
@ -18,7 +22,6 @@ class PAN13(PandoraWebDriverTestCase):
test_description = u'Planed downtime test'
tickets_associated = []
@is_enterprise
def test_A_create_planned_downtime_Quiet(self):
u"""
@ -30,16 +33,15 @@ class PAN13(PandoraWebDriverTestCase):
planned_name = gen_random_string(6)
create_planned_downtime(driver,planned_name,"Applications","Quiet",description=planned_name)
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('//a[contains(.,"Running")]')
element = driver.find_element_by_xpath('//img[@data-title="Running"]')
self.assertIsInstance(element,WebElement)
@is_enterprise
def test_B_create_planned_downtime_disabled_agents(self):
u"""
@ -49,16 +51,15 @@ class PAN13(PandoraWebDriverTestCase):
planned_name = gen_random_string(6)
create_planned_downtime(driver,planned_name,"Applications","Disabled Agents",description=planned_name)
create_planned_downtime(driver,planned_name,"Applications","Disabled Agents","Once",description=planned_name)
time.sleep(10)
search_planned_downtime(driver,planned_name)
element = driver.find_element_by_xpath('//a[contains(.,"Running")]')
element = driver.find_element_by_xpath('//img[@data-title="Running"]')
self.assertIsInstance(element,WebElement)
@is_enterprise
def test_C_create_planned_downtime_disabled_only_alerts(self):
u"""
@ -68,15 +69,97 @@ class PAN13(PandoraWebDriverTestCase):
planned_name = gen_random_string(6)
create_planned_downtime(driver,planned_name,"Applications","Disabled only Alerts",description=planned_name)
create_planned_downtime(driver,planned_name,"Applications","Disabled only Alerts","Once",description=planned_name)
time.sleep(10)
search_planned_downtime(driver,planned_name)
element = driver.find_element_by_xpath('//a[contains(.,"Running")]')
element = driver.find_element_by_xpath('//img[@data-title="Running"]')
self.assertIsInstance(element,WebElement)
def test_D_delete_planned_downtime(self):
driver=self.driver
self.login()
planned_name = gen_random_string(6)
create_planned_downtime(driver,planned_name,"Applications","Quiet","Once",description=planned_name,date_from='2016/09/18',date_to='2016/09/20',agent_module_list=[('pandorafms',['CPU Load','Agents_Unknown']),('lel',['Host Alive','Host Latency'])])
delete_planned_downtime(driver,planned_name)
def test_E_quiet_functionality(self):
driver=self.driver
planned_name = gen_random_string(6)
agent_name_A = gen_random_string(6)
agent_name_B = gen_random_string(6)
module_name_A_A = gen_random_string(6)
module_name_A_B = gen_random_string(6)
module_name_B_A = gen_random_string(6)
module_name_B_B = gen_random_string(6)
create_agent(driver,agent_name_A,ip="127.0.0.1",group="Applications")
create_agent(driver,agent_name_B,ip="127.0.0.1",group="Applications")
create_module('network_server',driver,agent_name=agent_name_A,module_name=module_name_A_A,component_group='Network Management',network_component='Host Alive')
create_module('network_server',driver,agent_name=agent_name_A,module_name=module_name_A_B,component_group='Network Management',network_component='Host Latency')
create_module('network_server',driver,agent_name=agent_name_B,module_name=module_name_B_A,component_group='Network Management',network_component='Host Alive')
create_module('network_server',driver,agent_name=agent_name_B,module_name=module_name_B_B,component_group='Network Management',network_component='Host Alive')
assign_alert_template_to_module(driver,agent_name_A,module_name_A_A,'Critical condition')
assign_alert_template_to_module(driver,agent_name_A,module_name_A_B,'Critical condition')
assign_alert_template_to_module(driver,agent_name_B,module_name_B_A,'Critical condition')
assign_alert_template_to_module(driver,agent_name_B,module_name_B_B,'Critical condition')
#Little hack to allow the planned downtime to be edited
fifteen_seconds_later = datetime.datetime.now() + datetime.timedelta(seconds=15)
fifteen_seconds_later_to_pandora = str(fifteen_seconds_later.hour)+":"+str(fifteen_seconds_later.minute)+":"+str(fifteen_seconds_later.second)
create_planned_downtime(driver,planned_name,"Applications","Quiet","Once",hour_from=fifteen_seconds_later_to_pandora,description=planned_name,agent_module_list=[(agent_name_A,[module_name_A_A]),(agent_name_B,[module_name_B_A])])
#We wait 10 seconds to the planned downtime to start. Since we do not specify a date, default dates are from now to one hour in the future.
time.sleep(40)
#Is the planned downtime running?
search_planned_downtime(driver,planned_name)
element = driver.find_element_by_xpath('//img[@data-title="Running"]')
self.assertIsInstance(element,WebElement)
force_alert_of_module(driver,agent_name_A,module_name_A_A,'Critical condition')
force_alert_of_module(driver,agent_name_A,module_name_A_B,'Critical condition')
force_alert_of_module(driver,agent_name_B,module_name_B_A,'Critical condition')
force_alert_of_module(driver,agent_name_B,module_name_B_B,'Critical condition')
search_events(driver,agent_name=agent_name_A,module_name=module_name_A_A)
event_who_should_not_be_present = driver.find_elements_by_xpath('//tbody/tr[td[3][contains(.,"Alert fired")] and td[4][contains(.,"'+agent_name_A+'")]]')
self.assertEqual(event_who_should_not_be_present,[])
search_events(driver,agent_name=agent_name_A,module_name=module_name_A_B)
event_who_should_be_present = driver.find_elements_by_xpath('//tbody/tr[td[3][contains(.,"Alert fired")] and td[4][contains(.,"'+agent_name_A+'")]]')
self.assertNotEqual(event_who_should_be_present,[])
search_events(driver,agent_name=agent_name_B,module_name=module_name_B_A)
event_who_should_not_be_present_b = driver.find_elements_by_xpath('//tbody/tr[td[3][contains(.,"Alert fired")] and td[4][contains(.,"'+agent_name_B+'")]]')
self.assertEqual(event_who_should_not_be_present_b,[])
search_events(driver,agent_name=agent_name_B,module_name=module_name_B_B)
event_who_should_be_present_b = driver.find_elements_by_xpath('//tbody/tr[td[3][contains(.,"Alert fired")] and td[4][contains(.,"'+agent_name_B+'")]]')
self.assertNotEqual(event_who_should_be_present_b,[])
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
from selenium import selenium
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait, Select
from selenium.webdriver.support import expected_conditions as EC
from module_functions import search_module
from common_functions_60 import *
import random, time
import string
def assign_alert_template_to_module (driver,agent_name,module_name,template_name):
search_module(driver,agent_name,module_name)
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(module_name)
Select(driver.find_element_by_id("template")).select_by_visible_text(template_name)
driver.find_element_by_id("submit-add").click()
def force_alert_of_module(driver,agent_name,module_name,template_name):
click_menu_element(driver,"Agent detail")
driver.find_element_by_id("text-search").clear()
driver.find_element_by_id("text-search").send_keys(agent_name)
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[td[3][contains(.,"'+module_name+'")] and td[4][contains(.,"'+template_name+'")]]/td[2]/a').click()
time.sleep(10)

View File

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
from selenium import selenium
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait, Select
from selenium.webdriver.support import expected_conditions as EC
from common_functions_60 import *
import random, time
import string
def search_events(driver,agent_name=None,module_name=None):
click_menu_element(driver,"View events")
driver.find_element_by_xpath('//a[contains(.,"Event control filter")]').click()
driver.find_element_by_xpath('//a[contains(.,"Advanced options")]').click()
if agent_name != None:
driver.find_element_by_id("text-text_agent").clear()
driver.find_element_by_id("text-text_agent").send_keys(agent_name)
time.sleep(3)
driver.find_element_by_xpath('//a[@class="ui-corner-all"][contains(.,"'+agent_name+'")]').click() # In this line you click the drop-down box search
if module_name != None:
driver.find_element_by_id("text-module_search").clear()
driver.find_element_by_id("text-module_search").send_keys(module_name)
time.sleep(3)
driver.find_element_by_xpath('//a[@class="ui-corner-all"][contains(.,"'+module_name+'")]').click() # In this line you click the drop-down box search
driver.find_element_by_id("submit-update").click()

View File

@ -16,20 +16,20 @@ def create_module(module_type,*args,**kwargs):
elif module_type=='data_server':
create_data_server_module(*args,**kwargs)
def create_network_server_module(driver,agent_name=None,module_name=None,component_group=None,type=None,network_component=None,min_warning=None,max_warning=None,min_critical=None,max_critical=None,ip=None,tag_name=None,description=None):
def create_network_server_module(driver,agent_name=None,module_name=None,component_group=None,type_of_module=None,network_component=None,min_warning=None,max_warning=None,min_critical=None,max_critical=None,ip=None,tag_name=None,description=None):
# component_group -> Example: Remote ICMP network agent (latency)
# network_component -> Example: Host Alive
#The type variable is optional, but required if component_group and network_component variables are specified
#The type_of_module variable is optional, but required if component_group and network_component variables are specified
if agent_name != None:
search_agent(driver,agent_name)
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="create_module_type"]/table/tbody/tr/td[5]/input').click()
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()
@ -65,7 +65,7 @@ def create_network_server_module(driver,agent_name=None,module_name=None,compone
else:
driver.find_element_by_id("text-name").clear()
driver.find_element_by_id("text-name").send_keys(module_name)
Select(driver.find_element_by_id("id_module_type")).select_by_visible_text(type)
Select(driver.find_element_by_id("id_module_type")).select_by_visible_text(type_of_module)
if module_name != None:
time.sleep(3)
@ -85,11 +85,11 @@ def create_network_server_module(driver,agent_name=None,module_name=None,compone
driver.find_element_by_id("submit-crtbutton").click()
def create_data_server_module(driver,module_name,agent_name=None,type=None,min_warning=None,max_warning=None,min_critical=None,max_critical=None,tag_name=None,description=None):
def create_data_server_module(driver,module_name,agent_name=None,type_of_module=None,min_warning=None,max_warning=None,min_critical=None,max_critical=None,tag_name=None,description=None):
# type -> Example: Generic numeric
# type_of_module -> Example: Generic numeric
# The type variable is Generic numeric by default
# The type_of_module variable is Generic numeric by default
if agent_name != None:
search_agent(driver,agent_name)
@ -104,9 +104,9 @@ def create_data_server_module(driver,module_name,agent_name=None,type=None,min_w
driver.find_element_by_id("text-name").clear()
driver.find_element_by_id("text-name").send_keys(module_name)
if type != None:
if type_of_module != None:
Select(driver.find_element_by_id("id_module_type")).select_by_visible_text(type)
Select(driver.find_element_by_id("id_module_type")).select_by_visible_text(type_of_module)
if min_warning != None:
@ -166,4 +166,6 @@ def search_module (driver,agent_name,module_name):
driver.find_element_by_id("text-search_string").send_keys(module_name)
driver.find_element_by_id("submit-filter").click()

View File

@ -9,7 +9,7 @@ import random, time
import string
def create_planned_downtime(driver,name,group,type_planned,description=None,execution=None,date_from=None,date_to=None,hour_from=None,hour_to=None,periodicity_type=None,from_day=None,to_day=None,list_days=None,list_agent=None):
def create_planned_downtime(driver,name,group,type_planned,execution,description=None,date_from=None,date_to=None,hour_from=None,hour_to=None,periodicity_type=None,from_day=None,to_day=None,list_days=None,agent_module_list=None):
#type_planned is: Disabled Agents, Quiet or Disabled only Alerts
@ -22,7 +22,12 @@ def create_planned_downtime(driver,name,group,type_planned,description=None,exec
#Execution by default is Once, date_from and date_to is date it's today's date
#list_agent is a list of agent that aplicate this planned downtime
#agent_module_list is a list of tuples: lista = [('agent_name_1',['module_name_1','module_name_2']),('agent_name_2',[])]
#CAREFUL! [] means 'Any' module
#Self checks
if (date_from is None and date_to is not None) or (date_from is not None and date_to is None):
raise Exception("If one date is provided, the other should be provided too")
click_menu_element(driver,"Scheduled downtime")
driver.find_element_by_id("submit-create").click()
@ -39,17 +44,21 @@ def create_planned_downtime(driver,name,group,type_planned,description=None,exec
driver.find_element_by_xpath('//option[contains(.,"'+type_planned+'")]').click()
if execution == "Once":
driver.find_element_by_id("text-once_date_from").clear()
driver.find_element_by_id("text-once_date_from").send_keys(date_from)
driver.find_element_by_id("text-once_date_to").clear()
driver.find_element_by_id("text-once_date_to").send_keys(date_to)
driver.find_element_by_id("text-once_time_from").clear()
driver.find_element_by_id("text-once_time_from").send_keys(hour_from)
driver.find_element_by_id("text-once_time_to").clear()
driver.find_element_by_id("text-once_time_to").send_keys(hour_to)
if date_from is not None:
driver.find_element_by_id("text-once_date_from").clear()
driver.find_element_by_id("text-once_date_from").send_keys(date_from)
if date_to is not None:
driver.find_element_by_id("text-once_date_to").clear()
driver.find_element_by_id("text-once_date_to").send_keys(date_to)
if hour_from is not None:
driver.find_element_by_id("text-once_time_from").clear()
driver.find_element_by_id("text-once_time_from").send_keys(hour_from)
if hour_to is not None:
driver.find_element_by_id("text-once_time_to").clear()
driver.find_element_by_id("text-once_time_to").send_keys(hour_to)
if execution == "Periodically":
Select(driver.find_element_by_id("type_periodicity")).select_by_visible_text(periodicity_type)
@ -69,19 +78,25 @@ def create_planned_downtime(driver,name,group,type_planned,description=None,exec
driver.find_element_by_id("text-periodically_time_to").clear()
driver.find_element_by_id("text-periodically_time_to").send_keys(hour_to)
driver.find_element_by_id("submit-crtbutton").click()
if list_agent != None:
for agent in list_agent:
Select(driver.find_element_by_id("id_agents")).select_by_visible_text(agent)
alert = driver.switch_to_alert()
alert.accept()
driver.find_element_by_id("submit-add_item").click()
driver.find_element_by_id("submit-add_item").click()
alert = driver.switch_to_alert()
alert.accept()
if agent_module_list is not None:
for agent_name,module_name_list in agent_module_list:
Select(driver.find_element_by_id("id_agents")).select_by_visible_text(agent_name)
if type_planned == "Quiet":
#Quiet types allow to select modules
time.sleep(3)
if module_name_list is not []:
Select(driver.find_element_by_id("module")).deselect_by_visible_text('Any')
for module_name in module_name_list:
Select(driver.find_element_by_id("module")).select_by_visible_text(module_name)
driver.find_element_by_id("submit-add_item").click()
try:
alert = driver.switch_to_alert()
alert.accept()
except:
pass
def search_planned_downtime(driver,name,type_planned=None,date_from=None,date_to=None,show_past_downtimes=False):
@ -118,8 +133,8 @@ def stop_downtime(driver,name):
def delete_planned_downtime(driver,name):
search_planned_downtime(driver,name)
if (u"Running" in driver.page_source):
stop_downtime(driver,name)
if (u"Not running" not in driver.page_source):
stop_downtime(driver,name)
search_planned_downtime(driver,name,show_past_downtimes=True)
driver.find_element_by_xpath('//*[@id="delete_downtime"]/img').click()