]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/openstacklib/spec/defines/openstacklib_db_mysql_spec.rb
try with modules from master
[dsa-puppet.git] / 3rdparty / modules / openstacklib / spec / defines / openstacklib_db_mysql_spec.rb
1 require 'spec_helper'
2
3 describe 'openstacklib::db::mysql' do
4
5   let :pre_condition do
6     'include mysql::server'
7   end
8
9   let (:title) { 'nova' }
10
11   let :required_params do
12     { :password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601' }
13   end
14
15   shared_examples 'openstacklib::db::mysql examples' do
16
17     context 'with only required parameters' do
18       let :params do
19         required_params
20       end
21
22       it { is_expected.to contain_mysql_database(title).with(
23         :charset => 'utf8',
24         :collate => 'utf8_general_ci'
25       )}
26       it { is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
27         :user       => title,
28         :database   => title,
29         :privileges => 'ALL'
30       )}
31     end
32
33     context 'with overriding dbname parameter' do
34       let :params do
35         { :dbname => 'foobar' }.merge(required_params)
36       end
37
38       it { is_expected.to contain_mysql_database(params[:dbname]).with(
39         :charset => 'utf8',
40         :collate => 'utf8_general_ci'
41       )}
42       it { is_expected.to contain_openstacklib__db__mysql__host_access("#{params[:dbname]}_127.0.0.1").with(
43         :user       => title,
44         :database   => params[:dbname],
45         :privileges => 'ALL'
46       )}
47     end
48
49     context 'with overriding user parameter' do
50       let :params do
51         { :user => 'foobar' }.merge(required_params)
52       end
53
54       it { is_expected.to contain_mysql_database(title).with(
55         :charset => 'utf8',
56         :collate => 'utf8_general_ci'
57       )}
58       it { is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
59         :user       => params[:user],
60         :database   => title,
61         :privileges => 'ALL',
62       )}
63     end
64
65     context 'when overriding charset parameter' do
66       let :params do
67         { :charset => 'latin1' }.merge(required_params)
68       end
69
70       it { is_expected.to contain_mysql_database(title).with_charset(params[:charset]) }
71     end
72
73     context 'when omitting the required parameter password_hash' do
74       let :params do
75         required_params.delete(:password_hash)
76       end
77       it { expect { is_expected.to raise_error(Puppet::Error) } }
78     end
79
80     context 'when notifying other resources' do
81       let :pre_condition do
82         'exec {"nova-db-sync":}'
83       end
84       let :params do
85         { :notify => 'Exec[nova-db-sync]'}.merge(required_params)
86       end
87
88       it { is_expected.to contain_exec('nova-db-sync').that_subscribes_to("Openstacklib::Db::Mysql[#{title}]") }
89     end
90
91     context 'when required for other openstack services' do
92       let :pre_condition do
93         'service {"keystone":}'
94       end
95       let :title do
96         'keystone'
97       end
98       let :params do
99         { :before => 'Service[keystone]'}.merge(required_params)
100       end
101
102       it { is_expected.to contain_service('keystone').that_requires("Openstacklib::Db::Mysql[keystone]") }
103     end
104
105     context "overriding allowed_hosts parameter with array value" do
106       let :params do
107         { :allowed_hosts  => ['127.0.0.1','%'] }.merge(required_params)
108       end
109
110       it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
111         :user          => title,
112         :password_hash => params[:password_hash],
113         :database      => title
114       )}
115       it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_%").with(
116         :user          => title,
117         :password_hash => params[:password_hash],
118         :database      => title
119       )}
120     end
121
122     context "overriding allowed_hosts parameter with string value" do
123       let :params do
124         { :allowed_hosts => '192.168.1.1' }.merge(required_params)
125       end
126
127       it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_192.168.1.1").with(
128         :user          => title,
129         :password_hash => params[:password_hash],
130         :database      => title
131       )}
132     end
133
134     context "overriding allowed_hosts parameter equals to host param " do
135       let :params do
136         { :allowed_hosts => '127.0.0.1' }.merge(required_params)
137       end
138
139       it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
140         :user          => title,
141         :password_hash => params[:password_hash],
142         :database      => title
143       )}
144     end
145
146   end
147
148   context 'on a Debian osfamily' do
149     let :facts do
150       { :osfamily => "Debian" }
151     end
152
153     include_examples 'openstacklib::db::mysql examples'
154   end
155
156   context 'on a RedHat osfamily' do
157     let :facts do
158       { :osfamily => 'RedHat' }
159     end
160
161     include_examples 'openstacklib::db::mysql examples'
162   end
163 end