Merge lp:~zyga/snapcraft/fix-process-leak into lp:~snappy-dev/snapcraft/core

Proposed by Zygmunt Krynicki on 2015-08-26
Status: Merged
Approved by: Michael Vogt on 2015-08-26
Approved revision: 136
Merged at revision: 136
Proposed branch: lp:~zyga/snapcraft/fix-process-leak
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 76 lines (+34/-30)
1 file modified
snapcraft/cmds.py (+34/-30)
To merge this branch: bzr merge lp:~zyga/snapcraft/fix-process-leak
Reviewer Review Type Date Requested Status
Michael Vogt 2015-08-26 Approve on 2015-08-26
Review via email: mp+269172@code.launchpad.net

Commit Message

Ensure that snapcraft run kills qemu

To post a comment you must log in.
Michael Vogt (mvo) wrote :

Yay, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snapcraft/cmds.py'
2--- snapcraft/cmds.py 2015-08-05 14:38:33 +0000
3+++ snapcraft/cmds.py 2015-08-26 09:00:05 +0000
4@@ -169,38 +169,42 @@
5 common.run(
6 ['sudo', 'ubuntu-device-flash', 'core', '--developer-mode', '--enable-ssh', '15.04', '-o', qemu_img],
7 cwd=qemudir)
8- qemu = subprocess.Popen(
9- ["kvm", "-m", "768", "-nographic",
10- "-snapshot", "-redir", "tcp:8022::22", qemu_img],
11- stdin=subprocess.PIPE)
12- n = tempfile.NamedTemporaryFile()
13- ssh_opts = [
14- "-oStrictHostKeyChecking=no",
15- "-oUserKnownHostsFile=%s" % n.name
16- ]
17- while True:
18+ qemu = None
19+ try:
20+ qemu = subprocess.Popen(
21+ ["kvm", "-m", "768", "-nographic",
22+ "-snapshot", "-redir", "tcp:8022::22", qemu_img],
23+ stdin=subprocess.PIPE)
24+ n = tempfile.NamedTemporaryFile()
25+ ssh_opts = [
26+ "-oStrictHostKeyChecking=no",
27+ "-oUserKnownHostsFile=%s" % n.name
28+ ]
29+ while True:
30+ ret_code = subprocess.call(
31+ ["ssh"] + ssh_opts +
32+ ["ubuntu@localhost", "-p", "8022", "true"])
33+ if ret_code == 0:
34+ break
35+ print("Waiting for device")
36+ time.sleep(1)
37+ snap_dir = os.path.join(os.getcwd(), "snap")
38+ # copy the snap
39+ snaps = glob.glob(snap_dir + "/*.snap")
40+ subprocess.call(
41+ ["scp"] + ssh_opts + [
42+ "-P", "8022", "-r"] + snaps + ["ubuntu@localhost:~/"])
43+ # install the snap
44 ret_code = subprocess.call(
45 ["ssh"] + ssh_opts +
46- ["ubuntu@localhost", "-p", "8022", "true"])
47- if ret_code == 0:
48- break
49- print("Waiting for device")
50- time.sleep(1)
51- snap_dir = os.path.join(os.getcwd(), "snap")
52- # copy the snap
53- snaps = glob.glob(snap_dir + "/*.snap")
54- subprocess.call(
55- ["scp"] + ssh_opts + [
56- "-P", "8022", "-r"] + snaps + ["ubuntu@localhost:~/"])
57- # install the snap
58- ret_code = subprocess.call(
59- ["ssh"] + ssh_opts +
60- ["ubuntu@localhost", "-p", "8022", "sudo snappy install *.snap"])
61- # "login"
62- subprocess.call(
63- ["ssh"] + ssh_opts + ["-p", "8022", "ubuntu@localhost"],
64- preexec_fn=os.setsid)
65- qemu.kill()
66+ ["ubuntu@localhost", "-p", "8022", "sudo snappy install *.snap"])
67+ # "login"
68+ subprocess.call(
69+ ["ssh"] + ssh_opts + ["-p", "8022", "ubuntu@localhost"],
70+ preexec_fn=os.setsid)
71+ finally:
72+ if qemu:
73+ qemu.kill()
74
75
76 def check_for_collisions(parts):

Subscribers

People subscribed via source and target branches