From 5cc19541b872ab249267756992af3b9f19d2197e Mon Sep 17 00:00:00 2001 From: Giulio Fidente Date: Fri, 25 Nov 2016 10:50:09 +0100 Subject: [PATCH] Improves support for ceph-mds This change adds a profile for the MDS service and extends the existing MDS class to enable the service on boot and set the daemon binding address. Change-Id: I558b43deaa9b243c54f3d7ae945f11dd4925eb5d Related-Bug: #1644784 --- manifests/mds.pp | 89 ++++++++++++++++--- manifests/params.pp | 1 + manifests/profile/mds.pp | 41 +++++++++ manifests/profile/params.pp | 4 + ...support-improvements-e30c7c4fdb838439.yaml | 19 ++++ spec/classes/ceph_mds_spec.rb | 29 ++++-- spec/classes/ceph_profile_mds_spec.rb | 50 +++++++++++ spec/fixtures/hieradata/common.yaml | 1 + 8 files changed, 215 insertions(+), 19 deletions(-) create mode 100644 manifests/profile/mds.pp create mode 100644 releasenotes/notes/mds-support-improvements-e30c7c4fdb838439.yaml create mode 100644 spec/classes/ceph_profile_mds_spec.rb diff --git a/manifests/mds.pp b/manifests/mds.pp index 93c781af..254d73c3 100644 --- a/manifests/mds.pp +++ b/manifests/mds.pp @@ -20,26 +20,95 @@ # # === Parameters: # +# [*public_addr*] The bind IP address. +# Optional. The IPv(4|6) address on which MDS binds itself. +# +# [*pkg_mds*] Package name for the MDS service. +# Optional. Defaults to the value of ceph::params::pkg_mds +# +# [*pkg_mds_ensure*] Ensure status for the pkg_mds package resources +# Optional. Defaults to present. +# # [*mds_activate*] Switch to activate the '[mds]' section in the config. -# Optional. Defaults to 'true'. +# Optional. Defaults to true. # # [*mds_data*] The path to the MDS data. -# Optional. Default provided by Ceph is '/var/lib/ceph/mds/$cluster-$id'. +# Optional. Same default as ceph. +# +# [*mds_enable*] Whether to enable ceph-mds instance on boot. +# Optional. Default is true. +# +# [*mds_ensure*] Whether to start the MDS service. +# Optional. Default is running. +# +# [*mds_id*] The ID of the MDS instance. +# Optional. Default is $::hostname # # [*keyring*] The location of the keyring used by MDSs -# Optional. Defaults to /var/lib/ceph/mds/$cluster-$id/keyring. +# Optional. Same default as ceph. +# +# [*cluster*] The ceph cluster +# Optional. Default to 'ceph'. # class ceph::mds ( - $mds_activate = true, - $mds_data = '/var/lib/ceph/mds/$cluster-$id', - $keyring = '/var/lib/ceph/mds/$cluster-$id/keyring', -) { + $public_addr = undef, + $pkg_mds = $::ceph::params::pkg_mds, + $pkg_mds_ensure = present, + $mds_activate = true, + $mds_data = undef, + $mds_enable = true, + $mds_ensure = 'running', + $mds_id = $::hostname, + $keyring = undef, + $cluster = 'ceph', +) inherits ceph::params { + if $mds_data { + $mds_data_real = $mds_data + } else { + $mds_data_real = "/var/lib/ceph/mds/${cluster}-${mds_id}" + } + + if $keyring { + $keyring_real = $keyring + } else { + $keyring_real = "${mds_data_real}/keyring" + } + + Ceph_config<||> ~> Service<| tag == 'ceph-mds' |> + Package<| tag == 'ceph' |> + -> File[$mds_data_real] + -> Service<| tag == 'ceph-mds' |> + + $mds_service_name = "ceph-mds@${mds_id}" + + service { $mds_service_name: + ensure => $mds_ensure, + enable => $mds_enable, + tag => ['ceph-mds'] + } + + package { $pkg_mds: + ensure => $pkg_mds_ensure, + tag => 'ceph', + } + + file { $mds_data_real: + ensure => directory, + owner => 'ceph', + group => 'ceph', + mode => '0750', + selinux_ignore_defaults => true, + } - # [mds] if $mds_activate { ceph_config { - 'mds/mds_data': value => $mds_data; - 'mds/keyring': value => $keyring; + 'mds/mds_data': value => $mds_data_real; + 'mds/keyring': value => $keyring_real; + } + if $public_addr { + ceph_config { + "mds.${mds_id}/public_addr": value => $public_addr; + } } } else { ceph_config { diff --git a/manifests/params.pp b/manifests/params.pp index b6a20c21..2d4d722f 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -47,6 +47,7 @@ class ceph::params ( $enable_sig = false, $release = 'jewel', ) { + $pkg_mds = 'ceph-mds' case $::osfamily { 'Debian': { diff --git a/manifests/profile/mds.pp b/manifests/profile/mds.pp new file mode 100644 index 00000000..c4a1845a --- /dev/null +++ b/manifests/profile/mds.pp @@ -0,0 +1,41 @@ +# +# Copyright (C) 2016 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Author: Giulio Fidente +# +# == Class: ceph::profile::mds +# +# Profile for a Ceph mds +# +class ceph::profile::mds { + require ::ceph::profile::base + + class { '::ceph::mds': + public_addr => $ceph::profile::params::public_addr, + } + + if !empty($ceph::profile::params::mds_key) { + ceph::key { "mds.${::hostname}": + cap_mon => 'allow profile mds', + cap_osd => 'allow rwx', + cap_mds => 'allow', + inject => true, + keyring_path => "/var/lib/ceph/mds/ceph-${::hostname}/keyring", + secret => $ceph::profile::params::mds_key, + user => 'ceph', + group => 'ceph' + } + } +} diff --git a/manifests/profile/params.pp b/manifests/profile/params.pp index 52c16eef..b4571b58 100644 --- a/manifests/profile/params.pp +++ b/manifests/profile/params.pp @@ -91,6 +91,9 @@ # This is useful when not specifying public_network or when there is more than one IP address on # the same network and you want to be specific about the IP to bind the MON on. # +# [*mds_key*] The mds secret key. +# Optional but required when using cephx. +# # [*mon_key*] The mon secret key. # Optional. Either mon_key or mon_keyring need to be set when using cephx. # @@ -189,6 +192,7 @@ class ceph::profile::params ( $cluster_network = undef, $public_network = undef, $public_addr = undef, + $mds_key = undef, $mon_key = undef, $mon_keyring = undef, $client_keys = {}, diff --git a/releasenotes/notes/mds-support-improvements-e30c7c4fdb838439.yaml b/releasenotes/notes/mds-support-improvements-e30c7c4fdb838439.yaml new file mode 100644 index 00000000..c7c63af4 --- /dev/null +++ b/releasenotes/notes/mds-support-improvements-e30c7c4fdb838439.yaml @@ -0,0 +1,19 @@ +--- +prelude: > + Improves support for the MDS service and adds a profile class for it. +features: + - | + The MDS class is extended to allow for binding address and instance ID + configuration. It now also ensures that the needed packages for the MDS + daemon are installed and that the service is manageable by Puppet. + - | + A new MDS profile class is added which, in addition to deploying the MDS + service will create a new keyring for it, allowing MDS profilation and + access to the OSD pools. +other: + - | + The package installed by default for the MDS service can be configured + via ceph::params::pkg_mds + - | + The keyring for the MDS service is only created if a key is given, the + key to use can be configured via ceph::profile::params::mds_key diff --git a/spec/classes/ceph_mds_spec.rb b/spec/classes/ceph_mds_spec.rb index c2453df9..239be662 100644 --- a/spec/classes/ceph_mds_spec.rb +++ b/spec/classes/ceph_mds_spec.rb @@ -21,22 +21,35 @@ describe 'ceph::mds' do shared_examples_for 'ceph mds' do describe "activated with default params" do - it { is_expected.to contain_ceph_config('mds/mds_data').with_value('/var/lib/ceph/mds/$cluster-$id') } - it { is_expected.to contain_ceph_config('mds/keyring').with_value('/var/lib/ceph/mds/$cluster-$id/keyring') } - + it { is_expected.to contain_ceph_config('mds/mds_data').with_value('/var/lib/ceph/mds/ceph-myhostname') } + it { is_expected.to contain_ceph_config('mds/keyring').with_value('/var/lib/ceph/mds/ceph-myhostname/keyring') } + it { is_expected.to contain_package('ceph-mds').with('ensure' => 'present') } end describe "activated with custom params" do let :params do { - :mds_data => '/usr/local/ceph/var/lib/mds/_cluster-_id', - :keyring => '/usr/local/ceph/var/lib/mds/_cluster-_id/keyring' + :public_addr => '1.2.3.4', + :mds_id => 'mymds', + :mds_data => '/usr/local/ceph/var/lib/mds/_cluster-_id', + :keyring => '/usr/local/ceph/var/lib/mds/_cluster-_id/keyring' } end it { is_expected.to contain_ceph_config('mds/mds_data').with_value('/usr/local/ceph/var/lib/mds/_cluster-_id') } it { is_expected.to contain_ceph_config('mds/keyring').with_value('/usr/local/ceph/var/lib/mds/_cluster-_id/keyring') } - + it { is_expected.to contain_package('ceph-mds').with('ensure' => 'present') } + it { + is_expected.to contain_service('ceph-mds@mymds').with('ensure' => 'running') + } + it { is_expected.to contain_ceph_config('mds.mymds/public_addr').with_value('1.2.3.4') } + it { is_expected.to contain_file('/usr/local/ceph/var/lib/mds/_cluster-_id').with( { + 'ensure' => 'directory', + 'owner' => 'ceph', + 'group' => 'ceph', + 'mode' => '0750', + 'selinux_ignore_defaults' => true, + } ) } end describe "not activated" do @@ -46,8 +59,6 @@ describe 'ceph::mds' do } end - it { is_expected.to_not contain_ceph_config('mds/mds_data').with_value('/var/lib/ceph/mds/_cluster-_id') } - it { is_expected.to_not contain_ceph_config('mds/keyring').with_value('/var/lib/ceph/mds/_cluster-_id/keyring') } it { is_expected.to contain_ceph_config('mds/mds_data').with_ensure('absent') } it { is_expected.to contain_ceph_config('mds/keyring').with_ensure('absent') } @@ -59,7 +70,7 @@ describe 'ceph::mds' do }).each do |os,facts| context "on #{os}" do let (:facts) do - facts.merge!(OSDefaults.get_facts()) + facts.merge!(OSDefaults.get_facts({:hostname => 'myhostname'})) end it_behaves_like 'ceph mds' diff --git a/spec/classes/ceph_profile_mds_spec.rb b/spec/classes/ceph_profile_mds_spec.rb new file mode 100644 index 00000000..760cdf92 --- /dev/null +++ b/spec/classes/ceph_profile_mds_spec.rb @@ -0,0 +1,50 @@ +# +# Copyright (C) 2016 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Author: Giulio Fidente +# +require 'spec_helper' + +describe 'ceph::profile::mds' do + + shared_examples_for 'ceph profile mds' do + + it { is_expected.to contain_class('ceph::mds').with( + 'public_addr' => '10.11.12.2', + )} + it { is_expected.to contain_ceph__key('mds.myhostname').with( + :cap_mon => 'allow profile mds', + :cap_osd => 'allow rwx', + :cap_mds => 'allow', + :inject => true, + :keyring_path => "/var/lib/ceph/mds/ceph-myhostname/keyring", + :secret => 'AQDLOh1VgEp6FRAAFzT7Zw+Y9V6JJExQAsRnRQ==', + :user => 'ceph', + :group => 'ceph' + )} + 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({:hostname => 'myhostname'})) + end + + it_behaves_like 'ceph profile mds' + end + end +end diff --git a/spec/fixtures/hieradata/common.yaml b/spec/fixtures/hieradata/common.yaml index f436f668..b244d446 100644 --- a/spec/fixtures/hieradata/common.yaml +++ b/spec/fixtures/hieradata/common.yaml @@ -25,6 +25,7 @@ ceph::profile::params::osd_max_scrubs: '1' ceph::profile::params::osd_op_threads: '2' ######## Keys +ceph::profile::params::mds_key: 'AQDLOh1VgEp6FRAAFzT7Zw+Y9V6JJExQAsRnRQ==' ceph::profile::params::mon_key: 'AQATGHJTUCBqIBAA7M2yafV1xctn1pgr3GcKPg==' ceph::profile::params::client_keys: 'client.admin':