Browse Source

switched from db_create_with_user to lwrp openstack_common_database

- replaced db_create_with_user with lwrp from common
- utilized new common attribute openstack.common.services to
dry recipe
- TODO: create test for rescue log message

related-Change-Id: I1940cd63aa1ae95586e6ecbed9476f7ce5fe19ab

Change-Id: Idb47c9b7e3ce954ddd1a544b71b96eed734e46e5
Jan Klare 3 years ago
parent
commit
1886e38a03
2 changed files with 36 additions and 77 deletions
  1. 11
    52
      recipes/openstack-db.rb
  2. 25
    25
      spec/openstack-db_spec.rb

+ 11
- 52
recipes/openstack-db.rb View File

@@ -22,55 +22,14 @@ class ::Chef::Recipe # rubocop:disable Documentation
22 22
   include ::Openstack
23 23
 end
24 24
 
25
-db_create_with_user(
26
-  'compute',
27
-  node['openstack']['db']['compute']['username'],
28
-  get_password('db', 'nova')
29
-)
30
-
31
-db_create_with_user(
32
-  'dashboard',
33
-  node['openstack']['db']['dashboard']['username'],
34
-  get_password('db', 'horizon')
35
-)
36
-
37
-db_create_with_user(
38
-  'identity',
39
-  node['openstack']['db']['identity']['username'],
40
-  get_password('db', 'keystone')
41
-)
42
-
43
-db_create_with_user(
44
-  'image',
45
-  node['openstack']['db']['image']['username'],
46
-  get_password('db', 'glance')
47
-)
48
-
49
-db_create_with_user(
50
-  'telemetry',
51
-  node['openstack']['db']['telemetry']['username'],
52
-  get_password('db', 'ceilometer')
53
-)
54
-
55
-db_create_with_user(
56
-  'network',
57
-  node['openstack']['db']['network']['username'],
58
-  get_password('db', 'neutron')
59
-)
60
-
61
-db_create_with_user(
62
-  'block-storage',
63
-  node['openstack']['db']['block-storage']['username'],
64
-  get_password('db', 'cinder')
65
-)
66
-
67
-db_create_with_user(
68
-  'orchestration',
69
-  node['openstack']['db']['orchestration']['username'],
70
-  get_password('db', 'heat')
71
-)
72
-db_create_with_user(
73
-  'bare-metal',
74
-  node['openstack']['db']['bare-metal']['username'],
75
-  get_password('db', 'ironic')
76
-)
25
+node['openstack']['common']['services'].each do |service, project|
26
+  begin
27
+    password = get_password('db', project)
28
+    openstack_common_database service do
29
+      user node['openstack']['db'][service]['username']
30
+      pass password
31
+    end
32
+  rescue Net::HTTPServerException
33
+    log "No databag item containing the database password for #{project} was found, so no database was created"
34
+  end
35
+end

+ 25
- 25
spec/openstack-db_spec.rb View File

@@ -4,31 +4,31 @@ require_relative 'spec_helper'
4 4
 
5 5
 describe 'openstack-ops-database::openstack-db' do
6 6
   include_context 'database-stubs'
7
+  describe 'ubuntu' do
8
+    let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
9
+    let(:node) { runner.node }
10
+    let(:chef_run) { runner.converge(described_recipe) }
7 11
 
8
-  before do
9
-    @chef_run = ::ChefSpec::SoloRunner.new ::UBUNTU_OPTS
10
-  end
11
-
12
-  it 'creates databases and users' do
13
-    expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user)
14
-      .with('compute', 'nova', 'test-pass')
15
-    expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user)
16
-      .with 'dashboard', 'horizon', 'test-pass'
17
-    expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user)
18
-      .with 'identity', 'keystone', 'test-pass'
19
-    expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user)
20
-      .with 'image', 'glance', 'test-pass'
21
-    expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user)
22
-      .with 'telemetry', 'ceilometer', 'test-pass'
23
-    expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user)
24
-      .with 'network', 'neutron', 'test-pass'
25
-    expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user)
26
-      .with 'block-storage', 'cinder', 'test-pass'
27
-    expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user)
28
-      .with 'orchestration', 'heat', 'test-pass'
29
-    expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user)
30
-      .with 'bare-metal', 'ironic', 'test-pass'
31
-
32
-    @chef_run.converge(described_recipe)
12
+    it 'creates all openstack service databases and the corresponding users' do
13
+      {
14
+        'bare-metal' => 'ironic',
15
+        'block-storage' => 'cinder',
16
+        'compute' => 'nova',
17
+        'dashboard' => 'horizon',
18
+        'database' => 'trove',
19
+        'identity' => 'keystone',
20
+        'image' => 'glance',
21
+        'network' => 'neutron',
22
+        'object-storage' => 'swift',
23
+        'orchestration' => 'heat',
24
+        'telemetry' => 'ceilometer'
25
+      }.each do |service, _project|
26
+        expect(chef_run).to create_openstack_common_database(service)
27
+          .with(user: node['openstack']['db'][service]['username'],
28
+                pass: 'test-pass')
29
+      end
30
+      ## TODO: utilize _project and create test for rescue with specific log message
31
+      ##       when databag does not exist
32
+    end
33 33
   end
34 34
 end

Loading…
Cancel
Save