diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 233: change the default behaviour of CommandRunner.run() to raise

Message ID 20120220200610.13705.20411.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Michael-Doyle Hudson Feb. 20, 2012, 8:06 p.m. UTC
Merge authors:
  Michael Hudson-Doyle (mwhudson)
Related merge proposals:
  https://code.launchpad.net/~mwhudson/lava-dispatcher/fail-should-fail/+merge/93755
  proposed by: Michael Hudson-Doyle (mwhudson)
  review: Approve - Zygmunt Krynicki (zkrynicki)
------------------------------------------------------------
revno: 233 [merge]
committer: Michael Hudson-Doyle <michael.hudson@linaro.org>
branch nick: trunk
timestamp: Tue 2012-02-21 09:04:16 +1300
message:
  change the default behaviour of CommandRunner.run() to raise
  and exception if the shell command it runs fails.
modified:
  lava_dispatcher/client/base.py
  lava_dispatcher/client/master.py


--
lp:lava-dispatcher
https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk

You are subscribed to branch lp:lava-dispatcher.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava_dispatcher/client/base.py'
--- lava_dispatcher/client/base.py	2012-02-07 20:30:14 +0000
+++ lava_dispatcher/client/base.py	2012-02-20 00:41:31 +0000
@@ -61,7 +61,7 @@ 
             index = self._connection.expect(
                 ['.+', pexpect.EOF, pexpect.TIMEOUT], timeout=1, lava_no_logging=1)
 
-    def run(self, cmd, response=None, timeout=-1):
+    def run(self, cmd, response=None, timeout=-1, failok=False):
         """Run `cmd` and wait for a shell response.
 
         :param cmd: The command to execute.
@@ -96,6 +96,9 @@ 
                 ['rc=(\d+\d?\d?)', pexpect.EOF, pexpect.TIMEOUT], timeout=2, lava_no_logging=1)
             if match_id == 0:
                 rc = int(self._connection.match.groups()[0])
+                if rc != 0 and not failok:
+                    raise OperationFailed(
+                        "executing %r failed with code %s" % (cmd, rc))
             else:
                 rc = None
         else:
@@ -117,7 +120,8 @@ 
         lava_server_ip = self._client.context.lava_server_ip
         self.run(
             "LC_ALL=C ping -W4 -c1 %s" % lava_server_ip,
-            ["1 received", "0 received", "Network is unreachable"], timeout=5)
+            ["1 received", "0 received", "Network is unreachable"],
+            timeout=5, failok=True)
         if self.match_id == 0:
             return True
         else:
@@ -143,7 +147,7 @@ 
             self, client.proc, client.tester_str, wait_for_rc)
 
     def export_display(self):
-        self.run("su - linaro -c 'DISPLAY=:0 xhost local:'")
+        self.run("su - linaro -c 'DISPLAY=:0 xhost local:'", failok=True)
         self.run("export DISPLAY=:0")
 
 

=== modified file 'lava_dispatcher/client/master.py'
--- lava_dispatcher/client/master.py	2012-02-08 16:42:05 +0000
+++ lava_dispatcher/client/master.py	2012-02-20 00:42:52 +0000
@@ -69,14 +69,10 @@ 
         decompression_char = 'z'
     elif tarball_url.endswith('.bz2'):
         decompression_char = 'j'
-    rc = session.run(
+    session.run(
         'wget -qO- %s |tar --numeric-owner -C %s -x%sf -' % (
             tarball_url, dest, decompression_char),
         timeout=timeout)
-    if rc != 0:
-        msg = "Deploy: failed to deploy to %s" % dest
-        raise OperationFailed(msg)
-
 
 def _deploy_linaro_rootfs(session, rootfs):
     logging.info("Deploying linaro image")
@@ -153,6 +149,7 @@ 
         % (data_part_org, data_part_lava))
     session.run('sed -i "s/mmcblk1p%s/mmcblk1p%s/g" init.rc'
         % (sys_part_org, sys_part_lava))
+    # failok true for this?:
     session.run(
         'sed -i "/export PATH/a \ \ \ \ export PS1 root@linaro: " init.rc')
 
@@ -174,7 +171,7 @@ 
     logging.info("Deploying the test root filesystem")
 #    sdcard_part_lava = session._client.device_option("sdcard_part_android")
 
-    session.run('umount /dev/disk/by-label/testrootfs')
+    session.run('umount /dev/disk/by-label/testrootfs', failok=True)
     session.run(
         'mkfs -t %s -q /dev/disk/by-label/testrootfs -L testrootfs' % rootfstype)
     session.run('udevadm trigger')
@@ -187,7 +184,9 @@ 
 #        "/devices/platform/omap/omap_hsmmc.0/mmc_host/mmc0" % sdcard_part_lava
 #    session.run(
 #        'sed -i "%s" /mnt/lava/system/etc/vold.fstab' % sed_cmd)
-    session.run('sed -i "s/^PS1=.*$/PS1=\'root@linaro: \'/" /mnt/lava/system/etc/mkshrc')
+    session.run(
+        'sed -i "s/^PS1=.*$/PS1=\'root@linaro: \'/" /mnt/lava/system/etc/mkshrc',
+        failok=True)
     session.run('umount /mnt/lava/system')
 
 def _purge_linaro_android_sdcard(session):
@@ -218,8 +217,9 @@ 
             prefix += ' '
         self._prefix = prefix
 
-    def run(self, cmd, response=None, timeout=-1):
-        return super(PrefixCommandRunner, self).run(self._prefix + cmd, response, timeout)
+    def run(self, cmd, response=None, timeout=-1, failok=False):
+        return super(PrefixCommandRunner, self).run(
+            self._prefix + cmd, response, timeout, failok)
 
 
 class MasterCommandRunner(NetworkCommandRunner):
@@ -440,11 +440,11 @@ 
 
     def _format_testpartition(self, session, fstype):
         logging.info("Format testboot and testrootfs partitions")
-        session.run('umount /dev/disk/by-label/testrootfs')
+        session.run('umount /dev/disk/by-label/testrootfs', failok=True)
         session.run(
             'mkfs -t %s -q /dev/disk/by-label/testrootfs -L testrootfs'
             % fstype)
-        session.run('umount /dev/disk/by-label/testboot')
+        session.run('umount /dev/disk/by-label/testboot', failok=True)
         session.run('mkfs.vfat /dev/disk/by-label/testboot -n testboot')
 
     def _generate_tarballs(self, image_file):