diff options
Diffstat (limited to 'wintest/wintest.py')
-rw-r--r-- | wintest/wintest.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/wintest/wintest.py b/wintest/wintest.py index 81e2eda515..36d0659f03 100644 --- a/wintest/wintest.py +++ b/wintest/wintest.py @@ -117,6 +117,7 @@ class wintest(): f.close() def run_cmd(self, cmd, dir=".", show=None, output=False, checkfail=True): + '''run a command''' cmd = self.substitute(cmd) if isinstance(cmd, list): self.info('$ ' + " ".join(cmd)) @@ -133,7 +134,9 @@ class wintest(): else: return subprocess.call(cmd, shell=shell, cwd=dir) + def run_child(self, cmd, dir="."): + '''create a child and return the Popen handle to it''' cwd = os.getcwd() cmd = self.substitute(cmd) if isinstance(cmd, list): @@ -145,7 +148,7 @@ class wintest(): else: shell=True os.chdir(dir) - ret = subprocess.Popen(cmd, shell=shell) + ret = subprocess.Popen(cmd, shell=shell, stderr=subprocess.STDOUT) os.chdir(cwd) return ret @@ -200,7 +203,7 @@ class wintest(): retries = retries - 1 raise RuntimeError("Failed to find %s" % contains) - def pexpect_spawn(self, cmd, timeout=60): + def pexpect_spawn(self, cmd, timeout=60, crlf=True): '''wrapper around pexpect spawn''' cmd = self.substitute(cmd) self.info("$ " + cmd) @@ -214,8 +217,9 @@ class wintest(): line = self.substitute(line) return ret.old_expect(line, timeout=timeout) - ret.old_sendline = ret.sendline - ret.sendline = sendline_sub + if crlf: + ret.old_sendline = ret.sendline + ret.sendline = sendline_sub ret.old_expect = ret.expect ret.expect = expect_sub @@ -223,8 +227,11 @@ class wintest(): def get_nameserver(self): '''Get the current nameserver from /etc/resolv.conf''' - child = self.pexpect_spawn('cat /etc/resolv.conf') - child.expect('nameserver') + child = self.pexpect_spawn('cat /etc/resolv.conf', crlf=False) + i = child.expect(['Generated by wintest', 'nameserver']) + if i == 0: + child.expect('your original resolv.conf') + child.expect('nameserver') child.expect('\d+.\d+.\d+.\d+') return child.after |