From 1eef27916f98e31e64ffeec311d3c23908a826fd Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sun, 26 Jun 2022 18:15:26 +0900 Subject: [PATCH] Introduce a new class to disable the default libvirt network libvirt by default enables the default network so that it can provide dhcp for all virtual machines running on that host. However this is not required in OpenStack deployments and should be removed. This change introduces a new class to disable the delete network. Change-Id: Ibc0801694770913d494aa260161fa406689436ad --- manifests/compute/libvirt/networks.pp | 40 +++++++++++++++ .../libvirt-networks-742a45231f4ffdb3.yaml | 6 +++ .../nova_compute_libvirt_networks_spec.rb | 49 +++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 manifests/compute/libvirt/networks.pp create mode 100644 releasenotes/notes/libvirt-networks-742a45231f4ffdb3.yaml create mode 100644 spec/classes/nova_compute_libvirt_networks_spec.rb diff --git a/manifests/compute/libvirt/networks.pp b/manifests/compute/libvirt/networks.pp new file mode 100644 index 000000000..e485bb4c9 --- /dev/null +++ b/manifests/compute/libvirt/networks.pp @@ -0,0 +1,40 @@ +# == Class: nova::compute::libvirt::networks +# +# Configures networks managed by libvirt +# +# === Parameters: +# +# [*disable_default_network*] +# (optional) Whether or not delete the default network. +# Defaults to true. +# +class nova::compute::libvirt::networks( + $disable_default_network = true, +) { + + include nova::deps + + if $disable_default_network { + exec { 'libvirt-default-net-disable-autostart': + command => 'virsh net-autostart default --disable', + path => ['/bin', '/usr/bin'], + onlyif => [ + 'virsh net-info default 2>/dev/null', + 'virsh net-info default 2>/dev/null | grep -i "^autostart:\s*yes"' + ] + } + exec { 'libvirt-default-net-destroy': + command => 'virsh net-destroy default', + path => ['/bin', '/usr/bin'], + onlyif => [ + 'virsh net-info default 2>/dev/null', + 'virsh net-info default 2>/dev/null | grep -i "^active:\s*yes"' + ] + } + + Service<| tag == 'libvirt-service' |> + -> Exec['libvirt-default-net-disable-autostart'] + -> Exec['libvirt-default-net-destroy'] + -> Service<| tag == 'nova-service' |> + } +} diff --git a/releasenotes/notes/libvirt-networks-742a45231f4ffdb3.yaml b/releasenotes/notes/libvirt-networks-742a45231f4ffdb3.yaml new file mode 100644 index 000000000..f94147276 --- /dev/null +++ b/releasenotes/notes/libvirt-networks-742a45231f4ffdb3.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The new ``nova::compute::libvirt::networks`` class has been added. This + class can be used to disable the default libvirt network, which is not used + in OpenStack deployments. diff --git a/spec/classes/nova_compute_libvirt_networks_spec.rb b/spec/classes/nova_compute_libvirt_networks_spec.rb new file mode 100644 index 000000000..764391d28 --- /dev/null +++ b/spec/classes/nova_compute_libvirt_networks_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe 'nova::compute::libvirt::networks' do + + shared_examples_for 'nova::compute::libvirt::networks' do + + context 'with defaults' do + it { is_expected.to contain_exec('libvirt-default-net-disable-autostart').with( + :command => 'virsh net-autostart default --disable', + :path => ['/bin', '/usr/bin'], + :onlyif => [ + 'virsh net-info default 2>/dev/null', + 'virsh net-info default 2>/dev/null | grep -i "^autostart:\s*yes"' + ] + ) } + it { is_expected.to contain_exec('libvirt-default-net-destroy').with( + :command => 'virsh net-destroy default', + :path => ['/bin', '/usr/bin'], + :onlyif => [ + 'virsh net-info default 2>/dev/null', + 'virsh net-info default 2>/dev/null | grep -i "^active:\s*yes"' + ] + ) } + end + + context 'when not disabling the default network' do + let :params do + { + :disable_default_network => false + } + end + it { is_expected.to_not contain_exec('libvirt-default-net-disable-autostart') } + it { is_expected.to_not contain_exec('libvirt-default-net-destroy') } + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + + it_configures 'nova::compute::libvirt::networks' + end + end + +end