diff --git a/README.md b/README.md index a236ea0..2b69058 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,14 @@ None - configures the mysql server for OpenStack +## postgresql-client ## + +- calls postgresql::ruby and postgresql::client and installs 'postgresql_python_packages' + +## postgresql-server ## + +- configures the PostgreSQL server for OpenStack + ## openstack-db ## - creates necessary tables, users, and grants for OpenStack diff --git a/attributes/default.rb b/attributes/default.rb index 35af4b6..8a1cd5a 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -23,8 +23,11 @@ default["openstack"]["db"]["bind_interface"] = "lo" case platform when "fedora", "redhat", "centos" # :pragma-foodcritic: ~FC024 - won"t fix this default["openstack"]["db"]["platform"]["mysql_python_packages"] = [ "MySQL-python" ] + default["openstack"]["db"]["platform"]["postgresql_python_packages"] = [ "python-psycopg2" ] when "suse" default["openstack"]["db"]["platform"]["mysql_python_packages"] = [ "python-mysql" ] + default["openstack"]["db"]["platform"]["postgresql_python_packages"] = [ "python-psycopg2" ] when "ubuntu" default["openstack"]["db"]["platform"]["mysql_python_packages"] = [ "python-mysqldb" ] + default["openstack"]["db"]["platform"]["postgresql_python_packages"] = [ "python-psycopg2" ] end diff --git a/metadata.rb b/metadata.rb index 33fb471..3896829 100644 --- a/metadata.rb +++ b/metadata.rb @@ -8,7 +8,9 @@ version "7.0.0" recipe "client", "Installs client packages for the database used by the deployment." recipe "server", "Installs and configures server packages for the database used by the deployment." recipe "mysql-client", "Installs MySQL client packages." -recipe "mysql-server", "Installs and configured MySQL server packages." +recipe "mysql-server", "Installs and configures MySQL server packages." +recipe "postgresql-client", "Installs PostgreSQL client packages." +recipe "postgresql-server", "Installs and configures PostgreSQL server packages." recipe "openstack-db", "Creates necessary tables, users, and grants for OpenStack." %w{ fedora ubuntu redhat centos suse }.each do |os| diff --git a/recipes/postgresql-client.rb b/recipes/postgresql-client.rb new file mode 100644 index 0000000..5d259b4 --- /dev/null +++ b/recipes/postgresql-client.rb @@ -0,0 +1,27 @@ +# +# Cookbook Name:: openstack-ops-database +# Recipe:: postgresql-client +# +# Copyright 2013, Opscode, Inc. +# Copyright 2013, AT&T Services, Inc. +# Copyright 2013, SUSE Linux GmbH +# +# 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. +# + +include_recipe "postgresql::ruby" +include_recipe "postgresql::client" + +node["openstack"]["db"]["platform"]["postgresql_python_packages"].each do |pkg| + package pkg +end diff --git a/recipes/postgresql-server.rb b/recipes/postgresql-server.rb new file mode 100644 index 0000000..56bf4e9 --- /dev/null +++ b/recipes/postgresql-server.rb @@ -0,0 +1,32 @@ +# +# Cookbook Name:: openstack-ops-database +# Recipe:: postgresql-server +# +# Copyright 2013, Opscode, Inc. +# Copyright 2012-2013, Rackspace US, Inc. +# Copyright 2013, AT&T Services, Inc. +# Copyright 2013, SUSE Linux GmbH +# +# 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. +# + +class ::Chef::Recipe + include ::Openstack +end + +listen_address = address_for node["openstack"]["db"]["bind_interface"] + +node.override["postgresql"]["config"]["listen_addresses"] = listen_address + +include_recipe "openstack-ops-database::postgresql-client" +include_recipe "postgresql::server" diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 24dcaef..3c83469 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -4,11 +4,21 @@ describe "openstack-ops-database::client" do before { ops_database_stubs } describe "ubuntu" do - it "uses proper database client recipe" do + it "uses mysql database client recipe by default" do chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS chef_run.converge "openstack-ops-database::client" expect(chef_run).to include_recipe "openstack-ops-database::mysql-client" end + + it "uses postgresql database client recipe when configured" do + chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS + node = chef_run.node + node.set["openstack"]["db"]["service_type"] = "postgresql" + + chef_run.converge "openstack-ops-database::client" + + expect(chef_run).to include_recipe "openstack-ops-database::postgresql-client" + end end end diff --git a/spec/postgresql-server_spec.rb b/spec/postgresql-server_spec.rb new file mode 100644 index 0000000..e4a5ee1 --- /dev/null +++ b/spec/postgresql-server_spec.rb @@ -0,0 +1,21 @@ +require_relative "spec_helper" + +describe "openstack-ops-database::postgresql-server" do + before { ops_database_stubs } + describe "ubuntu" do + before do + @chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS + # The postgresql cookbook will raise an "uninitialized constant + # Chef::Application" error without this attribute when running + # the tests + @chef_run.node.set["postgresql"]["password"]["postgres"] = String.new + @chef_run.converge "openstack-ops-database::postgresql-server" + end + + it "includes postgresql recipes" do + expect(@chef_run).to include_recipe( + "openstack-ops-database::postgresql-client") + expect(@chef_run).to include_recipe "postgresql::server" + end + end +end diff --git a/spec/server_spec.rb b/spec/server_spec.rb index be6685a..7528481 100644 --- a/spec/server_spec.rb +++ b/spec/server_spec.rb @@ -4,7 +4,7 @@ describe "openstack-ops-database::server" do before { ops_database_stubs } describe "ubuntu" do - it "uses proper database server recipe" do + it "uses mysql database server recipe by default" do chef_run = ::ChefSpec::ChefRunner.new(::UBUNTU_OPTS) do |n| n.set["mysql"] = { "server_debian_password" => "server-debian-password", @@ -16,5 +16,19 @@ describe "openstack-ops-database::server" do expect(chef_run).to include_recipe "openstack-ops-database::mysql-server" end + + it "uses postgresql database server recipe when configured" do + chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS do |n| + n.set["openstack"]["db"]["service_type"] = "postgresql" + # The postgresql cookbook will raise an "uninitialized constant + # Chef::Application" error without this attribute when running + # the tests + n.set["postgresql"]["password"]["postgres"] = String.new + end + + chef_run.converge "openstack-ops-database::server" + + expect(chef_run).to include_recipe "openstack-ops-database::postgresql-server" + end end end