Uplift Armband to Fuel Newton
[armband.git] / patches / fuel-library / arm64-bug-fixes / 0005-nova-libvirt-fix-delete-instance-with-nvram.patch
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
4
5 Backported from [1].
6
7 Closes-bug: 1567807
8
9 [1] https://review.openstack.org/#/q/
10     539d381434ccadcdc3f5d58c2705c35558a3a065
11
12 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
13 ---
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
18
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
20 new file mode 100644
21 index 0000000..5d4f67c
22 --- /dev/null
23 +++ b/deployment/puppet/openstack/files/nova-libvirt-delete-with-nvram.patch
24 @@ -0,0 +1,70 @@
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
28 +
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.
32 +
33 +[ Alexandru Avadanii ]
34 +Removed chunks affecting tests and adapted for OPNFV Armband.
35 +
36 +Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
37 +Co-authored-by: Derek Higgins <derekh@redhat.com>
38 +Change-Id: I46baa952b6c3a1a4c5cf2660931f317cafb5757d
39 +Closes-Bug: #1567807
40 +---
41 +
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):
46 +         try:
47 +             guest = self._host.get_guest(instance)
48 +             try:
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)
62 +
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)
72 +
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):
79 +                 yield VCPUInfo(
80 +                     id=vcpu[0], cpu=vcpu[3], state=vcpu[1], time=vcpu[2])
81 +
82 +-    def delete_configuration(self):
83 ++    def delete_configuration(self, support_uefi=False):
84 +         """Undefines a domain from hypervisor."""
85 +         try:
86 +-            self._domain.undefineFlags(
87 +-                libvirt.VIR_DOMAIN_UNDEFINE_MANAGED_SAVE)
88 ++            flags = libvirt.VIR_DOMAIN_UNDEFINE_MANAGED_SAVE
89 ++            if support_uefi:
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",
101      cwd     => $nova_path,
102      require => [Package['patch']],
103 +  } ->
104 +  # FIXME(armband): Backport fix: nova delete instance with nvram
105 +  file { "${nova_path}/nova-libvirt-delete-with-nvram.patch":
106 +    ensure => "file",
107 +    source => "puppet:///modules/openstack/nova-libvirt-delete-with-nvram.patch",
108 +  } ->
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",
113 +    cwd     => $nova_path,
114 +    require => [Package['patch']],
115    }
116
117    class { '::nova::cache':