Commit 89292b7d by Csók Tamás

selenium: logging revisited, errors corrected

parent 8ff74260
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>. # with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
import logging import logging
from sys import stdout
import random import random
import re import re
import urlparse import urlparse
...@@ -34,10 +33,14 @@ from vm.models import Instance ...@@ -34,10 +33,14 @@ from vm.models import Instance
from .config import SeleniumConfig from .config import SeleniumConfig
from .util import CircleSeleniumMixin, SeleniumMixin from .util import CircleSeleniumMixin, SeleniumMixin
logger = logging.getLogger(__name__)
consoleHandler = logging.StreamHandler(stdout)
logger.addHandler(consoleHandler)
conf = SeleniumConfig() conf = SeleniumConfig()
log_formatter = logging.Formatter(conf.log_format)
logger = logging.getLogger(conf.logger_name)
fileHandler = logging.handlers.RotatingFileHandler(
conf.log_file, maxBytes=conf.log_size, backupCount=conf.log_backup)
fileHandler.setFormatter(log_formatter)
fileHandler.setLevel(logging.WARNING)
logger.addHandler(fileHandler)
class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin): class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin):
...@@ -82,9 +85,9 @@ class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin): ...@@ -82,9 +85,9 @@ class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin):
elif len(template_pool) == 1: elif len(template_pool) == 1:
chosen = template_pool[0] chosen = template_pool[0]
else: else:
logging.warning("Selenium did not found any templates") logger.exception("Selenium did not found any templates")
logging.exception( raise Exception(
"System did not meet required conditions to continue") "Selenium did not found any templates")
self.driver.get('%s/dashboard/template/%s/' % (conf.host, chosen)) self.driver.get('%s/dashboard/template/%s/' % (conf.host, chosen))
acces_form = self.driver.find_element_by_css_selector( acces_form = self.driver.find_element_by_css_selector(
"form[action*='/dashboard/template/%(template_id)s/acl/']" "form[action*='/dashboard/template/%(template_id)s/acl/']"
...@@ -106,7 +109,7 @@ class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin): ...@@ -106,7 +109,7 @@ class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin):
user_text = re.split(r':[ ]?', user.text) user_text = re.split(r':[ ]?', user.text)
if len(user_text) == 2: if len(user_text) == 2:
found_name = re.search(r'[\w\W]+(?=\))', user_text[1]).group() found_name = re.search(r'[\w\W]+(?=\))', user_text[1]).group()
logging.info("'%(user)s' found in ACL " logger.warning("'%(user)s' found in ACL "
"list for template %(id)s" % { "list for template %(id)s" % {
'user': found_name, 'user': found_name,
'id': chosen}) 'id': chosen})
...@@ -124,7 +127,7 @@ class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin): ...@@ -124,7 +127,7 @@ class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin):
By.ID, 'confirmation-modal'))) By.ID, 'confirmation-modal')))
template_list = self.driver.find_elements_by_class_name( template_list = self.driver.find_elements_by_class_name(
'template-choose-list-element') 'template-choose-list-element')
logging.info('Selenium found %(count)s template possibilities' % { logger.warning('Selenium found %(count)s template possibilities' % {
'count': len(template_list)}) 'count': len(template_list)})
(self.assertIsNotNone( (self.assertIsNotNone(
template_list, "Selenium can not find the create template list") or template_list, "Selenium can not find the create template list") or
...@@ -157,7 +160,7 @@ class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin): ...@@ -157,7 +160,7 @@ class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin):
success = False success = False
self.login() self.login()
for template_id in self.template_ids: for template_id in self.template_ids:
logging.info("Deleting template %s" % template_id) logger.warning("Deleting template %s" % template_id)
self.delete_template(template_id) self.delete_template(template_id)
existing_templates = self.get_template_id() existing_templates = self.get_template_id()
if len(existing_templates) == 0: if len(existing_templates) == 0:
...@@ -181,7 +184,7 @@ class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin): ...@@ -181,7 +184,7 @@ class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin):
By.ID, 'confirmation-modal'))) By.ID, 'confirmation-modal')))
vm_list = self.driver.find_elements_by_class_name( vm_list = self.driver.find_elements_by_class_name(
'vm-create-template-summary') 'vm-create-template-summary')
logging.info("Selenium found %(vm_number)s virtual machine template " logger.warning("Selenium found %(vm_number)s virtual machine template "
" possibilities" % { " possibilities" % {
'vm_number': len(vm_list)}) 'vm_number': len(vm_list)})
(self.assertIsNotNone( (self.assertIsNotNone(
...@@ -200,8 +203,8 @@ class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin): ...@@ -200,8 +203,8 @@ class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin):
"none", "", "none", "",
"block", "none"] "block", "none"]
states = self.view_change("vm") states = self.view_change("vm")
logging.info('states: [%s]' % ', '.join(map(str, states))) logger.warning('states: [%s]' % ', '.join(map(str, states)))
logging.info('expected: [%s]' % ', '.join(map(str, expected_states))) logger.warning('expected: [%s]' % ', '.join(map(str, expected_states)))
self.assertListEqual(states, expected_states, self.assertListEqual(states, expected_states,
"The view mode does not change for VM listing") "The view mode does not change for VM listing")
...@@ -211,8 +214,8 @@ class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin): ...@@ -211,8 +214,8 @@ class BasicSeleniumTests(SeleniumTestCase, SeleniumMixin, CircleSeleniumMixin):
"none", "", "none", "",
"block", "none"] "block", "none"]
states = self.view_change("node") states = self.view_change("node")
logging.info('states: [%s]' % ', '.join(map(str, states))) logger.warning('states: [%s]' % ', '.join(map(str, states)))
logging.info('expected: [%s]' % ', '.join(map(str, expected_states))) logger.warning('expected: [%s]' % ', '.join(map(str, expected_states)))
self.assertListEqual(states, expected_states, self.assertListEqual(states, expected_states,
"The view mode does not change for NODE listing") "The view mode does not change for NODE listing")
......
...@@ -24,6 +24,16 @@ class SeleniumConfig: ...@@ -24,6 +24,16 @@ class SeleniumConfig:
wait_max_sec = 10 wait_max_sec = 10
# How much sec can pass before the activity is no longer happened recently # How much sec can pass before the activity is no longer happened recently
recently_sec = 90 recently_sec = 90
# Name of the logger (necessary to override test logger)
logger_name = "selenium"
# File where the log should be stored
log_file = "selenium.log"
# Log file max size in Bytes
log_size = 1024 * 100
# Format of the log file
log_format = "%(asctime)s: %(name)s: %(levelname)s: %(message)s"
# Backup count of the logfiles
log_backup = 5
# Accented letters from which selenium can choose to name stuff # Accented letters from which selenium can choose to name stuff
accents = u"áéíöóúűÁÉÍÖÓÜÚŰ" accents = u"áéíöóúűÁÉÍÖÓÜÚŰ"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment