diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..d54b7e6 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,5 @@ +fixtures: + repositories: + 'stdlib': 'git://github.com/puppetlabs/puppetlabs-stdlib.git' + symlinks: + "n1k_vsm": "#{source_dir}" diff --git a/Gemfile b/Gemfile index 8de9716..6d4ce9a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,30 @@ -source 'https://rubygems.org' +source ENV['GEM_SOURCE'] || "https://rubygems.org" group :development, :test do - gem 'puppetlabs_spec_helper', :require => false - gem 'puppet-lint', '~> 0.3.2' + gem 'puppetlabs_spec_helper', :require => 'false' + gem 'rspec-puppet', '~> 2.2.0', :require => 'false' + gem 'metadata-json-lint', :require => 'false' + gem 'puppet-lint-param-docs', :require => 'false' + gem 'puppet-lint-absolute_classname-check', :require => 'false' + gem 'puppet-lint-absolute_template_path', :require => 'false' + gem 'puppet-lint-trailing_newline-check', :require => 'false' + gem 'puppet-lint-unquoted_string-check', :require => 'false' + gem 'puppet-lint-leading_zero-check', :require => 'false' + gem 'puppet-lint-variable_contains_upcase', :require => 'false' + gem 'puppet-lint-numericvariable', :require => 'false' + gem 'json', :require => 'false' + gem 'webmock', :require => 'false' +end + +group :system_tests do + gem 'beaker-rspec', :require => 'false' + gem 'beaker-puppet_install_helper', :require => 'false' +end + +if facterversion = ENV['FACTER_GEM_VERSION'] + gem 'facter', facterversion, :require => false +else + gem 'facter', :require => false end if puppetversion = ENV['PUPPET_GEM_VERSION'] @@ -10,3 +32,5 @@ if puppetversion = ENV['PUPPET_GEM_VERSION'] else gem 'puppet', :require => false end + +# vim:ft=ruby diff --git a/manifests/deploy.pp b/manifests/deploy.pp index d03d68e..4427b26 100644 --- a/manifests/deploy.pp +++ b/manifests/deploy.pp @@ -5,8 +5,8 @@ # class n1k_vsm::deploy { - require n1k_vsm - include n1k_vsm + require ::n1k_vsm + include ::n1k_vsm #ensure tap interfaces and deploy the vsm $ctrltap = 'vsm-ctrl0' @@ -16,7 +16,7 @@ class n1k_vsm::deploy # Validate and get the array of digits for the vsm_mac_base (or use default) # Using _vmb as the name for the final string to increase readability $tmp_mac_base = regsubst($n1k_vsm::vsm_mac_base, '[^0-9a-fA-F]+', '') - if (inline_template('<%= @tmp_mac_base.length %>') < 7) { + if size($tmp_mac_base) < 7 { $vmb = split('005dc79', '') } else { $vmb = split($tmp_mac_base, '') diff --git a/manifests/init.pp b/manifests/init.pp index 261b30c..c6fb9b7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -109,7 +109,7 @@ class n1k_vsm( $phy_ip_addr = inline_template("<%= scope.lookupvar('::ipaddress_${_phy_if_bridge}') %>") $phy_ip_mask = inline_template("<%= scope.lookupvar('::netmask_${_phy_if_bridge}') %>") $gw_intf = $n1k_vsm::phy_gateway - include n1k_vsm::pkgprep_ovscfg + include ::n1k_vsm::pkgprep_ovscfg } notify {"Arg: intf ${phy_if_bridge} vsm_role ${vsm_role} domainid ${vsm_domain_id}" : withpath => true} @@ -117,7 +117,7 @@ class n1k_vsm( notify {"gw_dv ${gw_intf} ovs ${ovsbridge} vsmname ${n1k_vsm::vsmname}" : withpath => true} notify {"mgmtip ${n1k_vsm::mgmtip} vsm_mask ${n1k_vsm::mgmtnetmask} vsm_gw ${n1k_vsm::mgmtgateway}": withpath => false} - include n1k_vsm::vsmprep - include n1k_vsm::deploy + include ::n1k_vsm::vsmprep + include ::n1k_vsm::deploy Class['n1k_vsm::vsmprep'] -> Class['n1k_vsm::deploy'] } diff --git a/manifests/pkgprep_ovscfg.pp b/manifests/pkgprep_ovscfg.pp index 5705a3d..ec0a444 100644 --- a/manifests/pkgprep_ovscfg.pp +++ b/manifests/pkgprep_ovscfg.pp @@ -4,8 +4,8 @@ # class n1k_vsm::pkgprep_ovscfg { - require n1k_vsm - include n1k_vsm + require ::n1k_vsm + include ::n1k_vsm case $::osfamily { 'RedHat': { diff --git a/manifests/vsmprep.pp b/manifests/vsmprep.pp index 9a677bd..c5e79fc 100644 --- a/manifests/vsmprep.pp +++ b/manifests/vsmprep.pp @@ -5,9 +5,9 @@ # class n1k_vsm::vsmprep { - include 'stdlib' - require n1k_vsm - include n1k_vsm + include ::stdlib + require ::n1k_vsm + include ::n1k_vsm # prepare vsm folders ensure_resource('file', '/var/spool/cisco/', { diff --git a/spec/acceptance/nodesets/centos-70-x64.yml b/spec/acceptance/nodesets/centos-70-x64.yml new file mode 100644 index 0000000..5f097e9 --- /dev/null +++ b/spec/acceptance/nodesets/centos-70-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + centos-server-70-x64: + roles: + - master + platform: el-7-x86_64 + box: puppetlabs/centos-7.0-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/centos-7.0-64-nocm + hypervisor: vagrant +CONFIG: + log_level: debug + type: foss diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 100644 index 0000000..3bb3e62 --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1,11 @@ +HOSTS: + ubuntu-server-1404-x64: + roles: + - master + platform: ubuntu-14.04-amd64 + box: puppetlabs/ubuntu-14.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm + hypervisor: vagrant +CONFIG: + log_level: debug + type: git diff --git a/spec/acceptance/nodesets/nodepool-centos7.yml b/spec/acceptance/nodesets/nodepool-centos7.yml new file mode 100644 index 0000000..c552874 --- /dev/null +++ b/spec/acceptance/nodesets/nodepool-centos7.yml @@ -0,0 +1,10 @@ +HOSTS: + centos-70-x64: + roles: + - master + platform: el-7-x86_64 + hypervisor: none + ip: 127.0.0.1 +CONFIG: + type: foss + set_env: false diff --git a/spec/acceptance/nodesets/nodepool-trusty.yml b/spec/acceptance/nodesets/nodepool-trusty.yml new file mode 100644 index 0000000..7f503ca --- /dev/null +++ b/spec/acceptance/nodesets/nodepool-trusty.yml @@ -0,0 +1,10 @@ +HOSTS: + ubuntu-1404-x64: + roles: + - master + platform: ubuntu-14.04-amd64 + hypervisor: none + ip: 127.0.0.1 +CONFIG: + type: foss + set_env: false diff --git a/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml new file mode 100644 index 0000000..3bb3e62 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + ubuntu-server-1404-x64: + roles: + - master + platform: ubuntu-14.04-amd64 + box: puppetlabs/ubuntu-14.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm + hypervisor: vagrant +CONFIG: + log_level: debug + type: git diff --git a/spec/classes/n1kv_vsm_spec.rb b/spec/classes/n1kv_vsm_spec.rb new file mode 100644 index 0000000..564802b --- /dev/null +++ b/spec/classes/n1kv_vsm_spec.rb @@ -0,0 +1,21 @@ +# +# Copyright (C) 2015 eNovance SAS +# +# 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. +# + +require 'spec_helper' + +describe 'n1k_vsm' do + +end diff --git a/spec/classes/n1kv_vsm_vsmprep_spec.rb b/spec/classes/n1kv_vsm_vsmprep_spec.rb new file mode 100644 index 0000000..09f79c2 --- /dev/null +++ b/spec/classes/n1kv_vsm_vsmprep_spec.rb @@ -0,0 +1,78 @@ +# +# Copyright (C) 2015 eNovance SAS +# +# 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. +# + +require 'spec_helper' + +describe 'n1k_vsm::vsmprep' do + + let :params do + { } + end + + shared_examples_for 'n1k vsm prep' do + + context 'with default values' do + let :pre_condition do + "class { 'n1k_vsm': + phy_gateway => '1.1.1.3', + vsm_domain_id => '1', + vsm_admin_passwd => 'secrete', + vsm_mgmt_ip => '1.1.1.1', + vsm_mgmt_netmask => '255.255.255.0', + vsm_mgmt_gateway => '1.1.1.2', + }" + end + + # Currently we always just check if VSM is present + it 'installs latest n1kv sofware' do + is_expected.to contain_package('nexus-1000v-iso').with( + :ensure => 'present', + ) + end + end + + context 'with custom values' do + let :pre_condition do + "class { 'n1k_vsm': + phy_gateway => '1.1.1.3', + vsm_domain_id => '1', + vsm_admin_passwd => 'secrete', + vsm_mgmt_ip => '1.1.1.1', + vsm_mgmt_netmask => '255.255.255.0', + vsm_mgmt_gateway => '1.1.1.2', + n1kv_version => '5.2.1.SK3.2.2a-1', + }" + end + + # Currently we always just check if VSM is present + it 'installs latest n1kv sofware' do + is_expected.to contain_package('nexus-1000v-iso').with( + :ensure => 'present', + ) + end + end + + end + + context 'on RedHat platforms' do + let :facts do + { :osfamily => 'RedHat' } + end + + it_configures 'n1k vsm prep' + end + +end diff --git a/spec/shared_examples.rb b/spec/shared_examples.rb new file mode 100644 index 0000000..fec0eac --- /dev/null +++ b/spec/shared_examples.rb @@ -0,0 +1,5 @@ +shared_examples_for "a Puppet::Error" do |description| + it "with message matching #{description.inspect}" do + expect { is_expected.to have_class_count(1) }.to raise_error(Puppet::Error, description) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..700be6a --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,19 @@ +require 'puppetlabs_spec_helper/module_spec_helper' +require 'shared_examples' +require 'webmock/rspec' + +RSpec.configure do |c| + c.alias_it_should_behave_like_to :it_configures, 'configures' + c.alias_it_should_behave_like_to :it_raises, 'raises' + + c.default_facts = { + :kernel => 'Linux', + :concat_basedir => '/var/lib/puppet/concat', + :memorysize => '1000 MB', + :processorcount => '1', + :puppetversion => '3.7.3', + :uniqueid => '123' + } +end + +at_exit { RSpec::Puppet::Coverage.report! } diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..429e807 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,56 @@ +require 'beaker-rspec' +require 'beaker/puppet_install_helper' + +run_puppet_install_helper + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + modname = JSON.parse(open('metadata.json').read)['name'].split('-')[1] + + # Readable test descriptions + c.formatter = :documentation + + # Configure all nodes in nodeset + c.before :suite do + # Install module and dependencies + hosts.each do |host| + + # install git + install_package host, 'git' + + zuul_ref = ENV['ZUUL_REF'] + zuul_branch = ENV['ZUUL_BRANCH'] + zuul_url = ENV['ZUUL_URL'] + + repo = 'openstack/puppet-openstack-integration' + + # Start out with clean moduledir, don't trust r10k to purge it + on host, "rm -rf /etc/puppet/modules/*" + # Install dependent modules via git or zuul + r = on host, "test -e /usr/zuul-env/bin/zuul-cloner", { :acceptable_exit_codes => [0,1] } + if r.exit_code == 0 + zuul_clone_cmd = '/usr/zuul-env/bin/zuul-cloner ' + zuul_clone_cmd += '--cache-dir /opt/git ' + zuul_clone_cmd += "--zuul-ref #{zuul_ref} " + zuul_clone_cmd += "--zuul-branch #{zuul_branch} " + zuul_clone_cmd += "--zuul-url #{zuul_url} " + zuul_clone_cmd += "git://git.openstack.org #{repo}" + on host, zuul_clone_cmd + else + on host, "git clone https://git.openstack.org/#{repo} #{repo}" + end + + on host, "ZUUL_REF=#{zuul_ref} ZUUL_BRANCH=#{zuul_branch} ZUUL_URL=#{zuul_url} bash #{repo}/install_modules.sh" + + # Install the module being tested + on host, "rm -fr /etc/puppet/modules/#{modname}" + puppet_module_install(:source => proj_root, :module_name => modname) + + on host, "rm -fr #{repo}" + + # List modules installed to help with debugging + on host, puppet('module','list'), { :acceptable_exit_codes => 0 } + end + end +end