Convert spec testing to rspec-puppet-facts

Change-Id: I2864d8f095270c3f64e4000b3e8789e323f9dd19
This commit is contained in:
Tobias Urdin 2018-11-08 11:25:21 +01:00
parent 0af07a5466
commit 77521e235f
2 changed files with 85 additions and 66 deletions

View File

@ -18,72 +18,78 @@
require 'spec_helper'
describe 'ironic::bifrost' do
let :default_params do
{ :git_source_repo => 'https://git.openstack.org/openstack/bifrost',
:revision => master,
:git_dest_repo_folder => '/opt/stack/bifrost',
:bifrost_config_folder => '/etc/bifrost',
:ironic_url => '"http://localhost:6385/"',
:network_interface => '"virbr0"',
:testing => false,
:testing_user => 'ubuntu',
:http_boot_folder => '/httpboot',
:nginx_port => 8080,
:ssh_public_key_path => '"{{ ansible_env.HOME }}/.ssh/id_rsa.pub"',
:deploy_kernel => '"{{http_boot_folder}}/coreos_production_pxe.vmlinuz"',
:deploy_ramdisk => '"{{http_boot_folder}}/coreos_production_pxe_image-oem.cpio.gz"',
:deploy_kernel_url => '"http://{{ hostvars[inventory_hostname][\'ansible_\' + network_interface][\'ipv4\'][\'address\'] }}:{{nginx_port}}/coreos_production_pxe.vmlinuz"',
:deploy_ramdisk_url => '"http://{{ hostvars[inventory_hostname][\'ansible_\' + network_interface][\'ipv4\'][\'address\'] }}:{{nginx_port}}/coreos_production_pxe_image-oem.cpio.gz"',
:deploy_image_filename => '"deployment_image.qcow2"',
:deploy_image => '"{{http_boot_folder}}/{{deploy_image_filename}}"',
:create_image_via_dib => true,
:transform_boot_image => false,
{
:git_source_repo => 'https://git.openstack.org/openstack/bifrost',
:revision => master,
:git_dest_repo_folder => '/opt/stack/bifrost',
:bifrost_config_folder => '/etc/bifrost',
:ironic_url => '"http://localhost:6385/"',
:network_interface => '"virbr0"',
:testing => false,
:testing_user => 'ubuntu',
:http_boot_folder => '/httpboot',
:nginx_port => 8080,
:ssh_public_key_path => '"{{ ansible_env.HOME }}/.ssh/id_rsa.pub"',
:deploy_kernel => '"{{http_boot_folder}}/coreos_production_pxe.vmlinuz"',
:deploy_ramdisk => '"{{http_boot_folder}}/coreos_production_pxe_image-oem.cpio.gz"',
:deploy_kernel_url => '"http://{{ hostvars[inventory_hostname][\'ansible_\' + network_interface][\'ipv4\'][\'address\'] }}:{{nginx_port}}/coreos_production_pxe.vmlinuz"',
:deploy_ramdisk_url => '"http://{{ hostvars[inventory_hostname][\'ansible_\' + network_interface][\'ipv4\'][\'address\'] }}:{{nginx_port}}/coreos_production_pxe_image-oem.cpio.gz"',
:deploy_image_filename => '"deployment_image.qcow2"',
:deploy_image => '"{{http_boot_folder}}/{{deploy_image_filename}}"',
:create_image_via_dib => true,
:transform_boot_image => false,
:node_default_network_interface => 'eth0',
:ipv4_subnet_mask => '255.255.255.0',
:ipv4_gateway => '192.168.1.1',
:ipv4_nameserver => '8.8.8.8',
:network_mtu => '1500',
:dhcp_pool_start => '192.168.1.200',
:dhcp_pool_end => '192.168.1.250',
:ipmi_bridging => 'no',
:ipv4_subnet_mask => '255.255.255.0',
:ipv4_gateway => '192.168.1.1',
:ipv4_nameserver => '8.8.8.8',
:network_mtu => '1500',
:dhcp_pool_start => '192.168.1.200',
:dhcp_pool_end => '192.168.1.250',
:ipmi_bridging => 'no',
}
end
let :params do
{ :mysql_password => 'changeme',
:ironic_db_password => 'changeme',
{
:mysql_password => 'changeme',
:ironic_db_password => 'changeme',
:baremetal_json_hosts => 'test',
}
end
it 'should clone with vcsrepo bifrost repo with master branch' do
is_expected.to contain_vcsrepo('/opt/stack/bifrost').with(
'ensure' => 'present',
'provider' => 'git',
'revision' => 'master',
'source' => 'https://git.openstack.org/openstack/bifrost',
)
shared_examples 'ironic::bifrost' do
it { should contain_vcsrepo('/opt/stack/bifrost').with(
:ensure => 'present',
:provider => 'git',
:revision => 'master',
:source => 'https://git.openstack.org/openstack/bifrost',
)}
it { should contain_file('/etc/bifrost').with(
:ensure => 'directory',
)}
it { should contain_file('/etc/bifrost/bifrost_global_vars').with(
:ensure => 'present',
:content => /ironic_url/,
)}
it { should contain_file('/etc/bifrost/baremetal.json').with(
:ensure => 'present',
:content => /test/,
)}
end
it 'should contain folder /etc/bifrost' do
is_expected.to contain_file('/etc/bifrost').with(
'ensure' => 'directory',
)
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 'should contain file /etc/bifrost/bifrost_global_vars' do
is_expected.to contain_file('/etc/bifrost/bifrost_global_vars').with(
'ensure' => 'present',
'content' => /ironic_url/,
)
it_behaves_like 'ironic::bifrost'
end
end
it 'should contain file /etc/bifrost/baremetal.json' do
is_expected.to contain_file('/etc/bifrost/baremetal.json').with(
'ensure' => 'present',
'content' => /test/,
)
end
end

View File

@ -1,9 +1,9 @@
require 'spec_helper'
describe 'ironic::config' do
let :params do
{ :ironic_config => {
{
:ironic_config => {
'DEFAULT/foo' => { 'value' => 'fooValue' },
'DEFAULT/bar' => { 'value' => 'barValue' },
'DEFAULT/baz' => { 'ensure' => 'absent' }
@ -16,18 +16,31 @@ describe 'ironic::config' do
}
end
it { is_expected.to contain_class('ironic::deps') }
shared_examples 'ironic::config' do
it { should contain_class('ironic::deps') }
it 'configures arbitrary ironic configurations' do
is_expected.to contain_ironic_config('DEFAULT/foo').with_value('fooValue')
is_expected.to contain_ironic_config('DEFAULT/bar').with_value('barValue')
is_expected.to contain_ironic_config('DEFAULT/baz').with_ensure('absent')
it {
should contain_ironic_config('DEFAULT/foo').with_value('fooValue')
should contain_ironic_config('DEFAULT/bar').with_value('barValue')
should contain_ironic_config('DEFAULT/baz').with_ensure('absent')
}
it {
should contain_ironic_api_paste_ini('DEFAULT/foo2').with_value('fooValue')
should contain_ironic_api_paste_ini('DEFAULT/bar2').with_value('barValue')
should contain_ironic_api_paste_ini('DEFAULT/baz2').with_ensure('absent')
}
end
it 'configures arbitrary ironic-api-paste configurations' do
is_expected.to contain_ironic_api_paste_ini('DEFAULT/foo2').with_value('fooValue')
is_expected.to contain_ironic_api_paste_ini('DEFAULT/bar2').with_value('barValue')
is_expected.to contain_ironic_api_paste_ini('DEFAULT/baz2').with_ensure('absent')
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_behaves_like 'ironic::config'
end
end
end