Merge lp:~vishvananda/nova/lp829020-rbp into lp:~hudson-openstack/nova/milestone-proposed

Proposed by Vish Ishaya
Status: Merged
Approved by: Vish Ishaya
Approved revision: 1544
Merged at revision: 1179
Proposed branch: lp:~vishvananda/nova/lp829020-rbp
Merge into: lp:~hudson-openstack/nova/milestone-proposed
Diff against target: 132 lines (+40/-37)
1 file modified
nova/virt/libvirt/connection.py (+40/-37)
To merge this branch: bzr merge lp:~vishvananda/nova/lp829020-rbp
Reviewer Review Type Date Requested Status
OpenStack release team Pending
Review via email: mp+75441@code.launchpad.net

Description of the change

Fixes libvirt rescue to use the same strategy as xen. Use a new copy of the base image as the rescue image. It leaves the original rescue image flags in, so a hand picked rescue image can still be used if desired.

To post a comment you must log in.
lp:~vishvananda/nova/lp829020-rbp updated
1544. By Vish Ishaya

fix permissions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/virt/libvirt/connection.py'
2--- nova/virt/libvirt/connection.py 2011-09-15 19:30:26 +0000
3+++ nova/virt/libvirt/connection.py 2011-09-16 15:52:13 +0000
4@@ -29,9 +29,9 @@
5 (default: kvm).
6 :libvirt_uri: Override for the default libvirt URI (depends on libvirt_type).
7 :libvirt_xml_template: Libvirt XML Template.
8-:rescue_image_id: Rescue ami image (default: ami-rescue).
9-:rescue_kernel_id: Rescue aki image (default: aki-rescue).
10-:rescue_ramdisk_id: Rescue ari image (default: ari-rescue).
11+:rescue_image_id: Rescue ami image (None = original image).
12+:rescue_kernel_id: Rescue aki image (None = original image).
13+:rescue_ramdisk_id: Rescue ari image (None = original image).
14 :injected_network_template: Template file for injected network
15 :allow_same_net_traffic: Whether to allow in project network traffic
16
17@@ -84,9 +84,9 @@
18 FLAGS = flags.FLAGS
19 flags.DECLARE('live_migration_retry_count', 'nova.compute.manager')
20 # TODO(vish): These flags should probably go into a shared location
21-flags.DEFINE_string('rescue_image_id', 'ami-rescue', 'Rescue ami image')
22-flags.DEFINE_string('rescue_kernel_id', 'aki-rescue', 'Rescue aki image')
23-flags.DEFINE_string('rescue_ramdisk_id', 'ari-rescue', 'Rescue ari image')
24+flags.DEFINE_string('rescue_image_id', None, 'Rescue ami image')
25+flags.DEFINE_string('rescue_kernel_id', None, 'Rescue aki image')
26+flags.DEFINE_string('rescue_ramdisk_id', None, 'Rescue ari image')
27 flags.DEFINE_string('libvirt_xml_template',
28 utils.abspath('virt/libvirt.xml.template'),
29 'Libvirt XML Template')
30@@ -467,7 +467,7 @@
31 shutil.rmtree(temp_dir)
32
33 @exception.wrap_exception()
34- def reboot(self, instance, network_info):
35+ def reboot(self, instance, network_info, xml=None):
36 """Reboot a virtual machine, given an instance reference.
37
38 This method actually destroys and re-creates the domain to ensure the
39@@ -478,7 +478,9 @@
40 # NOTE(itoumsn): Use XML delived from the running instance
41 # instead of using to_xml(instance, network_info). This is almost
42 # the ultimate stupid workaround.
43- xml = virt_dom.XMLDesc(0)
44+ if not xml:
45+ xml = virt_dom.XMLDesc(0)
46+
47 # NOTE(itoumsn): self.shutdown() and wait instead of self.destroy() is
48 # better because we cannot ensure flushing dirty buffers
49 # in the guest OS. But, in case of KVM, shutdown() does not work...
50@@ -542,43 +544,42 @@
51 data recovery.
52
53 """
54- self.destroy(instance, network_info, cleanup=False)
55+
56+ virt_dom = self._conn.lookupByName(instance['name'])
57+ unrescue_xml = virt_dom.XMLDesc(0)
58+ unrescue_xml_path = os.path.join(FLAGS.instances_path,
59+ instance['name'],
60+ 'unrescue.xml')
61+ f = open(unrescue_xml_path, 'w')
62+ f.write(unrescue_xml)
63+ f.close()
64
65 xml = self.to_xml(instance, network_info, rescue=True)
66- rescue_images = {'image_id': FLAGS.rescue_image_id,
67- 'kernel_id': FLAGS.rescue_kernel_id,
68- 'ramdisk_id': FLAGS.rescue_ramdisk_id}
69- self._create_image(context, instance, xml, '.rescue', rescue_images)
70- self._create_new_domain(xml)
71-
72- def _wait_for_rescue():
73- """Called at an interval until the VM is running again."""
74- instance_name = instance['name']
75-
76- try:
77- state = self.get_info(instance_name)['state']
78- except exception.NotFound:
79- msg = _("During reboot, %s disappeared.") % instance_name
80- LOG.error(msg)
81- raise utils.LoopingCallDone
82-
83- if state == power_state.RUNNING:
84- msg = _("Instance %s rescued successfully.") % instance_name
85- LOG.info(msg)
86- raise utils.LoopingCallDone
87-
88- timer = utils.LoopingCall(_wait_for_rescue)
89- return timer.start(interval=0.5, now=True)
90+ rescue_images = {
91+ 'image_id': FLAGS.rescue_image_id or instance['image_ref'],
92+ 'kernel_id': FLAGS.rescue_kernel_id or instance['kernel_id'],
93+ 'ramdisk_id': FLAGS.rescue_ramdisk_id or instance['ramdisk_id'],
94+ }
95+ self._create_image(context, instance, xml, '.rescue', rescue_images,
96+ network_info=network_info)
97+ self.reboot(instance, network_info, xml=xml)
98
99 @exception.wrap_exception()
100- def unrescue(self, instance, network_info):
101+ def unrescue(self, instance, callback, network_info):
102 """Reboot the VM which is being rescued back into primary images.
103
104 Because reboot destroys and re-creates instances, unresue should
105 simply call reboot.
106
107 """
108- self.reboot(instance, network_info)
109+ unrescue_xml_path = os.path.join(FLAGS.instances_path,
110+ instance['name'],
111+ 'unrescue.xml')
112+ f = open(unrescue_xml_path)
113+ unrescue_xml = f.read()
114+ f.close()
115+ os.remove(unrescue_xml_path)
116+ self.reboot(instance, network_info, xml=unrescue_xml)
117
118 @exception.wrap_exception()
119 def poll_rescued_instances(self, timeout):
120@@ -813,8 +814,10 @@
121 utils.execute('mkdir', '-p', container_dir)
122
123 # NOTE(vish): No need add the suffix to console.log
124- os.close(os.open(basepath('console.log', ''),
125- os.O_CREAT | os.O_WRONLY, 0660))
126+ console_log = basepath('console.log', '')
127+ if os.path.exists(console_log):
128+ utils.execute('chown', os.getuid(), console_log, run_as_root=True)
129+ os.close(os.open(console_log, os.O_CREAT | os.O_WRONLY, 0660))
130
131 if not disk_images:
132 disk_images = {'image_id': inst['image_ref'],

Subscribers

People subscribed via source and target branches