Browse Source

Added spec classes for controller and northd

changes/42/301442/1
Babu Shanmugam 6 years ago
parent
commit
5a397f2ea7
  1. 11
      .gitignore
  2. 19
      Gemfile
  3. 18
      Rakefile
  4. 11
      manifests/controller.pp
  5. 4
      manifests/northd.pp
  6. 7
      spec/classes/init_spec.rb
  7. 74
      spec/classes/ovn_controller_spec.rb
  8. 45
      spec/classes/ovn_northd_spec.rb
  9. 5
      spec/shared_examples.rb
  10. 17
      spec/spec_helper.rb
  11. 1
      spec/spec_helper_acceptance.rb

11
.gitignore

@ -0,0 +1,11 @@
pkg/
Gemfile.lock
vendor/
spec/fixtures/
.vagrant/
.bundle/
coverage/
.idea/
*.swp
*.iml
openstack/

19
Gemfile

@ -2,6 +2,19 @@ source 'https://rubygems.org'
puppetversion = ENV.key?('PUPPET_VERSION') ? "#{ENV['PUPPET_VERSION']}" : ['>= 3.3']
gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 0.8.2'
gem 'puppet-lint', '>= 1.0.0'
gem 'facter', '>= 1.7.0'
group :development, :test do
gem 'puppetlabs_spec_helper', '>= 0.8.2'
gem 'puppet-lint', '>= 1.0.0'
gem 'facter', '>= 1.7.0'
gem 'rspec-puppet-facts', :require => 'false'
gem 'puppet-openstack_spec_helper',
:git => 'https://git.openstack.org/openstack/puppet-openstack_spec_helper',
:require => false
end
group :system_tests do
gem 'beaker-rspec', :require => 'false'
gem 'beaker-puppet_install_helper', :require => 'false'
gem 'r10k', :require => 'false'
end

18
Rakefile

@ -1,17 +1 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]
desc "Validate manifests, templates, and ruby files"
task :validate do
Dir['manifests/**/*.pp'].each do |manifest|
sh "puppet parser validate --noop #{manifest}"
end
Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
end
Dir['templates/**/*.erb'].each do |template|
sh "erb -P -x -T '-' #{template} | ruby -c"
end
end
require 'puppet-openstack_spec_helper/rake_tasks'

11
manifests/controller.pp

@ -21,10 +21,13 @@ class ovn::controller(
$ovn_encap_type = 'geneve',
$ovn_encap_ip = undef
) {
include $::ovn::params
include $::vswitch
include ::ovn::params
include ::vswitch::ovs
service { 'controller':
#validate_string($ovn_remote)
#validate_ip_address($ovn_encap_ip)
service { $::ovn::params::ovn_controller_service_name:
ensure => true,
name => $::ovn::params::ovn_controller_service_name,
enable => true,
@ -33,7 +36,7 @@ class ovn::controller(
Vs_config['external_ids:ovn-encap-ip']]
}
package { 'controller':
package { $::ovn::params::ovn_package_name:
ensure => present,
name => $::ovn::params::ovn_package_name,
before => Service['controller']

4
manifests/northd.pp

@ -4,14 +4,14 @@
# installs ovn package starts the ovn-northd service
#
class ovn::northd() {
include $::ovn::params
include ::ovn::params
service { 'northd':
ensure => true,
enable => true,
name => $::ovn::params::ovn_northd_service_name
}
package { 'ovn':
package { $::ovn::params::ovn_package_name:
ensure => present,
name => $::ovn::params::ovn_package_name,
before => Service['northd']

7
spec/classes/init_spec.rb

@ -1,7 +0,0 @@
require 'spec_helper'
describe 'ovn' do
context 'with defaults for all parameters' do
it { should contain_class('ovn') }
end
end

74
spec/classes/ovn_controller_spec.rb

@ -0,0 +1,74 @@
require 'spec_helper'
describe 'ovn::controller' do
let :redhat_platform_params do {
:ovn_package_name => 'openvswitch-ovn',
:ovn_controller_service_name => 'ovn-controller'
}
end
shared_examples 'ovn controller' do
it 'includes params' do
is_expected.to contain_class('ovn::params')
end
it 'includes controller' do
is_expected.to contain_class('ovn::controller')
end
it 'starts controller' do
is_expected.to contain_service(platform_params[:ovn_controller_service_name]).with(
:ensure => true,
:name => platform_params[:ovn_controller_service_name],
:enable => true,
)
end
it 'installs package' do
is_expected.to contain_package(platform_params[:ovn_package_name]).with(
:ensure => 'present',
:name => platform_params[:ovn_package_name],
:before => 'Service[controller]'
)
end
it 'configures ovsdb' do
is_expected.to contain_vs_config('external_ids:ovn-remote').with(
:ensure => 'present',
:value => params[:ovn_remote],
:require => 'Service[openvswitch]'
)
is_expected.to contain_vs_config('external_ids:ovn-encap-type').with(
:ensure => 'present',
:value => params[:ovn_encap_type],
:require => 'Service[openvswitch]'
)
is_expected.to contain_vs_config('external_ids:ovn-encap-ip').with(
:ensure => 'present',
:value => params[:ovn_encap_ip],
:require => 'Service[openvswitch]'
)
end
end
context 'with redhat platform' do
let :params do {
:ovn_remote => 'tcp:x.x.x.x:5000',
:ovn_encap_type => 'geneve',
:ovn_encap_ip => '1.2.3.4'
}
end
let :facts do
{:osfamily => 'Redhat',
}
end
let :platform_params do redhat_platform_params end
it_configures 'ovn controller'
end
end

45
spec/classes/ovn_northd_spec.rb

@ -0,0 +1,45 @@
require 'spec_helper'
describe 'ovn::northd' do
let :redhat_platform_params do {
:ovn_package_name => 'openvswitch-ovn',
:ovn_northd_service_name => 'ovn-northd'
}
end
shared_examples 'ovn northd' do
it 'includes params' do
is_expected.to contain_class('ovn::params')
end
it 'starts northd' do
is_expected.to contain_service('northd').with(
:ensure => true,
:name => platform_params[:ovn_northd_service_name],
:enable => true,
)
end
it 'installs package' do
is_expected.to contain_package(platform_params[:ovn_package_name]).with(
:ensure => 'present',
:name => platform_params[:ovn_package_name],
:before => 'Service[northd]'
)
end
end
context 'on redhat' do
let :platform_params do redhat_platform_params end
let :facts do
{:osfamily => 'Redhat',
}
end
it_configures 'ovn northd'
end
end

5
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

17
spec/spec_helper.rb

@ -1 +1,18 @@
require 'puppetlabs_spec_helper/module_spec_helper'
require 'shared_examples'
require 'puppet-openstack_spec_helper/defaults'
require 'rspec-puppet-facts'
include RspecPuppetFacts
RSpec.configure do |c|
c.alias_it_should_behave_like_to :it_configures, 'configures'
c.alias_it_should_behave_like_to :it_raises, 'raises'
# TODO(aschultz): remove this after all tests converted to use OSDefaults
# instead of referencing @default_facts
c.before :each do
@default_facts = OSDefaults.get_facts
end
end
at_exit { RSpec::Puppet::Coverage.report! }

1
spec/spec_helper_acceptance.rb

@ -0,0 +1 @@
require 'puppet-openstack_spec_helper/beaker_spec_helper'
Loading…
Cancel
Save