Manage backend section for Glare

Since Glare can be configured only through puppet-glare module
it should has ability to configure backend sections in config files.

Change-Id: If4638f4f087ba42e60f47f58a50edb837da2ffe9
This commit is contained in:
Denis Egorenko 2017-03-13 14:58:31 +04:00 committed by Mykyta Karpin
parent 8ffd763a2b
commit 74fcd918aa
19 changed files with 1066 additions and 10 deletions

View File

@ -0,0 +1,10 @@
Puppet::Type.type(:glare_swift_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
) do
def self.file_path
'/etc/glare/glare-swift.conf'
end
end

View File

@ -0,0 +1,57 @@
Puppet::Type.newtype(:glare_swift_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from glare-swift.conf'
newvalues(/\S+\/\S+/)
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
newvalues(/^[\S ]*$/)
def is_to_s( currentvalue )
if resource.secret?
return '[old secret redacted]'
else
return currentvalue
end
end
def should_to_s( newvalue )
if resource.secret?
return '[new secret redacted]'
else
return newvalue
end
end
end
newparam(:secret, :boolean => true) do
desc 'Whether to hide the value from Puppet logs. Defaults to `false`.'
newvalues(:true, :false)
defaultto false
end
newparam(:ensure_absent_val) do
desc 'A value that is specified as the value property will behave as if ensure => absent was specified'
defaultto('<SERVICE DEFAULT>')
end
autorequire(:package) do
if Facter.value(:osfamily) == 'Debian'
'glare-api'
elsif Facter.value(:osfamily) == 'RedHat'
'openstack-glare'
end
end
end

View File

@ -0,0 +1,62 @@
#
# == Class: glare::backend::cinder
#
# Setup Glare to backend artifacts into Cinder
#
# === Parameters
#
# [*cinder_catalog_info*]
# (optional) Info to match when looking for cinder in the service catalog.
# Format is : separated values of the form:
# <service_type>:<service_name>:<endpoint_type> (string value)
# Defaults to $::os_service_default.
#
# [*cinder_endpoint_template*]
# (optional) Override service catalog lookup with template for cinder endpoint.
# Should be a valid URL. Example: 'http://localhost:8776/v1/%(project_id)s'
# Defaults to $::os_service_default.
#
# [*cinder_ca_certificates_file*]
# (optional) Location of ca certicate file to use for cinder client requests.
# Should be a valid ca certicate file
# Defaults to $::os_service_default.
#
# [*cinder_http_retries*]
# (optional) Number of cinderclient retries on failed http calls.
# Should be a valid integer
# Defaults to $::os_service_default.
#
# [*cinder_api_insecure*]
# (optional) Allow to perform insecure SSL requests to cinder.
# Should be a valid boolean value
# Defaults to $::os_service_default.
#
# [*multi_store*]
# (optional) Boolean describing if multiple backends will be configured
# Defaults to false
#
class glare::backend::cinder(
$cinder_ca_certificates_file = $::os_service_default,
$cinder_api_insecure = $::os_service_default,
$cinder_catalog_info = $::os_service_default,
$cinder_endpoint_template = $::os_service_default,
$cinder_http_retries = $::os_service_default,
$multi_store = false,
) {
include ::glare::deps
# Glare hasn't its own store, glance_store should be used
glare_config {
'glance_store/cinder_api_insecure': value => $cinder_api_insecure;
'glance_store/cinder_catalog_info': value => $cinder_catalog_info;
'glance_store/cinder_http_retries': value => $cinder_http_retries;
'glance_store/cinder_endpoint_template': value => $cinder_endpoint_template;
'glance_store/cinder_ca_certificates_file': value => $cinder_ca_certificates_file;
}
if !$multi_store {
glare_config { 'glance_store/default_store': value => 'cinder'; }
}
}

31
manifests/backend/file.pp Normal file
View File

@ -0,0 +1,31 @@
# === class: glare::backend::file
#
# used to configure file backends for glare
#
# === parameters:
#
# [*filesystem_store_datadir*]
# Location where dist images are stored when
# default_store == file.
# Optional. Default: /var/lib/glare/images/
#
# [*multi_store*]
# (optional) Boolean describing if multiple backends will be configured
# Defaults to false
#
class glare::backend::file(
$filesystem_store_datadir = '/var/lib/glare/images/',
$multi_store = false,
) {
include ::glare::deps
# Glare hasn't its own store, glance_store should be used
glare_config {
'glance_store/filesystem_store_datadir': value => $filesystem_store_datadir;
}
if !$multi_store {
glare_config { 'glance_store/default_store': value => 'file'; }
}
}

73
manifests/backend/rbd.pp Normal file
View File

@ -0,0 +1,73 @@
# == class: glare::backend::rbd
#
# configures the storage backend for glare
# as a rbd instance
#
# === parameters:
#
# [*rbd_store_user*]
# Optional. Default: $::os_service_default.
#
# [*rbd_store_pool*]
# Optional. Default: $::os_service_default.
#
# [*rbd_store_ceph_conf*]
# Optional. Default: $::os_service_default.
#
# [*rbd_store_chunk_size*]
# Optional. Default: $::os_service_default.
#
# [*show_image_direct_url*]
# Optional. Enables direct COW from glare to rbd
# DEPRECATED, use show_image_direct_url in glare::api
#
# [*package_ensure*]
# (optional) Desired ensure state of packages.
# accepts latest or specific versions.
# Defaults to present.
#
# [*rados_connect_timeout*]
# Optinal. Timeout value (in seconds) used when connecting
# to ceph cluster. If value <= 0, no timeout is set and
# default librados value is used.
# Default: $::os_service_default.
#
# [*multi_store*]
# (optional) Boolean describing if multiple backends will be configured
# Defaults to false
#
class glare::backend::rbd(
$rbd_store_user = $::os_service_default,
$rbd_store_ceph_conf = $::os_service_default,
$rbd_store_pool = $::os_service_default,
$rbd_store_chunk_size = $::os_service_default,
$package_ensure = 'present',
$rados_connect_timeout = $::os_service_default,
$multi_store = false,
) {
include ::glare::deps
include ::glare::params
# Glare hasn't its own store, glance_store should be used
glare_config {
'glance_store/rbd_store_ceph_conf': value => $rbd_store_ceph_conf;
'glance_store/rbd_store_user': value => $rbd_store_user;
'glance_store/rbd_store_pool': value => $rbd_store_pool;
'glance_store/rbd_store_chunk_size': value => $rbd_store_chunk_size;
'glance_store/rados_connect_timeout': value => $rados_connect_timeout;
}
if !$multi_store {
glare_config { 'glance_store/default_store': value => 'rbd'; }
}
ensure_packages('python-ceph',
{
ensure => $package_ensure,
name => $::glare::params::pyceph_package_name,
tag => 'glare-support-package',
}
)
}

99
manifests/backend/s3.pp Normal file
View File

@ -0,0 +1,99 @@
# == class: glare::backend::s3
#
# configures the storage backend for glare
# as a s3 instance
#
# === parameters:
#
# [*access_key*]
# (Required) The S3 query token access key.
#
# [*secret_key*]
# (Required) The S3 query token secret key.
#
# [*host*]
# (Required) The host where the S3 server is listening.
#
# [*bucket*]
# (Required) The S3 bucket to be used to store the Glance data.
#
# [*bucket_url_format*]
# (Optional) The S3 calling format used to determine the bucket. Either
# 'subdomain' or 'path' can be used.
# Default: $::os_service_default.
#
# [*create_bucket_on_put*]
# (Optional) A boolean to determine if the S3 bucket should be created on
# upload if it does not exist or if an error should be returned to the user.
# Default: $::os_service_default.
#
# [*large_object_size*]
# (Optional) What size, in MB, should S3 start chunking image files and do a
# multipart upload in S3.
# Default: $::os_service_default.
#
# [*large_object_chunk_size*]
# (Optional) What multipart upload part size, in MB, should S3 use when
# uploading parts. The size must be greater than or equal to 5M.
# Default: $::os_service_default.
#
# [*object_buffer_dir*]
# (Optional) The local directory where uploads will be staged before they are
# transferred into S3.
# Default: $::os_service_default.
#
# [*thread_pools*]
# (Optional) The number of thread pools to perform a multipart upload in S3.
# Default: $::os_service_default.
#
# [*multi_store*]
# (optional) Boolean describing if multiple backends will be configured
# Defaults to false
#
class glare::backend::s3(
$access_key,
$secret_key,
$host,
$bucket,
$bucket_url_format = $::os_service_default,
$create_bucket_on_put = $::os_service_default,
$large_object_size = $::os_service_default,
$large_object_chunk_size = $::os_service_default,
$object_buffer_dir = $::os_service_default,
$thread_pools = $::os_service_default,
$multi_store = false,
) {
include ::glare::deps
if !is_service_default($large_object_chunk_size){
if !is_integer($large_object_chunk_size) or $large_object_chunk_size < 5 {
fail('glare::backend::s3::large_object_chunk_size must be an integer >= 5')
}
}
if !is_service_default($bucket_url_format){
if !($bucket_url_format in ['subdomain', 'path']) {
fail('glare::backend::s3::bucket_url_format must be either "subdomain" or "path"')
}
}
# Glare hasn't its own store, glance_store should be used
glare_config {
'glance_store/s3_store_access_key': value => $access_key;
'glance_store/s3_store_secret_key': value => $secret_key;
'glance_store/s3_store_host': value => $host;
'glance_store/s3_store_bucket': value => $bucket;
'glance_store/s3_store_bucket_url_format': value => $bucket_url_format;
'glance_store/s3_store_create_bucket_on_put': value => $create_bucket_on_put;
'glance_store/s3_store_large_object_size': value => $large_object_size;
'glance_store/s3_store_large_object_chunk_size': value => $large_object_chunk_size;
'glance_store/s3_store_thread_pools': value => $thread_pools;
'glance_store/s3_store_object_buffer_dir': value => $object_buffer_dir;
}
if !$multi_store {
glare_config { 'glance_store/default_store': value => 's3'; }
}
}

100
manifests/backend/swift.pp Normal file
View File

@ -0,0 +1,100 @@
# == class: glare::backend::swift
#
# configures the storage backend for glare
# as a swift instance
#
# === parameters:
#
# [*swift_store_user*]
# Required. Swift store user.
#
# [*swift_store_key*]
# Required. Swift store key.
#
# [*swift_store_auth_address*]
# Optional. Default: 'http://127.0.0.1:5000/v2.0/'
#
# [*swift_store_auth_project_domain_id*]
# Optional. Useful when keystone auth is version 3. Default: default
#
# [*swift_store_auth_user_domain_id*]
# Optional. Useful when keystone auth is version 3. Default: default
#
# [*swift_store_container*]
# Optional. Default: $::os_service_default.
#
# [*swift_store_auth_version*]
# Optional. Default: '2'
#
# [*swift_store_large_object_size*]
# Optional. Default: $::os_service_default.
#
# [*swift_store_create_container_on_put*]
# Optional. Default: $::os_service_default.
#
# [*swift_store_endpoint_type*]
# Optional. Default: 'internalURL'
#
# [*swift_store_region*]
# Optional. Default: $::os_service_default.
#
# [*default_swift_reference*]
# Optional. The reference to the default swift
# account/backing store parameters to use for adding
# new images. String value.
# Default to 'ref1'.
#
# [*multi_store*]
# (optional) Boolean describing if multiple backends will be configured
# Defaults to false
#
class glare::backend::swift(
$swift_store_user,
$swift_store_key,
$swift_store_auth_address = 'http://127.0.0.1:5000/v2.0/',
$swift_store_container = $::os_service_default,
$swift_store_auth_version = '2',
$swift_store_auth_project_domain_id = 'default',
$swift_store_auth_user_domain_id = 'default',
$swift_store_large_object_size = $::os_service_default,
$swift_store_create_container_on_put = $::os_service_default,
$swift_store_endpoint_type = 'internalURL',
$swift_store_region = $::os_service_default,
$default_swift_reference = 'ref1',
$multi_store = false,
) {
include ::glare::deps
include ::swift::client
Class['swift::client'] -> Anchor['glare::install::end']
Service<| tag == 'swift-service' |> -> Service['glare']
# Glare hasn't its own store, glance_store should be used
glare_config {
'glance_store/swift_store_region': value => $swift_store_region;
'glance_store/swift_store_container': value => $swift_store_container;
'glance_store/swift_store_create_container_on_put':
value => $swift_store_create_container_on_put;
'glance_store/swift_store_large_object_size':
value => $swift_store_large_object_size;
'glance_store/swift_store_endpoint_type':
value => $swift_store_endpoint_type;
'glance_store/swift_store_config_file': value => '/etc/glare/glare-swift.conf';
'glance_store/default_swift_reference': value => $default_swift_reference;
}
if !$multi_store {
glare_config { 'glance_store/default_store': value => 'swift'; }
}
glare_swift_config {
"${default_swift_reference}/user": value => $swift_store_user;
"${default_swift_reference}/key": value => $swift_store_key;
"${default_swift_reference}/auth_address": value => $swift_store_auth_address;
"${default_swift_reference}/auth_version": value => $swift_store_auth_version;
"${default_swift_reference}/user_domain_id": value => $swift_store_auth_user_domain_id;
"${default_swift_reference}/project_domain_id": value => $swift_store_auth_project_domain_id;
}
}

View File

@ -0,0 +1,95 @@
# == Class: glare::backend::vsphere
#
# Setup Glare to backend images into VMWare vCenter/ESXi
#
# === Parameters
#
# [*vcenter_insecure*]
# (optional) If true, the ESX/vCenter server certificate is not verified.
# If false, then the default CA truststore is used for verification.
# This option is ignored if "vcenter_ca_file" is set.
# Defaults to 'True'.
#
# [*vcenter_ca_file*]
# (optional) The name of the CA bundle file which will be used in
# verifying vCenter server certificate. If parameter is not set
# then system truststore is used. If parameter is set,
# vcenter_insecure value is ignored.
# Defaults to $::os_service_default.
#
# [*vcenter_datastores*]
# (Multi-valued) A list of datastores where the image
# can be stored. This option may be specified multiple times
# for specifying multiple datastores. The datastore name should
# be specified after its datacenter path, seperated by ":".
# An optional weight may be given after the datastore name,
# seperated again by ":". Thus, the required format
# becomes <datacenter_path>:<datastore_name>:<optional_weight>.
# When adding an image, the datastore with highest weight will be selected,
# unless there is not enough free space available in cases where the image
# size is already known. If no weight is given, it is assumed to be
# zero and the directory will be considered for selection last.
# If multiple datastores have the same weight, then the one with the most
# free space available is selected.
# Defaults to $::os_service_default.
#
# [*vcenter_host*]
# (required) vCenter/ESXi Server target system.
# Should be a valid an IP address or a DNS name.
#
# [*vcenter_user*]
# (required) Username for authenticating with vCenter/ESXi server.
#
# [*vcenter_password*]
# (required) Password for authenticating with vCenter/ESXi server.
#
# [*vcenter_image_dir*]
# (required) The name of the directory where the glare images will be stored
# in the VMware datastore.
#
# [*vcenter_task_poll_interval*]
# (optional) The interval used for polling remote tasks invoked on
# vCenter/ESXi server.
# Defaults to $::os_service_default.
#
# [*vcenter_api_retry_count*]
# (optional) Number of times VMware ESX/VC server API must be retried upon
# connection related issues.
# Defaults to $::os_service_default.
#
# [*multi_store*]
# (optional) Boolean describing if multiple backends will be configured
# Defaults to false.
#
class glare::backend::vsphere(
$vcenter_host,
$vcenter_user,
$vcenter_password,
$vcenter_image_dir,
$vcenter_datastores,
$vcenter_ca_file = $::os_service_default,
$vcenter_insecure = 'True',
$vcenter_task_poll_interval = $::os_service_default,
$vcenter_api_retry_count = $::os_service_default,
$multi_store = false,
) {
include ::glare::deps
# Glare hasn't its own store, glance_store should be used
glare_config {
'glance_store/vmware_insecure': value => $vcenter_insecure;
'glance_store/vmware_ca_file': value => $vcenter_ca_file;
'glance_store/vmware_server_host': value => $vcenter_host;
'glance_store/vmware_server_username': value => $vcenter_user;
'glance_store/vmware_server_password': value => $vcenter_password;
'glance_store/vmware_store_image_dir': value => $vcenter_image_dir;
'glance_store/vmware_task_poll_interval': value => $vcenter_task_poll_interval;
'glance_store/vmware_api_retry_count': value => $vcenter_api_retry_count;
'glance_store/vmware_datastores': value => $vcenter_datastores;
}
if !$multi_store {
glare_config { 'glance_store/default_store': value => 'vsphere'; }
}
}

View File

@ -20,13 +20,19 @@
# NOTE: The configuration MUST NOT be already handled by this module
# or Puppet catalog compilation will fail with duplicate resources.
#
# [*glare_paste_ini_config*]
# (optional) Allow configuration of glance-glare-paste.ini configurations.
#
class glare::config (
$glare_config = {},
$glare_paste_ini_config = {}
) {
include ::glare::deps
validate_hash($glare_config)
validate_hash($glare_paste_ini_config)
create_resources('glare_config', $glare_config)
create_resources('glare_paste_ini', $glare_paste_ini_config)
}

View File

@ -47,6 +47,9 @@ class glare::deps {
# the glare::install::end anchor. The line between glare-support-package and
# glare-package should be whether or not glare services would need to be
# restarted if the package state was changed.
Anchor['glare::install::begin']
-> Package<| tag == 'glare-support-package'|>
-> Anchor['glare::install::end']
# Installation or config changes will always restart services.
Anchor['glare::install::end'] ~> Anchor['glare::service::begin']

View File

@ -56,7 +56,7 @@
# [*stores*]
# (optional) List of which store classes and store class locations are
# currently known to glare at startup.
# Defaults to $::os_service_default,
# Defaults to undef,
# Example: file,http
# Possible values:
# * A comma separated list that could include:
@ -74,7 +74,11 @@
# [*default_store*]
# (optional) Allowed values: file, filesystem, http, https, swift,
# swift+http, swift+https, swift+config, rbd, sheepdog, cinder, vsphere
# default_store = $::os_service_default,
# default_store = undef,
#
# [*multi_store*]
# (optional) Boolean describing if multiple backends will be configured
# Defaults to false
#
# [*filesystem_store_datadir*]
#
@ -112,8 +116,9 @@ class glare (
$cert_file = $::os_service_default,
$key_file = $::os_service_default,
$ca_file = $::os_service_default,
$stores = $::os_service_default,
$default_store = $::os_service_default,
$stores = undef,
$default_store = undef,
$multi_store = false,
$filesystem_store_datadir = '/var/lib/glare/images',
$os_region_name = 'RegionOne',
$allow_anonymous_access = $::os_service_default,
@ -148,11 +153,52 @@ class glare (
'DEFAULT/allow_anonymous_access': value => $allow_anonymous_access;
}
# stores config
if $default_store {
$default_store_real = $default_store
}
if !empty($stores) {
# determine value for glance_store/stores
if size(any2array($stores)) > 1 {
$stores_real = join($stores, ',')
} else {
$stores_real = $stores[0]
}
if !$default_store_real {
# set default store based on provided stores when it isn't explicitly set
warning("default_store not provided, it will be automatically set to ${stores[0]}")
$default_store_real = $stores[0]
}
} elsif $default_store_real {
# set stores based on default_store if only default_store is provided
$stores_real = $default_store
} else {
warning('Glare is being provisioned without any stores configured')
}
if $default_store_real and $multi_store {
glare_config {
'glance_store/default_store': value => $default_store_real;
}
} elsif $multi_store {
glare_config {
'glance_store/default_store': ensure => absent;
}
}
if $stores_real {
glare_config {
'glance_store/stores': value => $stores_real;
}
} else {
glare_config {
'glance_store/stores': ensure => absent;
}
}
glare_config {
'glance_store/os_region_name' : value => $os_region_name;
'glance_store/stores' : value => $stores;
'glance_store/default_store' : value => $default_store;
'glance_store/filesystem_store_datadir': value => $filesystem_store_datadir;
'glance_store/os_region_name' : value => $os_region_name;
'glance_store/filesystem_store_datadir' : value => $filesystem_store_datadir;
}
if $pipeline != '' {

View File

@ -7,6 +7,11 @@ class glare::params {
'RedHat': {
$glare_package_name = 'openstack-glare'
$glare_service_name = 'openstack-glare-api'
if ($::operatingsystem != 'fedora' and versioncmp($::operatingsystemrelease, '7') < 0) {
$pyceph_package_name = 'python-ceph'
} else {
$pyceph_package_name = 'python-rbd'
}
}
'Debian': {
$glare_package_name = 'glare-api'

View File

@ -0,0 +1,75 @@
#
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.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.
#
# Unit tests for glare::backend::cinder class
#
require 'spec_helper'
describe 'glare::backend::cinder' do
let :pre_condition do
'class { "glare::keystone::authtoken": password => "pass" }'
end
shared_examples_for 'glare with cinder backend' do
context 'when default parameters' do
it 'configures glare.conf' do
is_expected.to contain_glare_config('glance_store/default_store').with_value('cinder')
is_expected.to contain_glare_config('glance_store/cinder_api_insecure').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/cinder_catalog_info').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/cinder_http_retries').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/cinder_ca_certificates_file').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/cinder_endpoint_template').with_value('<SERVICE DEFAULT>')
end
end
context 'when overriding parameters' do
let :params do
{
:cinder_api_insecure => true,
:cinder_ca_certificates_file => '/etc/ssh/ca.crt',
:cinder_catalog_info => 'volume:cinder:internalURL',
:cinder_endpoint_template => 'http://srv-foo:8776/v1/%(project_id)s',
:cinder_http_retries => '10',
}
end
it 'configures glare.conf' do
is_expected.to contain_glare_config('glance_store/cinder_api_insecure').with_value(true)
is_expected.to contain_glare_config('glance_store/cinder_ca_certificates_file').with_value('/etc/ssh/ca.crt')
is_expected.to contain_glare_config('glance_store/cinder_catalog_info').with_value('volume:cinder:internalURL')
is_expected.to contain_glare_config('glance_store/cinder_endpoint_template').with_value('http://srv-foo:8776/v1/%(project_id)s')
is_expected.to contain_glare_config('glance_store/cinder_http_retries').with_value('10')
end
end
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())
end
it_configures 'glare with cinder backend'
end
end
end

View File

@ -0,0 +1,33 @@
require 'spec_helper'
describe 'glare::backend::file' do
shared_examples_for 'glare::backend::file' do
it 'configures glare.conf' do
is_expected.to contain_glare_config('glance_store/default_store').with_value('file')
is_expected.to contain_glare_config('glance_store/filesystem_store_datadir').with_value('/var/lib/glare/images/')
end
describe 'when overriding datadir' do
let :params do
{:filesystem_store_datadir => '/tmp/'}
end
it 'configures glare.conf' do
is_expected.to contain_glare_config('glance_store/filesystem_store_datadir').with_value('/tmp/')
end
end
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())
end
it_configures 'glare::backend::file'
end
end
end

View File

@ -0,0 +1,70 @@
require 'spec_helper'
describe 'glare::backend::rbd' do
let (:facts) do
OSDefaults.get_facts({
:osfamily => 'Debian',
})
end
describe 'with default params' do
it { is_expected.to contain_glare_config('glance_store/default_store').with_value('rbd') }
it { is_expected.to contain_glare_config('glance_store/rbd_store_pool').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_glare_config('glance_store/rbd_store_ceph_conf').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_glare_config('glance_store/rbd_store_chunk_size').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_glare_config('glance_store/rados_connect_timeout').with_value('<SERVICE DEFAULT>')}
it { is_expected.to contain_glare_config('glance_store/rbd_store_user').with_value('<SERVICE DEFAULT>')}
it { is_expected.to contain_package('python-ceph').with(
:name => 'python-ceph',
:ensure => 'present'
)
}
end
describe 'when passing params' do
let :params do
{
:rbd_store_user => 'user',
:rbd_store_chunk_size => '2',
:package_ensure => 'latest',
:rados_connect_timeout => '30',
}
end
it { is_expected.to contain_glare_config('glance_store/rbd_store_user').with_value('user') }
it { is_expected.to contain_glare_config('glance_store/rbd_store_chunk_size').with_value('2') }
it { is_expected.to contain_glare_config('glance_store/rados_connect_timeout').with_value('30')}
it { is_expected.to contain_package('python-ceph').with(
:name => 'python-ceph',
:ensure => 'latest'
)
}
end
describe 'package on RedHat platform el6' do
let :facts do
OSDefaults.get_facts({
:osfamily => 'RedHat',
:operatingsystemrelease => '6.5',
})
end
it { is_expected.to contain_package('python-ceph').with(
:name => 'python-ceph',
:ensure => 'present'
)
}
end
describe 'package on RedHat platform el7' do
let :facts do
OSDefaults.get_facts({
:osfamily => 'RedHat',
:operatingsystemrelease => '7.0'
})
end
it { is_expected.to contain_package('python-ceph').with(
:name => 'python-rbd',
:ensure => 'present'
)
}
end
end

View File

@ -0,0 +1,122 @@
require 'spec_helper'
describe 'glare::backend::s3' do
shared_examples_for 'glare::backend::s3' do
let :params do
{
:access_key => 'access',
:secret_key => 'secret',
:host => 'host',
:bucket => 'bucket'
}
end
describe 'when default parameters' do
it 'configures glare.conf' do
is_expected.to contain_glare_config('glance_store/default_store').with_value('s3')
is_expected.to contain_glare_config('glance_store/s3_store_access_key').with_value('access')
is_expected.to contain_glare_config('glance_store/s3_store_secret_key').with_value('secret')
is_expected.to contain_glare_config('glance_store/s3_store_host').with_value('host')
is_expected.to contain_glare_config('glance_store/s3_store_bucket').with_value('bucket')
is_expected.to contain_glare_config('glance_store/s3_store_bucket_url_format').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/s3_store_create_bucket_on_put').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/s3_store_large_object_size').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/s3_store_large_object_chunk_size').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/s3_store_object_buffer_dir').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/s3_store_thread_pools').with_value('<SERVICE DEFAULT>')
end
end
describe 'when overriding parameters' do
let :params do
{
:access_key => 'access2',
:secret_key => 'secret2',
:host => 'host2',
:bucket => 'bucket2',
:bucket_url_format => 'path',
:create_bucket_on_put => true,
:large_object_size => 200,
:large_object_chunk_size => 20,
:object_buffer_dir => '/tmp',
:thread_pools => 20,
}
end
it 'configures glare.conf' do
is_expected.to contain_glare_config('glance_store/s3_store_access_key').with_value('access2')
is_expected.to contain_glare_config('glance_store/s3_store_secret_key').with_value('secret2')
is_expected.to contain_glare_config('glance_store/s3_store_host').with_value('host2')
is_expected.to contain_glare_config('glance_store/s3_store_bucket').with_value('bucket2')
is_expected.to contain_glare_config('glance_store/s3_store_bucket_url_format').with_value('path')
is_expected.to contain_glare_config('glance_store/s3_store_create_bucket_on_put').with_value('true')
is_expected.to contain_glare_config('glance_store/s3_store_large_object_size').with_value('200')
is_expected.to contain_glare_config('glance_store/s3_store_large_object_chunk_size').with_value('20')
is_expected.to contain_glare_config('glance_store/s3_store_object_buffer_dir').with_value('/tmp')
is_expected.to contain_glare_config('glance_store/s3_store_thread_pools').with_value('20')
end
end
describe 'with invalid bucket_url_format' do
let :params do
{
:access_key => 'access',
:secret_key => 'secret',
:host => 'host',
:bucket => 'bucket',
:bucket_url_format => 'invalid'
}
end
it 'throws errors' do
is_expected.to raise_error(Puppet::Error, /glare::backend::s3::bucket_url_format must be either "subdomain" or "path"/)
end
end
describe 'with invalid large_object_chunk_size' do
let :params do
{
:access_key => 'access',
:secret_key => 'secret',
:host => 'host',
:bucket => 'bucket',
:large_object_chunk_size => 1
}
end
it 'throws error' do
is_expected.to raise_error(Puppet::Error, /glare::backend::s3::large_object_chunk_size must be an integer >= 5/)
end
end
describe 'with non-integer large_object_chunk_size' do
let :params do
{
:access_key => 'access',
:secret_key => 'secret',
:host => 'host',
:bucket => 'bucket',
:large_object_chunk_size => 'string'
}
end
it 'throws error' do
is_expected.to raise_error(Puppet::Error, /glare::backend::s3::large_object_chunk_size must be an integer >= 5/)
end
end
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())
end
it_configures 'glare::backend::s3'
end
end
end

View File

@ -0,0 +1,81 @@
require 'spec_helper'
describe 'glare::backend::swift' do
shared_examples_for 'glare::backend::swift' do
let :params do
{
:swift_store_user => 'user',
:swift_store_key => 'key',
}
end
let :pre_condition do
'class { "glare::keystone::authtoken": password => "pass" }
include ::glare'
end
describe 'when default parameters' do
it { is_expected.to contain_class 'swift::client' }
it 'configures glare.conf' do
is_expected.to contain_glare_config('glance_store/default_store').with_value('swift')
is_expected.to contain_glare_config('glance_store/swift_store_large_object_size').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/swift_store_container').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/swift_store_create_container_on_put').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/swift_store_endpoint_type').with_value('internalURL')
is_expected.to contain_glare_config('glance_store/swift_store_region').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/swift_store_config_file').with_value('/etc/glare/glare-swift.conf')
is_expected.to contain_glare_config('glance_store/default_swift_reference').with_value('ref1')
end
end
describe 'when overriding parameters' do
let :params do
{
:swift_store_user => 'user2',
:swift_store_key => 'key2',
:swift_store_auth_version => '1',
:swift_store_auth_project_domain_id => 'proj_domain',
:swift_store_auth_user_domain_id => 'user_domain',
:swift_store_large_object_size => '100',
:swift_store_auth_address => '127.0.0.2:8080/v1.0/',
:swift_store_container => 'swift',
:swift_store_create_container_on_put => true,
:swift_store_endpoint_type => 'publicURL',
:swift_store_region => 'RegionTwo',
:default_swift_reference => 'swift_creds',
}
end
it 'configures glare.conf' do
is_expected.to contain_glare_config('glance_store/swift_store_container').with_value('swift')
is_expected.to contain_glare_config('glance_store/swift_store_create_container_on_put').with_value(true)
is_expected.to contain_glare_config('glance_store/swift_store_large_object_size').with_value('100')
is_expected.to contain_glare_config('glance_store/swift_store_endpoint_type').with_value('publicURL')
is_expected.to contain_glare_config('glance_store/swift_store_region').with_value('RegionTwo')
is_expected.to contain_glare_config('glance_store/default_swift_reference').with_value('swift_creds')
is_expected.to contain_glare_swift_config('swift_creds/key').with_value('key2')
is_expected.to contain_glare_swift_config('swift_creds/user').with_value('user2')
is_expected.to contain_glare_swift_config('swift_creds/auth_version').with_value('1')
is_expected.to contain_glare_swift_config('swift_creds/auth_address').with_value('127.0.0.2:8080/v1.0/')
is_expected.to contain_glare_swift_config('swift_creds/user_domain_id').with_value('user_domain')
is_expected.to contain_glare_swift_config('swift_creds/project_domain_id').with_value('proj_domain')
end
end
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())
end
it_configures 'glare::backend::swift'
end
end
end

View File

@ -0,0 +1,88 @@
#
# Copyright (C) 2014 Mirantis
#
# Author: Steapn Rogov <srogov@mirantis.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.
#
# Unit tests for glare::backend::vsphere class
#
require 'spec_helper'
describe 'glare::backend::vsphere' do
let :pre_condition do
'class { "glare::keystone::authtoken": password => "pass" }'
end
shared_examples_for 'glare with vsphere backend' do
context 'when default parameters' do
let :params do
{
:vcenter_host => '10.0.0.1',
:vcenter_user => 'root',
:vcenter_password => '123456',
:vcenter_datastores => 'Datacenter:Datastore',
:vcenter_image_dir => '/openstack_glance',
}
end
it 'configures glare.conf' do
is_expected.to contain_glare_config('glance_store/default_store').with_value('vsphere')
is_expected.to contain_glare_config('glance_store/vmware_insecure').with_value('True')
is_expected.to contain_glare_config('glance_store/vmware_server_host').with_value('10.0.0.1')
is_expected.to contain_glare_config('glance_store/vmware_server_username').with_value('root')
is_expected.to contain_glare_config('glance_store/vmware_server_password').with_value('123456')
is_expected.to contain_glare_config('glance_store/vmware_store_image_dir').with_value('/openstack_glance')
is_expected.to contain_glare_config('glance_store/vmware_task_poll_interval').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/vmware_api_retry_count').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/vmware_datastores').with_value('Datacenter:Datastore')
is_expected.to contain_glare_config('glance_store/vmware_ca_file').with_value('<SERVICE DEFAULT>')
end
end
context 'when overriding parameters' do
let :params do
{
:vcenter_host => '10.0.0.1',
:vcenter_user => 'root',
:vcenter_password => '123456',
:vcenter_datastores => 'Datacenter:Datastore',
:vcenter_image_dir => '/openstack_glance',
:vcenter_ca_file => '/etc/glance/vcenter-ca.pem',
:vcenter_task_poll_interval => '6',
:vcenter_api_retry_count => '11',
}
end
it 'configures glare.conf' do
is_expected.to contain_glare_config('glance_store/vmware_ca_file').with_value('/etc/glance/vcenter-ca.pem')
is_expected.to contain_glare_config('glance_store/vmware_task_poll_interval').with_value('6')
is_expected.to contain_glare_config('glance_store/vmware_api_retry_count').with_value('11')
end
end
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())
end
it_configures 'glare with vsphere backend'
end
end
end

View File

@ -46,8 +46,8 @@ describe 'glare' do
it 'configures storage' do
is_expected.to contain_glare_config('glance_store/os_region_name').with_value('RegionOne')
is_expected.to contain_glare_config('glance_store/stores').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/default_store').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/stores').with_ensure('absent')
is_expected.not_to contain_glare_config('glance_store/default_store')
is_expected.to contain_glare_config('glance_store/filesystem_store_datadir').with_value('/var/lib/glare/images')
end