From 6950f14eec03665230947f8b0dfa6ac990e03374 Mon Sep 17 00:00:00 2001 From: cbiselli Date: Fri, 23 Feb 2024 15:31:40 +0100 Subject: [PATCH 1/6] fixed lh version to 11.5 --- wptagent.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/wptagent.py b/wptagent.py index 78c5b5010..9e26037dd 100644 --- a/wptagent.py +++ b/wptagent.py @@ -583,6 +583,10 @@ def startup(self, detected_browsers): if self.get_node_version() < 16.0: logging.warning("Node.js 16 or newer is required for Lighthouse testing") + # Force lighthouse 11.5.0 + if self.get_lighthouse_version() != '11.5.0': + subprocess.call(['sudo', 'npm', 'i', '-g', 'lighthouse@11.5.0']) + # Check the iOS install if self.ios is not None: ret = self.requires('usbmuxwrapper') and ret @@ -623,6 +627,20 @@ def get_node_version(self): pass return version + def get_lighthouse_version(self): + """Get the installed version of lighthouse""" + version = None + try: + if sys.version_info >= (3, 0): + stdout = subprocess.check_output(['lighthouse', '--version'], encoding='UTF-8') + else: + stdout = subprocess.check_output(['lighthouse', '--version']) + version = stdout.strip() + except Exception: + pass + + return version + def update_windows_certificates(self): """ Update the root Windows certificates""" try: From a15f2bdb4cfa27e273c7e6ff12c7a259cc2a024d Mon Sep 17 00:00:00 2001 From: cbiselli Date: Thu, 29 Feb 2024 18:32:33 +0100 Subject: [PATCH 2/6] using lh v11.4 --- wptagent.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wptagent.py b/wptagent.py index 9e26037dd..c765a3b14 100644 --- a/wptagent.py +++ b/wptagent.py @@ -583,9 +583,9 @@ def startup(self, detected_browsers): if self.get_node_version() < 16.0: logging.warning("Node.js 16 or newer is required for Lighthouse testing") - # Force lighthouse 11.5.0 - if self.get_lighthouse_version() != '11.5.0': - subprocess.call(['sudo', 'npm', 'i', '-g', 'lighthouse@11.5.0']) + # Force lighthouse 11.4.0 + if self.get_lighthouse_version() != '11.4.0': + subprocess.call(['sudo', 'npm', 'i', '-g', 'lighthouse@11.4.0']) # Check the iOS install if self.ios is not None: From a5682db1990c2a7e668b4c353876d4d7367e23eb Mon Sep 17 00:00:00 2001 From: Leonardo Bartoli Date: Wed, 17 Apr 2024 17:46:27 +0200 Subject: [PATCH 3/6] Force selenium version to fix failing firefox tests --- wptagent.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wptagent.py b/wptagent.py index c765a3b14..175d82166 100644 --- a/wptagent.py +++ b/wptagent.py @@ -1076,6 +1076,19 @@ def get_browser_versions(browsers): browsers[browser]['version'] = get_file_version(exe) +def fix_selenium_version(): + """ + On older python versions we are going to force selenium version 3.141.0, + newer versions are going to use 4.8.3 + """ + from internal.os_util import run_elevated + version = '4.8.3' + if sys.version_info[1] == 6: + version = '3.141.0' + + run_elevated(sys.executable, f'-m pip install selenium=={version}') + + def main(): """Startup and initialization""" import argparse @@ -1221,6 +1234,9 @@ def main(): logging.critical("Requires python 2.7") exit(1) + # Make sure we are using a compatible selenium version + fix_selenium_version() + if options.list: from internal.ios_device import iOSDevice ios = iOSDevice() From 89be4e151b16f2f40545f1bdf21b43507525c0e6 Mon Sep 17 00:00:00 2001 From: Leonardo Bartoli Date: Thu, 18 Apr 2024 16:20:10 +0200 Subject: [PATCH 4/6] Resolved conflicts --- wptagent.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/wptagent.py b/wptagent.py index 7cde3369f..bba68e33d 100644 --- a/wptagent.py +++ b/wptagent.py @@ -585,10 +585,6 @@ def startup(self, detected_browsers): if self.get_node_version() < 16.0: logging.warning("Node.js 16 or newer is required for Lighthouse testing") - # Force lighthouse 11.4.0 - if self.get_lighthouse_version() != '11.4.0': - subprocess.call(['sudo', 'npm', 'i', '-g', 'lighthouse@11.4.0']) - # Check the iOS install if self.ios is not None: ret = self.requires('usbmuxwrapper') and ret @@ -629,20 +625,6 @@ def get_node_version(self): pass return version - def get_lighthouse_version(self): - """Get the installed version of lighthouse""" - version = None - try: - if sys.version_info >= (3, 0): - stdout = subprocess.check_output(['lighthouse', '--version'], encoding='UTF-8') - else: - stdout = subprocess.check_output(['lighthouse', '--version']) - version = stdout.strip() - except Exception: - pass - - return version - def update_windows_certificates(self): """ Update the root Windows certificates""" try: From 6676d42558be5ec47fa968f3eae599bbf855f76e Mon Sep 17 00:00:00 2001 From: Leonardo Bartoli Date: Thu, 18 Apr 2024 16:23:10 +0200 Subject: [PATCH 5/6] Added back setup_logging --- wptagent.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/wptagent.py b/wptagent.py index bba68e33d..55a70270f 100644 --- a/wptagent.py +++ b/wptagent.py @@ -1073,6 +1073,61 @@ def fix_selenium_version(): run_elevated(sys.executable, f'-m pip install selenium=={version}') +# Constant used for --logformat command line parameter mapping +LOG_FORMATS = ["syslog"] + +def setup_logging(verbosity=0, log_format=None, log_file=None): + """Setup logging according to passed command line values""" + + # Set log level and legacy format + basic_log_level = logging.CRITICAL + if verbosity is None: + pass # default critical + elif verbosity == 1: + basic_log_level = logging.ERROR + elif verbosity == 2: + basic_log_level = logging.WARNING + elif verbosity == 3: + basic_log_level = logging.INFO + elif verbosity >= 4: + basic_log_level = logging.DEBUG + + if log_format is None: + # legacy behavior + logging.basicConfig(level=basic_log_level, format="%(asctime)s.%(msecs)03d - %(message)s", + datefmt="%H:%M:%S") + + # If file is specified add self rotating file with just errors level or above. + if log_file is not None: + err_log = logging.handlers.RotatingFileHandler(log_file, maxBytes=1000000, + backupCount=5, delay=True) + err_log.setLevel(logging.ERROR) + logging.getLogger().addHandler(err_log) + else: + if log_format == "syslog" and log_file is not None: + from internal.rfc5424logging import Rfc5424SysLogHandler, logging_context + logger = logging.getLogger() + logger.setLevel(basic_log_level) + handler = Rfc5424SysLogHandler( \ + address=None, \ + socktype=None, \ + framing=None, \ + msg_as_utf8=True, \ + appname="wptagent", \ + # Currently used just for versioning + enterprise_id="1", \ + utc_timestamp=True, \ + file_name=log_file \ + ) + + logger.addHandler(handler) + logger.debug("Rfc5424SysLogHandler initialized", extra=logging_context().as_extra({"msg_as_utf8": True})) + else: + # used default loggger + logging.critical("log_file must be specified if log_format is used.") + exit(1) + + def main(): """Startup and initialization""" import argparse From f3a29e42c1e9510468577ce7f37f891a6ded623b Mon Sep 17 00:00:00 2001 From: Leonardo Bartoli Date: Thu, 18 Apr 2024 16:23:51 +0200 Subject: [PATCH 6/6] Removed newline --- wptagent.py | 1 - 1 file changed, 1 deletion(-) diff --git a/wptagent.py b/wptagent.py index 55a70270f..751417185 100644 --- a/wptagent.py +++ b/wptagent.py @@ -1127,7 +1127,6 @@ def setup_logging(verbosity=0, log_format=None, log_file=None): logging.critical("log_file must be specified if log_format is used.") exit(1) - def main(): """Startup and initialization""" import argparse