Browse Source

Add functionality to manage /etc/sysconfig/libvirt-guests

If resume_guests_state_on_host_boot is set in nova.conf also
libvirt-guests need to be configured in the right way to shutdown
running instances on a compute reboot.

Closes-bug: 1778216
Change-Id: I2766cdd66ff17756daaf1a75ad516a7af6eebddc
(cherry picked from commit df325e8f6d)
tags/12.5.0
Martin Schuppert 1 year ago
parent
commit
88cff3858f

+ 97
- 0
manifests/compute/libvirt_guests.pp View File

@@ -0,0 +1,97 @@
1
+# == Class: nova::compute::libvirt_guests
2
+#
3
+# manages configuration for starting running instances when compute node
4
+# gets rebooted.
5
+#
6
+# === Parameters:
7
+#
8
+# [*enabled*]
9
+#   (optional) Whether the libvirt-guests service will be run
10
+#   Defaults to false
11
+#
12
+# [*package_ensure*]
13
+#   (optional) The state of libvirt packages
14
+#   Defaults to 'present'
15
+#
16
+# [*on_boot*]
17
+#   (optional) libvirt-guests parameter - action taken on host boot
18
+#   - start  all guests which were running on shutdown are started on boot
19
+#            regardless on their autostart settings
20
+#   - ignore libvirt-guests init script won't start any guest on boot, however,
21
+#            guests marked as autostart will still be automatically started by
22
+#            libvirtd
23
+#   Defaults to 'ignore'
24
+#
25
+# [*on_shutdown*]
26
+#   (optional) libvirt-guests parameter - action taken on host shutdown
27
+#   - suspend  all running guests are suspended using virsh managedsave
28
+#   - shutdown all running guests are asked to shutdown. Please be careful with
29
+#              this settings since there is no way to distinguish between a
30
+#              guest which is stuck or ignores shutdown requests and a guest
31
+#              which just needs a long time to shutdown. When setting
32
+#              ON_SHUTDOWN=shutdown, you must also set SHUTDOWN_TIMEOUT to a
33
+#              value suitable for your guests.
34
+#   Defaults to 'shutdown'
35
+#
36
+# [*shutdown_timeout*]
37
+#   (optional) Number of seconds we're willing to wait for a guest to shut
38
+#   down. If parallel shutdown is enabled, this timeout applies as a timeout
39
+#   for shutting down all guests on a single URI defined in the variable URIS.
40
+#   If this is 0, then there is no time out (use with caution, as guests might
41
+#   not respond to a shutdown request). The default value is 300 seconds
42
+#   (5 minutes).
43
+#   Defaults to 300.
44
+#
45
+class nova::compute::libvirt_guests (
46
+  $enabled                           = false,
47
+  $package_ensure                    = 'present',
48
+  $shutdown_timeout                  = '300',
49
+  $on_boot                           = 'ignore',
50
+  $on_shutdown                       = 'shutdown',
51
+) {
52
+  include ::nova::params
53
+  include ::nova::deps
54
+
55
+  Anchor['nova::config::begin']
56
+  -> File_line<| tag == 'libvirt-guests-file_line'|>
57
+  -> Anchor['nova::config::end']
58
+
59
+  File_line<| tag == 'libvirt-guests-file_line' |>
60
+  ~> Service['libvirt-guests']
61
+
62
+  case $::osfamily {
63
+    'RedHat': {
64
+      file_line { '/etc/sysconfig/libvirt-guests ON_BOOT':
65
+        path  => '/etc/sysconfig/libvirt-guests',
66
+        line  => "ON_BOOT=${on_boot}",
67
+        match => '^#?ON_BOOT=.*',
68
+        tag   => 'libvirt-guests-file_line',
69
+      }
70
+
71
+      file_line { '/etc/sysconfig/libvirt-guests ON_SHUTDOWN':
72
+        path  => '/etc/sysconfig/libvirt-guests',
73
+        line  => "ON_SHUTDOWN=${on_shutdown}",
74
+        match => '^#?ON_SHUTDOWN=.*',
75
+        tag   => 'libvirt-guests-file_line',
76
+      }
77
+
78
+      file_line { '/etc/sysconfig/libvirt-guests SHUTDOWN_TIMEOUT':
79
+        path  => '/etc/sysconfig/libvirt-guests',
80
+        line  => "SHUTDOWN_TIMEOUT=${shutdown_timeout}",
81
+        match => '^#?SHUTDOWN_TIMEOUT=.*',
82
+        tag   => 'libvirt-guests-file_line',
83
+      }
84
+
85
+      nova::generic_service { 'libvirt-guests':
86
+        enabled        => $enabled,
87
+        manage_service => $enabled,
88
+        package_name   => $::nova::params::libvirt_guests_package_name,
89
+        service_name   => $::nova::params::libvirt_guests_service_name,
90
+        ensure_package => $package_ensure
91
+      }
92
+    }
93
+    default:  {
94
+      warning("Unsupported osfamily: ${::osfamily}, make sure you are configuring this yourself")
95
+    }
96
+  }
97
+}

+ 2
- 0
manifests/params.pp View File

@@ -17,6 +17,7 @@ class nova::params {
17 17
       $consoleauth_package_name      = 'openstack-nova-console'
18 18
       $doc_package_name              = 'openstack-nova-doc'
19 19
       $libvirt_package_name          = 'libvirt'
20
+      $libvirt_guests_package_name   = 'libvirt-client'
20 21
       $libvirt_daemon_package_prefix = 'libvirt-daemon-'
21 22
       $libvirt_nwfilter_package_name = 'libvirt-daemon-config-nwfilter'
22 23
       $network_package_name          = 'openstack-nova-network'
@@ -34,6 +35,7 @@ class nova::params {
34 35
       $conductor_service_name        = 'openstack-nova-conductor'
35 36
       $consoleauth_service_name      = 'openstack-nova-consoleauth'
36 37
       $libvirt_service_name          = 'libvirtd'
38
+      $libvirt_guests_service_name   = 'libvirt-guests'
37 39
       $virtlock_service_name         = 'virtlockd'
38 40
       $virtlog_service_name          = undef
39 41
       $network_service_name          = 'openstack-nova-network'

+ 7
- 0
releasenotes/notes/compute-libvirt-guests-b51fdee7cf4d0289.yaml View File

@@ -0,0 +1,7 @@
1
+---
2
+features:
3
+  - |
4
+    Adds nova::compute::libvirt_guests to manage /etc/sysconfig/libvirt-guests
5
+    to configure libvirt-guests for compute reboot and handle running instance
6
+    properly.
7
+

+ 75
- 0
spec/classes/nova_compute_libvirt_guests_spec.rb View File

@@ -0,0 +1,75 @@
1
+require 'spec_helper'
2
+require 'puppet/util/package'
3
+describe 'nova::compute::libvirt_guests' do
4
+
5
+  let :pre_condition do
6
+    "include nova\ninclude nova::compute"
7
+  end
8
+
9
+  shared_examples 'redhat-nova-compute-libvirt-guests' do
10
+    before do
11
+      facts.merge!({ :operatingsystem => 'RedHat', :osfamily => 'RedHat',
12
+        :operatingsystemrelease => 6.5,
13
+        :operatingsystemmajrelease => '6' })
14
+    end
15
+
16
+    describe 'with default parameters' do
17
+
18
+      it { is_expected.to contain_class('nova::params')}
19
+
20
+      it { is_expected.not_to contain_package('libvirt-client') }
21
+      it { is_expected.not_to contain_service('libvirt-guests') }
22
+
23
+      describe 'on rhel 7' do
24
+        before do
25
+          facts.merge!({
26
+            :operatingsystemrelease => 7.0,
27
+            :operatingsystemmajrelease => '7'
28
+          })
29
+        end
30
+
31
+        it { is_expected.to contain_service('libvirt-guests')}
32
+
33
+      end
34
+    end
35
+
36
+    describe 'with params' do
37
+      let :params do
38
+        { :enabled                   => true,
39
+        }
40
+      end
41
+
42
+      it { is_expected.to contain_file_line('/etc/sysconfig/libvirt-guests ON_BOOT').with(:line => 'ON_BOOT=ignore') }
43
+      it { is_expected.to contain_file_line('/etc/sysconfig/libvirt-guests ON_SHUTDOWN').with(:line => "ON_SHUTDOWN=shutdown") }
44
+      it { is_expected.to contain_file_line('/etc/sysconfig/libvirt-guests SHUTDOWN_TIMEOUT').with(:line => "SHUTDOWN_TIMEOUT=300") }
45
+
46
+      it { is_expected.to contain_package('libvirt-guests').with(
47
+        :name   => 'libvirt-client',
48
+        :ensure => 'present'
49
+      ) }
50
+
51
+      it { is_expected.to contain_service('libvirt-guests').with(
52
+        :name   => 'libvirt-guests',
53
+        :enable => true,
54
+        :ensure => 'running',
55
+      )}
56
+    end
57
+
58
+  end
59
+
60
+  on_supported_os({
61
+    :supported_os => OSDefaults.get_supported_os
62
+  }).each do |os,facts|
63
+    context "on #{os}" do
64
+
65
+      case [:osfamily]
66
+      when 'RedHat'
67
+        let (:facts) do
68
+          facts.merge!(OSDefaults.get_facts({ :os_package_type => 'rpm' }))
69
+        end
70
+        it_behaves_like 'redhat-nova-compute-libvirt-guests'
71
+      end
72
+    end
73
+  end
74
+
75
+end

Loading…
Cancel
Save