Merge "Added cellv2 support"

This commit is contained in:
Jenkins 2017-08-11 15:51:07 +00:00 committed by Gerrit Code Review
commit fe0ab45e81
16 changed files with 191 additions and 54 deletions

View File

@ -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'

14
Gemfile
View File

@ -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'

View File

@ -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

72
recipes/_nova_cell.rb Normal file
View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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

44
spec/_nova_cell_spec.rb Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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