Move role and recipe include methods to Common
These small wrappers are now needed by other cookbooks. They provide a easy way to create a clean spec test. Will put these into the Common openstack library module namespace for easy use across the cookbooks. Added common role defintion for compute worker. Eventually all the role definitions should be moved here. Added new spec for these wrappers. Change-Id: If548a9d63a42799e1401b18540878eca5ba2a0e1 Related-Bug: #1448255
This commit is contained in:
parent
9d549d2dd2
commit
348aaf4033
@ -658,6 +658,9 @@ end
|
||||
# The name of the Chef role that installs the Keystone Service API
|
||||
default['openstack']['identity_service_chef_role'] = 'os-identity'
|
||||
|
||||
# The name of the Chef role that sets up the compute worker
|
||||
default['openstack']['compute_worker_chef_role'] = 'os-compute-worker'
|
||||
|
||||
# Array of bare options for openrc (e.g. 'option=value')
|
||||
default['openstack']['misc_openrc'] = nil
|
||||
|
||||
|
26
libraries/wrappers.rb
Normal file
26
libraries/wrappers.rb
Normal file
@ -0,0 +1,26 @@
|
||||
# Cookbook Name:: openstack-common
|
||||
# library:: wrappers
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
module ::Openstack
|
||||
# Wrapper method to allow to easier spec testing
|
||||
def recipe_included?(recipe)
|
||||
node['recipes'].include?(recipe)
|
||||
end
|
||||
|
||||
# Wrapper method to allow to easier spec testing
|
||||
def role_included?(role)
|
||||
node['roles'].include?(role)
|
||||
end
|
||||
end
|
@ -4,7 +4,7 @@ maintainer_email 'opscode-chef-openstack@googlegroups.com'
|
||||
license 'Apache 2.0'
|
||||
description 'Common OpenStack attributes, libraries and recipes.'
|
||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||
version '11.2.0'
|
||||
version '11.3.0'
|
||||
|
||||
recipe 'openstack-common', 'Installs/Configures common recipes'
|
||||
recipe 'openstack-common::set_endpoints_by_interface', 'Set endpoints by interface'
|
||||
|
29
spec/wrappers_spec.rb
Normal file
29
spec/wrappers_spec.rb
Normal file
@ -0,0 +1,29 @@
|
||||
# encoding: UTF-8
|
||||
require_relative 'spec_helper'
|
||||
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'wrappers'
|
||||
|
||||
describe 'Openstack wrappers' do
|
||||
let(:subject) { Object.new.extend(Openstack) }
|
||||
|
||||
describe '#recipe_included' do
|
||||
it 'returns boolean for recipe list' do
|
||||
node_hash = {
|
||||
'recipes' => 'included_recipe'
|
||||
}
|
||||
allow(subject).to receive(:node).and_return(node_hash)
|
||||
expect(subject.recipe_included?('included_recipe')).to be_truthy
|
||||
expect(subject.recipe_included?('not_included_recipe')).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe '#role_included' do
|
||||
it 'returns boolean for role list' do
|
||||
node_hash = {
|
||||
'roles' => 'included_role'
|
||||
}
|
||||
allow(subject).to receive(:node).and_return(node_hash)
|
||||
expect(subject.role_included?('included_role')).to be_truthy
|
||||
expect(subject.role_included?('not_included_role')).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user