summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2017-05-03 15:38:53 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-05-18 14:01:47 +0100
commit0ef6fc5f9bf4d76e711a70942d4c7337b37c5b3f (patch)
treef7dbffc85a64cce492d919710f4c2f185d4db2cf /meta/lib
parent5b649b4bbd348f9933be4159c980c41a739bf68a (diff)
downloadpoky-0ef6fc5f9bf4d76e711a70942d4c7337b37c5b3f.tar.gz
QemuRunner: avoid tainting os.environ
That a utility function permanently changes the process environment is bad style and leads to subtle, hard to debug problems. For example, we had one oe-selftest which used runqemu() with an override for DEPLOY_DIR_IMAGE. Another test then just called runCmd() and ended up passing the wrong DEPLOY_DIR_IMAGE set earlier in os.environ. The approach used here is to pass the desired environment dict to the launch() method as a new, optional parameter, which then gets passed on to subproject.Popen(). The modified env variables do not get logged, as before. [YOCTO #11443] (From OE-Core rev: cab20f3b2fe668a63c58b44f2ad797fed74226fe) Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oeqa/utils/qemurunner.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index ba44b96f53..cd60ba71a3 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -98,11 +98,12 @@ class QemuRunner:
98 raise SystemExit 98 raise SystemExit
99 99
100 def start(self, qemuparams = None, get_ip = True, extra_bootparams = None, runqemuparams='', launch_cmd=None, discard_writes=True): 100 def start(self, qemuparams = None, get_ip = True, extra_bootparams = None, runqemuparams='', launch_cmd=None, discard_writes=True):
101 env = os.environ.copy()
101 if self.display: 102 if self.display:
102 os.environ["DISPLAY"] = self.display 103 env["DISPLAY"] = self.display
103 # Set this flag so that Qemu doesn't do any grabs as SDL grabs 104 # Set this flag so that Qemu doesn't do any grabs as SDL grabs
104 # interact badly with screensavers. 105 # interact badly with screensavers.
105 os.environ["QEMU_DONT_GRAB"] = "1" 106 env["QEMU_DONT_GRAB"] = "1"
106 if not os.path.exists(self.rootfs): 107 if not os.path.exists(self.rootfs):
107 logger.error("Invalid rootfs %s" % self.rootfs) 108 logger.error("Invalid rootfs %s" % self.rootfs)
108 return False 109 return False
@@ -110,12 +111,12 @@ class QemuRunner:
110 logger.error("Invalid TMPDIR path %s" % self.tmpdir) 111 logger.error("Invalid TMPDIR path %s" % self.tmpdir)
111 return False 112 return False
112 else: 113 else:
113 os.environ["OE_TMPDIR"] = self.tmpdir 114 env["OE_TMPDIR"] = self.tmpdir
114 if not os.path.exists(self.deploy_dir_image): 115 if not os.path.exists(self.deploy_dir_image):
115 logger.error("Invalid DEPLOY_DIR_IMAGE path %s" % self.deploy_dir_image) 116 logger.error("Invalid DEPLOY_DIR_IMAGE path %s" % self.deploy_dir_image)
116 return False 117 return False
117 else: 118 else:
118 os.environ["DEPLOY_DIR_IMAGE"] = self.deploy_dir_image 119 env["DEPLOY_DIR_IMAGE"] = self.deploy_dir_image
119 120
120 if not launch_cmd: 121 if not launch_cmd:
121 launch_cmd = 'runqemu %s %s ' % ('snapshot' if discard_writes else '', runqemuparams) 122 launch_cmd = 'runqemu %s %s ' % ('snapshot' if discard_writes else '', runqemuparams)
@@ -128,9 +129,9 @@ class QemuRunner:
128 launch_cmd += ' nographic' 129 launch_cmd += ' nographic'
129 launch_cmd += ' %s %s' % (self.machine, self.rootfs) 130 launch_cmd += ' %s %s' % (self.machine, self.rootfs)
130 131
131 return self.launch(launch_cmd, qemuparams=qemuparams, get_ip=get_ip, extra_bootparams=extra_bootparams) 132 return self.launch(launch_cmd, qemuparams=qemuparams, get_ip=get_ip, extra_bootparams=extra_bootparams, env=env)
132 133
133 def launch(self, launch_cmd, get_ip = True, qemuparams = None, extra_bootparams = None): 134 def launch(self, launch_cmd, get_ip = True, qemuparams = None, extra_bootparams = None, env = None):
134 try: 135 try:
135 threadsock, threadport = self.create_socket() 136 threadsock, threadport = self.create_socket()
136 self.server_socket, self.serverport = self.create_socket() 137 self.server_socket, self.serverport = self.create_socket()
@@ -157,7 +158,7 @@ class QemuRunner:
157 # blocking at the end of the runqemu script when using this within 158 # blocking at the end of the runqemu script when using this within
158 # oe-selftest (this makes stty error out immediately). There ought 159 # oe-selftest (this makes stty error out immediately). There ought
159 # to be a proper fix but this will suffice for now. 160 # to be a proper fix but this will suffice for now.
160 self.runqemu = subprocess.Popen(launch_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, preexec_fn=os.setpgrp) 161 self.runqemu = subprocess.Popen(launch_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, preexec_fn=os.setpgrp, env=env)
161 output = self.runqemu.stdout 162 output = self.runqemu.stdout
162 163
163 # 164 #