Merge lp:~corey.bryant/curtin/README into lp:~curtin-dev/curtin/trunk

Proposed by Corey Bryant
Status: Merged
Merged at revision: 131
Proposed branch: lp:~corey.bryant/curtin/README
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 105 lines (+69/-1)
2 files modified
curtin/commands/install.py (+68/-0)
doc/devel/README.txt (+1/-1)
To merge this branch: bzr merge lp:~corey.bryant/curtin/README
Reviewer Review Type Date Requested Status
curtin developers Pending
Review via email: mp+212497@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'curtin/commands/install.py'
2--- curtin/commands/install.py 2013-09-19 21:01:27 +0000
3+++ curtin/commands/install.py 2014-03-24 19:18:58 +0000
4@@ -19,6 +19,7 @@
5 import json
6 import os
7 import re
8+import shlex
9 import shutil
10 import tempfile
11
12@@ -158,6 +159,69 @@
13
14 return (['sh', '-c', shcmd, 'curtin-poweroff', delay] + args)
15
16+def apply_kexec(kexec, target):
17+ # load kexec kernel from target directory, similar to /etc/init.d/kexec-load
18+ # kexec:
19+ # mode: on
20+ grubcfg = "boot/grub/grub.cfg"
21+ target_grubcfg = os.path.join(target, grubcfg)
22+
23+ if kexec is None or kexec.get("mode") != "on":
24+ return False
25+
26+ if not isinstance(kexec, dict):
27+ raise TypeError("kexec is not a dict.")
28+
29+ if not util.which('kexec'):
30+ util.subp(args=['apt-get', 'install', 'kexec-tools', '--assume-yes',
31+ '--quiet'])
32+
33+ if not os.path.isfile(target_grubcfg):
34+ raise ValueError("%s does not exist in target" % grubcfg)
35+
36+ with open(target_grubcfg, "r") as fp:
37+ default = 0
38+ menu_lines = []
39+
40+ # get the default grub boot entry number and menu entry line numbers
41+ for line_num, line in enumerate(fp, 1):
42+ if re.search(r"set default=\"[0-9]+\"", line):
43+ default = int(re.sub(r"[^0-9]", '', line))
44+ if re.match(r"menuentry", line):
45+ menu_lines.append(line_num)
46+
47+ if not menu_lines:
48+ LOG.error("grub config file does not have a menuentry\n")
49+ return False
50+
51+ # get the begin and end line numbers for default menuentry section,
52+ # using end of file if it's the last menuentry section
53+ begin = menu_lines[default]
54+ if begin != menu_lines[-1]:
55+ end = menu_lines[default + 1] - 1
56+ else:
57+ end = line_num
58+
59+ fp.seek(0)
60+ lines = fp.readlines()
61+ kernel = append = initrd = ""
62+
63+ for i in range(begin, end):
64+ if 'linux' in lines[i]:
65+ split_line = shlex.split(lines[i])
66+ kernel = target + split_line[1]
67+ append = "--append=" + ' '.join(split_line[2:])
68+ if 'initrd' in lines[i]:
69+ split_line = shlex.split(lines[i])
70+ initrd = "--initrd=" + target + split_line[1]
71+
72+ if not kernel:
73+ LOG.error("grub config file does not have a kernel\n")
74+ return False
75+
76+ LOG.debug("kexec -l %s %s %s" % (kernel, append, initrd))
77+ util.subp(args=['kexec', '-l', kernel, append, initrd])
78+ return True
79
80 def cmd_install(args):
81 cfg = CONFIG_BUILTIN
82@@ -191,6 +255,10 @@
83 stage = Stage(name, cfg.get(commands_name, {}), env)
84 stage.run()
85
86+ if apply_kexec(cfg.get('kexec'), workingd.target):
87+ cfg['power_state'] = {'mode': 'reboot', 'delay': 'now',
88+ 'message': "'rebooting with kexec'"}
89+
90 finally:
91 for d in ('sys', 'dev', 'proc'):
92 util.do_umount(os.path.join(workingd.target, d))
93
94=== modified file 'doc/devel/README.txt'
95--- doc/devel/README.txt 2014-01-29 16:20:44 +0000
96+++ doc/devel/README.txt 2014-03-24 19:18:58 +0000
97@@ -35,7 +35,7 @@
98 cd ~/src/curtin/trunk
99 # use 'launch' to launch a kvm instance with user data to pack
100 # up local curtin and run it inside instance.
101-./tools/launch $BOOTIMG --publish $ROOTTGZ curtin install "PUBURL/${ROOTTGZ##*/}"
102+./tools/launch $BOOTIMG --publish $ROOTTGZ -- curtin install "PUBURL/${ROOTTGZ##*/}"
103
104 ## notes about 'launch' ##
105 * launch has --help so you can see that for some info.

Subscribers

People subscribed via source and target branches