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
=== modified file 'lava_dispatcher/client/base.py'
--- lava_dispatcher/client/base.py 2011-11-30 01:17:02 +0000
+++ lava_dispatcher/client/base.py 2011-12-11 17:18:23 +0000
@@ -59,7 +59,7 @@
59 index = 059 index = 0
60 while index == 0:60 while index == 0:
61 index = self._connection.expect(61 index = self._connection.expect(
62 ['.+', pexpect.EOF, pexpect.TIMEOUT], timeout=1)62 ['.+', pexpect.EOF, pexpect.TIMEOUT], timeout=1,lava_no_logging=1)
6363
64 def run(self, cmd, response=None, timeout=-1):64 def run(self, cmd, response=None, timeout=-1):
65 """Run `cmd` and wait for a shell response.65 """Run `cmd` and wait for a shell response.
@@ -93,7 +93,7 @@
93 self._connection.expect(self._prompt_str, timeout=timeout)93 self._connection.expect(self._prompt_str, timeout=timeout)
94 if self._wait_for_rc:94 if self._wait_for_rc:
95 match_id = self._connection.expect(95 match_id = self._connection.expect(
96 ['rc=(\d+\d?\d?)', pexpect.EOF, pexpect.TIMEOUT], timeout=2)96 ['rc=(\d+\d?\d?)', pexpect.EOF, pexpect.TIMEOUT], timeout=2, lava_no_logging=1)
97 if match_id == 0:97 if match_id == 0:
98 rc = int(self._connection.match.groups()[0])98 rc = int(self._connection.match.groups()[0])
99 else:99 else:
100100
=== modified file 'lava_dispatcher/client/master.py'
--- lava_dispatcher/client/master.py 2011-12-07 01:35:56 +0000
+++ lava_dispatcher/client/master.py 2011-12-11 17:18:23 +0000
@@ -389,7 +389,7 @@
389 self.proc.hard_reboot()389 self.proc.hard_reboot()
390 self._in_master_shell(300)390 self._in_master_shell(300)
391 self.proc.sendline('export PS1="$PS1 [rc=$(echo \$?)]: "')391 self.proc.sendline('export PS1="$PS1 [rc=$(echo \$?)]: "')
392 self.proc.expect(self.master_str, timeout=10)392 self.proc.expect(self.master_str, timeout=10, lava_no_logging=1)
393393
394 def _format_testpartition(self, session):394 def _format_testpartition(self, session):
395 logging.info("Format testboot and testrootfs partitions")395 logging.info("Format testboot and testrootfs partitions")
@@ -530,7 +530,7 @@
530 """530 """
531 self.proc.sendline("")531 self.proc.sendline("")
532 match_id = self.proc.expect(532 match_id = self.proc.expect(
533 [self.master_str, pexpect.TIMEOUT], timeout=timeout)533 [self.master_str, pexpect.TIMEOUT], timeout=timeout, lava_no_logging=1)
534 if match_id == 1:534 if match_id == 1:
535 raise OperationFailed535 raise OperationFailed
536 logging.info("System is in master image now")536 logging.info("System is in master image now")
537537
=== modified file 'lava_dispatcher/connection.py'
--- lava_dispatcher/connection.py 2011-12-09 21:00:57 +0000
+++ lava_dispatcher/connection.py 2011-12-11 17:18:23 +0000
@@ -42,9 +42,29 @@
42 # pexpect-like interface.42 # pexpect-like interface.
4343
44 def sendline(self, *args, **kw):44 def sendline(self, *args, **kw):
45 logging.debug("sendline : %s" %args[0])
45 return self.proc.sendline(*args, **kw)46 return self.proc.sendline(*args, **kw)
4647
48 def send(self, *args, **kw):
49 logging.debug("sendline : %s" %args[0])
50 return self.proc.send(*args, **kw)
51
47 def expect(self, *args, **kw):52 def expect(self, *args, **kw):
53 # some expect should not be logged because it is so much noise.
54 if kw.has_key('lava_no_logging'):
55 del kw['lava_no_logging']
56 return self.proc.expect(*args, **kw)
57
58 if (kw.has_key('timeout')):
59 timeout = kw['timeout']
60 else:
61 timeout = self.proc.timeout
62
63 if len(args) == 1:
64 logging.debug("expect (%d): '%s'" %(timeout, args[0]))
65 else:
66 logging.debug("expect (%d): '%s'" %(timeout, str(args)))
67
48 return self.proc.expect(*args, **kw)68 return self.proc.expect(*args, **kw)
4969
50 def sendcontrol(self, *args, **kw):70 def sendcontrol(self, *args, **kw):
@@ -58,14 +78,14 @@
58 # Extra bits.78 # Extra bits.
5979
60 def _enter_uboot(self):80 def _enter_uboot(self):
61 self.proc.expect("Hit any key to stop autoboot")81 self.expect("Hit any key to stop autoboot")
62 self.proc.sendline("")82 self.sendline("")
6383
64 def soft_reboot(self):84 def soft_reboot(self):
65 self.proc.sendline("reboot")85 self.sendline("reboot")
66 # set soft reboot timeout 120s, or do a hard reset86 # set soft reboot timeout 120s, or do a hard reset
67 logging.info("Rebooting the system")87 logging.info("Rebooting the system")
68 id = self.proc.expect(88 id = self.expect(
69 ['Restarting system.', 'The system is going down for reboot NOW',89 ['Restarting system.', 'The system is going down for reboot NOW',
70 'Will now restart', pexpect.TIMEOUT], timeout=120)90 'Will now restart', pexpect.TIMEOUT], timeout=120)
71 if id not in [0,1,2]:91 if id not in [0,1,2]:
@@ -97,8 +117,8 @@
97 logging.exception("_enter_uboot failed")117 logging.exception("_enter_uboot failed")
98 self.hard_reboot()118 self.hard_reboot()
99 self._enter_uboot()119 self._enter_uboot()
100 self.proc.sendline(boot_cmds[0])120 self.sendline(boot_cmds[0])
101 bootloader_prompt = re.escape(self.device_option('bootloader_prompt'))121 bootloader_prompt = re.escape(self.device_option('bootloader_prompt'))
102 for line in range(1, len(boot_cmds)):122 for line in range(1, len(boot_cmds)):
103 self.proc.expect(bootloader_prompt, timeout=300)123 self.expect(bootloader_prompt, timeout=300)
104 self.proc.sendline(boot_cmds[line])124 self.sendline(boot_cmds[line])

Subscribers

People subscribed via source and target branches