Move service_instance defined type to backend

... so that all defined types for backend configuration are placed in
the single backend directory.

Change-Id: I0a6c1f0d59a733e9a94d1ff5b06fe15392e4a77c
This commit is contained in:
Takashi Kajinami 2022-05-20 10:52:34 +09:00
parent 8bd5323dc3
commit 8005513f41
4 changed files with 235 additions and 30 deletions

View File

@ -0,0 +1,132 @@
# ==define manila::backend::service_instance
#
# ===Parameters
#
# [*service_instance_user*]
# (required) User in service instance.
#
# [*service_instance_password*]
# (required) Password to service instance user.
#
# [*create_service_image*]
# (optional) Upload the service image to glance.
# Defaults to: true
#
# [*service_image_name*]
# (optional) Name of image in glance, that will be used to create
# service instance.
# Defaults to: 'manila-service-image'
#
# [*service_image_location*]
# (optional) URL or pathname to the service image. This will be
# loaded into Glance. This is required when create_service_image is true.
#
# [*service_instance_name_template*]
# (optional) Name of service instance.
# Defaults to: 'manila_service_instance_%s'
#
# [*manila_service_keypair_name*]
# (optional) Name of keypair that will be created and used
# for service instance.
# Defaults to: 'manila-service'
#
# [*path_to_public_key*]
# (optional) Path to hosts public key.
# Defaults to: '~/.ssh/id_rsa.pub'
#
# [*path_to_private_key*]
# (optional) Path to hosts private key.
# Defaults to: '~/.ssh/id_rsa'
#
# [*max_time_to_build_instance*]
# (optional) Maximum time to wait for creating service instance.
# Defaults to: 300
#
# [*service_instance_security_group*]
# (optional) Name of security group, that will be used for
# service instance creation.
# Defaults to: 'manila-service'
#
# [*service_instance_flavor_id*]
# (optional) ID of flavor, that will be used for service instance
# creation.
# Defaults to: 1
#
# [*service_network_name*]
# (optional) Name of manila service network.
# Defaults to: 'manila_service_network'
#
# [*service_network_cidr*]
# (optional) CIDR of manila service network.
# Defaults to: '10.254.0.0/16'
#
# [*service_network_division_mask*]
# (optional) This mask is used for dividing service network into
# subnets, IP capacity of subnet with this mask directly
# defines possible amount of created service VMs
# per tenant's subnet.
# Defaults to: 28
#
# [*interface_driver*]
# (optional) Vif driver.
# Defaults to: 'manila.network.linux.interface.OVSInterfaceDriver'
#
# [*connect_share_server_to_tenant_network*]
# (optional) Attach share server directly to share network.
# Defaults to: false
#
define manila::backend::service_instance (
$service_instance_user,
$service_instance_password,
$create_service_image = true,
$service_image_name = 'manila-service-image',
$service_image_location = undef,
$service_instance_name_template = 'manila_service_instance_%s',
$manila_service_keypair_name = 'manila-service',
$path_to_public_key = '~/.ssh/id_rsa.pub',
$path_to_private_key = '~/.ssh/id_rsa',
$max_time_to_build_instance = 300,
$service_instance_security_group = 'manila-service',
$service_instance_flavor_id = 1,
$service_network_name = 'manila_service_network',
$service_network_cidr = '10.254.0.0/16',
$service_network_division_mask = 28,
$interface_driver = 'manila.network.linux.interface.OVSInterfaceDriver',
$connect_share_server_to_tenant_network = false,
) {
include manila::deps
if $create_service_image {
if $service_image_location {
glance_image { $service_image_name:
ensure => present,
is_public => 'yes',
container_format => 'bare',
disk_format => 'qcow2',
source => $service_image_location,
}
}
else {
fail('Missing required parameter service_image_location')
}
}
manila_config {
"${name}/service_image_name": value => $service_image_name;
"${name}/service_instance_name_template": value => $service_instance_name_template;
"${name}/service_instance_user": value => $service_instance_user;
"${name}/service_instance_password": value => $service_instance_password, secret => true;
"${name}/manila_service_keypair_name": value => $manila_service_keypair_name;
"${name}/path_to_public_key": value => $path_to_public_key;
"${name}/path_to_private_key": value => $path_to_private_key;
"${name}/max_time_to_build_instance": value => $max_time_to_build_instance;
"${name}/service_instance_security_group": value => $service_instance_security_group;
"${name}/service_instance_flavor_id": value => $service_instance_flavor_id;
"${name}/service_network_name": value => $service_network_name;
"${name}/service_network_cidr": value => $service_network_cidr;
"${name}/service_network_division_mask": value => $service_network_division_mask;
"${name}/interface_driver": value => $interface_driver;
"${name}/connect_share_server_to_tenant_network": value => $connect_share_server_to_tenant_network;
}
}

View File

@ -97,36 +97,26 @@ define manila::service_instance (
include manila::deps
if $create_service_image {
if $service_image_location {
glance_image { $service_image_name:
ensure => present,
is_public => 'yes',
container_format => 'bare',
disk_format => 'qcow2',
source => $service_image_location,
}
}
else {
fail('Missing required parameter service_image_location')
}
}
warning('The manila::service_instance defined type has been deprecated. \
use the manila::backend::service_instance defined type.')
manila_config {
"${name}/service_image_name": value => $service_image_name;
"${name}/service_instance_name_template": value => $service_instance_name_template;
"${name}/service_instance_user": value => $service_instance_user;
"${name}/service_instance_password": value => $service_instance_password, secret => true;
"${name}/manila_service_keypair_name": value => $manila_service_keypair_name;
"${name}/path_to_public_key": value => $path_to_public_key;
"${name}/path_to_private_key": value => $path_to_private_key;
"${name}/max_time_to_build_instance": value => $max_time_to_build_instance;
"${name}/service_instance_security_group": value => $service_instance_security_group;
"${name}/service_instance_flavor_id": value => $service_instance_flavor_id;
"${name}/service_network_name": value => $service_network_name;
"${name}/service_network_cidr": value => $service_network_cidr;
"${name}/service_network_division_mask": value => $service_network_division_mask;
"${name}/interface_driver": value => $interface_driver;
"${name}/connect_share_server_to_tenant_network": value => $connect_share_server_to_tenant_network;
manila::backend::service_instance { $name:
service_instance_user => $service_instance_user,
service_instance_password => $service_instance_password,
create_service_image => $create_service_image,
service_image_name => $service_image_name,
service_image_location => $service_image_location,
service_instance_name_template => $service_instance_name_template,
manila_service_keypair_name => $manila_service_keypair_name,
path_to_public_key => $path_to_public_key,
path_to_private_key => $path_to_private_key,
max_time_to_build_instance => $max_time_to_build_instance,
service_instance_security_group => $service_instance_security_group,
service_instance_flavor_id => $service_instance_flavor_id,
service_network_name => $service_network_name,
service_network_cidr => $service_network_cidr,
service_network_division_mask => $service_network_division_mask,
interface_driver => $interface_driver,
connect_share_server_to_tenant_network => $connect_share_server_to_tenant_network,
}
}

View File

@ -0,0 +1,5 @@
---
deprecations:
- |
The ``manila::service_instance`` defined type has been deprecated, in favor
of the new ``manila::backend::service_instance`` defined type.

View File

@ -0,0 +1,78 @@
require 'spec_helper'
describe 'manila::backend::service_instance' do
let(:title) {'DEFAULT'}
let :params do
{
:create_service_image => true,
:service_instance_name_template => 'manila_service_instance_%s',
:service_instance_user => 'user1',
:service_instance_password => 'pass1',
:manila_service_keypair_name => 'manila-service',
:path_to_public_key => '~/.ssh/id_rsa.pub',
:path_to_private_key => '~/.ssh/id_rsa',
:max_time_to_build_instance => 300,
:service_instance_security_group => 'manila-service',
:service_instance_flavor_id => 1,
:service_network_name => 'manila_service_network',
:service_network_cidr => '10.254.0.0/16',
:service_network_division_mask => 28,
:interface_driver => 'manila.network.linux.interface.OVSInterfaceDriver',
:connect_share_server_to_tenant_network => false,
}
end
shared_examples 'manila::backend::service_instance' do
context 'with default parameters' do
it 'configures service instance' do
expect {
params.each_pair do |config,value|
is_expected.to contain_manila_config("DEFAULT/#{config}").with_value( value )
end
}.to raise_error(Puppet::Error, /Missing required parameter service_image_location/)
end
end
context 'with service image provided' do
let (:req_params) { params.merge!({
:service_image_name => 'manila-service-image',
:service_image_location => 'http://example.com/manila_service_image.iso',
}) }
it 'creates Glance image' do
is_expected.to contain_glance_image(req_params[:service_image_name]).with(
:ensure => 'present',
:is_public => 'yes',
:container_format => 'bare',
:disk_format => 'qcow2',
:source => req_params[:service_image_location]
)
end
end
context 'with create_service_image false' do
let (:req_params) { params.merge!({
:create_service_image => false,
:service_image_name => 'manila-service-image',
}) }
it 'does not create Glance image' do
is_expected.to_not contain_glance_image(req_params[:service_image_name])
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_behaves_like 'manila::backend::service_instance'
end
end
end