diff --git a/Berksfile b/Berksfile index 84e5b6d..6ee299f 100644 --- a/Berksfile +++ b/Berksfile @@ -2,3 +2,5 @@ metadata cookbook "openstack-common", git: "git://github.com/stackforge/cookbook-openstack-common.git" +cookbook "openstack-identity", + git: "git://github.com/stackforge/cookbook-openstack-identity.git" diff --git a/Berksfile.lock b/Berksfile.lock index d9ebfa8..086f87c 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -4,9 +4,14 @@ "path": "." }, "openstack-common": { - "locked_version": "0.3.5", + "locked_version": "0.4.3", "git": "git://github.com/stackforge/cookbook-openstack-common.git", - "ref": "4af229d56319b44945fe9e8ebd2ab2aa87b29c83" + "ref": "eb5eed7126b6a6efbaf803e8a594d610cf661e97" + }, + "openstack-identity": { + "locked_version": "7.0.0", + "git": "git://github.com/stackforge/cookbook-openstack-identity.git", + "ref": "b881af26095cfa869a6970067c49597a0ee63586" }, "apt": { "locked_version": "2.0.0" diff --git a/README.md b/README.md index 139a708..455e47a 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,10 @@ common ---- - Common metering configuration. +identity_registration +---- +- Registers the endpoints with Keystone. + Attributes ========== diff --git a/attributes/default.rb b/attributes/default.rb index 42143eb..90185c2 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -43,6 +43,8 @@ default["openstack"]["metering"]["api"]["auth"]["cache_dir"] = "/var/cache/ceilo default["openstack"]["metering"]["user"] = "ceilometer" default["openstack"]["metering"]["group"] = "ceilometer" +default["openstack"]["metering"]["region"] = "RegionOne" + case platform when "suse" # :pragma-foodcritic: ~FC024 - won't fix this default["openstack"]["metering"]["platform"] = { diff --git a/metadata.rb b/metadata.rb index fd0f2ac..c0af040 100644 --- a/metadata.rb +++ b/metadata.rb @@ -11,9 +11,11 @@ recipe "openstack-metering::agent-compute", "Installs agent compute service." recipe "openstack-metering::api", "Installs API service." recipe "openstack-metering::collector", "Installs nova network service." recipe "openstack-metering::common", "Common metering configuration." +recipe "openstack-metering::identity_registration", "Registers the endpoints with Keystone" %w{ ubuntu suse }.each do |os| supports os end depends "openstack-common", "~> 0.4.0" +depends "openstack-identity", "~> 7.0.0" diff --git a/recipes/identity_registration.rb b/recipes/identity_registration.rb new file mode 100644 index 0000000..fa78086 --- /dev/null +++ b/recipes/identity_registration.rb @@ -0,0 +1,51 @@ +# +# Cookbook Name:: openstack-metering +# Recipe:: identity_registration +# +# Copyright 2013, AT&T Services, Inc. +# +# 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. +# + +require "uri" + +class ::Chef::Recipe + include ::Openstack +end + +api_endpoint = endpoint "metering-api" +identity_admin_endpoint = endpoint "identity-admin" +bootstrap_token = secret "secrets", "openstack_identity_bootstrap_token" +auth_uri = ::URI.decode identity_admin_endpoint.to_s + +openstack_identity_register "Register Metering Service" do + auth_uri auth_uri + bootstrap_token bootstrap_token + service_name "ceilometer" + service_type "metering" + service_description "Ceilometer Service" + + action :create_service +end + +openstack_identity_register "Register Metering Endpoint" do + auth_uri auth_uri + bootstrap_token bootstrap_token + service_type "metering" + endpoint_region node["openstack"]["metering"]["region"] + endpoint_adminurl ::URI.decode api_endpoint.to_s + endpoint_internalurl ::URI.decode api_endpoint.to_s + endpoint_publicurl ::URI.decode api_endpoint.to_s + + action :create_endpoint +end diff --git a/spec/identity_registration_spec.rb b/spec/identity_registration_spec.rb new file mode 100644 index 0000000..92dea7b --- /dev/null +++ b/spec/identity_registration_spec.rb @@ -0,0 +1,42 @@ +require_relative "spec_helper" + +describe "openstack-metering::identity_registration" do + before do + metering_stubs + @chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS + @chef_run.converge "openstack-metering::identity_registration" + end + + it "registers metering service" do + resource = @chef_run.find_resource( + "openstack-identity_register", + "Register Metering Service" + ).to_hash + + expect(resource).to include( + :auth_uri => "http://127.0.0.1:35357/v2.0", + :bootstrap_token => "bootstrap-token", + :service_name => "ceilometer", + :service_type => "metering", + :action => [:create_service] + ) + end + + it "registers metering endpoint" do + resource = @chef_run.find_resource( + "openstack-identity_register", + "Register Metering Endpoint" + ).to_hash + + expect(resource).to include( + :auth_uri => "http://127.0.0.1:35357/v2.0", + :bootstrap_token => "bootstrap-token", + :service_type => "metering", + :endpoint_region => "RegionOne", + :endpoint_adminurl => "http://127.0.0.1:8777/v1", + :endpoint_internalurl => "http://127.0.0.1:8777/v1", + :endpoint_publicurl => "http://127.0.0.1:8777/v1", + :action => [:create_endpoint] + ) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c7737c5..bd0b397 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,6 +25,9 @@ def metering_stubs ::Chef::Recipe.any_instance.stub(:user_password). with("guest"). and_return "rabbit-pass" + ::Chef::Recipe.any_instance.stub(:secret). + with("secrets", "openstack_identity_bootstrap_token"). + and_return "bootstrap-token" end def expect_runs_common_recipe