From 012902ad9212dc1fcd30baac2625407c9fc04694 Mon Sep 17 00:00:00 2001 From: Samuel Cassiba Date: Tue, 30 May 2017 02:39:26 -0700 Subject: [PATCH] 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 --- .rubocop_todo.yml | 14 ++++-- Gemfile | 14 ------ metadata.rb | 1 + recipes/_nova_cell.rb | 72 ++++++++++++++++++++++++++++++ recipes/api-metadata.rb | 2 +- recipes/api-os-compute.rb | 17 ++++--- recipes/compute.rb | 4 +- recipes/libvirt.rb | 9 ++-- recipes/nova-common.rb | 10 ++--- spec/_nova_cell_spec.rb | 44 ++++++++++++++++++ spec/api-os-compute-redhat_spec.rb | 8 ++++ spec/compute_spec.rb | 2 +- spec/libvirt-redhat_spec.rb | 2 +- spec/libvirt_spec.rb | 4 +- spec/nova-common_spec.rb | 19 ++++---- spec/spec_helper.rb | 23 ++++++++-- 16 files changed, 191 insertions(+), 54 deletions(-) delete mode 100644 Gemfile create mode 100644 recipes/_nova_cell.rb create mode 100644 spec/_nova_cell_spec.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c16eaaf4..45a8aa19 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-03-06 14:33:48 +0000 using RuboCop version 0.39.0. +# on 2017-08-02 01:11:06 -0400 using RuboCop version 0.47.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -10,6 +10,11 @@ Metrics/AbcSize: Max: 16 +# Offense count: 28 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/BlockLength: + Max: 373 + # Offense count: 2 # Configuration parameters: CountComments. Metrics/MethodLength: @@ -42,7 +47,7 @@ Style/Documentation: - 'recipes/nova-setup.rb' - 'recipes/placement_api.rb' -# Offense count: 1 +# Offense count: 3 # Configuration parameters: MinBodyLength. Style/GuardClause: Exclude: @@ -61,4 +66,7 @@ Style/Next: # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes Style/StringLiterals: - Enabled: false + Exclude: + - 'spec/identity_registration_spec.rb' + - 'spec/placement_api_spec.rb' + - 'spec/spec_helper.rb' diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 31c90b58..00000000 --- a/Gemfile +++ /dev/null @@ -1,14 +0,0 @@ -## THIS GEMFILE IS DEPRECATED AND WILL BE REMOVED AFTER THE NEXT RELEASE -## THERE WON'T BE ANY UPDATES TO THIS FILE DURING THIS RELEASE CYCLE -## WE SWITCHED TO CHEFDK AS THE BUNDLE FOR THE NEEDED GEMS - -source 'https://rubygems.org' - -gem 'chef', '~> 11.18.6' -gem 'json', '<= 1.7.7' # chef 11 dependency -gem 'berkshelf', '~> 3.2.1' -gem 'hashie', '~> 2.0' -gem 'chefspec', '~> 4.0.0' -gem 'rspec', '~> 3.0.0' -gem 'foodcritic', '~> 4.0' -gem 'rubocop', '~> 0.29.1' diff --git a/metadata.rb b/metadata.rb index 6d0165d2..a54c81a8 100644 --- a/metadata.rb +++ b/metadata.rb @@ -7,6 +7,7 @@ license 'Apache 2.0' description 'The OpenStack Compute service Nova.' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) version '15.0.0' +chef_version '>= 12.5' if respond_to?(:chef_version) %w(ubuntu redhat centos).each do |os| supports os diff --git a/recipes/_nova_cell.rb b/recipes/_nova_cell.rb new file mode 100644 index 00000000..29036320 --- /dev/null +++ b/recipes/_nova_cell.rb @@ -0,0 +1,72 @@ +# encoding: UTF-8 +# +# Cookbook Name:: openstack-compute +# Recipe:: _nova_cell +# +# Copyright 2017, Workday, Inc. +# +# 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. +# + +# This recipe is automatically included in openstack-compute::api-os-compute +# and not called directly. It creates a basic cellv2 setup, which is required +# from Ocata forward. + +nova_user = node['openstack']['compute']['user'] +nova_group = node['openstack']['compute']['group'] +db_password = get_password('db', 'nova_cell0') +bind_db = node['openstack']['bind_service']['db'] +listen_address = if bind_db['interface'] + address_for bind_db['interface'] + else + listen_address = bind_db['host'] + end + +execute 'map cell0' do + user nova_user + group nova_group + command "nova-manage cell_v2 map_cell0 --database_connection mysql+pymysql://nova_cell0:#{db_password}@#{listen_address}/nova_cell0?charset=utf8" + not_if 'nova-manage cell_v2 list_cells | grep -q cell0' + action :run +end + +execute 'create cell1' do + user nova_user + group nova_group + not_if 'nova-manage cell_v2 list_cells | grep -q cell1' + command 'nova-manage cell_v2 create_cell --verbose --name cell1' + action :run +end + +execute 'api db sync' do + timeout node['openstack']['compute']['dbsync_timeout'] + user nova_user + group nova_group + command 'nova-manage api_db sync' + action :run +end + +execute 'db sync' do + timeout node['openstack']['compute']['dbsync_timeout'] + user nova_user + group nova_group + command 'nova-manage db sync' + action :run +end + +execute 'discover hosts' do + user nova_user + group nova_group + command 'nova-manage cell_v2 discover_hosts' + action :run +end diff --git a/recipes/api-metadata.rb b/recipes/api-metadata.rb index 6d370ed0..e9f89cbc 100644 --- a/recipes/api-metadata.rb +++ b/recipes/api-metadata.rb @@ -40,7 +40,7 @@ template '/etc/nova/api-paste.ini' do source 'api-paste.ini.erb' owner node['openstack']['compute']['user'] group node['openstack']['compute']['group'] - mode 00644 + mode 0o0644 end service 'nova-api-metadata' do diff --git a/recipes/api-os-compute.rb b/recipes/api-os-compute.rb index c7fa8ffc..b11c6826 100644 --- a/recipes/api-os-compute.rb +++ b/recipes/api-os-compute.rb @@ -33,15 +33,16 @@ platform_options['api_os_compute_packages'].each do |pkg| end end -template '/etc/nova/api-paste.ini' do - source 'api-paste.ini.erb' - owner node['openstack']['compute']['user'] - group node['openstack']['compute']['group'] - mode 00644 -end - nova_user = node['openstack']['compute']['user'] nova_group = node['openstack']['compute']['group'] + +template '/etc/nova/api-paste.ini' do + source 'api-paste.ini.erb' + owner nova_user + group nova_group + mode 0o0644 +end + execute 'nova-manage api_db sync' do timeout node['openstack']['compute']['dbsync_timeout'] user nova_user @@ -59,3 +60,5 @@ service 'nova-api-os-compute' do 'template[/etc/nova/api-paste.ini]' ] end + +include_recipe 'openstack-compute::_nova_cell' diff --git a/recipes/compute.rb b/recipes/compute.rb index 6f8680f0..9285475a 100644 --- a/recipes/compute.rb +++ b/recipes/compute.rb @@ -53,14 +53,14 @@ end # TODO: (jklare) this has to be refactored!!! cookbook_file '/etc/nova/nova-compute.conf' do source 'nova-compute.conf' - mode 00644 + mode 0o0644 action :create end directory node['openstack']['compute']['conf']['DEFAULT']['instances_path'] do owner node['openstack']['compute']['user'] group node['openstack']['compute']['group'] - mode 00755 + mode 0o0755 recursive true end diff --git a/recipes/libvirt.rb b/recipes/libvirt.rb index 21c0f8f2..f724e440 100644 --- a/recipes/libvirt.rb +++ b/recipes/libvirt.rb @@ -81,7 +81,8 @@ def update_boot_kernel_and_trigger_reboot(flavor = 'default') update_grub2_default_kernel(flavor) else ::Chef::Application.fatal!( - 'Unknown bootloader. Could not change boot kernel.') + 'Unknown bootloader. Could not change boot kernel.' + ) end # trigger reboot through reboot_handler, if kernel-$flavor is not yet @@ -127,7 +128,7 @@ template '/etc/libvirt/libvirtd.conf' do source 'libvirtd.conf.erb' owner 'root' group 'root' - mode 00644 + mode 0o0644 variables( auth_tcp: node['openstack']['compute']['libvirt']['auth_tcp'], libvirt_group: node['openstack']['compute']['libvirt']['group'] @@ -139,7 +140,7 @@ template '/etc/default/libvirt-bin' do source 'libvirt-bin.erb' owner 'root' group 'root' - mode 00644 + mode 0o0644 notifies :restart, 'service[libvirt-bin]', :immediately only_if { platform_family? 'debian' } end @@ -148,7 +149,7 @@ template '/etc/sysconfig/libvirtd' do source 'libvirtd.erb' owner 'root' group 'root' - mode 00644 + mode 0o0644 notifies :restart, 'service[libvirt-bin]', :immediately only_if { platform_family? %w(rhel) } end diff --git a/recipes/nova-common.rb b/recipes/nova-common.rb index 7363cf7b..b1c6c1a6 100644 --- a/recipes/nova-common.rb +++ b/recipes/nova-common.rb @@ -56,21 +56,21 @@ end directory '/etc/nova' do owner node['openstack']['compute']['user'] group node['openstack']['compute']['group'] - mode 00750 + mode 0o0750 action :create end directory node['openstack']['compute']['conf']['DEFAULT']['state_path'] do owner node['openstack']['compute']['user'] group node['openstack']['compute']['group'] - mode 00755 + mode 0o0755 recursive true end directory node['openstack']['compute']['conf']['oslo_concurrency']['lock_path'] do owner node['openstack']['compute']['user'] group node['openstack']['compute']['group'] - mode 00755 + mode 0o0755 recursive true end @@ -214,7 +214,7 @@ template '/etc/nova/nova.conf' do source 'nova.conf.erb' owner node['openstack']['compute']['user'] group node['openstack']['compute']['group'] - mode 00640 + mode 0o0640 variables( # TODO(jaypipes): No support here for >1 image API servers # with the glance_api_servers configuration option... @@ -235,7 +235,7 @@ template '/etc/nova/rootwrap.conf' do # Must be root! owner 'root' group 'root' - mode 00644 + mode 0o0644 end execute 'enable nova login' do diff --git a/spec/_nova_cell_spec.rb b/spec/_nova_cell_spec.rb new file mode 100644 index 00000000..6207bfc8 --- /dev/null +++ b/spec/_nova_cell_spec.rb @@ -0,0 +1,44 @@ +# encoding: UTF-8 + +require_relative 'spec_helper' + +describe 'openstack-compute::_nova_cell' do + describe 'ubuntu' do + let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) } + let(:node) { runner.node } + let(:chef_run) { runner.converge(described_recipe) } + + include_context 'compute_stubs' + include_examples 'expect_runs_nova_cell_recipe' + + it 'creates the cell0 mapping' do + expect(chef_run).to run_execute('map cell0') + .with(user: 'nova', + group: 'nova') + end + + it 'creates a new cell' do + expect(chef_run).to run_execute('create cell1') + .with(user: 'nova', + group: 'nova') + end + + it 'executes api_db sync' do + expect(chef_run).to run_execute('api db sync') + .with(user: 'nova', + group: 'nova') + end + + it 'executes db sync' do + expect(chef_run).to run_execute('db sync') + .with(user: 'nova', + group: 'nova') + end + + it 'discovers compute hosts' do + expect(chef_run).to run_execute('discover hosts') + .with(user: 'nova', + group: 'nova') + end + end +end diff --git a/spec/api-os-compute-redhat_spec.rb b/spec/api-os-compute-redhat_spec.rb index 62ea929e..bc8d2988 100644 --- a/spec/api-os-compute-redhat_spec.rb +++ b/spec/api-os-compute-redhat_spec.rb @@ -13,6 +13,14 @@ describe 'openstack-compute::api-os-compute' do include_examples 'expect_creates_nova_state_dir' include_examples 'expect_creates_nova_lock_dir' + it 'executes nova-manage api_db sync' do + expect(chef_run).to run_execute('nova-manage api_db sync') + .with(timeout: 3600, + user: 'nova', + group: 'nova', + command: 'nova-manage api_db sync') + end + it 'upgrades openstack api packages' do expect(chef_run).to upgrade_package 'openstack-nova-api' end diff --git a/spec/compute_spec.rb b/spec/compute_spec.rb index 1dc3a852..5de07660 100644 --- a/spec/compute_spec.rb +++ b/spec/compute_spec.rb @@ -75,7 +75,7 @@ describe 'openstack-compute::compute' do it 'creates the file' do expect(chef_run).to create_cookbook_file(file.name).with( source: 'nova-compute.conf', - mode: 00644 + mode: 0o0644 ) end end diff --git a/spec/libvirt-redhat_spec.rb b/spec/libvirt-redhat_spec.rb index 421826be..3a0a7db5 100644 --- a/spec/libvirt-redhat_spec.rb +++ b/spec/libvirt-redhat_spec.rb @@ -43,7 +43,7 @@ describe 'openstack-compute::libvirt' do expect(chef_run).to create_template(file.name).with( owner: 'root', group: 'root', - mode: 0644 + mode: 0o644 ) end diff --git a/spec/libvirt_spec.rb b/spec/libvirt_spec.rb index ca555f05..3e0cfa64 100644 --- a/spec/libvirt_spec.rb +++ b/spec/libvirt_spec.rb @@ -62,7 +62,7 @@ describe 'openstack-compute::libvirt' do expect(chef_run).to create_template(file.name).with( owner: 'root', group: 'root', - mode: 0644 + mode: 0o644 ) end @@ -88,7 +88,7 @@ describe 'openstack-compute::libvirt' do expect(chef_run).to create_template(file.name).with( owner: 'root', group: 'root', - mode: 0644 + mode: 0o644 ) end diff --git a/spec/nova-common_spec.rb b/spec/nova-common_spec.rb index eda60770..31854200 100644 --- a/spec/nova-common_spec.rb +++ b/spec/nova-common_spec.rb @@ -35,7 +35,7 @@ describe 'openstack-compute::nova-common' do expect(chef_run).to create_directory('/etc/nova').with( owner: 'nova', group: 'nova', - mode: 0750 + mode: 0o750 ) end @@ -66,7 +66,7 @@ describe 'openstack-compute::nova-common' do expect(chef_run).to create_template(file.name).with( owner: 'nova', group: 'nova', - mode: 0640 + mode: 0o640 ) end @@ -155,7 +155,6 @@ describe 'openstack-compute::nova-common' do it 'uses default values for attributes' do [ - %r{^api_servers = http://127.0.0.1:9292$} ].each do |line| @@ -203,8 +202,7 @@ describe 'openstack-compute::nova-common' do node.set['openstack']['endpoints']['compute-vnc-bind']['bind_interface'] = 'lo' [/^vncserver_listen = 127.0.0.1$/, - /^vncserver_proxyclient_address = 127.0.0.1$/ - ].each do |line| + /^vncserver_proxyclient_address = 127.0.0.1$/].each do |line| expect(chef_run).to render_file(file.name).with_content(line) end end @@ -265,7 +263,8 @@ describe 'openstack-compute::nova-common' do it 'has no auto_assign_floating_ip' do expect(chef_run).not_to render_file(file.name).with_content( - 'auto_assign_floating_ip=false') + 'auto_assign_floating_ip=false' + ) end context 'rbd backend' do @@ -385,7 +384,7 @@ describe 'openstack-compute::nova-common' do expect(chef_run).to render_config_file(file.name) .with_section_content( 'api_database', - %r{connection = mysql://nova_api:nova_api_db_pass@127.0.0.1:3306/nova_api\?charset=utf8$} + %(connection = mysql+pymysql://nova_api:nova_api_db_pass@127.0.0.1:3306/nova_api?charset=utf8) ) end @@ -397,7 +396,7 @@ describe 'openstack-compute::nova-common' do node.set['openstack']['db']['compute']['username'] = 'nova' expect(chef_run).to render_config_file(file.name)\ - .with_section_content('database', %r{slave_connection = mysql://nova:nova_db_pass@10.10.1.1:3326/nova\?charset=utf8$}) + .with_section_content('database', %(slave_connection = mysql+pymysql://nova:nova_db_pass@10.10.1.1:3326/nova?charset=utf8)) end it 'sets overide database enabled_slave attribute as false' do @@ -407,7 +406,7 @@ describe 'openstack-compute::nova-common' do node.set['openstack']['db']['compute']['username'] = 'nova' expect(chef_run).to_not render_config_file(file.name)\ - .with_section_content('database', %r{slave_connection = mysql://nova:nova_db_pass@10.10.1.1:3326/nova\?charset=utf8$}) + .with_section_content('database', %(slave_connection = mysql+pymysql://nova:nova_db_pass@10.10.1.1:3326/nova?charset=utf8)) end end end @@ -419,7 +418,7 @@ describe 'openstack-compute::nova-common' do expect(chef_run).to create_template(file.name).with( user: 'root', group: 'root', - mode: 0644 + mode: 0o644 ) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4d059eb3..fecb5068 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -58,6 +58,9 @@ shared_context 'compute_stubs' do allow_any_instance_of(Chef::Recipe).to receive(:get_password) .with('db', 'nova_api') .and_return('nova_api_db_pass') + allow_any_instance_of(Chef::Recipe).to receive(:get_password) + .with('db', 'nova_cell0') + .and_return('nova_cell0_db_pass') allow_any_instance_of(Chef::Recipe).to receive(:get_password) .with('user', 'guest') .and_return('mq-pass') @@ -92,6 +95,12 @@ shared_context 'compute_stubs' do stub_command('virsh secret-list | grep 00000000-0000-0000-0000-000000000000').and_return(false) 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) 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) + stub_command('nova-manage api_db sync').and_return(true) + 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) + stub_command('nova-manage cell_v2 create_cell --verbose --name cell1').and_return(true) + stub_command('nova-manage cell_v2 list_cells | grep -q cell0').and_return(false) + stub_command('nova-manage cell_v2 list_cells | grep -q cell1').and_return(false) + stub_command('nova-manage cell_v2 discover_hosts').and_return(true) end end @@ -109,12 +118,18 @@ shared_examples 'expect_runs_nova_common_recipe' do end end +shared_examples 'expect_runs_nova_cell_recipe' do + it 'includes _nova_cell' do + expect(chef_run).to include_recipe 'openstack-compute::_nova_cell' + end +end + shared_examples 'expect_creates_nova_state_dir' do it 'creates the /var/lib/nova/lock directory' do expect(chef_run).to create_directory('/var/lib/nova').with( user: 'nova', group: 'nova', - mode: 0755 + mode: 0o755 ) end end @@ -124,7 +139,7 @@ shared_examples 'expect_creates_nova_lock_dir' do expect(chef_run).to create_directory('/var/lib/nova/lock').with( user: 'nova', group: 'nova', - mode: 0755 + mode: 0o755 ) end end @@ -134,7 +149,7 @@ shared_examples 'expect_creates_nova_instances_dir' do expect(chef_run).to create_directory('/var/lib/nova/instances').with( user: 'nova', group: 'nova', - mode: 0755 + mode: 0o755 ) end end @@ -145,7 +160,7 @@ shared_examples 'expect_creates_api_paste_template' do expect(chef_run).to create_template('/etc/nova/api-paste.ini').with( user: 'nova', group: 'nova', - mode: 0644 + mode: 0o644 ) end