diff --git a/README.md b/README.md index 805e72c60..b1db9f1bf 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,7 @@ This module supports the following neutron plugins: * Open vSwitch with ML2 * linuxbridge with ML2 +* Arista with ML2 * cisco-neutron with and without ML2 * NVP * PLUMgrid diff --git a/manifests/plugins/ml2/arista.pp b/manifests/plugins/ml2/arista.pp new file mode 100644 index 000000000..37ddca863 --- /dev/null +++ b/manifests/plugins/ml2/arista.pp @@ -0,0 +1,64 @@ +# +# Copyright (C) 2016 Matthew J. Black +# +# Author: Matthew J. Black +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# == Class: neutron::plugins::ml2::arista +# +# === Parameters +# +# [*eapi_host*] +# (required) The Arista EOS IP address. +# +# [*eapi_username*] +# (required) The Arista EOS api username. +# +# [*eapi_password*] +# (required) The Arista EOS api password. +# +# [*region_name*] +# (optional) Region name that is assigned to the OpenStack controller. +# This setting must be set if multiple regions are using the same Arista +# hardware. +# Defaults to $::os_service_default +# +# [*sync_interval*] +# (optional) Sync interval in seconds between neutron plugin and EOS. +# Defaults to $::os_service_default +# +# [*use_fqdn*] +# (optional) Defines if hostnames are sent to Arista EOS as FQDNS +# Defaults to $::os_service_default +# +class neutron::plugins::ml2::arista( + $eapi_host, + $eapi_username, + $eapi_password, + $region_name = $::os_service_default, + $sync_interval = $::os_service_default, + $use_fqdn = $::os_service_default, + +) { + require ::neutron::plugins::ml2 + + neutron_plugin_ml2 { + 'ml2_arista/eapi_host' : value => $eapi_host; + 'ml2_arista/eapi_username': value => $eapi_username; + 'ml2_arista/eapi_password': value => $eapi_password; + 'ml2_arista/region_name' : value => $region_name; + 'ml2_arista/sync_interval': value => $sync_interval; + 'ml2_arista/use_fqdn' : value => $use_fqdn; + } +} diff --git a/manifests/plugins/ml2/arista/l3.pp b/manifests/plugins/ml2/arista/l3.pp new file mode 100644 index 000000000..f920fe761 --- /dev/null +++ b/manifests/plugins/ml2/arista/l3.pp @@ -0,0 +1,77 @@ +# +# Copyright (C) 2016 Matthew J. Black +# +# Author: Matthew J. Black +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# == Class: neutron::plugins::ml2::arista::l3_arista +# +# === Parameters +# +# [*primary_l3_host*] +# (required) The Arista EOS IP address. +# +# [*primary_l3_host_username*] +# (required) The Arista EOS username. +# +# [*primary_l3_host_password*] +# (required) The Arista EOS password. +# +# [*secondary_l3_host*] +# (optional) The Arist EOS IP address for second switch MLAGed +# with the first one. Only required if $mlag_config is set to true. +# Defaults to $::os_service_default +# +# [*mlag_config*] +# (optional) Indicates that the switch is in MLAG mode. +# Defaults to $::os_service_default +# +# [*l3_sync_interval*] +# (optional) Sync interval in seconds between l3 service plugin and +# the EOS. +# Defaults to $::os_service_default +# +# [*use_vrf*] +# (optional) If it should create a router in VRF. +# Defaults to $::os_service_default +# +class neutron::plugins::ml2::arista::l3( + $primary_l3_host, + $primary_l3_host_username, + $primary_l3_host_password, + $secondary_l3_host = $::os_service_default, + $mlag_config = $::os_service_default, + $l3_sync_interval = $::os_service_default, + $use_vrf = $::os_service_default + +) { + require ::neutron::plugins::ml2 + + if !is_service_default($mlag_config) { + validate_bool($mlag_config) + if $mlag_config and is_service_default($secondary_l3_host) { + fail('Must set secondary_l3_host when mlag_config is true.') + } + } + + neutron_plugin_ml2 { + 'l3_arista/primary_l3_host' : value => $primary_l3_host; + 'l3_arista/primary_l3_host_username': value => $primary_l3_host_username; + 'l3_arista/primary_l3_host_password': value => $primary_l3_host_password; + 'l3_arista/secondary_l3_host' : value => $secondary_l3_host; + 'l3_arista/mlag_config' : value => $mlag_config; + 'l3_arista/l3_sync_interval' : value => $l3_sync_interval; + 'l3_arista/use_vrf' : value => $use_vrf; + } +} diff --git a/releasenotes/notes/added_arista_ml2_plugin-8bfd0c41981dac50.yaml b/releasenotes/notes/added_arista_ml2_plugin-8bfd0c41981dac50.yaml new file mode 100644 index 000000000..cad0fa89a --- /dev/null +++ b/releasenotes/notes/added_arista_ml2_plugin-8bfd0c41981dac50.yaml @@ -0,0 +1,6 @@ +--- +features: + - Added neutron::plugins::ml2::arista class to manage the arista + ml2 driver. + - Added neutron::plugins::ml2::arista::l3_arista class to manage + the arista ml2 l3 plugin. diff --git a/spec/classes/neutron_plugins_ml2_arista_l3_spec.rb b/spec/classes/neutron_plugins_ml2_arista_l3_spec.rb new file mode 100644 index 000000000..78ff45d0c --- /dev/null +++ b/spec/classes/neutron_plugins_ml2_arista_l3_spec.rb @@ -0,0 +1,87 @@ +# +# Copyright (C) 2016 Matthew J. Black +# +# Author: Matthew J. Black +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# Unit tests for neutron::plugins::ml2::arista::l3 class +# +require 'spec_helper' + +describe 'neutron::plugins::ml2::arista::l3' do + + let :pre_condition do + "class { 'neutron::server': auth_password => 'password'} + class { 'neutron': + rabbit_password => 'passw0rd', + core_plugin => 'neutron.plugins.ml2.plugin.Ml2Plugin' }" + end + + let :default_params do + { + :secondary_l3_host => '', + :mlag_config => '', + :l3_sync_interval => '', + :use_vrf => '' + } + end + + let :params do + { :primary_l3_host => '127.0.0.1', + :primary_l3_host_username => 'neutron', + :primary_l3_host_password => 'passw0rd', + } + end + + shared_examples_for 'neutron plugin ml2 arista l3_arista' do + before do + params.merge!(default_params) + end + + it 'configures ml2 arista l3_arista settings' do + is_expected.to contain_neutron_plugin_ml2('l3_arista/primary_l3_host').with_value(params[:primary_l3_host]) + is_expected.to contain_neutron_plugin_ml2('l3_arista/primary_l3_host_username').with_value(params[:primary_l3_host_username]) + is_expected.to contain_neutron_plugin_ml2('l3_arista/primary_l3_host_password').with_value(params[:primary_l3_host_password]) + end + end + + shared_examples_for 'ml2 l3_arista should fail when mlag is true and secondary is service default' do + let :params do + {} + end + + before do + params.merge!(default_params) + params[:mlag_config] = true + end + + it 'should fail when mlag is true and secondary l3 host is service default' do + is_expected.to raise_error(Puppet::Error, /Must set secondary_l3_host when mlag_config is true./) + 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_configures 'neutron plugin ml2 arista l3_arista' + end + end +end diff --git a/spec/classes/neutron_plugins_ml2_arista_spec.rb b/spec/classes/neutron_plugins_ml2_arista_spec.rb new file mode 100644 index 000000000..8767ef40c --- /dev/null +++ b/spec/classes/neutron_plugins_ml2_arista_spec.rb @@ -0,0 +1,71 @@ +# +# Copyright (C) 2016 Matthew J. Black +# +# Author: Matthew J. Black +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# Unit tests for neutron::plugins::ml2::arista class +# +require 'spec_helper' + +describe 'neutron::plugins::ml2::arista' do + + let :pre_condition do + "class { 'neutron::server': auth_password => 'password'} + class { 'neutron': + rabbit_password => 'passw0rd', + core_plugin => 'neutron.plugins.ml2.plugin.Ml2Plugin' }" + end + + let :default_params do + { + :region_name => '', + :sync_interval => '', + :use_fqdn => '' + } + end + + let :params do + { :eapi_host => '127.0.0.1', + :eapi_username => 'neutron', + :eapi_password => 'passw0rd' + } + end + + shared_examples_for 'neutron plugin ml2 arista' do + before do + params.merge!(default_params) + end + + it 'configures ml2 arista settings' do + is_expected.to contain_neutron_plugin_ml2('ml2_arista/eapi_host').with_value(params[:eapi_host]) + is_expected.to contain_neutron_plugin_ml2('ml2_arista/eapi_username').with_value(params[:eapi_username]) + is_expected.to contain_neutron_plugin_ml2('ml2_arista/eapi_password').with_value(params[:eapi_password]) + 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_configures 'neutron plugin ml2 arista' + end + end +end