Commit 0383a1ae authored by Andrew Woodward's avatar Andrew Woodward

Add ceph_config ini helper

* add a ini_file helper as ceph_config.
* set the seperator as ' = ' in order to be the same as ceph-deploy
* add path param so that seperator can be easily tested.
** also allows for users to change the default path if desired.
* add test case to prove spacing around seperator.
* add simple test case to ensure type works.

Closes-bug: #1243852
Change-Id: I0f3bb41d75d48d8af3b5b7cfb7768c4d3de2c002
parent c15e3fcc
......@@ -4,5 +4,7 @@ fixtures:
'apt':
repo: 'git://github.com/puppetlabs/puppetlabs-apt.git'
ref: '1.4.0'
'inifile': 'git://github.com/puppetlabs/puppetlabs-inifile'
symlinks:
'ceph': "#{source_dir}"
*.swp
*~
.project
metadata.json
spec/fixtures/modules/*
pkg
Gemfile.lock
......@@ -7,4 +7,5 @@ summary 'Community Developed Ceph Module'
description 'Puppet module to install and configure Ceph'
project_page 'https://launchpad.net/puppet-ceph'
dependency 'puppetlabs/inifile', '>=1.0.0 <2.0.0'
dependency 'puppetlabs/stdlib', '>= 2.5.0'
# Copyright (C) Dan Bode <bodepd@gmail.com>
#
# 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: Dan Bode <bodepd@gmail.com>
# Author: Andrew Woodward <xarses>
Puppet::Type.type(:ceph_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
) do
def section
resource[:name].split('/', 2).first
end
def setting
resource[:name].split('/', 2).last
end
def separator
' = '
end
def self.file_path
'/etc/ceph/ceph.conf'
end
# required to be able to hack the path in unit tests
# also required if a user wants to otherwise overwrite the default file_path
# Note: purge will not work on over-ridden file_path
def file_path
if not resource[:path]
self.class.file_path
else
resource[:path]
end
end
end
# Copyright (C) Dan Bode <bodepd@gmail.com>
#
# 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: Dan Bode <bodepd@gmail.com>
# Author: Mathieu Gagne <mgagne>
Puppet::Type.newtype(:ceph_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from ./ceph.conf'
newvalues(/\S+\/\S+/)
end
# required in order to be able to unit test file contents
# Note: purge will not work on over-ridden file_path
# lifted from ini_file
newparam(:path) do
desc 'A file path to over ride the default file path if necessary'
validate do |value|
unless (Puppet.features.posix? and value =~ /^\//) or (Puppet.features.microsoft_windows? and (value =~ /^.:\// or value =~ /^\/\/[^\/]+\/[^\/]+/))
raise(Puppet::Error, "File paths must be fully qualified, not '#{value}'")
end
end
defaultto false
end
newproperty(:value) do
desc 'The value of the setting to be defined.'
munge do |value|
value = value.to_s.strip
value.capitalize! if value =~ /^(true|false)$/i
value
end
end
end
# Copyright (C) 2013 Mirantis 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: Andrew Woodward <xarses>
# This is aparently one of the few ways to do this load
# see https://github.com/stackforge/puppet-nova/blob/master/spec/unit/provider/nova_config/ini_setting_spec.rb
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'inifile',
'lib')
)
require 'spec_helper'
require 'puppet'
provider_class = Puppet::Type.type(:ceph_config).provider(:ini_setting)
describe provider_class do
include PuppetlabsSpec::Files
let(:tmpfile) { tmpfilename("ceph_config_test") }
let(:params) { {
:path => tmpfile,
} }
def validate(expected, tmpfile = tmpfile)
File.read(tmpfile).should == expected
end
it 'should create keys = value and ensure space around equals' do
resource = Puppet::Type::Ceph_config.new(params.merge(
:name => 'global/ceph_is_foo', :value => 'bar'))
provider = provider_class.new(resource)
provider.exists?.should be_nil
provider.create
validate(<<-EOS
[global]
ceph_is_foo = bar
EOS
)
end
it 'should default to file_path if param path is not passed' do
resource = Puppet::Type::Ceph_config.new(
:name => 'global/ceph_is_foo', :value => 'bar')
provider = provider_class.new(resource)
provider.file_path.should == '/etc/ceph/ceph.conf'
end
end
\ No newline at end of file
# Copyright (C) 2013 Mirantis 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: Andrew Woodward <xarses>
require 'puppet'
require 'puppet/type/ceph_config'
describe 'Puppet::Type.type(:ceph_config)' do
before :each do
@ceph_config = Puppet::Type.type(:ceph_config).new(
:name => 'global/ceph_is_foo', :value => 'bar')
end
it 'should work bascily' do
@ceph_config[:value] = 'max'
@ceph_config[:value].should == 'max'
end
it 'should convert true to True' do
@ceph_config[:value] = 'tRuE'
@ceph_config[:value].should == 'True'
end
it 'should convert false to False' do
@ceph_config[:value] = 'fAlSe'
@ceph_config[:value].should == 'False'
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment