Fix cinder type ensurabilty

This change adds additional logic to our cinder type management to
allow for the automatic cleanup of cinder types when they are no longer
configured. Previously we were only creating types and when we unlock
the ability to reconfigure an environment, we would leave the old cinder
types still configured. A user would have to manually cleanup the cinder
types via the 'cinder type-delete' command.  This change replaces the
usage of the cinder::type resource with the new cinder_type provider
that allows for ensure => 'absent'. The old cinder::type has also been
deprecated so this removes its usage.

With this change we are also moving the resource we were using to a
proper resource with tests under the osnailyfacter module.

Change-Id: Ib547c4c76b89cab10ccbcefc021f62b621a79c08
Related-Blueprint: granular-task-ensurability
Related-Bug: #1555360
This commit is contained in:
Alex Schultz 2016-03-09 16:42:27 -07:00
parent 42c6555ff9
commit dfe8fc28a2
5 changed files with 116 additions and 65 deletions

View File

@ -6,3 +6,5 @@ fixtures:
apache: "#{source_dir}/../apache"
concat: "#{source_dir}/../concat"
mysql: "#{source_dir}/../mysql"
cinder: "#{source_dir}/../cinder"
openstacklib: "#{source_dir}/../openstacklib"

View File

@ -0,0 +1,37 @@
# == Class: osnailyfacter::openstack::manage_cinder_types
#
# Wrapper resource to allow the management of cinder types using hashes from
# the hiera data.
#
# === Parameters
#
# [*ensure*]
# (optional) Should the type be 'present' or 'absent'
# Defaults to 'present'
#
# [*volume_backend_names*]
# (optional) A hash with the cinder type data to set with the cinder_type
# provider. If ensure is set to 'present', this should be an hash with a value
# for the $name provided to this resource.
# Defaults to {}
#
# [*key*]
# (optional) The name of the key to set for the cinder_type.
# Defaults to 'volume_backend_name'
#
define osnailyfacter::openstack::manage_cinder_types (
$ensure = 'present',
$volume_backend_names = {},
$key = 'volume_backend_name',
) {
if $ensure == 'present' {
$value = $volume_backend_names[$name]
cinder_type { $name:
properties => ["${key}=${value}"]
}
} else {
cinder_type { $name:
ensure => absent
}
}
}

View File

@ -1,46 +1,18 @@
#TODO (degorenko): remove this define, when Puppet will be upgraded to 4.x version
define create_cinder_types (
$volume_backend_names,
$os_password,
$os_tenant_name = 'admin',
$os_username = 'admin',
$os_auth_url = 'http://127.0.0.1:5000/v2.0/',
$os_region_name = 'RegionOne',
$vtype = $name,
$key = 'volume_backend_name',
) {
notice('MODULAR: openstack-cinder/create_cinder_types.pp')
include ::cinder::client
cinder::type { $vtype:
os_password => $os_password,
set_key => $key,
set_value => $volume_backend_names[$vtype],
os_tenant_name => $os_tenant_name,
os_username => $os_username,
os_auth_url => $os_auth_url,
os_region_name => $os_region_name,
}
}
$access_hash = hiera_hash('access', {})
$public_vip = hiera('public_vip')
$public_ssl_hash = hiera_hash('public_ssl')
$ssl_hash = hiera_hash('use_ssl', {})
$region = hiera('region', 'RegionOne')
$storage_hash = hiera_hash('storage', {})
$backends = $storage_hash['volume_backend_names']
$public_protocol = get_ssl_property($ssl_hash, $public_ssl_hash, 'keystone', 'public', 'protocol', 'http')
$public_address = get_ssl_property($ssl_hash, $public_ssl_hash, 'keystone', 'public', 'hostname', [$public_vip])
$available_backends = delete_values($backends, false)
$backend_names = keys($available_backends)
$available_backends = delete_values($backends, false)
$available_backend_names = keys($available_backends)
create_cinder_types { $backend_names:
$unavailable_backends = delete($backends, $available_backend_names)
$unavailable_backend_names = keys($unavailable_backends)
::osnailyfacter::openstack::manage_cinder_types { $available_backend_names:
ensure => 'present',
volume_backend_names => $available_backends,
os_password => $access_hash['password'],
os_tenant_name => $access_hash['tenant'],
os_username => $access_hash['user'],
os_auth_url => "${public_protocol}://${public_address}:5000/v2.0/",
os_region_name => $region,
}
::osnailyfacter::openstack::manage_cinder_types { $unavailable_backend_names:
ensure => 'absent',
}

View File

@ -0,0 +1,49 @@
require 'spec_helper'
describe 'osnailyfacter::openstack::manage_cinder_types' do
let :facts do
{
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:operatingsystemrelease => '14.04',
:concat_basedir => '/var/lib/puppet/concat'
}
end
context 'with a present type' do
let(:title) { 'volumes_lvm' }
let(:params) do
{
:ensure => 'present',
:volume_backend_names => {
'volumes_lvm' => 'LVM-backend'
}
}
end
it 'should include a cinder_type' do
is_expected.to contain_cinder_type('volumes_lvm').with(
:properties => ["volume_backend_name=LVM-backend"]
)
end
end
context 'with an absent type' do
let(:title) { 'volumes_lvm' }
let(:params) do
{
:ensure => 'absent',
}
end
it 'should include a cinder_type with absent' do
is_expected.to contain_cinder_type('volumes_lvm').with(
:ensure => 'absent',
)
end
end
end

View File

@ -5,39 +5,30 @@ manifest = 'openstack-cinder/create_cinder_types.pp'
describe manifest do
shared_examples 'catalog' do
access_admin = Noop.hiera_structure('access', {})
public_vip = Noop.hiera('public_vip')
region = Noop.hiera('region', 'RegionOne')
volume_backend_names = Noop.hiera_structure 'storage/volume_backend_names'
available_backends = volume_backend_names.delete_if { |key,value| ! value }
backend_names = available_backends.keys
volume_backend_names = Noop.hiera_structure 'storage/volume_backend_names'
available_backends = volume_backend_names.select { |key, value| value }
available_backend_names = available_backends.keys
unavailable_backends = volume_backend_names.select { |key,value| ! value }
unavailable_backend_names = unavailable_backends.keys
if Noop.hiera_structure('use_ssl', false)
public_protocol = 'https'
public_address = Noop.hiera_structure('use_ssl/keystone_public_hostname')
admin_protocol = 'https'
admin_address = Noop.hiera_structure('use_ssl/keystone_admin_hostname')
elsif Noop.hiera_structure('public_ssl/services')
public_protocol = 'https'
public_address = Noop.hiera_structure('public_ssl/hostname')
else
public_protocol = 'http'
public_address = Noop.hiera('public_vip')
available_backend_names.each do |backend_name|
it "should create cinder type #{backend_name}" do
should contain_osnailyfacter__openstack__manage_cinder_types(backend_name).with(
:ensure => 'present',
:volume_backend_names => available_backends,
)
end
end
backend_names.each do |backend_name|
it 'should contain creating cinder types' do
should contain_create_cinder_types(backend_name).with(
'volume_backend_names' => available_backends,
'os_password' => access_admin['password'],
'os_tenant_name' => access_admin['tenant'],
'os_username' => access_admin['user'],
'os_auth_url' => "#{public_protocol}://#{public_address}:5000/v2.0/",
'os_region_name' => region,
unavailable_backend_names.each do |backend_name|
it "should remove cinder type #{backend_name}" do
should contain_osnailyfacter__openstack__manage_cinder_types(backend_name).with(
:ensure => 'absent',
)
end
end
end
test_ubuntu_and_centos manifest
end