Merge "Add ability to translate net name to UUID" into stable/newton

This commit is contained in:
Jenkins 2017-03-28 15:53:34 +00:00 committed by Gerrit Code Review
commit 22acdd3e88
7 changed files with 111 additions and 3 deletions

View File

@ -0,0 +1,3 @@
ironic_config {
'neutron/cleaning_network': value => 'cleaning_net', transform_to => 'net_uuid';
}

View File

@ -1,5 +1,8 @@
require 'csv'
require 'puppet/util/inifile'
require 'puppet/provider/openstack'
require 'puppet/provider/openstack/auth'
require 'puppet/provider/openstack/credentials'
class Puppet::Provider::Ironic < Puppet::Provider
@ -149,5 +152,24 @@ correctly configured.")
end
hash
end
end
class Puppet::Provider::Ironic::OpenstackRequest
include Puppet::Provider::Openstack::Auth
def openstack_request(service, action, properties=nil, options={})
credentials = Puppet::Provider::Openstack::CredentialsV3.new
openstack = Puppet::Provider::Openstack
set_credentials(credentials, get_os_vars_from_env)
unless credentials.set?
credentials.unset
set_credentials(credentials, get_os_vars_from_rcfile(rc_filename))
end
unless credentials.set?
raise(Puppet::Error::OpenstackAuthInputError, 'Insufficient credentials to authenticate')
end
openstack.request(service, action, properties, credentials, options)
end
end

View File

@ -1,3 +1,5 @@
require File.join(File.dirname(__FILE__), '..','..','..', 'puppet/provider/ironic')
Puppet::Type.type(:ironic_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
@ -7,4 +9,18 @@ Puppet::Type.type(:ironic_config).provide(
'/etc/ironic/ironic.conf'
end
def to_net_uuid(name)
properties = [name, '--column', 'id']
openstack = Puppet::Provider::Ironic::OpenstackRequest.new
res = openstack.openstack_request('network', 'show', properties)
return res[:id]
end
def from_net_uuid(uuid)
properties = [uuid, '--column', 'name']
openstack = Puppet::Provider::Ironic::OpenstackRequest.new
res = openstack.openstack_request('network', 'show', properties)
return res[:name]
end
end

View File

@ -46,6 +46,8 @@ Puppet::Type.newtype(:ironic_config) do
defaultto('<SERVICE DEFAULT>')
end
newparam(:transform_to)
autorequire(:package) do
'ironic-common'
end

View File

@ -72,6 +72,7 @@
# [*cleaning_network_uuid*]
# (optional) UUID of the network to create Neutron ports on, when booting
# to a ramdisk for cleaning using Neutron DHCP.
# Can not be specified together with cleaning_network_name.
# Defaults to $::os_service_default
#
# [*cleaning_disk_erase*]
@ -94,6 +95,7 @@
# [*provisioning_network_uuid*]
# (optional) Neutron network UUID for the ramdisk to be booted into for
# provisioning nodes. Required for neutron network interface.
# Can not be specified together with provisioning_network_name.
# Defaults to $::os_service_default
#
# [*configdrive_use_swift*]
@ -106,6 +108,18 @@
# configdrive_use_swift is true.
# Defaults to $::os_service_default
#
# [*cleaning_network_name*]
# (optional) If provided the name will be converted to UUID and set
# as value of neutron/cleaning_network_uuid option in ironic.conf
# Can not be specified together with cleaning_network_uuid.
# Defaults to undef, which leaves the configuration intact
#
# [*provisioning_network_name*]
# (optional) If provided the name will be converted to UUID and set
# as value of neutron/provisioning_network_uuid option in ironic.conf
# Can not be specified together with provisioning_network_uuid.
# Defaults to undef, which leaves the configuration intact
#
class ironic::conductor (
$package_ensure = 'present',
$enabled = true,
@ -125,6 +139,8 @@ class ironic::conductor (
$provisioning_network_uuid = $::os_service_default,
$configdrive_use_swift = $::os_service_default,
$configdrive_swift_container = $::os_service_default,
$cleaning_network_name = undef,
$provisioning_network_name = undef,
) {
include ::ironic::deps
@ -133,6 +149,16 @@ class ironic::conductor (
$enabled_drivers_real = pick($::ironic::enabled_drivers, $enabled_drivers)
if ($cleaning_network_name and !is_service_default($cleaning_network_uuid)) {
fail("cleaning_network_name and cleaning_network_uuid can not be \
specified in the same time.")
}
if ($provisioning_network_name and !is_service_default($provisioning_network_uuid)) {
fail("provisioning_network_name and provisioning_network_uuid can not be \
specified in the same time.")
}
validate_array($enabled_drivers_real)
# NOTE(dtantsur): all in-tree drivers are IPA-based, so it won't hurt
@ -186,8 +212,6 @@ class ironic::conductor (
'glance/swift_account': value => $swift_account;
'glance/swift_temp_url_key': value => $swift_temp_url_key, secret => true;
'glance/swift_temp_url_duration': value => $swift_temp_url_duration;
'neutron/cleaning_network_uuid': value => $cleaning_network_uuid;
'neutron/provisioning_network_uuid': value => $provisioning_network_uuid;
'deploy/http_url': value => $http_url_real;
'deploy/http_root': value => $http_root_real;
'deploy/erase_devices_priority': value => $erase_devices_priority;
@ -197,6 +221,26 @@ class ironic::conductor (
'conductor/configdrive_swift_container': value => $configdrive_swift_container;
}
if $cleaning_network_name {
ironic_config {
'neutron/cleaning_network_uuid': value => $cleaning_network_name, transform_to => 'net_uuid';
}
} else {
ironic_config {
'neutron/cleaning_network_uuid': value => $cleaning_network_uuid;
}
}
if $provisioning_network_name {
ironic_config {
'neutron/provisioning_network_uuid': value => $provisioning_network_name, transform_to => 'net_uuid';
}
} else {
ironic_config {
'neutron/provisioning_network_uuid': value => $provisioning_network_uuid;
}
}
# Install package
if $::ironic::params::conductor_package {
package { 'ironic-conductor':

View File

@ -0,0 +1,7 @@
---
features:
- Add the ability to specify a name string for the provisioning_network in
ironic_config using the transform_to argument.
Add ``cleaning_network_name`` and ``provisioning_network_name`` options to
::ironic::conductor class. Theirs names will be automatically converted to
UUIDs and appropriate config options will be set.

View File

@ -119,6 +119,20 @@ describe 'ironic::conductor' do
end
end
context 'when overriding parameters' do
before :each do
params.merge!(
:provisioning_network_name => 'abc',
:cleaning_network_name => 'abc',
)
end
it 'should set provisioning/cleaning with new value' do
is_expected.to contain_ironic_config('neutron/cleaning_network_uuid').with_value('abc').with_transform_to('net_uuid')
is_expected.to contain_ironic_config('neutron/provisioning_network_uuid').with_value('abc').with_transform_to('net_uuid')
end
end
end
context 'on Debian platforms' do