diff --git a/manifests/plugins/ml2/networking_ansible_host.pp b/manifests/plugins/ml2/networking_ansible_host.pp index dfd3b99ba..97a0ad2cd 100644 --- a/manifests/plugins/ml2/networking_ansible_host.pp +++ b/manifests/plugins/ml2/networking_ansible_host.pp @@ -5,47 +5,53 @@ # === Parameters # # [*ansible_network_os*] -# (required) Operating system of the network device +# (Required) Operating system of the network device # # [*ansible_host*] -# (required) IP Address of the network device +# (Required) IP Address of the network device # # [*ansible_user*] -# (required) Username to connect to the network device +# (Required) Username to connect to the network device # # [*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 +# Defaults to $::os_service_default # # [*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 +# Defaults to $::os_service_default # # [*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*] -# Chassis MAC ID of the network device. Used to map lldp provided value -# to the hostname when using ironic introspection. +# (Optional) Chassis MAC ID of the network device. Used to map lldp provided +# value to the hostname when using ironic introspection. +# Defaults to $::os_service_default # # [*manage_vlans*] # Should networking-ansible create and delete VLANs on the device. +# Defaults to $::os_service_default # define neutron::plugins::ml2::networking_ansible_host( $ansible_network_os, $ansible_host, $ansible_user, - $ansible_ssh_pass = undef, - $ansible_ssh_private_key_file = undef, - $mac = undef, + $ansible_ssh_pass = $::os_service_default, + $ansible_ssh_private_key_file = $::os_service_default, + $mac = $::os_service_default, $hostname = $title, - $manage_vlans = undef, - ) { + $manage_vlans = $::os_service_default, +) { + include neutron::deps require neutron::plugins::ml2 - if (($ansible_ssh_pass == undef and $ansible_ssh_private_key_file == undef) or - ($ansible_ssh_pass != undef and $ansible_ssh_private_key_file != undef)) { + if ((is_service_default($ansible_ssh_pass) and is_service_default($ansible_ssh_private_key_file)) or + (!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') } diff --git a/spec/classes/neutron_plugins_ml2_networking_ansible_spec.rb b/spec/classes/neutron_plugins_ml2_networking_ansible_spec.rb index bc8fec9a4..fd39ae4c7 100644 --- a/spec/classes/neutron_plugins_ml2_networking_ansible_spec.rb +++ b/spec/classes/neutron_plugins_ml2_networking_ansible_spec.rb @@ -3,22 +3,22 @@ require 'spec_helper' describe 'neutron::plugins::ml2::networking_ansible' do let :default_params do { - :package_ensure => 'present', + :package_ensure => 'present', } end let :params do { :host_configs => { 'host1' => { 'ansible_network_os' => 'junos', - 'ansible_host' => '10.0.0.1', - 'ansible_user' => 'ansible', - 'ansible_ssh_pass' => 'password1' }, - 'host2' => { 'ansible_network_os' => 'junos', - 'ansible_host' => '10.0.0.1', - 'ansible_user' => 'ansible', + 'ansible_host' => '192.0.2.1', + 'ansible_user' => 'ansible', + 'ansible_ssh_pass' => 'password1' }, + 'host2' => { 'ansible_network_os' => 'junos', + 'ansible_host' => '192.0.2.1', + 'ansible_user' => 'ansible', 'ansible_ssh_private_key_file' => '/path/to/key', - 'mac' => '01:23:45:67:89:AB', - 'manage_vlans' => false},}, + 'mac' => '01:23:45:67:89:AB', + 'manage_vlans' => false},}, :coordination_uri => 'etcd://127.0.0.1:2379' } 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_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('') 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('') - should contain_neutron_plugin_ml2('ansible:host1/mac').with_value(nil) + should contain_neutron_plugin_ml2('ansible:host1/mac').with_value('') 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('') should contain_neutron_plugin_ml2('ansible:host2/manage_vlans').with_value(false) end } diff --git a/spec/defines/neutron_plugins_ml2_networking_ansible_host_spec.rb b/spec/defines/neutron_plugins_ml2_networking_ansible_host_spec.rb new file mode 100644 index 000000000..a24f03f44 --- /dev/null +++ b/spec/defines/neutron_plugins_ml2_networking_ansible_host_spec.rb @@ -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('') + is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/mac')\ + .with_value('') + is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/manage_vlans')\ + .with_value('') + 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('').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('') + is_expected.to contain_neutron_plugin_ml2('ansible:myhostname/manage_vlans')\ + .with_value('') + 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('') + 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