1 From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
2 Date: Thu, 19 Jan 2017 23:03:54 +0100
3 Subject: [PATCH] nova: libvirt: fix delete instance with nvram
9 [1] https://review.openstack.org/#/q/
10 539d381434ccadcdc3f5d58c2705c35558a3a065
12 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
14 .../files/nova-libvirt-delete-with-nvram.patch | 70 ++++++++++++++++++++++
15 .../openstack_tasks/manifests/roles/compute.pp | 12 ++++
16 2 files changed, 82 insertions(+)
17 create mode 100644 deployment/puppet/openstack/files/nova-libvirt-delete-with-nvram.patch
19 diff --git a/deployment/puppet/openstack/files/nova-libvirt-delete-with-nvram.patch b/deployment/puppet/openstack/files/nova-libvirt-delete-with-nvram.patch
21 index 0000000..5d4f67c
23 +++ b/deployment/puppet/openstack/files/nova-libvirt-delete-with-nvram.patch
25 +From: Kevin Zhao <kevin.zhao@linaro.org>
26 +Date: Thu, 5 Jan 2017 21:32:41 +0000
27 +Subject: [PATCH] libvirt: fix nova can't delete the instance with nvram
29 +Currently libvirt needs a flag when deleting an VM with a nvram file,
30 +without which nova can't delete an instance booted with UEFI. Add
31 +deletion flag for NVRAM. Also add a test case.
33 +[ Alexandru Avadanii ]
34 +Removed chunks affecting tests and adapted for OPNFV Armband.
36 +Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
37 +Co-authored-by: Derek Higgins <derekh@redhat.com>
38 +Change-Id: I46baa952b6c3a1a4c5cf2660931f317cafb5757d
42 +diff --git a/virt/libvirt/driver.py b/virt/libvirt/driver.py
43 +--- a/virt/libvirt/driver.py
44 ++++ b/virt/libvirt/driver.py
45 +@@ -903,7 +903,8 @@ class LibvirtDriver(driver.ComputeDriver):
47 + guest = self._host.get_guest(instance)
49 +- guest.delete_configuration()
50 ++ support_uefi = self._has_uefi_support()
51 ++ guest.delete_configuration(support_uefi)
52 + except libvirt.libvirtError as e:
53 + with excutils.save_and_reraise_exception():
54 + errcode = e.get_error_code()
55 +@@ -1241,7 +1242,8 @@ class LibvirtDriver(driver.ComputeDriver):
56 + # If any part of this block fails, the domain is
57 + # re-defined regardless.
58 + if guest.has_persistent_configuration():
59 +- guest.delete_configuration()
60 ++ support_uefi = self._has_uefi_support()
61 ++ guest.delete_configuration(support_uefi)
63 + # Start copy with VIR_DOMAIN_REBASE_REUSE_EXT flag to
64 + # allow writing to existing external volume file
65 +@@ -1760,7 +1762,8 @@ class LibvirtDriver(driver.ComputeDriver):
66 + # If any part of this block fails, the domain is
67 + # re-defined regardless.
68 + if guest.has_persistent_configuration():
69 +- guest.delete_configuration()
70 ++ support_uefi = self._has_uefi_support()
71 ++ guest.delete_configuration(support_uefi)
73 + # NOTE (rmk): Establish a temporary mirror of our root disk and
74 + # issue an abort once we have a complete copy.
75 +diff --git a/virt/libvirt/guest.py b/virt/libvirt/guest.py
76 +--- a/virt/libvirt/guest.py
77 ++++ b/virt/libvirt/guest.py
78 +@@ -262,11 +262,13 @@ class Guest(object):
80 + id=vcpu[0], cpu=vcpu[3], state=vcpu[1], time=vcpu[2])
82 +- def delete_configuration(self):
83 ++ def delete_configuration(self, support_uefi=False):
84 + """Undefines a domain from hypervisor."""
86 +- self._domain.undefineFlags(
87 +- libvirt.VIR_DOMAIN_UNDEFINE_MANAGED_SAVE)
88 ++ flags = libvirt.VIR_DOMAIN_UNDEFINE_MANAGED_SAVE
90 ++ flags |= libvirt.VIR_DOMAIN_UNDEFINE_NVRAM
91 ++ self._domain.undefineFlags(flags)
92 + except libvirt.libvirtError:
93 + LOG.debug("Error from libvirt during undefineFlags. %d"
94 + "Retrying with undefine", self.id)
95 diff --git a/deployment/puppet/openstack_tasks/manifests/roles/compute.pp b/deployment/puppet/openstack_tasks/manifests/roles/compute.pp
96 index f6e6698..dd0c034 100644
97 --- a/deployment/puppet/openstack_tasks/manifests/roles/compute.pp
98 +++ b/deployment/puppet/openstack_tasks/manifests/roles/compute.pp
99 @@ -301,6 +301,18 @@ class openstack_tasks::roles::compute {
100 unless => "patch -p1 -R -N --dry-run < ${nova_path}/libvirt-vga-console.patch",
102 require => [Package['patch']],
104 + # FIXME(armband): Backport fix: nova delete instance with nvram
105 + file { "${nova_path}/nova-libvirt-delete-with-nvram.patch":
107 + source => "puppet:///modules/openstack/nova-libvirt-delete-with-nvram.patch",
109 + exec { 'nova libvirt delete instance with nvram':
110 + path => ['/usr/bin'],
111 + command => "patch -p1 < ${nova_path}/nova-libvirt-delete-with-nvram.patch",
112 + unless => "patch -p1 -R -N --dry-run < ${nova_path}/nova-libvirt-delete-with-nvram.patch",
114 + require => [Package['patch']],
117 class { '::nova::cache':