From 9326e4237f4d161f297dc4493ab4928ea6e2bf0f Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Mon, 7 Nov 2016 19:22:21 -0500 Subject: Initial Commit. Change-Id: I212ec4be42357edddd931e9e479e33131ccd4bac Signed-off-by: Feng Pan --- spec/acceptance/fdio_spec.rb | 51 ++++++++++++ spec/acceptance/honeycomb_spec.rb | 33 ++++++++ spec/acceptance/nodesets/centos-70-x64.yml | 11 +++ spec/acceptance/nodesets/default.yml | 10 +++ spec/acceptance/nodesets/nodepool-centos7.yml | 10 +++ spec/acceptance/nodesets/nodepool-trusty.yml | 10 +++ spec/acceptance/nodesets/nodepool-xenial.yml | 10 +++ .../acceptance/nodesets/ubuntu-server-1404-x64.yml | 11 +++ spec/classes/fdio_spec.rb | 95 ++++++++++++++++++++++ spec/classes/honeycomb_spec.rb | 32 ++++++++ spec/shared_examples.rb | 5 ++ spec/spec_helper.rb | 10 +++ spec/spec_helper_acceptance.rb | 1 + spec/unit/provider/vpp_service/vpp_spec.rb | 46 +++++++++++ spec/unit/type/vpp_service_spec.rb | 56 +++++++++++++ 15 files changed, 391 insertions(+) create mode 100644 spec/acceptance/fdio_spec.rb create mode 100644 spec/acceptance/honeycomb_spec.rb create mode 100644 spec/acceptance/nodesets/centos-70-x64.yml create mode 100644 spec/acceptance/nodesets/default.yml create mode 100644 spec/acceptance/nodesets/nodepool-centos7.yml create mode 100644 spec/acceptance/nodesets/nodepool-trusty.yml create mode 100644 spec/acceptance/nodesets/nodepool-xenial.yml create mode 100644 spec/acceptance/nodesets/ubuntu-server-1404-x64.yml create mode 100644 spec/classes/fdio_spec.rb create mode 100644 spec/classes/honeycomb_spec.rb create mode 100644 spec/shared_examples.rb create mode 100644 spec/spec_helper.rb create mode 100644 spec/spec_helper_acceptance.rb create mode 100644 spec/unit/provider/vpp_service/vpp_spec.rb create mode 100644 spec/unit/type/vpp_service_spec.rb (limited to 'spec') diff --git a/spec/acceptance/fdio_spec.rb b/spec/acceptance/fdio_spec.rb new file mode 100644 index 0000000..5c30de1 --- /dev/null +++ b/spec/acceptance/fdio_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper_acceptance' + +describe 'fdio' do + + context 'default parameters' do + + it 'should work with no errors' do + pp= <<-EOS + class { '::fdio': } + EOS + + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + describe package('vpp') do + it { should be_installed } + end + + describe file('/etc/vpp/startup.conf') do + it { is_expected.to exist } + its(:content) { should match /uio-driver\s+uio_pci_generic/ } + its(:content) { should_not match /dev/ } + end + + describe service('vpp') do + it { should be_running } + it { should be_enabled } + end + end + + context 'pinning' do + it 'should work with no errors' do + pp= <<-EOS + class { '::fdio': + vpp_cpu_main_core => '1', + vpp_cpu_corelist_workers => '2', + } + EOS + + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + describe file('/etc/vpp/startup.conf') do + its(:content) { should match /main-core\s+1/ } + its(:content) { should match /corelist-workers\s+2/ } + end + + end +end diff --git a/spec/acceptance/honeycomb_spec.rb b/spec/acceptance/honeycomb_spec.rb new file mode 100644 index 0000000..426d3b9 --- /dev/null +++ b/spec/acceptance/honeycomb_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper_acceptance' + +describe 'fdio::honeycomb' do + + describe 'default parameters' do + it 'should work with no errors' do + pp= <<-EOS + class { '::fdio::honeycomb': } + EOS + + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + describe package('honeycomb') do + it { should be_installed } + end + + describe file('/opt/honeycomb/config/honeycomb.json') do + it { is_expected.to exist } + its(:content) { should match /"restconf-port":\s+8181/ } + its(:content) { should match /"restconf-websocket-port":\s+7779/ } + its(:content) { should match /"username":\s+"admin"/} + its(:content) { should match /"password":\s+"admin"/} + end + + describe service('honeycomb') do + it { should be_running } + it { should be_enabled } + end + end + +end \ No newline at end of file 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..486b6a3 --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1,10 @@ +HOSTS: + ubuntu-server-14.04-amd64: + 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: + type: foss 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..9fc624e --- /dev/null +++ b/spec/acceptance/nodesets/nodepool-trusty.yml @@ -0,0 +1,10 @@ +HOSTS: + ubuntu-14.04-amd64: + 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/nodepool-xenial.yml b/spec/acceptance/nodesets/nodepool-xenial.yml new file mode 100644 index 0000000..99dd318 --- /dev/null +++ b/spec/acceptance/nodesets/nodepool-xenial.yml @@ -0,0 +1,10 @@ +HOSTS: + ubuntu-16.04-amd64: + roles: + - master + platform: ubuntu-16.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..8001929 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + ubuntu-server-14.04-amd64: + 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: foss diff --git a/spec/classes/fdio_spec.rb b/spec/classes/fdio_spec.rb new file mode 100644 index 0000000..0cc065a --- /dev/null +++ b/spec/classes/fdio_spec.rb @@ -0,0 +1,95 @@ +require 'spec_helper' + +describe 'fdio' do + + shared_examples_for 'fdio - default' do + it { should compile } + it { should compile.with_all_deps } + + # Confirm presence of classes + it { should contain_class('fdio') } + it { should contain_class('fdio::params') } + it { should contain_class('fdio::install') } + it { should contain_class('fdio::config') } + it { should contain_class('fdio::service') } + + # Confirm relationships between classes + it { should contain_class('fdio::install').that_comes_before('Class[fdio::config]') } + it { should contain_class('fdio::config').that_requires('Class[fdio::install]') } + it { should contain_class('fdio::config').that_notifies('Class[fdio::service]') } + it { should contain_class('fdio::service').that_subscribes_to('Class[fdio::config]') } + it { should contain_class('fdio::service').that_comes_before('Class[fdio]') } + it { should contain_class('fdio').that_requires('Class[fdio::service]') } + end + + shared_examples_for 'fdio - rpm' do + it { + should contain_yumrepo('fdio-release').with( + 'baseurl' => 'https://nexus.fd.io/content/repositories/fd.io.centos7/', + 'enabled' => 1, + ) + } + it { should contain_package('vpp').that_requires('Yumrepo[fdio-release]') } + + context 'with stable 16.09 branch' do + let(:params) {{:repo_branch => 'stable.1609'}} + + it { + should contain_yumrepo('fdio-stable.1609').with( + 'baseurl' => 'https://nexus.fd.io/content/repositories/fd.io.stable.1609.centos7/', + 'enabled' => 1, + ) + } + it { should contain_package('vpp').that_requires('Yumrepo[fdio-stable.1609]') } + end + end + + shared_examples_for 'fdio - config' do + it { + should contain_file('/etc/vpp/startup.conf').with( + 'path' => '/etc/vpp/startup.conf', + ) + } + it { + should contain_exec('insert_dpdk_kmod').with( + 'command' => 'modprobe uio_pci_generic', + 'unless' => 'lsmod | grep uio_pci_generic', + ) + } + end + + shared_examples_for 'fdio - service' do + it { + should contain_vpp_service('vpp').with( + 'ensure' => 'present', + 'pci_devs' => [], + 'state' => 'up', + ) + } + + context 'with pci dev' do + let(:params) {{:vpp_dpdk_devs => ['0000:00:07.0']}} + + it { + should contain_vpp_service('vpp').with( + 'ensure' => 'present', + 'pci_devs' => ['0000:00:07.0'], + 'state' => 'up', + ) + } + end + end + + context 'on RedHat platforms' do + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystem => 'CentOS', + :operatingsystemmajrelease => '7', + }} + + it_configures 'fdio - default' + it_configures 'fdio - rpm' + it_configures 'fdio - config' + it_configures 'fdio - service' + end +end \ No newline at end of file diff --git a/spec/classes/honeycomb_spec.rb b/spec/classes/honeycomb_spec.rb new file mode 100644 index 0000000..8ba367a --- /dev/null +++ b/spec/classes/honeycomb_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe 'fdio::honeycomb' do + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystem => 'CentOS', + :operatingsystemmajrelease => '7', + }} + + it { should compile } + it { should compile.with_all_deps } + it { should contain_class('fdio::honeycomb') } + it { should contain_class('fdio::install').that_comes_before('Class[fdio::config]') } + it { should contain_package('honeycomb').that_requires('Package[vpp]') } + it { should contain_file('honeycomb.json').that_requires('Package[honeycomb]') } + it { should contain_file('honeycomb.json').that_notifies('Service[honeycomb]') } + it { should contain_service('honeycomb').that_requires('Package[honeycomb]') } + it { should contain_service('honeycomb').that_requires('Vpp_service[vpp]') } + + it { should contain_file('honeycomb.json').with( + 'ensure' => 'file', + 'path' => '/opt/honeycomb/config/honeycomb.json', + 'owner' => 'honeycomb', + 'group' => 'honeycomb', + ) + } + it { should contain_service('honeycomb').with( + 'ensure' => 'running', + 'enable' => 'true', + ) + } +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..cad00b1 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,10 @@ +require 'puppetlabs_spec_helper/module_spec_helper' +require 'shared_examples' +require 'puppet-openstack_spec_helper/facts' + +RSpec.configure do |c| + c.alias_it_should_behave_like_to :it_configures, 'configures' + c.alias_it_should_behave_like_to :it_raises, 'raises' +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..9196bc9 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1 @@ +require 'puppet-openstack_spec_helper/beaker_spec_helper' diff --git a/spec/unit/provider/vpp_service/vpp_spec.rb b/spec/unit/provider/vpp_service/vpp_spec.rb new file mode 100644 index 0000000..1d9d9ba --- /dev/null +++ b/spec/unit/provider/vpp_service/vpp_spec.rb @@ -0,0 +1,46 @@ +require 'puppet' +require 'puppet/provider/vpp_service/vpp' +require 'spec_helper' + +provider_class = Puppet::Type.type(:vpp_service).provider(:vpp) + +describe 'Puppet::Type.type(:vpp_service).provider(:vpp)' do + + let :vpp_attrs do + { + :name => 'vpp service config', + :pci_devs => '0000:00:07.0', + :ensure => 'present', + :state => 'up', + :copy_kernel_nic_ip => 'false', + } + end + + let :resource do + Puppet::Type::Vpp_service.new(vpp_attrs) + end + + let :provider do + provider_class.new(resource) + end + + describe 'on create' do + it 'should call service restart' do + provider.expects(:vpp_pre_config) + provider.expects(:configure_vpp_interfaces) + provider.expects(:systemctlcmd).with('restart', 'vpp') + provider.expects(:systemctlcmd).with('enable', 'vpp') + provider.expects(:systemctlcmd).with('is-enabled', 'vpp') + provider.expects(:systemctlcmd).with('is-active', 'vpp') + provider.create + end + end + + describe "when changing state" do + it 'should change state' do + provider.stubs(:get_int_prefix).returns('GigabitEthernet0/7/0') + provider.expects(:vppctlcmd).with('set int state', 'GigabitEthernet0/7/0', 'down') + provider.state = 'down' + end + end +end \ No newline at end of file diff --git a/spec/unit/type/vpp_service_spec.rb b/spec/unit/type/vpp_service_spec.rb new file mode 100644 index 0000000..9b08ffa --- /dev/null +++ b/spec/unit/type/vpp_service_spec.rb @@ -0,0 +1,56 @@ +require 'puppet' +require 'puppet/type/vpp_service' +require 'spec_helper' + +describe 'Puppet::Type.type(:neutron_config)' do + + before :each do + @vpp_service = Puppet::Type.type(:vpp_service).new(:name => 'vpp service config') + end + + it 'should have default values' do + expect(@vpp_service[:state]).to eq(:up) + expect(@vpp_service[:copy_kernel_nic_ip]).to eq(:true) + end + + it 'should accept a single pci dev' do + Puppet::Type.type(:vpp_service).new(:name => 'vpp service config', :pci_devs => '0000:00:07.0') + end + + it 'should accept array of pci devs' do + Puppet::Type.type(:vpp_service).new(:name => 'vpp service config', :pci_devs => ['0000:00:07.0', '0000:00:08.0']) + end + + it 'should not accept invalid pci dev format' do + expect { + Puppet::Type.type(:vpp_service).new(:name => 'vpp service config', :pci_devs => ['0/7/0', '0000:00:08.0']) + }.to raise_error(Puppet::Error, /Incorrect PCI dev address/) + end + + it 'should accept valid states' do + @vpp_service[:state] = :up + expect(@vpp_service[:state]).to eq(:up) + @vpp_service[:state] = :down + expect(@vpp_service[:state]).to eq(:down) + end + + it 'should not accept invalid state' do + expect { + @vpp_service[:state] = :shut + }.to raise_error(Puppet::Error, /Invalid value/) + end + + it 'should accept valid copy_kernel_nic_ip' do + @vpp_service[:copy_kernel_nic_ip] = :true + expect(@vpp_service[:copy_kernel_nic_ip]).to eq(:true) + @vpp_service[:copy_kernel_nic_ip] = :false + expect(@vpp_service[:copy_kernel_nic_ip]).to eq(:false) + end + + it 'should not accept invalid copy_kernel_nic_ip' do + expect { + @vpp_service[:copy_kernel_nic_ip] = :yes + }.to raise_error(Puppet::Error, /Invalid value/) + end + +end -- cgit 1.2.3-korg