Merge lp:~le-chi-thu/lava-dispatcher/log_send_and_expect into lp:lava-dispatcher

Proposed by Le Chi Thu
Status: Merged
Merge reported by: Le Chi Thu
Merged at revision: not available
Proposed branch: lp:~le-chi-thu/lava-dispatcher/log_send_and_expect
Merge into: lp:lava-dispatcher
Diff against target: 108 lines (+31/-11)
3 files modified
lava_dispatcher/client/base.py (+2/-2)
lava_dispatcher/client/master.py (+2/-2)
lava_dispatcher/connection.py (+27/-7)
To merge this branch: bzr merge lp:~le-chi-thu/lava-dispatcher/log_send_and_expect
Reviewer Review Type Date Requested Status
Paul Larson (community) Approve
Le Chi Thu (community) Needs Resubmitting
Michael Hudson-Doyle (community) Approve
Review via email: mp+84673@code.launchpad.net

Description of the change

Add logging for sending and expecting statements.

To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Seems fine.

review: Approve
Revision history for this message
Paul Larson (pwlars) wrote :

Would be nice if it displayed the timeout even if we don't specify one - sometimes the default timeout isn't so obvious. It's easy to get by looking at the timeout property of the proc object. Otherwise, looks ok to merge

174. By Le Chi Thu <email address hidden> <email address hidden>

Log the default timeout if the timeout is not specified

Revision history for this message
Le Chi Thu (le-chi-thu) wrote :

Log the default timeout if the timeout is not specified

review: Needs Resubmitting
Revision history for this message
Paul Larson (pwlars) wrote :

65 + if (kw.has_key('timeout')):
66 + timeout = kw['timeout']
67 + else:
68 + timeout = self.proc.timeout
69 +
70 + if len(args) == 1:
71 + logging.debug("expect (%d): '%s'" %(timeout, args[0]))
72 + else:
73 + logging.debug("expect (%d): '%s'" %(timeout, str(args)))

We should combine these two blocks, no need to have this ambiguous check for len(args) == 1 if we just checked whether timeout was specified.

Also, there is a small merge conflict to fix. Otherwise, still looks fine.

review: Approve
175. By Le Chi Thu <email address hidden> <email address hidden>

Fixed merge conflix with trunk

Revision history for this message
Le Chi Thu (le-chi-thu) wrote :

Major args is only one element and Iit will print a string which look
better than to print an array of one element.

Merge conflict is resolved.

>>> args=["hello"]
>>> print "expect '%s'"%args[0]
expect 'hello'
>>> print "expect %s"%str(args)
expect ['hello']

On 9 December 2011 00:22, Paul Larson <email address hidden> wrote:

> Review: Approve
>
> 65 + if (kw.has_key('timeout')):
> 66 + timeout = kw['timeout']
> 67 + else:
> 68 + timeout = self.proc.timeout
> 69 +
> 70 + if len(args) == 1:
> 71 + logging.debug("expect (%d): '%s'" %(timeout, args[0]))
> 72 + else:
> 73 + logging.debug("expect (%d): '%s'" %(timeout, str(args)))
>
> We should combine these two blocks, no need to have this ambiguous check
> for len(args) == 1 if we just checked whether timeout was specified.
>
> Also, there is a small merge conflict to fix. Otherwise, still looks fine.
> --
>
> https://code.launchpad.net/~le-chi-thu/lava-dispatcher/log_send_and_expect/+merge/84673
> You are the owner of lp:~le-chi-thu/lava-dispatcher/log_send_and_expect.
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lava_dispatcher/client/base.py'
2--- lava_dispatcher/client/base.py 2011-11-30 01:17:02 +0000
3+++ lava_dispatcher/client/base.py 2011-12-11 17:18:23 +0000
4@@ -59,7 +59,7 @@
5 index = 0
6 while index == 0:
7 index = self._connection.expect(
8- ['.+', pexpect.EOF, pexpect.TIMEOUT], timeout=1)
9+ ['.+', pexpect.EOF, pexpect.TIMEOUT], timeout=1,lava_no_logging=1)
10
11 def run(self, cmd, response=None, timeout=-1):
12 """Run `cmd` and wait for a shell response.
13@@ -93,7 +93,7 @@
14 self._connection.expect(self._prompt_str, timeout=timeout)
15 if self._wait_for_rc:
16 match_id = self._connection.expect(
17- ['rc=(\d+\d?\d?)', pexpect.EOF, pexpect.TIMEOUT], timeout=2)
18+ ['rc=(\d+\d?\d?)', pexpect.EOF, pexpect.TIMEOUT], timeout=2, lava_no_logging=1)
19 if match_id == 0:
20 rc = int(self._connection.match.groups()[0])
21 else:
22
23=== modified file 'lava_dispatcher/client/master.py'
24--- lava_dispatcher/client/master.py 2011-12-07 01:35:56 +0000
25+++ lava_dispatcher/client/master.py 2011-12-11 17:18:23 +0000
26@@ -389,7 +389,7 @@
27 self.proc.hard_reboot()
28 self._in_master_shell(300)
29 self.proc.sendline('export PS1="$PS1 [rc=$(echo \$?)]: "')
30- self.proc.expect(self.master_str, timeout=10)
31+ self.proc.expect(self.master_str, timeout=10, lava_no_logging=1)
32
33 def _format_testpartition(self, session):
34 logging.info("Format testboot and testrootfs partitions")
35@@ -530,7 +530,7 @@
36 """
37 self.proc.sendline("")
38 match_id = self.proc.expect(
39- [self.master_str, pexpect.TIMEOUT], timeout=timeout)
40+ [self.master_str, pexpect.TIMEOUT], timeout=timeout, lava_no_logging=1)
41 if match_id == 1:
42 raise OperationFailed
43 logging.info("System is in master image now")
44
45=== modified file 'lava_dispatcher/connection.py'
46--- lava_dispatcher/connection.py 2011-12-09 21:00:57 +0000
47+++ lava_dispatcher/connection.py 2011-12-11 17:18:23 +0000
48@@ -42,9 +42,29 @@
49 # pexpect-like interface.
50
51 def sendline(self, *args, **kw):
52+ logging.debug("sendline : %s" %args[0])
53 return self.proc.sendline(*args, **kw)
54
55+ def send(self, *args, **kw):
56+ logging.debug("sendline : %s" %args[0])
57+ return self.proc.send(*args, **kw)
58+
59 def expect(self, *args, **kw):
60+ # some expect should not be logged because it is so much noise.
61+ if kw.has_key('lava_no_logging'):
62+ del kw['lava_no_logging']
63+ return self.proc.expect(*args, **kw)
64+
65+ if (kw.has_key('timeout')):
66+ timeout = kw['timeout']
67+ else:
68+ timeout = self.proc.timeout
69+
70+ if len(args) == 1:
71+ logging.debug("expect (%d): '%s'" %(timeout, args[0]))
72+ else:
73+ logging.debug("expect (%d): '%s'" %(timeout, str(args)))
74+
75 return self.proc.expect(*args, **kw)
76
77 def sendcontrol(self, *args, **kw):
78@@ -58,14 +78,14 @@
79 # Extra bits.
80
81 def _enter_uboot(self):
82- self.proc.expect("Hit any key to stop autoboot")
83- self.proc.sendline("")
84+ self.expect("Hit any key to stop autoboot")
85+ self.sendline("")
86
87 def soft_reboot(self):
88- self.proc.sendline("reboot")
89+ self.sendline("reboot")
90 # set soft reboot timeout 120s, or do a hard reset
91 logging.info("Rebooting the system")
92- id = self.proc.expect(
93+ id = self.expect(
94 ['Restarting system.', 'The system is going down for reboot NOW',
95 'Will now restart', pexpect.TIMEOUT], timeout=120)
96 if id not in [0,1,2]:
97@@ -97,8 +117,8 @@
98 logging.exception("_enter_uboot failed")
99 self.hard_reboot()
100 self._enter_uboot()
101- self.proc.sendline(boot_cmds[0])
102+ self.sendline(boot_cmds[0])
103 bootloader_prompt = re.escape(self.device_option('bootloader_prompt'))
104 for line in range(1, len(boot_cmds)):
105- self.proc.expect(bootloader_prompt, timeout=300)
106- self.proc.sendline(boot_cmds[line])
107+ self.expect(bootloader_prompt, timeout=300)
108+ self.sendline(boot_cmds[line])

Subscribers

People subscribed via source and target branches