Merge "Add ability to translate net name to UUID"

This commit is contained in:
Jenkins 2017-03-27 11:03:19 +00:00 committed by Gerrit Code Review
commit 36dd4c1b6f
7 changed files with 112 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 'csv'
require 'puppet/util/inifile' require 'puppet/util/inifile'
require 'puppet/provider/openstack'
require 'puppet/provider/openstack/auth'
require 'puppet/provider/openstack/credentials'
class Puppet::Provider::Ironic < Puppet::Provider class Puppet::Provider::Ironic < Puppet::Provider
@ -149,5 +152,24 @@ correctly configured.")
end end
hash hash
end 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 end

View File

@ -1,10 +1,27 @@
require File.join(File.dirname(__FILE__), '..','..','..', 'puppet/provider/ironic')
Puppet::Type.type(:ironic_config).provide( Puppet::Type.type(:ironic_config).provide(
:ini_setting, :ini_setting,
:parent => Puppet::Type.type(:openstack_config).provider(:ini_setting) :parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
) do ) do
def self.file_path def self.file_path
'/etc/ironic/ironic.conf' '/etc/ironic/ironic.conf'
end 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 end

View File

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

View File

@ -61,6 +61,7 @@
# [*cleaning_network*] # [*cleaning_network*]
# (optional) UUID or name of the network to create Neutron ports on, when # (optional) UUID or name of the network to create Neutron ports on, when
# booting to a ramdisk for cleaning using Neutron DHCP. # booting to a ramdisk for cleaning using Neutron DHCP.
# Can not be specified together with cleaning_network_name.
# Defaults to $::os_service_default # Defaults to $::os_service_default
# #
# [*cleaning_disk_erase*] # [*cleaning_disk_erase*]
@ -83,6 +84,7 @@
# [*provisioning_network*] # [*provisioning_network*]
# (optional) Neutron network UUID or name for the ramdisk to be booted into # (optional) Neutron network UUID or name for the ramdisk to be booted into
# for provisioning nodes. Required for neutron network interface. # for provisioning nodes. Required for neutron network interface.
# Can not be specified together with provisioning_network_name.
# Defaults to $::os_service_default # Defaults to $::os_service_default
# #
# [*configdrive_use_swift*] # [*configdrive_use_swift*]
@ -100,6 +102,18 @@
# requested. One of "netboot" or "local". # requested. One of "netboot" or "local".
# Defaults to $::os_service_default # 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 option in ironic.conf
# Can not be specified together with cleaning_network.
# 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 option in ironic.conf
# Can not be specified together with provisioning_network.
# Defaults to undef, which leaves the configuration intact
#
# DEPRECATED # DEPRECATED
# #
# [*cleaning_network_uuid*] # [*cleaning_network_uuid*]
@ -143,6 +157,8 @@ class ironic::conductor (
$configdrive_use_swift = $::os_service_default, $configdrive_use_swift = $::os_service_default,
$configdrive_swift_container = $::os_service_default, $configdrive_swift_container = $::os_service_default,
$default_boot_option = $::os_service_default, $default_boot_option = $::os_service_default,
$cleaning_network_name = undef,
$provisioning_network_name = undef,
# DEPRECATED # DEPRECATED
$cleaning_network_uuid = undef, $cleaning_network_uuid = undef,
$provisioning_network_uuid = undef, $provisioning_network_uuid = undef,
@ -169,6 +185,16 @@ class ironic::conductor (
$cleaning_network_real = pick($cleaning_network_uuid, $cleaning_network) $cleaning_network_real = pick($cleaning_network_uuid, $cleaning_network)
$provisioning_network_real = pick($provisioning_network_uuid, $provisioning_network) $provisioning_network_real = pick($provisioning_network_uuid, $provisioning_network)
if ($cleaning_network_name and !is_service_default($cleaning_network_real)) {
fail("cleaning_network_name and cleaning_network or cleaning_network_uuid can not be \
specified in the same time.")
}
if ($provisioning_network_name and !is_service_default($provisioning_network_real)) {
fail("provisioning_network_name and provisioning_network or provisioning_network_uuid can not be \
specified in the same time.")
}
if $swift_account or $swift_temp_url_key or $swift_temp_url_duration { if $swift_account or $swift_temp_url_key or $swift_temp_url_duration {
warning("swift_account, swift_temp_url_key and swift_temp_url_duration were \ warning("swift_account, swift_temp_url_key and swift_temp_url_duration were \
moved to ironic::glance manifest") moved to ironic::glance manifest")
@ -227,8 +253,6 @@ moved to ironic::glance manifest")
'conductor/force_power_state_during_sync': value => $force_power_state_during_sync; 'conductor/force_power_state_during_sync': value => $force_power_state_during_sync;
'conductor/automated_clean': value => $automated_clean; 'conductor/automated_clean': value => $automated_clean;
'conductor/api_url': value => $api_url; 'conductor/api_url': value => $api_url;
'neutron/cleaning_network': value => $cleaning_network_real;
'neutron/provisioning_network': value => $provisioning_network_real;
'deploy/http_url': value => $http_url_real; 'deploy/http_url': value => $http_url_real;
'deploy/http_root': value => $http_root_real; 'deploy/http_root': value => $http_root_real;
'deploy/erase_devices_priority': value => $erase_devices_priority; 'deploy/erase_devices_priority': value => $erase_devices_priority;
@ -239,6 +263,26 @@ moved to ironic::glance manifest")
'deploy/default_boot_option': value => $default_boot_option; 'deploy/default_boot_option': value => $default_boot_option;
} }
if $cleaning_network_name {
ironic_config {
'neutron/cleaning_network': value => $cleaning_network_name, transform_to => 'net_uuid';
}
} else {
ironic_config {
'neutron/cleaning_network': value => $cleaning_network_real;
}
}
if $provisioning_network_name {
ironic_config {
'neutron/provisioning_network': value => $provisioning_network_name, transform_to => 'net_uuid';
}
} else {
ironic_config {
'neutron/provisioning_network': value => $provisioning_network_real;
}
}
# Install package # Install package
if $::ironic::params::conductor_package { if $::ironic::params::conductor_package {
package { 'ironic-conductor': 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

@ -117,6 +117,20 @@ describe 'ironic::conductor' do
end end
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').with_value('abc').with_transform_to('net_uuid')
is_expected.to contain_ironic_config('neutron/provisioning_network').with_value('abc').with_transform_to('net_uuid')
end
end
end end
on_supported_os({ on_supported_os({