From 4a5e0adbe2286f39977c56bcd121283cdbab49bf Mon Sep 17 00:00:00 2001 From: cdelatte Date: Wed, 1 Jul 2015 09:06:29 -0400 Subject: [PATCH] module to set quotas per volume type This will set the quotas per volume type passed in Change-Id: I6af7347cbf8d907a7cc004a594aafdb2745c280f --- manifests/quota_set.pp | 86 +++++++++++++++++++++++++++ spec/defines/cinder_quota_set_spec.rb | 64 ++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 manifests/quota_set.pp create mode 100644 spec/defines/cinder_quota_set_spec.rb diff --git a/manifests/quota_set.pp b/manifests/quota_set.pp new file mode 100644 index 00000000..cec059f0 --- /dev/null +++ b/manifests/quota_set.pp @@ -0,0 +1,86 @@ +# == Class: cinder::quota_set +# +# Setup and configure Cinder quotas per volume type. +# +# === Parameters +# +# [*os_password*] +# (Required) The keystone tenant:username password. +# +# [*os_tenant_name*] +# (Optional) The keystone tenant name. +# Defaults to 'admin'. +# +# [*os_username*] +# (Optional) The keystone user name. +# Defaults to 'admin'. +# +# [*os_auth_url*] +# (Optional) The keystone auth url. +# Defaults to 'http://127.0.0.1:5000/v2.0/'. +# +# [*os_region_name*] +# (Optional) The keystone region name. +# Default is unset. +# +# [*quota_volumes*] +# (Optional) Number of volumes allowed per project. +# Defaults to 10. +# +# [*quota_snapshots*] +# (Optional) Number of volume snapshots allowed per project. +# Defaults to 10. +# +# [*quota_gigabytes*] +# (Optional) Number of volume gigabytes (snapshots are also included) +# allowed per project. +# Defaults to 1000. +# +# [*class_name*] +# (Optional) Quota class to use. +# Defaults to 'default'. +# +# [*volume_type*] +# volume type that will have quota changed +# Defaults to $name +# + +define cinder::quota_set ( + $os_password, + $os_tenant_name = 'admin', + $os_username = 'admin', + $os_auth_url = 'http://127.0.0.1:5000/v2.0/', + $os_region_name = undef, + $quota_volumes = 10, + $quota_snapshots = 10, + $quota_gigabytes = 1000, + $class_name = 'default', + $volume_type = $name, +) { + + if $os_region_name { + $cinder_env = [ + "OS_TENANT_NAME=${os_tenant_name}", + "OS_USERNAME=${os_username}", + "OS_PASSWORD=${os_password}", + "OS_AUTH_URL=${os_auth_url}", + "OS_REGION_NAME=${os_region_name}", + ] + } + else { + $cinder_env = [ + "OS_TENANT_NAME=${os_tenant_name}", + "OS_USERNAME=${os_username}", + "OS_PASSWORD=${os_password}", + "OS_AUTH_URL=${os_auth_url}", + ] + } + + exec {"cinder quota-class-update ${class_name}": + command => "cinder quota-class-update ${class_name} --volumes ${quota_volumes} --snapshots ${quota_snapshots} --gigabytes ${quota_gigabytes} --volume-type '${volume_type}'", + onlyif => 'cinder quota-class-show default | grep -qP -- -1', + environment => $cinder_env, + require => Package['python-cinderclient'], + path => ['/usr/bin', '/bin'], + } +} diff --git a/spec/defines/cinder_quota_set_spec.rb b/spec/defines/cinder_quota_set_spec.rb new file mode 100644 index 00000000..df82b2d4 --- /dev/null +++ b/spec/defines/cinder_quota_set_spec.rb @@ -0,0 +1,64 @@ +#Author: Craig DeLatte + +require 'spec_helper' + +describe 'cinder::quota_set' do + + let(:title) {'hippo'} + + let :params do { + :os_password => 'asdf', + :os_tenant_name => 'admin', + :os_username => 'admin', + :os_auth_url => 'http://127.127.127.1:5000/v2.0/', + :quota_volumes => '10', + :quota_snapshots => '10', + :quota_gigabytes => '1000', + :class_name => 'default', + } + end + + shared_examples_for 'cinder_quota_set' do + [{}, + { :os_region_name => 'test' } + ].each do |param_set| + describe "when #{param_set == {} ? 'using default' : 'specifying'} class parameters" do + before do + params.merge!(param_set) + end + it do + is_expected.to contain_exec('cinder quota-class-update default').with( + :command => "cinder quota-class-update default --volumes 10 --snapshots 10 --gigabytes 1000 --volume-type 'hippo'", + :environment => (param_set == {}) ? + ['OS_TENANT_NAME=admin', + 'OS_USERNAME=admin', + 'OS_PASSWORD=asdf', + 'OS_AUTH_URL=http://127.127.127.1:5000/v2.0/'] : + ['OS_TENANT_NAME=admin', + 'OS_USERNAME=admin', + 'OS_PASSWORD=asdf', + 'OS_AUTH_URL=http://127.127.127.1:5000/v2.0/', + 'OS_REGION_NAME=test'], + :onlyif => 'cinder quota-class-show default | grep -qP -- -1', + :require => 'Package[python-cinderclient]') + end + end + end + end + + context 'on Debian platforms' do + let :facts do + { :operatingsystem => 'Ubuntu', + :osfamily => 'Debian' } + end + it_configures 'cinder_quota_set' + end + + context 'on Redhat platforms' do + let :facts do + { :operatingsystem => 'Redhat', + :osfamily => 'Redhat' } + end + it_configures 'cinder_quota_set' + end +end