X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=spec%2Fspec_helper.rb;h=1aff33cb327dbf939772c4bca829667c59d5fba7;hb=refs%2Fchanges%2F99%2F55399%2F1;hp=5971b55f54f24f75786752daeff0b8e85bdcf78b;hpb=1363b7212a332c3c419b04ccc9e91990b525958c;p=integration%2Fpackaging%2Fpuppet-opendaylight.git diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5971b55..1aff33c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ require 'puppetlabs_spec_helper/module_spec_helper' -def supported_os_tests() +# Tests that are common to all possible configurations +def generic_tests(yum_repo) # Confirm that module compiles it { should compile } it { should compile.with_all_deps } @@ -20,36 +21,119 @@ def supported_os_tests() it { should contain_class('opendaylight::service').that_comes_before('opendaylight') } it { should contain_class('opendaylight').that_requires('opendaylight::service') } - # Confirm presense of other resources + # Confirm presense of generic resources it { should contain_service('opendaylight') } - it { should contain_yumrepo('opendaylight') } - it { should contain_package('opendaylight') } it { should contain_file('org.apache.karaf.features.cfg') } - # Confirm relationships between other resources - it { should contain_package('opendaylight').that_requires('Yumrepo[opendaylight]') } - it { should contain_yumrepo('opendaylight').that_comes_before('Package[opendaylight]') } + # Confirm properties of generic resources + # NB: These hashes don't work with Ruby 1.8.7, but we + # don't support 1.8.7 so that's okay. See issue #36. + it { + should contain_service('opendaylight').with( + 'ensure' => 'running', + 'enable' => 'true', + 'hasstatus' => 'true', + 'hasrestart' => 'true', + ) + } + it { + should contain_file('org.apache.karaf.features.cfg').with( + 'ensure' => 'file', + 'path' => '/opt/opendaylight-0.2.2/etc/org.apache.karaf.features.cfg', + ) + } +end +# Shared tests that specialize in testing Karaf feature installs +def karaf_feature_tests(features) # Confirm properties of other resources - # There's a more elegant way to do these long sets of checks - # using multi-line hashes, but it breaks in Ruby 1.8.7 - it { should contain_yumrepo('opendaylight').with_enabled('1').with_gpgcheck('0').with_descr('OpenDaylight SDN controller') } - it { should contain_package('opendaylight').with_ensure('present') } - it { should contain_service('opendaylight').with_ensure('running').with_enable('true').with_hasstatus('true').with_hasrestart('true') } - it { should contain_file('org.apache.karaf.features.cfg').with_ensure('file').with_path('/opt/opendaylight-0.2.1/etc/org.apache.karaf.features.cfg') } + # NB: These hashes don't work with Ruby 1.8.7, but we + # don't support 1.8.7 so that's okay. See issue #36. + it { + should contain_file('org.apache.karaf.features.cfg').with( + 'ensure' => 'file', + 'path' => '/opt/opendaylight-0.2.2/etc/org.apache.karaf.features.cfg', + 'content' => /^featuresBoot=#{features.join(",")}/ + ) + } end +def install_method_tests(method, yum_repo, tarball_url='', unitfile_url='') + case method + when 'rpm' + # Confirm presense of RPM-related resources + it { should contain_yumrepo('opendaylight') } + it { should contain_package('opendaylight') } + it { should contain_package('opendaylight').that_requires('Yumrepo[opendaylight]') } + it { should contain_yumrepo('opendaylight').that_comes_before('Package[opendaylight]') } + + # Confirm properties of RPM-related resources + # NB: These hashes don't work with Ruby 1.8.7, but we + # don't support 1.8.7 so that's okay. See issue #36. + it { + should contain_yumrepo('opendaylight').with( + 'enabled' => '1', + 'gpgcheck' => '0', + 'descr' => 'OpenDaylight SDN controller', + 'baseurl' => yum_repo, + ) + } + it { + should contain_package('opendaylight').with( + 'ensure' => 'present', + ) + } + when 'tarball' + if tarball_url == '' + fail('Expected tarball_url param') + end + + if unitfile_url == '' + fail('Expected unitfile_url param') + end + + # Confirm presense of tarball-related resources + it { should contain_archive('opendaylight-0.2.2') } + it { should contain_archive('opendaylight-systemd') } + + # Confirm properties of tarball-related resources + # NB: These hashes don't work with Ruby 1.8.7, but we + # don't support 1.8.7 so that's okay. See issue #36. + it { + should contain_archive('opendaylight-0.2.2').with( + 'ensure' => 'present', + 'url' => tarball_url, + 'target' => '/opt/', + 'checksum' => false, + 'strip_components' => 1, + ) + } + it { + should contain_archive('opendaylight-systemd').with( + 'ensure' => 'present', + 'url' => unitfile_url, + 'target' => '/usr/lib/systemd/system/', + 'root_dir' => '.', + 'checksum' => false, + 'strip_components' => 1, + ) + } + else + fail("Unexpected install method: #{method}") + end +end -def unsupported_os_tests(operatingsystem, operatingsystemmajrelease) +# Shared tests for unsupported OSs +def unsupported_os_tests(expected_err_msg) # Confirm that classes fail on unsupported OSs - it { expect { should contain_class('opendaylight') }.to raise_error(Puppet::Error, /Unsupported OS: #{operatingsystem} #{operatingsystemmajrelease}/) } - it { expect { should contain_class('opendaylight::install') }.to raise_error(Puppet::Error, /Unsupported OS: #{operatingsystem} #{operatingsystemmajrelease}/) } - it { expect { should contain_class('opendaylight::config') }.to raise_error(Puppet::Error, /Unsupported OS: #{operatingsystem} #{operatingsystemmajrelease}/) } - it { expect { should contain_class('opendaylight::service') }.to raise_error(Puppet::Error, /Unsupported OS: #{operatingsystem} #{operatingsystemmajrelease}/) } + it { expect { should contain_class('opendaylight') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) } + it { expect { should contain_class('opendaylight::install') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) } + it { expect { should contain_class('opendaylight::config') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) } + it { expect { should contain_class('opendaylight::service') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) } # Confirm that other resources fail on unsupported OSs - it { expect { should contain_yumrepo('opendaylight') }.to raise_error(Puppet::Error, /Unsupported OS: #{operatingsystem} #{operatingsystemmajrelease}/) } - it { expect { should contain_package('opendaylight') }.to raise_error(Puppet::Error, /Unsupported OS: #{operatingsystem} #{operatingsystemmajrelease}/) } - it { expect { should contain_service('opendaylight') }.to raise_error(Puppet::Error, /Unsupported OS: #{operatingsystem} #{operatingsystemmajrelease}/) } - it { expect { should contain_file('org.apache.karaf.features.cfg') }.to raise_error(Puppet::Error, /Unsupported OS: #{operatingsystem} #{operatingsystemmajrelease}/) } + it { expect { should contain_yumrepo('opendaylight') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) } + it { expect { should contain_package('opendaylight') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) } + it { expect { should contain_service('opendaylight') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) } + it { expect { should contain_file('org.apache.karaf.features.cfg') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) } end