Additional cell_v2 commands

This change exposes additional cell v2 management commands that can be
used as part of managing cell v2. The map_instances and
map_cell_and_hosts commands can be pulled in to be run as part of
upgrades or general management.

Change-Id: Ie731f3d5b8396786f579f80d87714ce2e949a5df
This commit is contained in:
Alex Schultz 2017-01-23 13:48:50 -07:00
parent dc2f3a3586
commit 290b6422df
5 changed files with 172 additions and 0 deletions

View File

@ -0,0 +1,22 @@
# == Class: nova::cell_v2::map_cell_and_hosts
#
# Class to run the map_cell_and_hosts action for cell v2
#
# === Parameters
#
# [*extra_params*]
# (String) Extra parameters to pass to the nova-manage commands.
# Defaults to ''.
#
class nova::cell_v2::map_cell_and_hosts (
$extra_params = '',
) {
include ::nova::deps
exec { 'nova-cell_v2-map_cell_and_hosts':
path => ['/bin', '/usr/bin'],
command => "nova-manage ${extra_params} cell_v2 map_cell_and_hosts",
refreshonly => true,
}
}

View File

@ -0,0 +1,47 @@
# == Class: nova::cell_v2::map_instances
#
# Resource to run the map_instances action for cell v2
#
# === Parameters
#
# [*cell_uuid*]
# (String) Cell UUID to map unmigrated instances to. It is recommended to use
# this rather than cell name. Either cell_uuid or cell_name must be provided.
# Defaults to undef.
#
# [*cell_name*]
# (String) Cell name to map the unmigrated instances to. We will attempt to
# extract the cell uuid using the name as the command requires a cell uuid.
# NOTE: This will not work if you have multiple cells with the same name.
# Defaults to undef.
#
# [*extra_params*]
# (String) Extra parameters to pass to the nova-manage commands.
# Defaults to ''.
#
class nova::cell_v2::map_instances (
$cell_uuid = undef,
$cell_name = undef,
$extra_params = '',
) {
include ::nova::deps
if (!$cell_uuid and !$cell_name) {
fail('Either cell_uuid or cell_name must be provided')
}
if ($cell_uuid) {
$cell_uuid_real = $cell_uuid
} else {
# NOTE(aschultz): This is what breaks if you have multiple cells with the
# same name. So that's why using cell_uuid is better.
$cell_uuid_real = "$(nova-manage cell_v2 list_cells | sed -e '1,3d' -e '\$d' | awk -F ' *| *' '\$2 == \"${cell_name}\" {print \$4}')"
}
exec { 'nova-cell_v2-map_instances':
path => ['/bin', '/usr/bin'],
command => "nova-manage ${extra_params} cell_v2 map_instances --cell_uuid=${cell_uuid_real}",
refreshonly => true,
}
}

View File

@ -0,0 +1,7 @@
---
features:
- |
Add classes to expose refreshonly versions of the
"nova-manage cell_v2 map_cell_and_hosts" and
"nova-manage cell_v2 map_instances" commands that can be used to manage
cell v2.

View File

@ -0,0 +1,47 @@
require 'spec_helper'
describe 'nova::cell_v2::map_cell_and_hosts' do
shared_examples_for 'nova::cell_v2::map_cell_and_hosts' do
context 'with defaults' do
it {
is_expected.to contain_exec('nova-cell_v2-map_cell_and_hosts').with(
:path => ['/bin', '/usr/bin'],
:command => 'nova-manage cell_v2 map_cell_and_hosts',
:refreshonly => true,
)
}
end
context "overriding extra_params" do
let :params do
{
:extra_params => '--config-file /etc/nova/nova.conf'
}
end
it {
is_expected.to contain_exec('nova-cell_v2-map_cell_and_hosts').with(
:path => ['/bin', '/usr/bin'],
:command => 'nova-manage --config-file /etc/nova/nova.conf cell_v2 map_cell_and_hosts',
:refreshonly => true,
)
}
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::cell_v2::map_cell_and_hosts'
end
end
end

View File

@ -0,0 +1,49 @@
require 'spec_helper'
describe 'nova::cell_v2::map_instances' do
shared_examples_for 'nova::cell_v2::map_instances' do
context 'with defaults' do
let (:params) { { :cell_uuid => 'uuid' } }
it {
is_expected.to contain_exec('nova-cell_v2-map_instances').with(
:path => ['/bin', '/usr/bin'],
:command => 'nova-manage cell_v2 map_instances --cell_uuid=uuid',
:refreshonly => true,
)
}
end
context "overriding extra_params" do
let :params do
{
:extra_params => '--config-file /etc/nova/nova.conf',
:cell_uuid => 'uuid'
}
end
it {
is_expected.to contain_exec('nova-cell_v2-map_instances').with(
:path => ['/bin', '/usr/bin'],
:command => 'nova-manage --config-file /etc/nova/nova.conf cell_v2 map_instances --cell_uuid=uuid',
:refreshonly => true,
)
}
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::cell_v2::map_instances'
end
end
end