bugfix: Fix failure caused by unset locale 39/4139/2
authorMartin Klozik <martinx.klozik@intel.com>
Wed, 9 Dec 2015 12:53:43 +0000 (12:53 +0000)
committerMaryam Tahhan <maryam.tahhan@intel.com>
Mon, 14 Dec 2015 14:46:05 +0000 (14:46 +0000)
In case, that VSPERF detects missing locale settings, it will
set language and encodding settings to default values specified
by configuration parameter DEFAULT_LOCALE.
Localized external commands with output parsed by VSPERF
are executed with modified locale to ensure correct VSPERF
function. Locale settings for such commands is specified
by configuration parameter DEFAULT_CMD_LOCALE.

Change-Id: If5c15115b778ce90046e390f10438b780f82695b
JIRA: VSPERF-132
Signed-off-by: Martin Klozik <martinx.klozik@intel.com>
Reviewed-by: Maryam Tahhan <maryam.tahhan@intel.com>
Reviewed-by: Al Morton <acmorton@att.com>
Reviewed-by: Brian Castelli <brian.castelli@spirent.com>
Reviewed-by: Gurpreet Singh <gurpreet.singh@spirent.com>
Reviewed-by: Tv Rao <tv.rao@freescale.com>
conf/00_common.conf
tools/collectors/sysmetrics/pidstat.py
tools/report/report.jinja
tools/systeminfo.py
tools/tasks.py
vnfs/qemu/qemu.py
vsperf

index 225cf47..944619c 100644 (file)
 
 import os
 
+# default language and encoding, which will be set in case
+# that locale is not set properly
+DEFAULT_LOCALE = 'en_US.UTF-8'
+
+# default language and encoding, which will be used by external
+# commands; This values will be set in case, that VSPERF parses
+# command output.
+DEFAULT_CMD_LOCALE = 'en_US.UTF-8'
+
 # ############################
 # Directories
 # ############################
@@ -28,13 +37,13 @@ TRAFFICGEN_DIR = os.path.join(ROOT_DIR, 'tools/pkt_gen')
 SYSMETRICS_DIR = os.path.join(ROOT_DIR, 'tools/collectors')
 
 # deployment specific paths to OVS and DPDK
-OVS_DIR_VANILLA  = os.path.join(ROOT_DIR, 'src_vanilla/ovs/ovs/')
+OVS_DIR_VANILLA = os.path.join(ROOT_DIR, 'src_vanilla/ovs/ovs/')
 
-RTE_SDK_CUSE  = os.path.join(ROOT_DIR, 'src_cuse/dpdk/dpdk/')
-OVS_DIR_CUSE  = os.path.join(ROOT_DIR, 'src_cuse/ovs/ovs/')
+RTE_SDK_CUSE = os.path.join(ROOT_DIR, 'src_cuse/dpdk/dpdk/')
+OVS_DIR_CUSE = os.path.join(ROOT_DIR, 'src_cuse/ovs/ovs/')
 
-RTE_SDK_USER  = os.path.join(ROOT_DIR, 'src/dpdk/dpdk/')
-OVS_DIR_USER  = os.path.join(ROOT_DIR, 'src/ovs/ovs/')
+RTE_SDK_USER = os.path.join(ROOT_DIR, 'src/dpdk/dpdk/')
+OVS_DIR_USER = os.path.join(ROOT_DIR, 'src/ovs/ovs/')
 
 # the same qemu version is used for vanilla, vHost User and Cuse
 QEMU_DIR = os.path.join(ROOT_DIR, 'src/qemu/qemu/')
index 608a0d6..5106697 100644 (file)
@@ -74,7 +74,8 @@ class Pidstat(collector.ICollector):
         pids = systeminfo.get_pids(monitor)
         if pids:
             with open(self._log, 'w') as logfile:
-                cmd = ['sudo', 'pidstat', settings.getValue('PIDSTAT_OPTIONS'),
+                cmd = ['sudo', 'LC_ALL=' + settings.getValue('DEFAULT_CMD_LOCALE'),
+                       'pidstat', settings.getValue('PIDSTAT_OPTIONS'),
                        '-p', ','.join(pids),
                        str(settings.getValue('PIDSTAT_SAMPLE_INTERVAL'))]
                 self._logger.debug('%s', ' '.join(cmd))
index 491dbe9..6542a20 100644 (file)
@@ -20,7 +20,7 @@
 <a name="Introduction"></a>
 ## 1. Introduction
 
-The objective of the OPNFV project titled **“Characterise vSwitch Performance for Telco NFV Use Cases”**, is to evaluate a virtual switch to identify its suitability for a Telco Network Function Virtualization (NFV) environment. As well as this, the project aims to identify any gaps or bottlenecks in order to drive architectural changes to improve virtual switch performance and determinism. The purpose of this document is to summarize the results of the tests carried out on the virtual switch in the Network Function Virtualization Infrastructure (NFVI) and, from these results, provide evaluations and recommendations for the virtual switch. Test results will be outlined in [Details of the Level Test Report](#DetailsoftheLevelTestReport), preceded by the [Document Identifier](#DocId), [Scope](#Scope) and [References](#References).
+The objective of the OPNFV project titled **"Characterise vSwitch Performance for Telco NFV Use Cases"**, is to evaluate a virtual switch to identify its suitability for a Telco Network Function Virtualization (NFV) environment. As well as this, the project aims to identify any gaps or bottlenecks in order to drive architectural changes to improve virtual switch performance and determinism. The purpose of this document is to summarize the results of the tests carried out on the virtual switch in the Network Function Virtualization Infrastructure (NFVI) and, from these results, provide evaluations and recommendations for the virtual switch. Test results will be outlined in [Details of the Level Test Report](#DetailsoftheLevelTestReport), preceded by the [Document Identifier](#DocId), [Scope](#Scope) and [References](#References).
 
 This document is currently in draft form.
 
index d3e24e5..cb9ca6e 100644 (file)
@@ -145,7 +145,8 @@ def get_pids(proc_names_list):
     """
 
     try:
-        pids = subprocess.check_output(['pidof'] + proc_names_list)
+        pids = subprocess.check_output(['sudo', 'LC_ALL=' + settings.getValue('DEFAULT_CMD_LOCALE'), 'pidof']
+                                       + proc_names_list)
     except subprocess.CalledProcessError:
         # such process isn't running
         return None
index 09dd88d..90b7e55 100644 (file)
@@ -29,7 +29,6 @@ from conf import settings
 
 
 CMD_PREFIX = 'cmd : '
-_MY_ENCODING = locale.getdefaultlocale()[1]
 
 def _get_stdout():
     """Get stdout value for ``subprocess`` calls.
@@ -68,6 +67,7 @@ def run_task(cmd, logger, msg=None, check_error=False):
 
     stdout = []
     stderr = []
+    my_encoding = locale.getdefaultlocale()[1]
 
     if msg:
         logger.info(msg)
@@ -87,11 +87,11 @@ def run_task(cmd, logger, msg=None, check_error=False):
                 if file_d == proc.stdout.fileno():
                     line = proc.stdout.readline()
                     if settings.getValue('VERBOSITY') == 'debug':
-                        sys.stdout.write(line.decode(_MY_ENCODING))
+                        sys.stdout.write(line.decode(my_encoding))
                     stdout.append(line)
                 if file_d == proc.stderr.fileno():
                     line = proc.stderr.readline()
-                    sys.stderr.write(line.decode(_MY_ENCODING))
+                    sys.stderr.write(line.decode(my_encoding))
                     stderr.append(line)
 
             if proc.poll() is not None:
@@ -103,8 +103,8 @@ def run_task(cmd, logger, msg=None, check_error=False):
             ex = subprocess.CalledProcessError(proc.returncode, cmd, stderr)
             handle_error(ex)
 
-    return ('\n'.join(sout.decode(_MY_ENCODING).strip() for sout in stdout),
-            ('\n'.join(sout.decode(_MY_ENCODING).strip() for sout in stderr)))
+    return ('\n'.join(sout.decode(my_encoding).strip() for sout in stdout),
+            ('\n'.join(sout.decode(my_encoding).strip() for sout in stderr)))
 
 def run_background_task(cmd, logger, msg):
     """Run task in background and log when started.
index 4b0bf0b..f292d7d 100644 (file)
@@ -163,7 +163,7 @@ class IVnfQemu(IVnf):
 
         self._logger.info('Affinitizing guest...')
 
-        cur_locale = locale.getlocale()[1]
+        cur_locale = locale.getdefaultlocale()[1]
         proc = subprocess.Popen(
             ('echo', 'info cpus'), stdout=subprocess.PIPE)
         output = subprocess.check_output(
diff --git a/vsperf b/vsperf
index f6ddc63..2f85fba 100755 (executable)
--- a/vsperf
+++ b/vsperf
@@ -26,6 +26,7 @@ import datetime
 import shutil
 import unittest
 import xmlrunner
+import locale
 
 sys.dont_write_bytecode = True
 
@@ -237,6 +238,17 @@ def apply_filter(tests, tc_filter):
     return result
 
 
+def check_and_set_locale():
+    """ Function will check locale settings. In case, that it isn't configured
+    properly, then default values specified by DEFAULT_LOCALE will be used.
+    """
+
+    system_locale = locale.getdefaultlocale()
+    if None in system_locale:
+        os.environ['LC_ALL'] = settings.getValue('DEFAULT_LOCALE')
+        logging.warning("Locale was not properly configured. Default values were set. Old locale: %s, New locale: %s",
+                        system_locale, locale.getdefaultlocale())
+
 class MockTestCase(unittest.TestCase):
     """Allow use of xmlrunner to generate Jenkins compatible output without
     using xmlrunner to actually run tests.
@@ -309,6 +321,9 @@ def main():
     configure_logging(settings.getValue('VERBOSITY'))
     logger = logging.getLogger()
 
+    # check and fix locale
+    check_and_set_locale()
+
     # configure trafficgens
 
     if args['trafficgen']: