diff --git a/Cheffile b/Cheffile index aea12960..bedf5b38 100644 --- a/Cheffile +++ b/Cheffile @@ -1,3 +1,7 @@ #!/usr/bin/env ruby site "http://community.opscode.com/api/v1" + +cookbook "database" +cookbook "openstack-utils", + :git => "git@github.com:att-cloud/cookbook-openstack-utils.git" diff --git a/Gemfile b/Gemfile index b4d5f873..c0b83dc3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source :rubygems -gem "chefspec", :git => "git://github.com/acrmp/chefspec.git" +gem "chefspec", "~> 0.9.0" gem "librarian", "~> 0.0.24" gem "foodcritic", "~> 1.6.1" gem "hashie", "~> 1.2.0" diff --git a/Gemfile.lock b/Gemfile.lock index 92f939c3..b66080f4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,13 +1,3 @@ -GIT - remote: git://github.com/acrmp/chefspec.git - revision: 5cb01c464a572132edac802549efbc3c7c85485a - specs: - chefspec (0.8.0) - chef (>= 0.9.12) - erubis - minitest-chef-handler (~> 0.6.0) - rspec (~> 2.11.0) - GEM remote: http://rubygems.org/ specs: @@ -32,6 +22,11 @@ GEM treetop (~> 1.4.9) uuidtools yajl-ruby (~> 1.1) + chefspec (0.9.0) + chef (>= 0.9.12) + erubis + minitest-chef-handler (~> 0.6.0) + rspec (~> 2.11.0) ci_reporter (1.7.3) builder (>= 2.1.2) coderay (1.0.8) @@ -115,7 +110,7 @@ PLATFORMS ruby DEPENDENCIES - chefspec! + chefspec (~> 0.9.0) foodcritic (~> 1.6.1) hashie (~> 1.2.0) librarian (~> 0.0.24) diff --git a/libraries/default.rb b/libraries/default.rb index d30bf166..4844f277 100644 --- a/libraries/default.rb +++ b/libraries/default.rb @@ -101,7 +101,7 @@ module Openstack user_prov = Chef::Provider::Database::PostgresqlUser # See https://github.com/opscode-cookbooks/postgresql/blob/master/recipes/server.rb#L41 super_user = 'postgres' - super_password = node['postgresql']['password']['postgres'] + super_password = @node['postgresql']['password']['postgres'] when 'mysql' db_prov = Chef::Provider::Database::Mysql user_prov = Chef::Provider::Database::MysqlUser @@ -110,7 +110,7 @@ module Openstack # For some reason, setting this to anything other than localhost fails miserably :( host = 'localhost' - super_password = node['mysql']['server_root_password'] + super_password = @node['mysql']['server_root_password'] else Chef::Log.error("Unsupported database type #{type}") end @@ -129,7 +129,7 @@ module Openstack database_name db_name action :create end - + # create user database_user user do provider user_prov @@ -137,7 +137,7 @@ module Openstack password pass action :create end - + # grant privs to user database_user user do provider user_prov diff --git a/spec/default_spec.rb b/spec/default_spec.rb index 998143fc..ad646838 100644 --- a/spec/default_spec.rb +++ b/spec/default_spec.rb @@ -3,7 +3,10 @@ require ::File.join ::File.dirname(__FILE__), "..", "libraries", "default" describe ::Openstack do before do - @chef_run = ::ChefSpec::ChefRunner.new.converge "openstack-common::default" + @chef_run = ::ChefSpec::ChefRunner.new do |n| + n.set['mysql'] = {} + n.set['mysql']['server_root_password'] = "pass" + end.converge "openstack-common::default" @subject = ::Object.new.extend(::Openstack) end @@ -67,7 +70,7 @@ describe ::Openstack do "host" => "localhost" } } - } + } } ::Openstack.stub(:uri_from_hash).and_return "http://localhost" @subject.instance_variable_set(:@node, uri_hash) @@ -140,15 +143,12 @@ describe ::Openstack do @subject.db_create_with_user("nonexisting", "user", "pass").should be_nil end it "returns db info and creates database with user when service found" do - stub_const("Chef::Provider::Database::Mysql", nil) - Chef::Recipe.any_instance.stub(:database).and_return(Hash.new) + @subject.stub(:database).and_return(Hash.new) + @subject.stub(:database_user).and_return(Hash.new) @subject.instance_variable_set(:@node, @chef_run.node) - expect = { - 'host' => '127.0.0.1', - 'port' => 3306 - } result = @subject.db_create_with_user("compute", "user", "pass") - result.should eq expect + result['host'].should eq "127.0.0.1" + result['port'].should eq "3306" end end end