From cabd8b9d56a320abd12c98c1e26037d351944014 Mon Sep 17 00:00:00 2001 From: Noah van Dresser Date: Fri, 8 Jul 2016 10:42:23 -0700 Subject: [PATCH] Added Environ plugin which enables setting environment variables. Modified configparse optionxform str to make option names case sensitive. Bug fix for ModuleCmd to use io.StringIO.seek() instead of StringIO.StringIO.len(). Signed-off-by: Noah van Dresser --- pylib/System/TestDef.py | 2 ++ pylib/Utilities/Environ.py | 37 ++++++++++++++++++++++++++++ pylib/Utilities/Environ.yapsy-plugin | 18 ++++++++++++++ pylib/Utilities/ModuleCmd.py | 4 +-- 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 pylib/Utilities/Environ.py create mode 100644 pylib/Utilities/Environ.yapsy-plugin diff --git a/pylib/System/TestDef.py b/pylib/System/TestDef.py index f451ffe84..4316790c5 100644 --- a/pylib/System/TestDef.py +++ b/pylib/System/TestDef.py @@ -438,6 +438,8 @@ def configTest(self): print("Test .ini file not found!: " + testFile) sys.exit(1) self.config = configparser.ConfigParser() + # Set the config parser to make option names case sensitive. + self.config.optionxform = str self.config.read(self.log['inifiles']) for section in self.config.sections(): if self.logger is not None: diff --git a/pylib/Utilities/Environ.py b/pylib/Utilities/Environ.py new file mode 100644 index 000000000..23c5cd247 --- /dev/null +++ b/pylib/Utilities/Environ.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# +# Copyright (c) 2015-2016 Intel, Inc. All rights reserved. +# $COPYRIGHT$ +# +# Additional copyrights may follow +# +# $HEADER$ +# + +import shutil +import os +from BaseMTTUtility import * + +class Environ(BaseMTTUtility): + def __init__(self): + BaseMTTUtility.__init__(self) + self.options = {} + + def print_name(self): + return "Environ" + + def print_options(self, testDef, prefix): + lines = testDef.printOptions(self.options) + for line in lines: + print prefix + line + return + + def execute(self, log, keyvals, testDef): + testDef.logger.verbose_print("Environ Execute") + + # Set any provided key values + kvkeys = keyvals.keys() + for kvkey in kvkeys: + os.environ[kvkey] = keyvals[kvkey] + log['status'] = 0 + return diff --git a/pylib/Utilities/Environ.yapsy-plugin b/pylib/Utilities/Environ.yapsy-plugin new file mode 100644 index 000000000..03455ac47 --- /dev/null +++ b/pylib/Utilities/Environ.yapsy-plugin @@ -0,0 +1,18 @@ +# +# Copyright (c) 2015-2016 Intel, Inc. All rights reserved. +# $COPYRIGHT$ +# +# Additional copyrights may follow +# +# $HEADER$ +# + +[Core] +Name = Environ +Module = Environ + +[Documentation] +Author = Noah van Dresser +Version = 0.1 +Website = N/A +Description = Set environment variables diff --git a/pylib/Utilities/ModuleCmd.py b/pylib/Utilities/ModuleCmd.py index 6694af61e..431abfbe2 100644 --- a/pylib/Utilities/ModuleCmd.py +++ b/pylib/Utilities/ModuleCmd.py @@ -97,7 +97,7 @@ def loadModules(self, modules, testDef): sys.stdout = saved_stdout sys.stderr = saved_stderr - status = load_stderr.len + status = load_stderr.seek(0, os.SEEK_END) stdout = load_stdout.getvalue() stderr = load_stderr.getvalue() load_stdout.close() @@ -137,7 +137,7 @@ def unloadModules(self, modules, testDef): sys.stdout = saved_stdout sys.stderr = saved_stderr - status = unload_stderr.len + status = unload_stderr.seek(0, os.SEEK_END) stdout = unload_stdout.getvalue() stderr = unload_stderr.getvalue() unload_stdout.close()