From 348aaf4033f26712ed1d3a08719eb47e8cafb1be Mon Sep 17 00:00:00 2001 From: Mark Vanderwiel Date: Fri, 24 Apr 2015 13:52:01 -0500 Subject: [PATCH] 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 --- attributes/default.rb | 3 +++ libraries/wrappers.rb | 26 ++++++++++++++++++++++++++ metadata.rb | 2 +- spec/wrappers_spec.rb | 29 +++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 libraries/wrappers.rb create mode 100644 spec/wrappers_spec.rb diff --git a/attributes/default.rb b/attributes/default.rb index 33aa0807..7411a3cb 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -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 diff --git a/libraries/wrappers.rb b/libraries/wrappers.rb new file mode 100644 index 00000000..872ce3ea --- /dev/null +++ b/libraries/wrappers.rb @@ -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 diff --git a/metadata.rb b/metadata.rb index f1bbc72c..98befe10 100644 --- a/metadata.rb +++ b/metadata.rb @@ -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' diff --git a/spec/wrappers_spec.rb b/spec/wrappers_spec.rb new file mode 100644 index 00000000..f7df16a7 --- /dev/null +++ b/spec/wrappers_spec.rb @@ -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