From 53e6f7a64e59e5af03b219f5cf54f118dc8b867a Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Mon, 12 Dec 2016 14:52:57 -0700 Subject: [PATCH] Add cell_v2 simple_cell_setup As part of Ocata, nova has made the cell_v2 setup manditory for the nova-api db sync process. This change adds a simple cell_v2 setup with a cell0 and an execution of the 'nova-manage cell_v2 simple_cell_setup' as part of the nova-api db setup and sync process. Change-Id: Idfc369e9e17f7d5a30ce4ff52beb604dd4a6ac23 Closes-Bug: #1649341 (cherry picked from commit 4234ce3df430f16d3e9278e587238148db8e3a47) --- manifests/db/mysql_api.pp | 20 ++++++ manifests/db/sync_api.pp | 11 ++++ manifests/db/sync_cell_v2.pp | 46 ++++++++++++++ manifests/deps.pp | 2 + ...v2-simple-cell-setup-025a90918590c872.yaml | 5 ++ spec/acceptance/nova_wsgi_apache_spec.rb | 4 ++ spec/classes/nova_db_mysql_api_spec.rb | 16 +++++ spec/classes/nova_db_sync_api_spec.rb | 34 +++++----- spec/classes/nova_db_sync_cell_v2_spec.rb | 62 +++++++++++++++++++ 9 files changed, 185 insertions(+), 15 deletions(-) create mode 100644 manifests/db/sync_cell_v2.pp create mode 100644 releasenotes/notes/cell_v2-simple-cell-setup-025a90918590c872.yaml create mode 100644 spec/classes/nova_db_sync_cell_v2_spec.rb diff --git a/manifests/db/mysql_api.pp b/manifests/db/mysql_api.pp index de64d5fef..a9336f5ab 100644 --- a/manifests/db/mysql_api.pp +++ b/manifests/db/mysql_api.pp @@ -31,6 +31,11 @@ # (optional) Additional hosts that are allowed to access this DB # Defaults to undef # +# [*setup_cell0*] +# (optional) Setup a cell0 for the cell_v2 functionality. This option will +# be set to true by default in Ocata when the cell v2 setup is mandatory. +# Defaults to false +# class nova::db::mysql_api( $password, $dbname = 'nova_api', @@ -39,6 +44,7 @@ class nova::db::mysql_api( $charset = 'utf8', $collate = 'utf8_general_ci', $allowed_hosts = undef, + $setup_cell0 = false, ) { include ::nova::deps @@ -53,6 +59,20 @@ class nova::db::mysql_api( allowed_hosts => $allowed_hosts, } + if $setup_cell0 { + # need for cell_v2 + ::openstacklib::db::mysql { 'nova_api_cell0': + user => $user, + password_hash => mysql_password($password), + dbname => "${dbname}_cell0", + host => $host, + charset => $charset, + collate => $collate, + allowed_hosts => $allowed_hosts, + create_user => false, + } + } + Anchor['nova::db::begin'] ~> Class['nova::db::mysql_api'] ~> Anchor['nova::db::end'] diff --git a/manifests/db/sync_api.pp b/manifests/db/sync_api.pp index b1ab8a4a0..12eb31f48 100644 --- a/manifests/db/sync_api.pp +++ b/manifests/db/sync_api.pp @@ -9,8 +9,15 @@ # the command line between 'nova-manage' and 'db sync'. # Defaults to undef # +# [*cellv2_setup*] +# (optional) This flag toggles if we run the cell_v2 simple_cell_setup action +# with nova-manage. This flag will be set to true in Ocata when the cell v2 +# setup is mandatory. +# Defaults to false. +# class nova::db::sync_api( $extra_params = undef, + $cellv2_setup = false, ) { include ::nova::deps @@ -29,4 +36,8 @@ class nova::db::sync_api( ], notify => Anchor['nova::dbsync_api::end'], } + + if $cellv2_setup { + include ::nova::db::sync_cell_v2 + } } diff --git a/manifests/db/sync_cell_v2.pp b/manifests/db/sync_cell_v2.pp new file mode 100644 index 000000000..7d86ec46e --- /dev/null +++ b/manifests/db/sync_cell_v2.pp @@ -0,0 +1,46 @@ +# +# Class to execute nova cell_v2 setup +# +# ==Parameters +# +# [*extra_params*] +# (optional) String of extra command line parameters to append +# to the nova-manage db sync command. These will be inserted in +# the command line between 'nova-manage' and 'db sync'. +# Defaults to '' +# +# [*transport_url*] +# (optional) This is the transport url to use for the simple cell setup. +# By default the command should look for the DEFAULT/transport_url from +# the nova configuration. If not available, you need to provide the +# transport url via the parameters. Prior to Ocata, the transport-url +# was a required parameter. +# Defaults to undef. +# +class nova::db::sync_cell_v2 ( + $extra_params = '', + $transport_url = undef, +) { + + include ::nova::deps + + if $transport_url { + $transport_url_real = "--transport-url=${transport_url}" + } else { + $transport_url_real = '' + } + exec { 'nova-cell_v2-simple-cell-setup': + command => "/usr/bin/nova-manage ${extra_params} cell_v2 simple_cell_setup ${transport_url_real}", + refreshonly => true, + try_sleep => 5, + tries => 10, + logoutput => on_failure, + subscribe => [ + Anchor['nova::install::end'], + Anchor['nova::config::end'], + Anchor['nova::dbsync_api::end'], + Anchor['nova::cell_v2::begin'] + ], + notify => Anchor['nova::cell_v2::end'], + } +} diff --git a/manifests/deps.pp b/manifests/deps.pp index e34ac0863..970bf8bce 100644 --- a/manifests/deps.pp +++ b/manifests/deps.pp @@ -22,6 +22,8 @@ class nova::deps { -> anchor { 'nova::dbsync::end': } ~> anchor { 'nova::dbsync_api::begin': } -> anchor { 'nova::dbsync_api::end': } + ~> anchor { 'nova::cell_v2::begin': } + -> anchor { 'nova::cell_v2::end': } ~> anchor { 'nova::service::begin': } ~> Service<| tag == 'nova-service' |> ~> anchor { 'nova::service::end': } diff --git a/releasenotes/notes/cell_v2-simple-cell-setup-025a90918590c872.yaml b/releasenotes/notes/cell_v2-simple-cell-setup-025a90918590c872.yaml new file mode 100644 index 000000000..d6464df47 --- /dev/null +++ b/releasenotes/notes/cell_v2-simple-cell-setup-025a90918590c872.yaml @@ -0,0 +1,5 @@ +--- +features: + - Adds cell_v2 simple_cell_setup as part of the nova-api database setup. +upgrade: + - The cell_v2 setup will become mandatory in Ocata. diff --git a/spec/acceptance/nova_wsgi_apache_spec.rb b/spec/acceptance/nova_wsgi_apache_spec.rb index a5c1dd090..7cc7e5a2a 100644 --- a/spec/acceptance/nova_wsgi_apache_spec.rb +++ b/spec/acceptance/nova_wsgi_apache_spec.rb @@ -50,6 +50,10 @@ describe 'basic nova' do class { '::nova::keystone::authtoken': password => 'a_big_secret', } + # TODO(aschultz): remove this once https://review.openstack.org/#/c/409970/ lands + class { '::nova::db::sync_cell_v2': + transport_url => 'rabbit://nova:an_even_bigger_secret@127.0.0.1:5672/', + } class { '::nova::api': service_name => 'httpd', } diff --git a/spec/classes/nova_db_mysql_api_spec.rb b/spec/classes/nova_db_mysql_api_spec.rb index c2f2e41c5..68e7ba341 100644 --- a/spec/classes/nova_db_mysql_api_spec.rb +++ b/spec/classes/nova_db_mysql_api_spec.rb @@ -22,6 +22,8 @@ describe 'nova::db::mysql_api' do :charset => 'utf8', :collate => 'utf8_general_ci', )} + + it { is_expected.to_not contain_openstacklib__db__mysql('nova_api_cell0') } end context 'overriding allowed_hosts param to array' do @@ -68,6 +70,20 @@ describe 'nova::db::mysql_api' do )} end + context 'when enabling cell0 setup' do + let :params do + { :setup_cell0 => true }.merge(required_params) + end + + it { is_expected.to contain_openstacklib__db__mysql('nova_api_cell0').with( + :user => 'nova_api', + :password_hash => '*AA1420F182E88B9E5F874F6FBE7459291E8F4601', + :charset => 'utf8', + :collate => 'utf8_general_ci', + :create_user => false, + )} + end + end on_supported_os({ diff --git a/spec/classes/nova_db_sync_api_spec.rb b/spec/classes/nova_db_sync_api_spec.rb index ff287b7c3..8ea7d4dd8 100644 --- a/spec/classes/nova_db_sync_api_spec.rb +++ b/spec/classes/nova_db_sync_api_spec.rb @@ -3,19 +3,26 @@ require 'spec_helper' describe 'nova::db::sync_api' do shared_examples_for 'nova-dbsync-api' do - - it 'runs nova-db-sync-api' do - is_expected.to contain_exec('nova-db-sync-api').with( - :command => '/usr/bin/nova-manage api_db sync', - :refreshonly => 'true', - :logoutput => 'on_failure' - ) + context 'with defaults' do + it { + is_expected.to contain_exec('nova-db-sync-api').with( + :command => '/usr/bin/nova-manage api_db sync', + :refreshonly => 'true', + :logoutput => 'on_failure', + :subscribe => ['Anchor[nova::install::end]', + 'Anchor[nova::config::end]', + 'Anchor[nova::dbsync_api::begin]'], + :notify => 'Anchor[nova::dbsync_api::end]', + ) + } + it { is_expected.to_not contain_class('nova::db::sync_cell_v2') } end - describe "overriding extra_params" do + context "overriding extra_params" do let :params do { :extra_params => '--config-file /etc/nova/nova.conf', + :cellv2_setup => true } end @@ -25,9 +32,9 @@ describe 'nova::db::sync_api' do :refreshonly => 'true', :logoutput => 'on_failure' ) - } - end - + } + it { is_expected.to contain_class('nova::db::sync_cell_v2') } + end end @@ -36,10 +43,7 @@ describe 'nova::db::sync_api' do }).each do |os,facts| context "on #{os}" do let (:facts) do - facts.merge(OSDefaults.get_facts({ - :processorcount => 8, - :concat_basedir => '/var/lib/puppet/concat' - })) + facts.merge(OSDefaults.get_facts()) end it_configures 'nova-dbsync-api' diff --git a/spec/classes/nova_db_sync_cell_v2_spec.rb b/spec/classes/nova_db_sync_cell_v2_spec.rb new file mode 100644 index 000000000..a0bd30ab0 --- /dev/null +++ b/spec/classes/nova_db_sync_cell_v2_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' + +describe 'nova::db::sync_cell_v2' do + + shared_examples_for 'nova-db-sync-cell_v2' do + context 'with defaults' do + + it { + is_expected.to contain_exec('nova-cell_v2-simple-cell-setup').with( + :command => '/usr/bin/nova-manage cell_v2 simple_cell_setup ', + :refreshonly => 'true', + :try_sleep => 5, + :tries => 10, + :logoutput => 'on_failure', + :subscribe => ['Anchor[nova::install::end]', + 'Anchor[nova::config::end]', + 'Anchor[nova::dbsync_api::end]', + 'Anchor[nova::cell_v2::begin]'], + :notify => 'Anchor[nova::cell_v2::end]', + ) + } + end + + context "overriding extra_params" do + let :params do + { + :extra_params => '--config-file /etc/nova/nova.conf', + :transport_url => 'rabbit://user:pass@host:1234/virt' + } + end + + it { + is_expected.to contain_exec('nova-cell_v2-simple-cell-setup').with( + :command => '/usr/bin/nova-manage --config-file /etc/nova/nova.conf cell_v2 simple_cell_setup --transport-url=rabbit://user:pass@host:1234/virt', + :refreshonly => 'true', + :try_sleep => 5, + :tries => 10, + :logoutput => 'on_failure', + :subscribe => ['Anchor[nova::install::end]', + 'Anchor[nova::config::end]', + 'Anchor[nova::dbsync_api::end]', + 'Anchor[nova::cell_v2::begin]'], + :notify => 'Anchor[nova::cell_v2::end]', + ) + } + end + end + + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge(OSDefaults.get_facts()) + end + + it_configures 'nova-db-sync-cell_v2' + end + end + +end