diff --git a/manifests/params.pp b/manifests/params.pp index c41090086..8aa08dfc9 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -89,6 +89,7 @@ class neutron::params { $networking_baremetal_package = 'python2-networking-baremetal' $networking_baremetal_agent_package = 'python2-ironic-neutron-agent' $networking_baremetal_agent_service = 'ironic-neutron-agent' + $networking_ansible_package = 'python2-networking-ansible' } elsif($::osfamily == 'Debian') { $nobody_user_group = 'nogroup' $package_name = 'neutron-common' diff --git a/manifests/plugins/ml2/networking_ansible.pp b/manifests/plugins/ml2/networking_ansible.pp new file mode 100644 index 000000000..dff4a3afe --- /dev/null +++ b/manifests/plugins/ml2/networking_ansible.pp @@ -0,0 +1,48 @@ +# == Class: neutron::plugins::ml2::networking_ansible +# +# Configures the networking-ansible ML2 Mechanism Driver +# +# === Parameters +# +# [*host_configs*] +# (required) Network devices and their configurations +# Hash Format: +# +# { +# => {"ansible_network_os" => "junos", +# "ansible_host" => "10.0.0.1", +# "ansible_user" => 'ansible', +# "ansible_ssh_pass" => "***"}, +# => {"ansible_network_os" => "junos", +# "ansible_host" => "10.0.0.2", +# "ansible_user" => 'ansible', +# "ansible_ssh_pass" => "***"}, +# } +# +# [*package_ensure*] +# (optional) The intended state of the python-networking-ansible +# package, i.e. any of the possible values of the 'ensure' +# property for a package resource type. +# Defaults to 'present' +# +class neutron::plugins::ml2::networking_ansible( + $host_configs, + $package_ensure = 'present', + ) { + include ::neutron::deps + include ::neutron::params + require ::neutron::plugins::ml2 + + if($::osfamily != 'RedHat') { + # Drivers are only packaged for RedHat at this time + fail("Unsupported osfamily ${::osfamily}") + } + + ensure_resource('package', 'python2-networking-ansible', + { + ensure => $package_ensure, + tag => ['openstack', 'neutron-package'] + } + ) + create_resources(neutron::plugins::ml2::networking_ansible_host, $host_configs) +} diff --git a/manifests/plugins/ml2/networking_ansible_host.pp b/manifests/plugins/ml2/networking_ansible_host.pp new file mode 100644 index 000000000..c84de17d0 --- /dev/null +++ b/manifests/plugins/ml2/networking_ansible_host.pp @@ -0,0 +1,39 @@ +# Defined type for networking-ansible configuration for a host/switch +# +# == Class: neutron::plugins::ml2::networking_ansible_host +# +# === Parameters +# +# [*ansible_network_os*] +# (required) Operating system of the network device +# +# [*ansible_host*] +# (required) IP Address of the network device +# +# [*ansible_user*] +# (required) Username to connect to the network device +# +# [*ansible_ssh_pass*] +# (required) SSH password to connect to the network device +# +# [*hostname*] +# (required) The hostname of a host connected to the switch. +# +define neutron::plugins::ml2::networking_ansible_host( + $ansible_network_os, + $ansible_host, + $ansible_user, + $ansible_ssh_pass, + $hostname = $title, + ) { + include ::neutron::deps + require ::neutron::plugins::ml2 + + $section = "ansible:${hostname}" + neutron_plugin_ml2 { + "${section}/ansible_network_os": value => $ansible_network_os; + "${section}/ansible_host": value => $ansible_host; + "${section}/ansible_user": value => $ansible_user; + "${section}/ansible_ssh_pass": value => $ansible_ssh_pass, secret => true; + } +} diff --git a/releasenotes/notes/networking-ansible-ml2-plugin-a2889e2a81e1afb2.yaml b/releasenotes/notes/networking-ansible-ml2-plugin-a2889e2a81e1afb2.yaml new file mode 100644 index 000000000..674ec25e4 --- /dev/null +++ b/releasenotes/notes/networking-ansible-ml2-plugin-a2889e2a81e1afb2.yaml @@ -0,0 +1,3 @@ +--- +features: + - Added support for networking-ansible ML2 plugin. diff --git a/spec/classes/neutron_plugins_ml2_networking_ansible_spec.rb b/spec/classes/neutron_plugins_ml2_networking_ansible_spec.rb new file mode 100644 index 000000000..770355d82 --- /dev/null +++ b/spec/classes/neutron_plugins_ml2_networking_ansible_spec.rb @@ -0,0 +1,75 @@ +require 'spec_helper' + +describe 'neutron::plugins::ml2::networking_ansible' do + let :default_params do + { :package_ensure => 'present', + } + end + + let :test_facts do + { :operatingsystem => 'default', + :operatingsystemrelease => 'default' + } + 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_ssh_pass' => 'password2'},} + } + end + + shared_examples_for 'networking-ansible ml2 plugin' do + let :p do + default_params.merge(params) + end + + it { is_expected.to contain_class('neutron::params') } + + it 'installs networking-ansible python2-networking-ansible package' do + is_expected.to contain_package('python2-networking-ansible').with( + :name => platform_params[:networking_ansible_package], + :ensure => p[:package_ensure], + :tag => ['openstack', 'neutron-package'], + ) + is_expected.to contain_package('python2-networking-ansible').that_requires('Anchor[neutron::install::begin]') + is_expected.to contain_package('python2-networking-ansible').that_notifies('Anchor[neutron::install::end]') + end + it { + params[:host_configs].each do |host_config| + is_expected.to contain_neutron__plugins__ml2__networking_ansible_host(host_config.first) + 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 + let (:platform_params) do + case facts[:osfamily] + when 'RedHat' + { :networking_ansible_package => 'python2-networking-ansible'} + end + end + case facts[:osfamily] + when 'RedHat' + it_behaves_like 'networking-ansible ml2 plugin' + when facts[:osfamily] != 'RedHat' + it 'fails with unsupported osfamily' do + is_expected.to raise_error(Puppet::Error, /Unsupported osfamily.*/) + end + end + end + end + +end