glance refactor
this refactor of glance does three things: * makes the backend pluggable and adds support for a swift backend. * removes repetitive glance_* prefixes from variables. * updates the openstack::controller class to use these new glance params Change-Id: Id88163283340d25b9b79fbdb8ba2ddd043fd363a
This commit is contained in:
@@ -196,14 +196,14 @@ class openstack::all (
|
|||||||
|
|
||||||
######## GLANCE ##########
|
######## GLANCE ##########
|
||||||
class { 'openstack::glance':
|
class { 'openstack::glance':
|
||||||
verbose => $verbose,
|
verbose => $verbose,
|
||||||
db_type => $db_type,
|
db_type => $db_type,
|
||||||
db_host => '127.0.0.1',
|
db_host => '127.0.0.1',
|
||||||
glance_db_user => $glance_db_user,
|
db_user => $glance_db_user,
|
||||||
glance_db_dbname => $glance_db_dbname,
|
db_name => $glance_db_dbname,
|
||||||
glance_db_password => $glance_db_password,
|
db_password => $glance_db_password,
|
||||||
glance_user_password => $glance_user_password,
|
user_password => $glance_user_password,
|
||||||
enabled => $enabled,
|
enabled => $enabled,
|
||||||
}
|
}
|
||||||
|
|
||||||
######## NOVA ###########
|
######## NOVA ###########
|
||||||
|
@@ -103,6 +103,10 @@ class openstack::controller (
|
|||||||
$glance_db_user = 'glance',
|
$glance_db_user = 'glance',
|
||||||
$glance_db_dbname = 'glance',
|
$glance_db_dbname = 'glance',
|
||||||
$glance_api_servers = undef,
|
$glance_api_servers = undef,
|
||||||
|
$glance_backend = 'file',
|
||||||
|
# Glance Swift Backend
|
||||||
|
$swift_store_user = 'swift_store_user',
|
||||||
|
$swift_store_key = 'swift_store_key',
|
||||||
# Nova
|
# Nova
|
||||||
$nova_admin_tenant_name = 'services',
|
$nova_admin_tenant_name = 'services',
|
||||||
$nova_admin_user = 'nova',
|
$nova_admin_user = 'nova',
|
||||||
@@ -230,14 +234,18 @@ class openstack::controller (
|
|||||||
|
|
||||||
######## BEGIN GLANCE ##########
|
######## BEGIN GLANCE ##########
|
||||||
class { 'openstack::glance':
|
class { 'openstack::glance':
|
||||||
verbose => $verbose,
|
verbose => $verbose,
|
||||||
db_type => $db_type,
|
db_type => $db_type,
|
||||||
db_host => $db_host,
|
db_host => $db_host,
|
||||||
glance_db_user => $glance_db_user,
|
keystone_host => '127.0.0.1',
|
||||||
glance_db_dbname => $glance_db_dbname,
|
db_user => $glance_db_user,
|
||||||
glance_db_password => $glance_db_password,
|
db_name => $glance_db_dbname,
|
||||||
glance_user_password => $glance_user_password,
|
db_password => $glance_db_password,
|
||||||
enabled => $enabled,
|
user_password => $glance_user_password,
|
||||||
|
backend => $glance_backend,
|
||||||
|
swift_store_user => $swift_store_user,
|
||||||
|
swift_store_key => $swift_store_key,
|
||||||
|
enabled => $enabled,
|
||||||
}
|
}
|
||||||
|
|
||||||
######## BEGIN NOVA ###########
|
######## BEGIN NOVA ###########
|
||||||
|
@@ -6,18 +6,21 @@
|
|||||||
# - Keystone for authentication
|
# - Keystone for authentication
|
||||||
# - keystone tenant: services
|
# - keystone tenant: services
|
||||||
# - keystone username: glance
|
# - keystone username: glance
|
||||||
# - storage backend: file
|
# - storage backend: file (default) or Swift
|
||||||
#
|
#
|
||||||
# === Parameters
|
# === Parameters
|
||||||
#
|
#
|
||||||
|
# [user_password] Password for glance auth user. Required.
|
||||||
|
# [db_password] Password for glance DB. Required.
|
||||||
# [db_host] Host where DB resides. Required.
|
# [db_host] Host where DB resides. Required.
|
||||||
# [glance_user_password] Password for glance auth user. Required.
|
|
||||||
# [glance_db_password] Password for glance DB. Required.
|
|
||||||
# [keystone_host] Host whre keystone is running. Optional. Defaults to '127.0.0.1'
|
# [keystone_host] Host whre keystone is running. Optional. Defaults to '127.0.0.1'
|
||||||
# [auth_uri] URI used for auth. Optional. Defaults to "http://${keystone_host}:5000/"
|
|
||||||
# [db_type] Type of sql databse to use. Optional. Defaults to 'mysql'
|
# [db_type] Type of sql databse to use. Optional. Defaults to 'mysql'
|
||||||
# [glance_db_user] Name of glance DB user. Optional. Defaults to 'glance'
|
# [db_user] Name of glance DB user. Optional. Defaults to 'glance'
|
||||||
# [glance_db_dbname] Name of glance DB. Optional. Defaults to 'glance'
|
# [db_name] Name of glance DB. Optional. Defaults to 'glance'
|
||||||
|
# [backend] Backends used to store images. Defaults to file.
|
||||||
|
# [swift_store_user] The Swift service user account. Defaults to false.
|
||||||
|
# [swift_store_key] The Swift service user password Defaults to false.
|
||||||
|
# [swift_store_auth_addres] The URL where the Swift auth service lives. Defaults to "http://${keystone_host}:5000/v2.0/"
|
||||||
# [verbose] Log verbosely. Optional. Defaults to 'False'
|
# [verbose] Log verbosely. Optional. Defaults to 'False'
|
||||||
# [enabled] Used to indicate if the service should be active (true) or passive (false).
|
# [enabled] Used to indicate if the service should be active (true) or passive (false).
|
||||||
# Optional. Defaults to true
|
# Optional. Defaults to true
|
||||||
@@ -25,29 +28,32 @@
|
|||||||
# === Example
|
# === Example
|
||||||
#
|
#
|
||||||
# class { 'openstack::glance':
|
# class { 'openstack::glance':
|
||||||
# glance_user_password => 'changeme',
|
# user_password => 'changeme',
|
||||||
# db_password => 'changeme',
|
# db_password => 'changeme',
|
||||||
# db_host => '127.0.0.1',
|
# db_host => '127.0.0.1',
|
||||||
# }
|
# }
|
||||||
|
|
||||||
class openstack::glance (
|
class openstack::glance (
|
||||||
$db_host,
|
$user_password,
|
||||||
$glance_user_password,
|
$db_password,
|
||||||
$glance_db_password,
|
$db_host = '127.0.0.1',
|
||||||
$keystone_host = '127.0.0.1',
|
$keystone_host = '127.0.0.1',
|
||||||
$auth_uri = "http://127.0.0.1:5000/",
|
$db_type = 'mysql',
|
||||||
$db_type = 'mysql',
|
$db_user = 'glance',
|
||||||
$glance_db_user = 'glance',
|
$db_name = 'glance',
|
||||||
$glance_db_dbname = 'glance',
|
$backend = 'file',
|
||||||
$verbose = 'False',
|
$swift_store_user = false,
|
||||||
$enabled = true
|
$swift_store_key = false,
|
||||||
|
$swift_store_auth_address = "http://127.0.0.1:5000/v2.0/",
|
||||||
|
$verbose = 'False',
|
||||||
|
$enabled = true
|
||||||
) {
|
) {
|
||||||
|
|
||||||
# Configure the db string
|
# Configure the db string
|
||||||
case $db_type {
|
if $db_type == 'mysql' {
|
||||||
'mysql': {
|
$sql_connection = "mysql://${db_user}:${db_password}@${db_host}/${db_name}"
|
||||||
$sql_connection = "mysql://${glance_db_user}:${glance_db_password}@${db_host}/${glance_db_dbname}"
|
} else {
|
||||||
}
|
fail("Unsupported db_type ${db_type}. Only mysql is currently supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install and configure glance-api
|
# Install and configure glance-api
|
||||||
@@ -59,7 +65,7 @@ class openstack::glance (
|
|||||||
auth_host => $keystone_host,
|
auth_host => $keystone_host,
|
||||||
keystone_tenant => 'services',
|
keystone_tenant => 'services',
|
||||||
keystone_user => 'glance',
|
keystone_user => 'glance',
|
||||||
keystone_password => $glance_user_password,
|
keystone_password => $user_password,
|
||||||
sql_connection => $sql_connection,
|
sql_connection => $sql_connection,
|
||||||
enabled => $enabled,
|
enabled => $enabled,
|
||||||
}
|
}
|
||||||
@@ -73,12 +79,32 @@ class openstack::glance (
|
|||||||
auth_type => 'keystone',
|
auth_type => 'keystone',
|
||||||
keystone_tenant => 'services',
|
keystone_tenant => 'services',
|
||||||
keystone_user => 'glance',
|
keystone_user => 'glance',
|
||||||
keystone_password => $glance_user_password,
|
keystone_password => $user_password,
|
||||||
sql_connection => $sql_connection,
|
sql_connection => $sql_connection,
|
||||||
enabled => $enabled,
|
enabled => $enabled,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Configure file storage backend
|
# Configure file storage backend
|
||||||
class { 'glance::backend::file': }
|
if($backend == 'swift') {
|
||||||
|
|
||||||
|
if ! $swift_store_user {
|
||||||
|
fail('swift_store_user must be set when configuring swift as the glance backend')
|
||||||
|
}
|
||||||
|
if ! $swift_store_key {
|
||||||
|
fail('swift_store_key must be set when configuring swift as the glance backend')
|
||||||
|
}
|
||||||
|
|
||||||
|
class { 'glance::backend::swift':
|
||||||
|
swift_store_user => $swift_store_user,
|
||||||
|
swift_store_key => $swift_store_key,
|
||||||
|
swift_store_auth_address => $swift_store_auth_address,
|
||||||
|
swift_store_create_container_on_put => 'True',
|
||||||
|
}
|
||||||
|
} elsif($backend == 'file') {
|
||||||
|
# Configure file storage backend
|
||||||
|
class { 'glance::backend::file': }
|
||||||
|
} else {
|
||||||
|
fail("Unsupported backend ${backend}")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
110
spec/classes/openstack_glance_spec.rb
Normal file
110
spec/classes/openstack_glance_spec.rb
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'openstack::glance' do
|
||||||
|
|
||||||
|
let :facts do
|
||||||
|
{
|
||||||
|
:operatingsystem => 'Ubuntu',
|
||||||
|
:osfamily => 'Debian'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
let :params do
|
||||||
|
{
|
||||||
|
:user_password => 'glance_user_pass',
|
||||||
|
:db_password => 'glance_db_pass',
|
||||||
|
:keystone_host => '127.0.1.1'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'with only required parameters' do
|
||||||
|
it 'should configure with applicable defaults' do
|
||||||
|
should contain_class('glance::api').with(
|
||||||
|
:verbose => 'False',
|
||||||
|
:debug => 'False',
|
||||||
|
:auth_type => 'keystone',
|
||||||
|
:auth_port => '35357',
|
||||||
|
:auth_host => '127.0.1.1',
|
||||||
|
:keystone_tenant => 'services',
|
||||||
|
:keystone_user => 'glance',
|
||||||
|
:keystone_password => 'glance_user_pass',
|
||||||
|
:sql_connection => 'mysql://glance:glance_db_pass@127.0.0.1/glance',
|
||||||
|
:enabled => true
|
||||||
|
)
|
||||||
|
should contain_class('glance::registry').with(
|
||||||
|
:verbose => 'False',
|
||||||
|
:debug => 'False',
|
||||||
|
:auth_host => '127.0.1.1',
|
||||||
|
:auth_port => '35357',
|
||||||
|
:auth_type => 'keystone',
|
||||||
|
:keystone_tenant => 'services',
|
||||||
|
:keystone_user => 'glance',
|
||||||
|
:keystone_password => 'glance_user_pass',
|
||||||
|
:sql_connection => 'mysql://glance:glance_db_pass@127.0.0.1/glance',
|
||||||
|
:enabled => true
|
||||||
|
)
|
||||||
|
should contain_class('glance::backend::file')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'with an invalid db_type' do
|
||||||
|
before do
|
||||||
|
params.merge!(:db_type => 'sqlite' )
|
||||||
|
end
|
||||||
|
it 'should fail' do
|
||||||
|
expect { subject }.to raise_error(Puppet::Error, /Unsupported db_type sqlite/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'with an invalid backend' do
|
||||||
|
before do
|
||||||
|
params.merge!(:backend => 'ceph')
|
||||||
|
end
|
||||||
|
it 'should fail' do
|
||||||
|
expect { subject }.to raise_error(Puppet::Error, /Unsupported backend ceph/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'when configuring swift as the backend' do
|
||||||
|
|
||||||
|
before do
|
||||||
|
params.merge!({
|
||||||
|
:backend => 'swift',
|
||||||
|
:swift_store_user => 'dan',
|
||||||
|
:swift_store_key => '123'
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should configure swift as the backend' do
|
||||||
|
should_not contain_class('glance::backend::file')
|
||||||
|
|
||||||
|
should contain_class('glance::backend::swift').with(
|
||||||
|
:swift_store_user => 'dan',
|
||||||
|
:swift_store_key => '123',
|
||||||
|
:swift_store_auth_address => 'http://127.0.0.1:5000/v2.0/',
|
||||||
|
:swift_store_create_container_on_put => 'True'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'user key must be set' do
|
||||||
|
before do
|
||||||
|
params.delete(:swift_store_key)
|
||||||
|
end
|
||||||
|
it 'should fail' do
|
||||||
|
expect do
|
||||||
|
subject
|
||||||
|
end.to raise_error(Puppet::Error, /swift_store_key must be set when configuring swift/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
describe 'user name must be set' do
|
||||||
|
before do
|
||||||
|
params.delete(:swift_store_user)
|
||||||
|
end
|
||||||
|
it 'should fail' do
|
||||||
|
expect do
|
||||||
|
subject
|
||||||
|
end.to raise_error(Puppet::Error, /swift_store_user must be set when configuring swift/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user