Browse Source

Added cellv2 support

- Added basic cellv2 recipe, as it is required from Ocata on
- Style and lint fixes to support newer chefdk
- Rewrote metadata.rb for readability
- Removed ancient Gemfile

Change-Id: I97b453fc419bfbf01679dadf39a256b1f0f99859
changes/79/469179/12
Samuel Cassiba 2 years ago
parent
commit
012902ad92

+ 11
- 3
.rubocop_todo.yml View File

@@ -1,6 +1,6 @@
1 1
 # This configuration was generated by
2 2
 # `rubocop --auto-gen-config`
3
-# on 2017-03-06 14:33:48 +0000 using RuboCop version 0.39.0.
3
+# on 2017-08-02 01:11:06 -0400 using RuboCop version 0.47.1.
4 4
 # The point is for the user to remove these configuration records
5 5
 # one by one as the offenses are removed from the code base.
6 6
 # Note that changes in the inspected code, or installation of new
@@ -10,6 +10,11 @@
10 10
 Metrics/AbcSize:
11 11
   Max: 16
12 12
 
13
+# Offense count: 28
14
+# Configuration parameters: CountComments, ExcludedMethods.
15
+Metrics/BlockLength:
16
+  Max: 373
17
+
13 18
 # Offense count: 2
14 19
 # Configuration parameters: CountComments.
15 20
 Metrics/MethodLength:
@@ -42,7 +47,7 @@ Style/Documentation:
42 47
     - 'recipes/nova-setup.rb'
43 48
     - 'recipes/placement_api.rb'
44 49
 
45
-# Offense count: 1
50
+# Offense count: 3
46 51
 # Configuration parameters: MinBodyLength.
47 52
 Style/GuardClause:
48 53
   Exclude:
@@ -61,4 +66,7 @@ Style/Next:
61 66
 # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
62 67
 # SupportedStyles: single_quotes, double_quotes
63 68
 Style/StringLiterals:
64
-  Enabled: false
69
+  Exclude:
70
+    - 'spec/identity_registration_spec.rb'
71
+    - 'spec/placement_api_spec.rb'
72
+    - 'spec/spec_helper.rb'

+ 0
- 14
Gemfile View File

@@ -1,14 +0,0 @@
1
-## THIS GEMFILE IS DEPRECATED AND WILL BE REMOVED AFTER THE NEXT RELEASE
2
-## THERE WON'T BE ANY UPDATES TO THIS FILE DURING THIS RELEASE CYCLE
3
-## WE SWITCHED TO CHEFDK AS THE BUNDLE FOR THE NEEDED GEMS
4
-
5
-source 'https://rubygems.org'
6
-
7
-gem 'chef', '~> 11.18.6'
8
-gem 'json', '<= 1.7.7' # chef 11 dependency
9
-gem 'berkshelf', '~> 3.2.1'
10
-gem 'hashie', '~> 2.0'
11
-gem 'chefspec', '~> 4.0.0'
12
-gem 'rspec', '~> 3.0.0'
13
-gem 'foodcritic', '~> 4.0'
14
-gem 'rubocop', '~> 0.29.1'

+ 1
- 0
metadata.rb View File

@@ -7,6 +7,7 @@ license 'Apache 2.0'
7 7
 description 'The OpenStack Compute service Nova.'
8 8
 long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
9 9
 version '15.0.0'
10
+chef_version '>= 12.5' if respond_to?(:chef_version)
10 11
 
11 12
 %w(ubuntu redhat centos).each do |os|
12 13
   supports os

+ 72
- 0
recipes/_nova_cell.rb View File

@@ -0,0 +1,72 @@
1
+# encoding: UTF-8
2
+#
3
+# Cookbook Name:: openstack-compute
4
+# Recipe:: _nova_cell
5
+#
6
+# Copyright 2017, Workday, Inc.
7
+#
8
+# Licensed under the Apache License, Version 2.0 (the "License");
9
+# you may not use this file except in compliance with the License.
10
+# You may obtain a copy of the License at
11
+#
12
+#     http://www.apache.org/licenses/LICENSE-2.0
13
+#
14
+# Unless required by applicable law or agreed to in writing, software
15
+# distributed under the License is distributed on an "AS IS" BASIS,
16
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+# See the License for the specific language governing permissions and
18
+# limitations under the License.
19
+#
20
+
21
+# This recipe is automatically included in openstack-compute::api-os-compute
22
+# and not called directly. It creates a basic cellv2 setup, which is required
23
+# from Ocata forward.
24
+
25
+nova_user = node['openstack']['compute']['user']
26
+nova_group = node['openstack']['compute']['group']
27
+db_password = get_password('db', 'nova_cell0')
28
+bind_db = node['openstack']['bind_service']['db']
29
+listen_address = if bind_db['interface']
30
+                   address_for bind_db['interface']
31
+                 else
32
+                   listen_address = bind_db['host']
33
+                 end
34
+
35
+execute 'map cell0' do
36
+  user nova_user
37
+  group nova_group
38
+  command "nova-manage cell_v2 map_cell0 --database_connection mysql+pymysql://nova_cell0:#{db_password}@#{listen_address}/nova_cell0?charset=utf8"
39
+  not_if 'nova-manage cell_v2 list_cells | grep -q cell0'
40
+  action :run
41
+end
42
+
43
+execute 'create cell1' do
44
+  user nova_user
45
+  group nova_group
46
+  not_if 'nova-manage cell_v2 list_cells | grep -q cell1'
47
+  command 'nova-manage cell_v2 create_cell --verbose --name cell1'
48
+  action :run
49
+end
50
+
51
+execute 'api db sync' do
52
+  timeout node['openstack']['compute']['dbsync_timeout']
53
+  user nova_user
54
+  group nova_group
55
+  command 'nova-manage api_db sync'
56
+  action :run
57
+end
58
+
59
+execute 'db sync' do
60
+  timeout node['openstack']['compute']['dbsync_timeout']
61
+  user nova_user
62
+  group nova_group
63
+  command 'nova-manage db sync'
64
+  action :run
65
+end
66
+
67
+execute 'discover hosts' do
68
+  user nova_user
69
+  group nova_group
70
+  command 'nova-manage cell_v2 discover_hosts'
71
+  action :run
72
+end

+ 1
- 1
recipes/api-metadata.rb View File

@@ -40,7 +40,7 @@ template '/etc/nova/api-paste.ini' do
40 40
   source 'api-paste.ini.erb'
41 41
   owner node['openstack']['compute']['user']
42 42
   group node['openstack']['compute']['group']
43
-  mode 00644
43
+  mode 0o0644
44 44
 end
45 45
 
46 46
 service 'nova-api-metadata' do

+ 8
- 5
recipes/api-os-compute.rb View File

@@ -33,15 +33,16 @@ platform_options['api_os_compute_packages'].each do |pkg|
33 33
   end
34 34
 end
35 35
 
36
+nova_user = node['openstack']['compute']['user']
37
+nova_group = node['openstack']['compute']['group']
38
+
36 39
 template '/etc/nova/api-paste.ini' do
37 40
   source 'api-paste.ini.erb'
38
-  owner node['openstack']['compute']['user']
39
-  group node['openstack']['compute']['group']
40
-  mode 00644
41
+  owner nova_user
42
+  group nova_group
43
+  mode 0o0644
41 44
 end
42 45
 
43
-nova_user = node['openstack']['compute']['user']
44
-nova_group = node['openstack']['compute']['group']
45 46
 execute 'nova-manage api_db sync' do
46 47
   timeout node['openstack']['compute']['dbsync_timeout']
47 48
   user nova_user
@@ -59,3 +60,5 @@ service 'nova-api-os-compute' do
59 60
     'template[/etc/nova/api-paste.ini]'
60 61
   ]
61 62
 end
63
+
64
+include_recipe 'openstack-compute::_nova_cell'

+ 2
- 2
recipes/compute.rb View File

@@ -53,14 +53,14 @@ end
53 53
 # TODO: (jklare) this has to be refactored!!!
54 54
 cookbook_file '/etc/nova/nova-compute.conf' do
55 55
   source 'nova-compute.conf'
56
-  mode 00644
56
+  mode 0o0644
57 57
   action :create
58 58
 end
59 59
 
60 60
 directory node['openstack']['compute']['conf']['DEFAULT']['instances_path'] do
61 61
   owner node['openstack']['compute']['user']
62 62
   group node['openstack']['compute']['group']
63
-  mode 00755
63
+  mode 0o0755
64 64
   recursive true
65 65
 end
66 66
 

+ 5
- 4
recipes/libvirt.rb View File

@@ -81,7 +81,8 @@ def update_boot_kernel_and_trigger_reboot(flavor = 'default')
81 81
     update_grub2_default_kernel(flavor)
82 82
   else
83 83
     ::Chef::Application.fatal!(
84
-      'Unknown bootloader. Could not change boot kernel.')
84
+      'Unknown bootloader. Could not change boot kernel.'
85
+    )
85 86
   end
86 87
 
87 88
   # trigger reboot through reboot_handler, if kernel-$flavor is not yet
@@ -127,7 +128,7 @@ template '/etc/libvirt/libvirtd.conf' do
127 128
   source 'libvirtd.conf.erb'
128 129
   owner 'root'
129 130
   group 'root'
130
-  mode 00644
131
+  mode 0o0644
131 132
   variables(
132 133
     auth_tcp: node['openstack']['compute']['libvirt']['auth_tcp'],
133 134
     libvirt_group: node['openstack']['compute']['libvirt']['group']
@@ -139,7 +140,7 @@ template '/etc/default/libvirt-bin' do
139 140
   source 'libvirt-bin.erb'
140 141
   owner 'root'
141 142
   group 'root'
142
-  mode 00644
143
+  mode 0o0644
143 144
   notifies :restart, 'service[libvirt-bin]', :immediately
144 145
   only_if { platform_family? 'debian' }
145 146
 end
@@ -148,7 +149,7 @@ template '/etc/sysconfig/libvirtd' do
148 149
   source 'libvirtd.erb'
149 150
   owner 'root'
150 151
   group 'root'
151
-  mode 00644
152
+  mode 0o0644
152 153
   notifies :restart, 'service[libvirt-bin]', :immediately
153 154
   only_if { platform_family? %w(rhel) }
154 155
 end

+ 5
- 5
recipes/nova-common.rb View File

@@ -56,21 +56,21 @@ end
56 56
 directory '/etc/nova' do
57 57
   owner node['openstack']['compute']['user']
58 58
   group node['openstack']['compute']['group']
59
-  mode 00750
59
+  mode 0o0750
60 60
   action :create
61 61
 end
62 62
 
63 63
 directory node['openstack']['compute']['conf']['DEFAULT']['state_path'] do
64 64
   owner node['openstack']['compute']['user']
65 65
   group node['openstack']['compute']['group']
66
-  mode 00755
66
+  mode 0o0755
67 67
   recursive true
68 68
 end
69 69
 
70 70
 directory node['openstack']['compute']['conf']['oslo_concurrency']['lock_path'] do
71 71
   owner node['openstack']['compute']['user']
72 72
   group node['openstack']['compute']['group']
73
-  mode 00755
73
+  mode 0o0755
74 74
   recursive true
75 75
 end
76 76
 
@@ -214,7 +214,7 @@ template '/etc/nova/nova.conf' do
214 214
   source 'nova.conf.erb'
215 215
   owner node['openstack']['compute']['user']
216 216
   group node['openstack']['compute']['group']
217
-  mode 00640
217
+  mode 0o0640
218 218
   variables(
219 219
     # TODO(jaypipes): No support here for >1 image API servers
220 220
     # with the glance_api_servers configuration option...
@@ -235,7 +235,7 @@ template '/etc/nova/rootwrap.conf' do
235 235
   # Must be root!
236 236
   owner 'root'
237 237
   group 'root'
238
-  mode 00644
238
+  mode 0o0644
239 239
 end
240 240
 
241 241
 execute 'enable nova login' do

+ 44
- 0
spec/_nova_cell_spec.rb View File

@@ -0,0 +1,44 @@
1
+# encoding: UTF-8
2
+
3
+require_relative 'spec_helper'
4
+
5
+describe 'openstack-compute::_nova_cell' do
6
+  describe 'ubuntu' do
7
+    let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
8
+    let(:node) { runner.node }
9
+    let(:chef_run) { runner.converge(described_recipe) }
10
+
11
+    include_context 'compute_stubs'
12
+    include_examples 'expect_runs_nova_cell_recipe'
13
+
14
+    it 'creates the cell0 mapping' do
15
+      expect(chef_run).to run_execute('map cell0')
16
+        .with(user: 'nova',
17
+              group: 'nova')
18
+    end
19
+
20
+    it 'creates a new cell' do
21
+      expect(chef_run).to run_execute('create cell1')
22
+        .with(user: 'nova',
23
+              group: 'nova')
24
+    end
25
+
26
+    it 'executes api_db sync' do
27
+      expect(chef_run).to run_execute('api db sync')
28
+        .with(user: 'nova',
29
+              group: 'nova')
30
+    end
31
+
32
+    it 'executes db sync' do
33
+      expect(chef_run).to run_execute('db sync')
34
+        .with(user: 'nova',
35
+              group: 'nova')
36
+    end
37
+
38
+    it 'discovers compute hosts' do
39
+      expect(chef_run).to run_execute('discover hosts')
40
+        .with(user: 'nova',
41
+              group: 'nova')
42
+    end
43
+  end
44
+end

+ 8
- 0
spec/api-os-compute-redhat_spec.rb View File

@@ -13,6 +13,14 @@ describe 'openstack-compute::api-os-compute' do
13 13
     include_examples 'expect_creates_nova_state_dir'
14 14
     include_examples 'expect_creates_nova_lock_dir'
15 15
 
16
+    it 'executes nova-manage api_db sync' do
17
+      expect(chef_run).to run_execute('nova-manage api_db sync')
18
+        .with(timeout: 3600,
19
+              user: 'nova',
20
+              group: 'nova',
21
+              command: 'nova-manage api_db sync')
22
+    end
23
+
16 24
     it 'upgrades openstack api packages' do
17 25
       expect(chef_run).to upgrade_package 'openstack-nova-api'
18 26
     end

+ 1
- 1
spec/compute_spec.rb View File

@@ -75,7 +75,7 @@ describe 'openstack-compute::compute' do
75 75
       it 'creates the file' do
76 76
         expect(chef_run).to create_cookbook_file(file.name).with(
77 77
           source: 'nova-compute.conf',
78
-          mode: 00644
78
+          mode: 0o0644
79 79
         )
80 80
       end
81 81
     end

+ 1
- 1
spec/libvirt-redhat_spec.rb View File

@@ -43,7 +43,7 @@ describe 'openstack-compute::libvirt' do
43 43
         expect(chef_run).to create_template(file.name).with(
44 44
           owner: 'root',
45 45
           group: 'root',
46
-          mode: 0644
46
+          mode: 0o644
47 47
         )
48 48
       end
49 49
 

+ 2
- 2
spec/libvirt_spec.rb View File

@@ -62,7 +62,7 @@ describe 'openstack-compute::libvirt' do
62 62
         expect(chef_run).to create_template(file.name).with(
63 63
           owner: 'root',
64 64
           group: 'root',
65
-          mode: 0644
65
+          mode: 0o644
66 66
         )
67 67
       end
68 68
 
@@ -88,7 +88,7 @@ describe 'openstack-compute::libvirt' do
88 88
         expect(chef_run).to create_template(file.name).with(
89 89
           owner: 'root',
90 90
           group: 'root',
91
-          mode: 0644
91
+          mode: 0o644
92 92
         )
93 93
       end
94 94
 

+ 9
- 10
spec/nova-common_spec.rb View File

@@ -35,7 +35,7 @@ describe 'openstack-compute::nova-common' do
35 35
       expect(chef_run).to create_directory('/etc/nova').with(
36 36
         owner: 'nova',
37 37
         group: 'nova',
38
-        mode: 0750
38
+        mode: 0o750
39 39
       )
40 40
     end
41 41
 
@@ -66,7 +66,7 @@ describe 'openstack-compute::nova-common' do
66 66
         expect(chef_run).to create_template(file.name).with(
67 67
           owner: 'nova',
68 68
           group: 'nova',
69
-          mode: 0640
69
+          mode: 0o640
70 70
         )
71 71
       end
72 72
 
@@ -155,7 +155,6 @@ describe 'openstack-compute::nova-common' do
155 155
 
156 156
       it 'uses default values for attributes' do
157 157
         [
158
-
159 158
           %r{^api_servers = http://127.0.0.1:9292$}
160 159
 
161 160
         ].each do |line|
@@ -203,8 +202,7 @@ describe 'openstack-compute::nova-common' do
203 202
         node.set['openstack']['endpoints']['compute-vnc-bind']['bind_interface'] = 'lo'
204 203
 
205 204
         [/^vncserver_listen = 127.0.0.1$/,
206
-         /^vncserver_proxyclient_address = 127.0.0.1$/
207
-        ].each do |line|
205
+         /^vncserver_proxyclient_address = 127.0.0.1$/].each do |line|
208 206
           expect(chef_run).to render_file(file.name).with_content(line)
209 207
         end
210 208
       end
@@ -265,7 +263,8 @@ describe 'openstack-compute::nova-common' do
265 263
 
266 264
       it 'has no auto_assign_floating_ip' do
267 265
         expect(chef_run).not_to render_file(file.name).with_content(
268
-          'auto_assign_floating_ip=false')
266
+          'auto_assign_floating_ip=false'
267
+        )
269 268
       end
270 269
 
271 270
       context 'rbd backend' do
@@ -385,7 +384,7 @@ describe 'openstack-compute::nova-common' do
385 384
         expect(chef_run).to render_config_file(file.name)
386 385
           .with_section_content(
387 386
             'api_database',
388
-            %r{connection = mysql://nova_api:nova_api_db_pass@127.0.0.1:3306/nova_api\?charset=utf8$}
387
+            %(connection = mysql+pymysql://nova_api:nova_api_db_pass@127.0.0.1:3306/nova_api?charset=utf8)
389 388
           )
390 389
       end
391 390
 
@@ -397,7 +396,7 @@ describe 'openstack-compute::nova-common' do
397 396
           node.set['openstack']['db']['compute']['username'] = 'nova'
398 397
 
399 398
           expect(chef_run).to render_config_file(file.name)\
400
-            .with_section_content('database', %r{slave_connection = mysql://nova:nova_db_pass@10.10.1.1:3326/nova\?charset=utf8$})
399
+            .with_section_content('database', %(slave_connection = mysql+pymysql://nova:nova_db_pass@10.10.1.1:3326/nova?charset=utf8))
401 400
         end
402 401
 
403 402
         it 'sets overide database enabled_slave attribute as false' do
@@ -407,7 +406,7 @@ describe 'openstack-compute::nova-common' do
407 406
           node.set['openstack']['db']['compute']['username'] = 'nova'
408 407
 
409 408
           expect(chef_run).to_not render_config_file(file.name)\
410
-            .with_section_content('database', %r{slave_connection = mysql://nova:nova_db_pass@10.10.1.1:3326/nova\?charset=utf8$})
409
+            .with_section_content('database', %(slave_connection = mysql+pymysql://nova:nova_db_pass@10.10.1.1:3326/nova?charset=utf8))
411 410
         end
412 411
       end
413 412
     end
@@ -419,7 +418,7 @@ describe 'openstack-compute::nova-common' do
419 418
         expect(chef_run).to create_template(file.name).with(
420 419
           user: 'root',
421 420
           group: 'root',
422
-          mode: 0644
421
+          mode: 0o644
423 422
         )
424 423
       end
425 424
 

+ 19
- 4
spec/spec_helper.rb View File

@@ -58,6 +58,9 @@ shared_context 'compute_stubs' do
58 58
     allow_any_instance_of(Chef::Recipe).to receive(:get_password)
59 59
       .with('db', 'nova_api')
60 60
       .and_return('nova_api_db_pass')
61
+    allow_any_instance_of(Chef::Recipe).to receive(:get_password)
62
+      .with('db', 'nova_cell0')
63
+      .and_return('nova_cell0_db_pass')
61 64
     allow_any_instance_of(Chef::Recipe).to receive(:get_password)
62 65
       .with('user', 'guest')
63 66
       .and_return('mq-pass')
@@ -92,6 +95,12 @@ shared_context 'compute_stubs' do
92 95
     stub_command('virsh secret-list | grep 00000000-0000-0000-0000-000000000000').and_return(false)
93 96
     stub_command('virsh secret-set-value --secret 00000000-0000-0000-0000-000000000000 --base64 $(ceph-authtool -p -n client.cinder /etc/ceph/ceph.client.cinder.keyring)').and_return(false)
94 97
     stub_command('virsh secret-get-value 00000000-0000-0000-0000-000000000000 | grep $(ceph-authtool -p -n client.cinder /etc/ceph/ceph.client.cinder.keyring)').and_return(false)
98
+    stub_command('nova-manage api_db sync').and_return(true)
99
+    stub_command('nova-manage cell_v2 map_cell0 --database_connection mysql+pymysql://nova_cell0:mypass@127.0.0.1/nova_cell0?charset=utf8').and_return(true)
100
+    stub_command('nova-manage cell_v2 create_cell --verbose --name cell1').and_return(true)
101
+    stub_command('nova-manage cell_v2 list_cells | grep -q cell0').and_return(false)
102
+    stub_command('nova-manage cell_v2 list_cells | grep -q cell1').and_return(false)
103
+    stub_command('nova-manage cell_v2 discover_hosts').and_return(true)
95 104
   end
96 105
 end
97 106
 
@@ -109,12 +118,18 @@ shared_examples 'expect_runs_nova_common_recipe' do
109 118
   end
110 119
 end
111 120
 
121
+shared_examples 'expect_runs_nova_cell_recipe' do
122
+  it 'includes _nova_cell' do
123
+    expect(chef_run).to include_recipe 'openstack-compute::_nova_cell'
124
+  end
125
+end
126
+
112 127
 shared_examples 'expect_creates_nova_state_dir' do
113 128
   it 'creates the /var/lib/nova/lock directory' do
114 129
     expect(chef_run).to create_directory('/var/lib/nova').with(
115 130
       user: 'nova',
116 131
       group: 'nova',
117
-      mode: 0755
132
+      mode: 0o755
118 133
     )
119 134
   end
120 135
 end
@@ -124,7 +139,7 @@ shared_examples 'expect_creates_nova_lock_dir' do
124 139
     expect(chef_run).to create_directory('/var/lib/nova/lock').with(
125 140
       user: 'nova',
126 141
       group: 'nova',
127
-      mode: 0755
142
+      mode: 0o755
128 143
     )
129 144
   end
130 145
 end
@@ -134,7 +149,7 @@ shared_examples 'expect_creates_nova_instances_dir' do
134 149
     expect(chef_run).to create_directory('/var/lib/nova/instances').with(
135 150
       user: 'nova',
136 151
       group: 'nova',
137
-      mode: 0755
152
+      mode: 0o755
138 153
     )
139 154
   end
140 155
 end
@@ -145,7 +160,7 @@ shared_examples 'expect_creates_api_paste_template' do
145 160
     expect(chef_run).to create_template('/etc/nova/api-paste.ini').with(
146 161
       user: 'nova',
147 162
       group: 'nova',
148
-      mode: 0644
163
+      mode: 0o644
149 164
     )
150 165
   end
151 166
 

Loading…
Cancel
Save