Introduce fuel cli bootstrap package configuration

Partially implements: blueprint dynamically-build-bootstrap
Change-Id: I68c18c48c6b0b09a5851d93e3adf4b85b4cef326
This commit is contained in:
Valyavskiy Viacheslav 2015-11-26 20:20:35 +03:00
parent a85b59f9b2
commit bc2a7aae38
5 changed files with 162 additions and 1 deletions

View File

@ -25,7 +25,8 @@ Class['docker::dockerctl'] ->
Class['docker'] ->
Class['openstack::logrotate'] ->
Class['nailgun::supervisor'] ->
Class['monit']
Class['monit'] ->
Class['nailgun::bootstrap_cli']
class { 'nailgun::packages': }
@ -87,6 +88,13 @@ class { 'nailgun::supervisor':
conf_file => 'nailgun/supervisord.conf.base.erb',
}
class { 'nailgun::bootstrap_cli':
settings => $::fuel_settings['BOOTSTRAP'],
direct_repo_addresses => [ $::fuel_settings['ADMIN_NETWORK']['ipaddress'] ],
bootstrap_cli_package => 'fuel-bootstrap-cli',
config_path => '/etc/fuel-bootstrap-cli/fuel_bootstrap_cli.yaml',
}
class { 'osnailyfacter::ssh':
password_auth => 'yes',
}

View File

@ -0,0 +1,32 @@
require 'yaml'
Puppet::Type.type(:merge_yaml_settings).provide(:ruby) do
desc "Support for merging yaml configuration files."
def create
merged_settings = get_merged_settings
File.open(@resource[:name], "w") { |f| f.puts merged_settings.to_yaml }
end
def destroy
File.unlink(@resource[:name])
end
def exists?
get_dict(@resource[:sample_settings]) == get_merged_settings
end
def get_merged_settings
sample_settings = get_dict(@resource[:sample_settings])
override_settings = get_dict(@resource[:override_settings])
sample_settings.merge(override_settings)
end
def get_dict(obj)
return obj if obj.is_a?(Hash)
YAML.load_file(obj)
end
private :get_merged_settings, :get_dict
end

View File

@ -0,0 +1,19 @@
Puppet::Type.newtype(:merge_yaml_settings) do
desc = "Type to merge yaml configuration files"
ensurable
newparam(:name) do
desc "Path for destination settings file"
end
newparam(:sample_settings) do
desc "Path or Hash containing source settings"
end
newparam(:override_settings) do
desc "Path or Hash containing custom settings"
end
end

View File

@ -0,0 +1,57 @@
#
# == Class: nailgun::bootstrap_cli
#
# Installs and configures fuel-bootstrap-cli package
#
# === Parameters
#
# [*bootstrap_cli_package*]
# (optional) The bootstrap cli package name
# Defaults to 'fuel-bootstrap-cli'
#
# [*settings*]
# (optional) The hash of new settings for bootstrap cli package.
# It will be merged with current package's settings(config_path)
# and parameters from current variable will have highest priority
# in case of equal parameters in both configuration sources.
# Defaults to {}
#
# [*direct_repo_addresses*]
# (optional) Array containing direct repositories ip addresses.
# Proxy servers will not be used for these ip addresses.
# Defaults to ['127.0.0.1']
#
# [*config_path*]
# (optional) The path to configuration file of bootstrap cli package
# Defaults to '/etc/fuel-bootstrap-cli/fuel_bootstrap_cli.yaml'
#
# === Examples
#
# class { 'nailgun::bootstrap_cli':
# bootstrap_cli_package => 'fuel-bootstrap-cli',
# settings => {},
# direct_repo_addresses => [ '192.168.0.1' ],
# config_path => '/etc/fuel-bootstrap-cli/fuel_bootstrap_cli.yaml',
# }
#
class nailgun::bootstrap_cli(
$bootstrap_cli_package = 'fuel-bootstrap-cli',
$settings = {},
$direct_repo_addresses = ['127.0.0.1'],
$config_path = '/etc/fuel-bootstrap-cli/fuel_bootstrap_cli.yaml',
) {
$additional_settings = {'direct_repo_addresses' => $direct_repo_addresses}
$custom_settings = merge($settings, $additional_settings)
package { $bootstrap_cli_package:
ensure => present,
}
merge_yaml_settings { $config_path:
sample_settings => $config_path,
override_settings => $custom_settings,
ensure => present,
require => Package[$bootstrap_cli_package],
}
}

View File

@ -1,7 +1,52 @@
require 'spec_helper'
require 'shared-examples'
require 'yaml'
manifest = 'master/host-only.pp'
describe manifest do
shared_examples 'catalog' do
config_path = '/etc/fuel-bootstrap-cli/fuel_bootstrap_cli.yaml'
bootstrap_cli_package = 'fuel-bootstrap-cli'
bootstrap_hash = {
'MIRROR_DISTRO' => "http://archive.ubuntu.com/ubuntu",
'MIRROR_MOS' => "http://mirror.fuel-infra.org/mos-repos/ubuntu/8.0",
'HTTP_PROXY' => "",
'EXTRA_APT_REPOS' => "",
'flavor' => "centos"
}
additional_settings_hash = {
'direct_repo_addresses' => ['10.109.0.2']
}
it 'should declare nailgun::bootstrap_cli class with proper arguments' do
should contain_class('nailgun::bootstrap_cli').with(
'settings' => bootstrap_hash,
'direct_repo_addresses' => additional_settings_hash['direct_repo_addresses'],
'bootstrap_cli_package' => bootstrap_cli_package,
'config_path' => config_path,
)
end
it "should install fuel-bootstrap-cli package" do
should contain_package(bootstrap_cli_package).with(
'ensure' => 'present',
)
end
custom_settings = bootstrap_hash.merge(additional_settings_hash)
it 'should declare merge_yaml_settings' do
should contain_merge_yaml_settings(config_path).with({
'sample_settings' => config_path,
'override_settings' => custom_settings,
'ensure' => 'present',
'require' => "Package[#{bootstrap_cli_package}]",
})
end
end
test_centos manifest
end