Merge lp:~qzhang/lava-dispatcher/refactor-install-abrek into lp:lava-dispatcher

Proposed by Spring Zhang
Status: Rejected
Rejected by: Neil Williams
Proposed branch: lp:~qzhang/lava-dispatcher/refactor-install-abrek
Merge into: lp:lava-dispatcher
Diff against target: 193 lines (+63/-90)
3 files modified
dispatcher/actions/abrek.py (+31/-52)
dispatcher/actions/deploy.py (+20/-38)
dispatcher/client.py (+12/-0)
To merge this branch: bzr merge lp:~qzhang/lava-dispatcher/refactor-install-abrek
Reviewer Review Type Date Requested Status
Spring Zhang (community) Needs Resubmitting
Review via email: mp+55594@code.launchpad.net

Description of the change

use cmd_seq list to reduce some duplicated code in cmd_install_abrek() in abrek.py

To post a comment you must log in.
24. By Spring Zhang

1. fix a minor error
2. summary run cmd_seq to a method in LavaClient
3. modify deploy.py by new method

Revision history for this message
Spring Zhang (qzhang) wrote :

create a new method run_shell_cmd_seq() in LavaClient to run a command sequence, also applied to deploy.py

review: Needs Resubmitting
25. By Spring Zhang

merge from mainline r22

Revision history for this message
Spring Zhang (qzhang) wrote :

How about the cmd_seq() method?

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

I think something like this is still a good idea, but this branch must conflict horribly by now.

Unmerged revisions

25. By Spring Zhang

merge from mainline r22

24. By Spring Zhang

1. fix a minor error
2. summary run cmd_seq to a method in LavaClient
3. modify deploy.py by new method

23. By Spring Zhang

use cmd_seq list to reduce some duplicated code

22. By Spring Zhang

copy cmds to list

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dispatcher/actions/abrek.py'
2--- dispatcher/actions/abrek.py 2011-03-30 14:31:59 +0000
3+++ dispatcher/actions/abrek.py 2011-04-05 16:01:17 +0000
4@@ -22,65 +22,44 @@
5 def run(self, tests):
6 #Make sure in master image
7 #, or exception can be caught and do boot_master_image()
8+ client = self.client
9 try:
10- self.client.in_master_shell()
11+ client.in_master_shell()
12 except:
13- self.client.boot_master_image()
14-
15- #install bazaar in tester image
16- self.client.run_shell_command(
17- 'mkdir -p /mnt/root',
18- response = MASTER_STR)
19- self.client.run_shell_command(
20- 'mount /dev/disk/by-label/testrootfs /mnt/root',
21- response = MASTER_STR)
22- self.client.run_shell_command(
23- 'cp -f /mnt/root/etc/resolv.conf /mnt/root/etc/resolv.conf.bak',
24- response = MASTER_STR)
25- self.client.run_shell_command(
26- 'cp -L /etc/resolv.conf /mnt/root/etc',
27- response = MASTER_STR)
28- #eliminate warning: Can not write log, openpty() failed
29- # (/dev/pts not mounted?), does not work
30- self.client.run_shell_command(
31- 'mount --rbind /dev /mnt/root/dev',
32- response = MASTER_STR)
33- self.client.run_shell_command(
34- 'chroot /mnt/root apt-get update',
35- response = MASTER_STR)
36- #Install necessary packages for build abrek
37- self.client.run_shell_command(
38- 'chroot /mnt/root apt-get -y install bzr python-apt python-distutils-extra',
39- response = MASTER_STR, timeout=2400)
40- self.client.run_shell_command(
41- 'chroot /mnt/root bzr branch lp:abrek',
42- response = MASTER_STR)
43- self.client.run_shell_command(
44- 'chroot /mnt/root sh -c "cd abrek && python setup.py install"',
45- response = MASTER_STR)
46+ client.boot_master_image()
47+
48+ #Construct command sequence list
49+ cmd_seq = [
50+ ['mkdir -p /mnt/root',],
51+ ['mount /dev/disk/by-label/testrootfs /mnt/root',],
52+ ['cp -f /mnt/root/etc/resolv.conf /mnt/root/etc/resolv.conf.bak',],
53+ ['cp -L /etc/resolv.conf /mnt/root/etc',],
54+ #eliminate warning: Can not write log, openpty() failed
55+ # (/dev/pts not mounted?), does not work
56+ ['mount --rbind /dev /mnt/root/dev',],
57+ ['chroot /mnt/root apt-get update',],
58+ #Install necessary packages for build abrek
59+ ['chroot /mnt/root apt-get -y install bzr python-apt python-distutils-extra', 2400],
60+ ['chroot /mnt/root bzr branch lp:abrek',],
61+ ['chroot /mnt/root sh -c "cd abrek && python setup.py install"',]
62+ ]
63+ for test in tests:
64+ cmd_seq.append(['chroot /mnt/root abrek install %s' % test,])
65+ #clean up
66+ cmd_seq = cmd_seq + [
67+ ['cp -f /mnt/root/etc/resolv.conf.bak /mnt/root/etc/resolv.conf',],
68+ ['rm -rf /mnt/root/abrek',],
69+ ['cat /proc/mounts | awk \'{print $2}\' | grep "^/mnt/root/dev" | sort -r | xargs umount',]
70+ ]
71+
72+ client.run_shell_cmd_seq(cmd_seq)
73
74 #Test if abrek installed
75 try:
76- self.client.run_shell_command(
77+ client.run_shell_command(
78 'chroot /mnt/root abrek help',
79 response = "list-tests", timeout = 10)
80 except:
81 raise OperationFailed("abrek deployment failed")
82
83- for test in tests:
84- self.client.run_shell_command(
85- 'chroot /mnt/root abrek install %s' % test,
86- response = MASTER_STR)
87- #clean up
88- self.client.run_shell_command(
89- 'cp -f /mnt/root/etc/resolv.conf.bak /mnt/root/etc/resolv.conf',
90- response = MASTER_STR)
91- self.client.run_shell_command(
92- 'rm -rf /mnt/root/abrek',
93- response = MASTER_STR)
94- self.client.run_shell_command(
95- 'cat /proc/mounts | awk \'{print $2}\' | grep "^/mnt/root/dev" | sort -r | xargs umount',
96- response = MASTER_STR)
97- self.client.run_shell_command(
98- 'umount /mnt/root',
99- response = MASTER_STR)
100+ client.run_shell_command('umount /mnt/root', response = MASTER_STR)
101
102=== modified file 'dispatcher/actions/deploy.py'
103--- dispatcher/actions/deploy.py 2011-03-30 14:31:59 +0000
104+++ dispatcher/actions/deploy.py 2011-04-05 16:01:17 +0000
105@@ -118,45 +118,27 @@
106 return boot_tgz, root_tgz
107
108 def deploy_linaro_rootfs(self, rootfs):
109- client = self.client
110+ cmd_seq = [
111+ ['mkfs.ext3 -q /dev/disk/by-label/testrootfs -L testrootfs', ],
112+ ['udevadm trigger',],
113+ ['mkdir -p /mnt/root',],
114+ ['mount /dev/disk/by-label/testrootfs /mnt/root',],
115+ ['wget -qO- %s |tar --numeric-owner -C /mnt/root -xzf -' % rootfs, 600],
116+ ['umount /mnt/root',]
117+ ]
118+
119 print "Deploying linaro image"
120- client.run_shell_command(
121- 'mkfs.ext3 -q /dev/disk/by-label/testrootfs -L testrootfs',
122- response = MASTER_STR)
123- client.run_shell_command(
124- 'udevadm trigger',
125- response = MASTER_STR)
126- client.run_shell_command(
127- 'mkdir -p /mnt/root',
128- response = MASTER_STR)
129- client.run_shell_command(
130- 'mount /dev/disk/by-label/testrootfs /mnt/root',
131- response = MASTER_STR)
132- client.run_shell_command(
133- 'wget -qO- %s |tar --numeric-owner -C /mnt/root -xzf -' % rootfs,
134- response = MASTER_STR, timeout = 600)
135- client.run_shell_command(
136- 'umount /mnt/root',
137- response = MASTER_STR)
138+ self.client.run_shell_cmd_seq(cmd_seq)
139
140 def deploy_linaro_bootfs(self, bootfs):
141- client = self.client
142- client.run_shell_command(
143- 'mkfs.vfat /dev/disk/by-label/testboot -n testboot',
144- response = MASTER_STR)
145- client.run_shell_command(
146- 'udevadm trigger',
147- response = MASTER_STR)
148- client.run_shell_command(
149- 'mkdir -p /mnt/boot',
150- response = MASTER_STR)
151- client.run_shell_command(
152- 'mount /dev/disk/by-label/testboot /mnt/boot',
153- response = MASTER_STR)
154- client.run_shell_command(
155- 'wget -qO- %s |tar --numeric-owner -C /mnt/boot -xzf -' % bootfs,
156- response = MASTER_STR)
157- client.run_shell_command(
158- 'umount /mnt/boot',
159- response = MASTER_STR)
160+ cmd_seq = [
161+ ['mkfs.vfat /dev/disk/by-label/testboot -n testboot',],
162+ ['udevadm trigger',],
163+ ['mkdir -p /mnt/boot',],
164+ ['mount /dev/disk/by-label/testboot /mnt/boot',],
165+ ['wget -qO- %s |tar --numeric-owner -C /mnt/boot -xzf -' % bootfs,],
166+ ['umount /mnt/boot',],
167+ ]
168+
169+ self.client.run_shell_cmd_seq(cmd_seq)
170
171
172=== modified file 'dispatcher/client.py'
173--- dispatcher/client.py 2011-03-30 14:40:29 +0000
174+++ dispatcher/client.py 2011-04-05 16:01:17 +0000
175@@ -76,6 +76,18 @@
176 if response:
177 self.proc.expect(response, timeout=timeout)
178
179+ def run_shell_cmd_seq(self, cmd_seq):
180+ """
181+ cmd_seq is assumed to be a list:
182+ [[cmd1, timeout1], [cmd2, timeout2], ...]
183+ """
184+ for cmd in cmd_seq:
185+ if len(cmd) == 1:
186+ self.client.run_shell_command(cmd[0], response = MASTER_STR)
187+ else:
188+ self.client.run_shell_command(cmd[0], response = MASTER_STR,
189+ timeout = cmd[1])
190+
191 def check_network_up(self):
192 self.proc.sendline("LC_ALL=C ping -W4 -c1 %s" % LAVA_SERVER_IP)
193 id = self.proc.expect(["1 received", "0 received",

Subscribers

People subscribed via source and target branches