From 6e67434c27d23d38c4a2bc52b944a9c7df5ff222 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Fri, 4 Jun 2021 00:01:03 +0900 Subject: [PATCH] Add support for iscsid configuration The iscsid service is used in sevral components like nova, cinder, glance and so on to connect to iscsi devices. This change introduces the new class to manage basic configuration of the iscsid service. Co-authored-by: Alfredo Moralejo Change-Id: I3fc6d1192632cc1458d00900508d548f522e9cdb --- manifests/iscsid.pp | 58 +++++++++++++++++++ manifests/params.pp | 13 +++++ .../notes/iscsid-0a9fe8a9dba4047b.yaml | 5 ++ spec/classes/openstacklib_iscsid_spec.rb | 47 +++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 manifests/iscsid.pp create mode 100644 releasenotes/notes/iscsid-0a9fe8a9dba4047b.yaml create mode 100644 spec/classes/openstacklib_iscsid_spec.rb diff --git a/manifests/iscsid.pp b/manifests/iscsid.pp new file mode 100644 index 00000000..8d1ebe6d --- /dev/null +++ b/manifests/iscsid.pp @@ -0,0 +1,58 @@ +# == Class: openstacklib::iscsid +# +# Installs and configures the iscsid daemon +# +# == Parameters +# +# [*enabled*] +# (optional) Should the service be enabled. +# Defaults to true. +# +# [*manage_service*] +# (optional) Whether the service should be managed by Puppet. +# Defaults to true. +# +# [*package_ensure*] +# (optional) ensure state for package. +# Defaults to 'present' +# +class openstacklib::iscsid( + $enabled = true, + $manage_service = true, + $package_ensure = 'present' +) { + + include openstacklib::params + + package { 'open-iscsi': + ensure => $package_ensure, + name => $::openstacklib::params::open_iscsi_package_name, + tag => 'openstack', + } + + # In CentOS9/RHEL9 initiatorname.iscsi is not created automatically + # so should be created + exec { 'create-initiatorname-file': + command => 'echo "InitiatorName=`/usr/sbin/iscsi-iname`" > /etc/iscsi/initiatorname.iscsi', + path => ['/usr/bin','/usr/sbin','/bin','/usr/bin'], + unless => 'test -e /etc/iscsi/initiatorname.iscsi', + require => Package['open-iscsi'], + } + + if $manage_service { + if $enabled { + $service_ensure = 'running' + } else { + $service_ensure = 'stopped' + } + + # iscsid service is started automatically when iscsiadm command is + # executed but there is no harm even if the service is already started. + service { 'iscsid': + ensure => $service_ensure, + enable => $enabled, + } + Package['open-iscsi'] ~> Service['iscsid'] + Exec['create-initiatorname-file'] ~> Service['iscsid'] + } +} diff --git a/manifests/params.pp b/manifests/params.pp index 300b404e..7ce9482d 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -9,4 +9,17 @@ class openstacklib::params { $pyvers = $::openstacklib::defaults::pyvers $openstackclient_package_name = "python${pyvers}-openstackclient" + + case $::osfamily { + 'RedHat': { + $open_iscsi_package_name = 'iscsi-initiator-utils' + } + 'Debian': { + $open_iscsi_package_name = 'open-iscsi' + } + default:{ + fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, \ +module ${module_name} only support osfamily RedHat and Debian") + } + } } diff --git a/releasenotes/notes/iscsid-0a9fe8a9dba4047b.yaml b/releasenotes/notes/iscsid-0a9fe8a9dba4047b.yaml new file mode 100644 index 00000000..70848d2d --- /dev/null +++ b/releasenotes/notes/iscsid-0a9fe8a9dba4047b.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The new ``openstacklib::iscsid`` class has been added. This class can be + used to set up basic configurations for the iscsid service. diff --git a/spec/classes/openstacklib_iscsid_spec.rb b/spec/classes/openstacklib_iscsid_spec.rb new file mode 100644 index 00000000..e043cb6c --- /dev/null +++ b/spec/classes/openstacklib_iscsid_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe 'openstacklib::iscsid' do + shared_examples_for 'openstacklib::iscsid' do + context 'with default params' do + it { is_expected.to contain_package('open-iscsi').with( + :name => platform_params[:open_iscsi_package_name], + :ensure => 'present', + :tag => 'openstack', + )} + + it { is_expected.to contain_exec('create-initiatorname-file').with({ + :command => 'echo "InitiatorName=`/usr/sbin/iscsi-iname`" > /etc/iscsi/initiatorname.iscsi', + :path => ['/usr/bin','/usr/sbin','/bin','/usr/bin'], + :unless => 'test -e /etc/iscsi/initiatorname.iscsi', + }).that_requires('Package[open-iscsi]')} + + it { is_expected.to contain_service('iscsid').with( + :ensure => 'running', + :enable => true, + ) } + 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 + + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { :open_iscsi_package_name => 'open-iscsi' } + when 'RedHat' + { :open_iscsi_package_name => 'iscsi-initiator-utils' } + end + end + + it_behaves_like 'openstacklib::iscsid' + end + end + +end