Use $::os_service_default instead of undef
Passing value => undef leaves parameters unmanaged. Use $::os_service_default to ensure the parameters are cleared, in case the parameter is removed from manifests/hieradata. This change also introduces unit tests for the following resource type. neutron::plugins::ml2::networking_ansible_host Change-Id: Ife25bbf7cdf70793c24da5aa2634a3f46b247a5f
This commit is contained in:
@@ -5,47 +5,53 @@
|
|||||||
# === Parameters
|
# === Parameters
|
||||||
#
|
#
|
||||||
# [*ansible_network_os*]
|
# [*ansible_network_os*]
|
||||||
# (required) Operating system of the network device
|
# (Required) Operating system of the network device
|
||||||
#
|
#
|
||||||
# [*ansible_host*]
|
# [*ansible_host*]
|
||||||
# (required) IP Address of the network device
|
# (Required) IP Address of the network device
|
||||||
#
|
#
|
||||||
# [*ansible_user*]
|
# [*ansible_user*]
|
||||||
# (required) Username to connect to the network device
|
# (Required) Username to connect to the network device
|
||||||
#
|
#
|
||||||
# [*ansible_ssh_pass*]
|
# [*ansible_ssh_pass*]
|
||||||
# SSH password to connect to the network device
|
# (Optional) SSH password to connect to the network device
|
||||||
# This or ansible_ssh_private_key_file should be provided
|
# This or ansible_ssh_private_key_file should be provided
|
||||||
|
# Defaults to $::os_service_default
|
||||||
#
|
#
|
||||||
# [*ansible_ssh_private_key_file*]
|
# [*ansible_ssh_private_key_file*]
|
||||||
# SSH private key to connect to the network device
|
# (Optional) SSH private key to connect to the network device
|
||||||
# This or ansible_ssh_pass should be provided
|
# This or ansible_ssh_pass should be provided
|
||||||
|
# Defaults to $::os_service_default
|
||||||
#
|
#
|
||||||
# [*hostname*]
|
# [*hostname*]
|
||||||
# (required) The hostname of a host connected to the switch.
|
# (Optional) The hostname of a host connected to the switch.
|
||||||
|
# Defaults to $title
|
||||||
#
|
#
|
||||||
# [*mac*]
|
# [*mac*]
|
||||||
# Chassis MAC ID of the network device. Used to map lldp provided value
|
# (Optional) Chassis MAC ID of the network device. Used to map lldp provided
|
||||||
# to the hostname when using ironic introspection.
|
# value to the hostname when using ironic introspection.
|
||||||
|
# Defaults to $::os_service_default
|
||||||
#
|
#
|
||||||
# [*manage_vlans*]
|
# [*manage_vlans*]
|
||||||
# Should networking-ansible create and delete VLANs on the device.
|
# Should networking-ansible create and delete VLANs on the device.
|
||||||
|
# Defaults to $::os_service_default
|
||||||
#
|
#
|
||||||
define neutron::plugins::ml2::networking_ansible_host(
|
define neutron::plugins::ml2::networking_ansible_host(
|
||||||
$ansible_network_os,
|
$ansible_network_os,
|
||||||
$ansible_host,
|
$ansible_host,
|
||||||
$ansible_user,
|
$ansible_user,
|
||||||
$ansible_ssh_pass = undef,
|
$ansible_ssh_pass = $::os_service_default,
|
||||||
$ansible_ssh_private_key_file = undef,
|
$ansible_ssh_private_key_file = $::os_service_default,
|
||||||
$mac = undef,
|
$mac = $::os_service_default,
|
||||||
$hostname = $title,
|
$hostname = $title,
|
||||||
$manage_vlans = undef,
|
$manage_vlans = $::os_service_default,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
include neutron::deps
|
include neutron::deps
|
||||||
require neutron::plugins::ml2
|
require neutron::plugins::ml2
|
||||||
|
|
||||||
if (($ansible_ssh_pass == undef and $ansible_ssh_private_key_file == undef) or
|
if ((is_service_default($ansible_ssh_pass) and is_service_default($ansible_ssh_private_key_file)) or
|
||||||
($ansible_ssh_pass != undef and $ansible_ssh_private_key_file != undef)) {
|
(!is_service_default($ansible_ssh_pass) and !is_service_default($ansible_ssh_private_key_file))) {
|
||||||
fail('One of ansible_ssh_pass OR ansible_ssh_private_key_file should be set')
|
fail('One of ansible_ssh_pass OR ansible_ssh_private_key_file should be set')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,22 +3,22 @@ require 'spec_helper'
|
|||||||
describe 'neutron::plugins::ml2::networking_ansible' do
|
describe 'neutron::plugins::ml2::networking_ansible' do
|
||||||
let :default_params do
|
let :default_params do
|
||||||
{
|
{
|
||||||
:package_ensure => 'present',
|
:package_ensure => 'present',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
let :params do
|
let :params do
|
||||||
{ :host_configs => {
|
{ :host_configs => {
|
||||||
'host1' => { 'ansible_network_os' => 'junos',
|
'host1' => { 'ansible_network_os' => 'junos',
|
||||||
'ansible_host' => '10.0.0.1',
|
'ansible_host' => '192.0.2.1',
|
||||||
'ansible_user' => 'ansible',
|
'ansible_user' => 'ansible',
|
||||||
'ansible_ssh_pass' => 'password1' },
|
'ansible_ssh_pass' => 'password1' },
|
||||||
'host2' => { 'ansible_network_os' => 'junos',
|
'host2' => { 'ansible_network_os' => 'junos',
|
||||||
'ansible_host' => '10.0.0.1',
|
'ansible_host' => '192.0.2.1',
|
||||||
'ansible_user' => 'ansible',
|
'ansible_user' => 'ansible',
|
||||||
'ansible_ssh_private_key_file' => '/path/to/key',
|
'ansible_ssh_private_key_file' => '/path/to/key',
|
||||||
'mac' => '01:23:45:67:89:AB',
|
'mac' => '01:23:45:67:89:AB',
|
||||||
'manage_vlans' => false},},
|
'manage_vlans' => false},},
|
||||||
:coordination_uri => 'etcd://127.0.0.1:2379'
|
:coordination_uri => 'etcd://127.0.0.1:2379'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -54,15 +54,15 @@ describe 'neutron::plugins::ml2::networking_ansible' do
|
|||||||
should contain_neutron__plugins__ml2__networking_ansible_host(host_config.first)
|
should contain_neutron__plugins__ml2__networking_ansible_host(host_config.first)
|
||||||
|
|
||||||
should contain_neutron_plugin_ml2('ansible:host1/ansible_ssh_pass').with_value('password1')
|
should contain_neutron_plugin_ml2('ansible:host1/ansible_ssh_pass').with_value('password1')
|
||||||
should contain_neutron_plugin_ml2('ansible:host1/ansible_ssh_private_key_file').with_value(nil)
|
should contain_neutron_plugin_ml2('ansible:host1/ansible_ssh_private_key_file').with_value('<SERVICE DEFAULT>')
|
||||||
|
|
||||||
should contain_neutron_plugin_ml2('ansible:host2/ansible_ssh_private_key_file').with_value('/path/to/key')
|
should contain_neutron_plugin_ml2('ansible:host2/ansible_ssh_private_key_file').with_value('/path/to/key')
|
||||||
should contain_neutron_plugin_ml2('ansible:host2/ansible_ssh_pass').with_value(nil)
|
should contain_neutron_plugin_ml2('ansible:host2/ansible_ssh_pass').with_value('<SERVICE DEFAULT>')
|
||||||
|
|
||||||
should contain_neutron_plugin_ml2('ansible:host1/mac').with_value(nil)
|
should contain_neutron_plugin_ml2('ansible:host1/mac').with_value('<SERVICE DEFAULT>')
|
||||||
should contain_neutron_plugin_ml2('ansible:host2/mac').with_value('01:23:45:67:89:AB')
|
should contain_neutron_plugin_ml2('ansible:host2/mac').with_value('01:23:45:67:89:AB')
|
||||||
|
|
||||||
should contain_neutron_plugin_ml2('ansible:host1/manage_vlans').with_value(nil)
|
should contain_neutron_plugin_ml2('ansible:host1/manage_vlans').with_value('<SERVICE DEFAULT>')
|
||||||
should contain_neutron_plugin_ml2('ansible:host2/manage_vlans').with_value(false)
|
should contain_neutron_plugin_ml2('ansible:host2/manage_vlans').with_value(false)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
121
spec/defines/neutron_plugins_ml2_networking_ansible_host_spec.rb
Normal file
121
spec/defines/neutron_plugins_ml2_networking_ansible_host_spec.rb
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'neutron::plugins::ml2::networking_ansible_host' do
|
||||||
|
let (:title) do
|
||||||
|
'myhostname'
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples 'neutron::plugins::ml2::networking_ansible_host' do
|
||||||
|
let :params do
|
||||||
|
{
|
||||||
|
:ansible_network_os => 'openvswitch',
|
||||||
|
:ansible_host => '192.0.2.10',
|
||||||
|
:ansible_user => 'neutron',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'without credential' do
|
||||||
|
it { should raise_error(Puppet::Error) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with both ssh pass and ssh key file set' do
|
||||||
|
before do
|
||||||
|
params.merge!({
|
||||||
|
:ansible_ssh_pass => 'secrete',
|
||||||
|
:ansible_ssh_private_key_file => '/var/lib/neutron/.ssh/id_rsa',
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
it { should raise_error(Puppet::Error) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with ssh pass' do
|
||||||
|
before do
|
||||||
|
params.merge!({
|
||||||
|
:ansible_ssh_pass => 'secrete'
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'configures the host' do
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_network_os')\
|
||||||
|
.with_value('openvswitch')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_host')\
|
||||||
|
.with_value('192.0.2.10')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_user')\
|
||||||
|
.with_value('neutron')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_ssh_pass')\
|
||||||
|
.with_value('secrete').with_secret(true)
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_ssh_private_key_file')\
|
||||||
|
.with_value('<SERVICE DEFAULT>')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/mac')\
|
||||||
|
.with_value('<SERVICE DEFAULT>')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/manage_vlans')\
|
||||||
|
.with_value('<SERVICE DEFAULT>')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with ssh key file' do
|
||||||
|
before do
|
||||||
|
params.merge!({
|
||||||
|
:ansible_ssh_private_key_file => '/var/lib/neutron/.ssh/id_rsa'
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'configures the host' do
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_network_os')\
|
||||||
|
.with_value('openvswitch')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_host')\
|
||||||
|
.with_value('192.0.2.10')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_user')\
|
||||||
|
.with_value('neutron')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_ssh_pass')\
|
||||||
|
.with_value('<SERVICE DEFAULT>').with_secret(true)
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_ssh_private_key_file')\
|
||||||
|
.with_value('/var/lib/neutron/.ssh/id_rsa')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/mac')\
|
||||||
|
.with_value('<SERVICE DEFAULT>')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/manage_vlans')\
|
||||||
|
.with_value('<SERVICE DEFAULT>')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with parameters' do
|
||||||
|
before do
|
||||||
|
params.merge!({
|
||||||
|
:ansible_ssh_pass => 'secrete',
|
||||||
|
:mac => '00:00:5e:00:53:01',
|
||||||
|
:manage_vlans => false,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'configures the host' do
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_network_os')\
|
||||||
|
.with_value('openvswitch')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_host')\
|
||||||
|
.with_value('192.0.2.10')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_user')\
|
||||||
|
.with_value('neutron')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_ssh_pass')\
|
||||||
|
.with_value('secrete').with_secret(true)
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/ansible_ssh_private_key_file')\
|
||||||
|
.with_value('<SERVICE DEFAULT>')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/mac')\
|
||||||
|
.with_value('00:00:5e:00:53:01')
|
||||||
|
is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/manage_vlans')\
|
||||||
|
.with_value(false)
|
||||||
|
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 'neutron::plugins::ml2::networking_ansible_host'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user