Merge "Refactoring ChefSpec tests"

This commit is contained in:
Jenkins
2014-03-25 10:07:05 +00:00
committed by Gerrit Code Review
18 changed files with 796 additions and 966 deletions

View File

@@ -23,4 +23,4 @@ depends 'openstack-common', '~> 8.0'
depends 'openstack-identity', '~> 8.0' depends 'openstack-identity', '~> 8.0'
depends 'openstack-image', '~> 8.0' depends 'openstack-image', '~> 8.0'
depends 'selinux' depends 'selinux'
depends 'python' depends 'python', '>= 1.4.6'

View File

@@ -5,33 +5,30 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::api' do describe 'openstack-block-storage::api' do
before { block_storage_stubs }
describe 'suse' do describe 'suse' do
before do let(:runner) { ChefSpec::Runner.new(SUSE_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::SUSE_OPTS let(:node) { runner.node }
@chef_run.converge 'openstack-block-storage::api' let(:chef_run) { runner.converge(described_recipe) }
end
include_context 'block-storage-stubs'
it 'installs cinder api packages' do it 'installs cinder api packages' do
expect(@chef_run).to upgrade_package 'openstack-cinder-api' expect(chef_run).to upgrade_package 'openstack-cinder-api'
end end
it 'installs mysql python packages by default' do it 'installs mysql python packages by default' do
expect(@chef_run).to upgrade_package 'python-mysql' expect(chef_run).to upgrade_package 'python-mysql'
end end
it 'installs postgresql python packages if explicitly told' do it 'installs postgresql python packages if explicitly told' do
chef_run = ::ChefSpec::Runner.new ::SUSE_OPTS
node = chef_run.node
node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql' node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql'
chef_run.converge 'openstack-block-storage::api'
expect(chef_run).to upgrade_package 'python-psycopg2' expect(chef_run).to upgrade_package 'python-psycopg2'
expect(chef_run).not_to upgrade_package 'python-mysql' expect(chef_run).not_to upgrade_package 'python-mysql'
end end
it 'starts cinder api on boot' do it 'starts cinder api on boot' do
expect(@chef_run).to enable_service 'openstack-cinder-api' expect(chef_run).to enable_service 'openstack-cinder-api'
end end
expect_creates_policy_json( expect_creates_policy_json(

View File

@@ -5,26 +5,23 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::api' do describe 'openstack-block-storage::api' do
before { block_storage_stubs }
describe 'redhat' do describe 'redhat' do
before do let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS let(:node) { runner.node }
@chef_run.converge 'openstack-block-storage::api' let(:chef_run) { runner.converge(described_recipe) }
end
include_context 'block-storage-stubs'
it 'installs cinder api packages' do it 'installs cinder api packages' do
expect(@chef_run).to upgrade_package 'python-cinderclient' expect(chef_run).to upgrade_package 'python-cinderclient'
end end
it 'installs mysql python packages by default' do it 'installs mysql python packages by default' do
expect(@chef_run).to upgrade_package 'MySQL-python' expect(chef_run).to upgrade_package 'MySQL-python'
end end
it 'installs db2 python packages if explicitly told' do it 'installs db2 python packages if explicitly told' do
chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS
node = chef_run.node
node.set['openstack']['db']['block-storage']['service_type'] = 'db2' node.set['openstack']['db']['block-storage']['service_type'] = 'db2'
chef_run.converge 'openstack-block-storage::api'
['python-ibm-db', 'python-ibm-db-sa'].each do |pkg| ['python-ibm-db', 'python-ibm-db-sa'].each do |pkg|
expect(chef_run).to upgrade_package pkg expect(chef_run).to upgrade_package pkg
@@ -32,17 +29,14 @@ describe 'openstack-block-storage::api' do
end end
it 'installs postgresql python packages if explicitly told' do it 'installs postgresql python packages if explicitly told' do
chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS
node = chef_run.node
node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql' node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql'
chef_run.converge 'openstack-block-storage::api'
expect(chef_run).to upgrade_package 'python-psycopg2' expect(chef_run).to upgrade_package 'python-psycopg2'
expect(chef_run).not_to upgrade_package 'MySQL-python' expect(chef_run).not_to upgrade_package 'MySQL-python'
end end
it 'starts cinder api on boot' do it 'starts cinder api on boot' do
expect(@chef_run).to enable_service 'openstack-cinder-api' expect(chef_run).to enable_service 'openstack-cinder-api'
end end
end end
end end

View File

@@ -5,158 +5,139 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::api' do describe 'openstack-block-storage::api' do
before { block_storage_stubs }
describe 'ubuntu' do describe 'ubuntu' do
before do let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| let(:node) { runner.node }
n.set['openstack']['block-storage']['syslog']['use'] = true let(:chef_run) { runner.converge(described_recipe) }
end
@chef_run.converge 'openstack-block-storage::api'
end
expect_runs_openstack_common_logging_recipe include_context 'block-storage-stubs'
include_examples 'common-logging'
it 'does not run logging recipe' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
chef_run.converge 'openstack-block-storage::api'
expect(chef_run).not_to include_recipe 'openstack-common::logging'
end
it 'installs cinder api packages' do
expect(@chef_run).to upgrade_package 'cinder-api'
expect(@chef_run).to upgrade_package 'python-cinderclient'
end
it 'installs mysql python packages by default' do
expect(@chef_run).to upgrade_package 'python-mysqldb'
end
it 'installs postgresql python packages if explicitly told' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
node = chef_run.node
node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql'
chef_run.converge 'openstack-block-storage::api'
expect(chef_run).to upgrade_package 'python-psycopg2'
expect(chef_run).not_to upgrade_package 'python-mysqldb'
end
describe '/var/cache/cinder' do
before do
@dir = @chef_run.directory '/var/cache/cinder'
end
it 'has proper owner' do
expect(@dir.owner).to eq('cinder')
expect(@dir.group).to eq('cinder')
end
it 'has proper modes' do
expect(sprintf('%o', @dir.mode)).to eq '700'
end
end
it 'starts cinder api on boot' do
expect(@chef_run).to enable_service 'cinder-api'
end
expect_creates_cinder_conf 'service[cinder-api]', 'cinder', 'cinder' expect_creates_cinder_conf 'service[cinder-api]', 'cinder', 'cinder'
describe 'cinder.conf' do it 'installs cinder api packages' do
before do expect(chef_run).to upgrade_package('cinder-api')
@file = '/etc/cinder/cinder.conf' expect(chef_run).to upgrade_package('python-cinderclient')
end end
it 'starts cinder api on boot' do
expect(chef_run).to enable_service('cinder-api')
end
it 'installs mysql python packages by default' do
expect(chef_run).to upgrade_package('python-mysqldb')
end
it 'installs postgresql python packages if explicitly told' do
node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql'
expect(chef_run).to upgrade_package('python-psycopg2')
expect(chef_run).not_to upgrade_package('python-mysqldb')
end
describe '/var/cache/cinder' do
let(:dir) { chef_run.directory('/var/cache/cinder') }
it 'has proper owner' do
expect(dir.owner).to eq('cinder')
expect(dir.group).to eq('cinder')
end
it 'has proper modes' do
expect(sprintf('%o', dir.mode)).to eq('700')
end
end
describe 'cinder.conf' do
let(:file) { chef_run.template('/etc/cinder/cinder.conf') }
it 'runs logging recipe if node attributes say to' do it 'runs logging recipe if node attributes say to' do
expect(@chef_run).to render_file(@file).with_content('log_config = /etc/openstack/logging.conf') node.set['openstack']['block-storage']['syslog']['use'] = true
expect(chef_run).to render_file(file.name).with_content('log_config = /etc/openstack/logging.conf')
end end
it 'does not run logging recipe' do context 'rdb driver' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS before do
chef_run.converge 'openstack-block-storage::api' node.set['openstack']['block-storage']['volume'] = {
expect(chef_run).not_to render_file(@file).with_content('log_config = /etc/openstack/logging.conf')
end
it 'has rbd driver settings' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
n.set['openstack']['block-storage']['volume'] = {
'driver' => 'cinder.volume.drivers.rbd.RBDDriver' 'driver' => 'cinder.volume.drivers.rbd.RBDDriver'
} }
end end
chef_run.converge 'openstack-block-storage::api'
expect(chef_run).to render_file(@file).with_content(/^rbd_/) # FIXME(galstrom21): this block needs to check all of the default
expect(chef_run).not_to render_file(@file).with_content(/^netapp_/) # rdb_* configuration options
it 'has default rbd_* options set' do
expect(chef_run).to render_file(file.name).with_content(/^rbd_/)
expect(chef_run).not_to render_file(file.name).with_content(/^netapp_/)
end
end end
it 'has netapp driver settings' do context 'netapp driver' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| before do
n.set['openstack']['block-storage']['volume'] = { node.set['openstack']['block-storage']['volume'] = {
'driver' => 'cinder.volume.drivers.netapp.NetAppISCSIDriver' 'driver' => 'cinder.volume.drivers.netapp.NetAppISCSIDriver'
} }
end end
chef_run.converge 'openstack-block-storage::api'
expect(chef_run).to render_file(@file).with_content(/^netapp_/) # FIXME(galstrom21): this block needs to check all of the default
expect(chef_run).not_to render_file(@file).with_content(/^rbd_/) # netapp_* configuration options
it 'has default netapp_* options set' do
expect(chef_run).to render_file(file.name).with_content(/^netapp_/)
expect(chef_run).not_to render_file(file.name).with_content(/^rbd_/)
end
end end
end end
it 'runs db migrations' do it 'runs db migrations' do
cmd = 'cinder-manage db sync' expect(chef_run).to run_execute('cinder-manage db sync')
expect(@chef_run).to run_execute(cmd)
end end
expect_creates_policy_json 'service[cinder-api]', 'cinder', 'cinder' expect_creates_policy_json 'service[cinder-api]', 'cinder', 'cinder'
describe 'api-paste.ini' do describe 'api-paste.ini' do
before do let(:file) { chef_run.template('/etc/cinder/api-paste.ini') }
@file = @chef_run.template '/etc/cinder/api-paste.ini'
end
it 'has proper owner' do it 'has proper owner' do
expect(@file.owner).to eq('cinder') expect(file.owner).to eq('cinder')
expect(@file.group).to eq('cinder') expect(file.group).to eq('cinder')
end end
it 'has proper modes' do it 'has proper modes' do
expect(sprintf('%o', @file.mode)).to eq '644' expect(sprintf('%o', file.mode)).to eq('644')
end end
it 'has signing_dir' do it 'has signing_dir' do
expect(@chef_run).to render_file(@file.name).with_content('signing_dir = /var/cache/cinder/api') expect(chef_run).to render_file(file.name).with_content('signing_dir = /var/cache/cinder/api')
end end
it 'notifies cinder-api restart' do it 'notifies cinder-api restart' do
expect(@file).to notify('service[cinder-api]').to(:restart) expect(file).to notify('service[cinder-api]').to(:restart)
end end
it 'has auth_uri' do it 'has auth_uri' do
expect(@chef_run).to render_file(@file.name).with_content('auth_uri = http://127.0.0.1:5000/v2.0') expect(chef_run).to render_file(file.name).with_content('auth_uri = http://127.0.0.1:5000/v2.0')
end end
it 'has auth_host' do it 'has auth_host' do
expect(@chef_run).to render_file(@file.name).with_content('auth_host = 127.0.0.1') expect(chef_run).to render_file(file.name).with_content('auth_host = 127.0.0.1')
end end
it 'has auth_port' do it 'has auth_port' do
expect(@chef_run).to render_file(@file.name).with_content('auth_port = 35357') expect(chef_run).to render_file(file.name).with_content('auth_port = 35357')
end end
it 'has auth_protocol' do it 'has auth_protocol' do
expect(@chef_run).to render_file(@file.name).with_content('auth_protocol = http') expect(chef_run).to render_file(file.name).with_content('auth_protocol = http')
end end
it 'has no auth_version when auth_version is v2.0' do it 'has no auth_version when auth_version is v2.0' do
expect(@chef_run).not_to render_file(@file.name).with_content('auth_version = v2.0') expect(chef_run).not_to render_file(file.name).with_content('auth_version = v2.0')
end end
it 'has auth_version when auth version is not v2.0' do it 'has auth_version when auth version is not v2.0' do
@chef_run.node.set['openstack']['block-storage']['api']['auth']['version'] = 'v3.0' node.set['openstack']['block-storage']['api']['auth']['version'] = 'v3.0'
expect(@chef_run).to render_file(@file.name).with_content('auth_version = v3.0')
expect(chef_run).to render_file(file.name).with_content('auth_version = v3.0')
end end
end end
end end

View File

@@ -5,18 +5,15 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::cinder-common' do describe 'openstack-block-storage::cinder-common' do
before { block_storage_stubs } describe 'rhel' do
before do let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS do |n| let(:node) { runner.node }
n.set['openstack']['mq'] = { let(:chef_run) { runner.converge(described_recipe) }
'host' => '127.0.0.1'
} include_context 'block-storage-stubs'
n.set['openstack']['block-storage']['syslog']['use'] = true
end
@chef_run.converge 'openstack-block-storage::cinder-common'
end
it 'installs the openstack-cinder package' do it 'installs the openstack-cinder package' do
expect(@chef_run).to upgrade_package 'openstack-cinder' expect(chef_run).to upgrade_package 'openstack-cinder'
end
end end
end end

View File

@@ -5,18 +5,15 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::cinder-common' do describe 'openstack-block-storage::cinder-common' do
before { block_storage_stubs } describe 'suse' do
before do let(:runner) { ChefSpec::Runner.new(SUSE_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::SUSE_OPTS do |n| let(:node) { runner.node }
n.set['openstack']['mq'] = { let(:chef_run) { runner.converge(described_recipe) }
'host' => '127.0.0.1'
} include_context 'block-storage-stubs'
n.set['openstack']['block-storage']['syslog']['use'] = true
end
@chef_run.converge 'openstack-block-storage::cinder-common'
end
it 'installs the openstack-cinder package' do it 'installs the openstack-cinder package' do
expect(@chef_run).to upgrade_package 'openstack-cinder' expect(chef_run).to upgrade_package 'openstack-cinder'
end
end end
end end

View File

@@ -5,314 +5,295 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::cinder-common' do describe 'openstack-block-storage::cinder-common' do
before { block_storage_stubs } describe 'ubuntu' do
before do let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| let(:node) { runner.node }
n.set['openstack']['mq'] = { let(:chef_run) do
'host' => '127.0.0.1' node.set['openstack']['mq']['host'] = '127.0.0.1'
} node.set['openstack']['mq']['block-storage']['rabbit']['notification_topic'] = 'rabbit_topic'
n.set['openstack']['mq']['block-storage']['rabbit']['notification_topic'] = 'rabbit_topic'
end runner.converge(described_recipe)
@chef_run.converge 'openstack-block-storage::cinder-common'
end end
include_context 'block-storage-stubs'
it 'installs the cinder-common package' do it 'installs the cinder-common package' do
expect(@chef_run).to upgrade_package 'cinder-common' expect(chef_run).to upgrade_package 'cinder-common'
end end
describe '/etc/cinder' do describe '/etc/cinder' do
before do let(:dir) { chef_run.directory('/etc/cinder') }
@dir = @chef_run.directory '/etc/cinder'
end
it 'has proper owner' do it 'has proper owner' do
expect(@dir.owner).to eq('cinder') expect(dir.owner).to eq('cinder')
expect(@dir.group).to eq('cinder') expect(dir.group).to eq('cinder')
end end
it 'has proper modes' do it 'has proper modes' do
expect(sprintf('%o', @dir.mode)).to eq '750' expect(sprintf('%o', dir.mode)).to eq '750'
end end
end end
describe 'cinder.conf' do describe 'cinder.conf' do
before do let(:file) { chef_run.template('/etc/cinder/cinder.conf') }
@file = @chef_run.template '/etc/cinder/cinder.conf'
end
it 'has proper owner' do it 'has proper owner' do
expect(@file.owner).to eq('cinder') expect(file.owner).to eq('cinder')
expect(@file.group).to eq('cinder') expect(file.group).to eq('cinder')
end end
it 'has proper modes' do it 'has proper modes' do
expect(sprintf('%o', @file.mode)).to eq '644' expect(sprintf('%o', file.mode)).to eq '644'
end end
it 'has name templates' do it 'has name templates' do
expect(@chef_run).to render_file(@file.name).with_content('volume_name_template=volume-%s') expect(chef_run).to render_file(file.name).with_content('volume_name_template=volume-%s')
expect(@chef_run).to render_file(@file.name).with_content('snapshot_name_template=snapshot-%s') expect(chef_run).to render_file(file.name).with_content('snapshot_name_template=snapshot-%s')
end end
it 'has rpc_backend set' do it 'has rpc_backend set' do
expect(@chef_run).to render_file(@file.name).with_content('rpc_backend=cinder.openstack.common.rpc.impl_kombu') expect(chef_run).to render_file(file.name).with_content('rpc_backend=cinder.openstack.common.rpc.impl_kombu')
end end
it 'has has volumes_dir set' do it 'has has volumes_dir set' do
expect(@chef_run).to render_file(@file.name).with_content('volumes_dir=/var/lib/cinder/volumes') expect(chef_run).to render_file(file.name).with_content('volumes_dir=/var/lib/cinder/volumes')
end end
it 'has correct volume.driver set' do it 'has correct volume.driver set' do
expect(@chef_run).to render_file(@file.name).with_content('volume_driver=cinder.volume.drivers.lvm.LVMISCSIDriver') expect(chef_run).to render_file(file.name).with_content('volume_driver=cinder.volume.drivers.lvm.LVMISCSIDriver')
end end
it 'has rpc_thread_pool_size' do it 'has rpc_thread_pool_size' do
expect(@chef_run).to render_file(@file.name).with_content('rpc_thread_pool_size=64') expect(chef_run).to render_file(file.name).with_content('rpc_thread_pool_size=64')
end end
it 'has rpc_conn_pool_size' do it 'has rpc_conn_pool_size' do
expect(@chef_run).to render_file(@file.name).with_content('rpc_conn_pool_size=30') expect(chef_run).to render_file(file.name).with_content('rpc_conn_pool_size=30')
end end
it 'has rpc_response_timeout' do it 'has rpc_response_timeout' do
expect(@chef_run).to render_file(@file.name).with_content('rpc_response_timeout=60') expect(chef_run).to render_file(file.name).with_content('rpc_response_timeout=60')
end end
it 'has rabbit_host' do it 'has rabbit_host' do
expect(@chef_run).to render_file(@file.name).with_content('rabbit_host=127.0.0.1') expect(chef_run).to render_file(file.name).with_content('rabbit_host=127.0.0.1')
end end
it 'does not have rabbit_hosts' do it 'does not have rabbit_hosts' do
expect(@chef_run).not_to render_file(@file.name).with_content('rabbit_hosts=') expect(chef_run).not_to render_file(file.name).with_content('rabbit_hosts=')
end end
it 'does not have rabbit_ha_queues' do it 'does not have rabbit_ha_queues' do
expect(@chef_run).not_to render_file(@file.name).with_content('rabbit_ha_queues=') expect(chef_run).not_to render_file(file.name).with_content('rabbit_ha_queues=')
end end
it 'has log_file' do it 'has log_file' do
expect(@chef_run).to render_file(@file.name).with_content('log_file = /var/log/cinder/cinder.log') expect(chef_run).to render_file(file.name).with_content('log_file = /var/log/cinder/cinder.log')
end end
it 'has log_config when syslog is true' do it 'has log_config when syslog is true' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| node.set['openstack']['block-storage']['syslog']['use'] = true
n.set['openstack']['block-storage']['syslog']['use'] = true
end
chef_run.converge 'openstack-block-storage::cinder-common'
expect(chef_run).to render_file(@file.name).with_content('log_config = /etc/openstack/logging.conf') expect(chef_run).to render_file(file.name).with_content('log_config = /etc/openstack/logging.conf')
end end
it 'has rabbit_port' do it 'has rabbit_port' do
expect(@chef_run).to render_file(@file.name).with_content('rabbit_port=5672') expect(chef_run).to render_file(file.name).with_content('rabbit_port=5672')
end end
it 'has rabbit_use_ssl' do it 'has rabbit_use_ssl' do
expect(@chef_run).to render_file(@file.name).with_content('rabbit_use_ssl=false') expect(chef_run).to render_file(file.name).with_content('rabbit_use_ssl=false')
end end
it 'has rabbit_userid' do it 'has rabbit_userid' do
expect(@chef_run).to render_file(@file.name).with_content('rabbit_userid=guest') expect(chef_run).to render_file(file.name).with_content('rabbit_userid=guest')
end end
it 'has rabbit_password' do it 'has rabbit_password' do
expect(@chef_run).to render_file(@file.name).with_content('rabbit_password=mq-pass') expect(chef_run).to render_file(file.name).with_content('rabbit_password=mq-pass')
end end
it 'has rabbit_virtual_host' do it 'has rabbit_virtual_host' do
expect(@chef_run).to render_file(@file.name).with_content('rabbit_virtual_host=/') expect(chef_run).to render_file(file.name).with_content('rabbit_virtual_host=/')
end end
it 'has rabbit notification_topics' do it 'has rabbit notification_topics' do
expect(@chef_run).to render_file(@file.name).with_content('notification_topics=rabbit_topic') expect(chef_run).to render_file(file.name).with_content('notification_topics=rabbit_topic')
end end
describe 'rabbit ha' do describe 'rabbit ha' do
before do before do
@chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) do |n| node.set['openstack']['mq']['block-storage']['rabbit']['ha'] = true
n.set['openstack']['mq']['block-storage']['rabbit']['ha'] = true
end
@chef_run.converge 'openstack-block-storage::cinder-common'
end end
it 'has rabbit_hosts' do it 'has rabbit_hosts' do
expect(@chef_run).to render_file(@file.name).with_content('rabbit_hosts=1.1.1.1:5672,2.2.2.2:5672') expect(chef_run).to render_file(file.name).with_content('rabbit_hosts=1.1.1.1:5672,2.2.2.2:5672')
end end
it 'has rabbit_ha_queues' do it 'has rabbit_ha_queues' do
expect(@chef_run).to render_file(@file.name).with_content('rabbit_ha_queues=True') expect(chef_run).to render_file(file.name).with_content('rabbit_ha_queues=True')
end end
it 'does not have rabbit_host' do it 'does not have rabbit_host' do
expect(@chef_run).not_to render_file(@file.name).with_content('rabbit_host=127.0.0.1') expect(chef_run).not_to render_file(file.name).with_content('rabbit_host=127.0.0.1')
end end
it 'does not have rabbit_port' do it 'does not have rabbit_port' do
expect(@chef_run).not_to render_file(@file.name).with_content('rabbit_port=5672') expect(chef_run).not_to render_file(file.name).with_content('rabbit_port=5672')
end end
end end
describe 'qpid' do describe 'qpid' do
before do before do
@chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) do |n| node.set['openstack']['mq']['block-storage']['service_type'] = 'qpid'
n.set['openstack']['mq']['block-storage']['service_type'] = 'qpid' node.set['openstack']['block-storage']['notification_driver'] = 'cinder.test_driver'
n.set['openstack']['block-storage']['notification_driver'] = 'cinder.test_driver' node.set['openstack']['mq']['block-storage']['qpid']['notification_topic'] = 'qpid_topic'
n.set['openstack']['mq']['block-storage']['qpid']['notification_topic'] = 'qpid_topic'
# we set username here since the attribute in common currently # we set username here since the attribute in common currently
# defaults to '' # defaults to ''
n.set['openstack']['mq']['block-storage']['qpid']['username'] = 'guest' node.set['openstack']['mq']['block-storage']['qpid']['username'] = 'guest'
end
@chef_run.converge 'openstack-block-storage::cinder-common'
end end
it 'has qpid_hostname' do it 'has qpid_hostname' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_hostname=127.0.0.1') expect(chef_run).to render_file(file.name).with_content('qpid_hostname=127.0.0.1')
end end
it 'has qpid_port' do it 'has qpid_port' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_port=5672') expect(chef_run).to render_file(file.name).with_content('qpid_port=5672')
end end
it 'has qpid_username' do it 'has qpid_username' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_username=guest') expect(chef_run).to render_file(file.name).with_content('qpid_username=guest')
end end
it 'has qpid_password' do it 'has qpid_password' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_password=mq-pass') expect(chef_run).to render_file(file.name).with_content('qpid_password=mq-pass')
end end
it 'has qpid_sasl_mechanisms' do it 'has qpid_sasl_mechanisms' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_sasl_mechanisms=') expect(chef_run).to render_file(file.name).with_content('qpid_sasl_mechanisms=')
end end
it 'has qpid_reconnect_timeout' do it 'has qpid_reconnect_timeout' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_reconnect_timeout=0') expect(chef_run).to render_file(file.name).with_content('qpid_reconnect_timeout=0')
end end
it 'has qpid_reconnect_limit' do it 'has qpid_reconnect_limit' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_reconnect_limit=0') expect(chef_run).to render_file(file.name).with_content('qpid_reconnect_limit=0')
end end
it 'has qpid_reconnect_interval_min' do it 'has qpid_reconnect_interval_min' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_reconnect_interval_min=0') expect(chef_run).to render_file(file.name).with_content('qpid_reconnect_interval_min=0')
end end
it 'has qpid_reconnect_interval_max' do it 'has qpid_reconnect_interval_max' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_reconnect_interval_max=0') expect(chef_run).to render_file(file.name).with_content('qpid_reconnect_interval_max=0')
end end
it 'has qpid_reconnect_interval' do it 'has qpid_reconnect_interval' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_reconnect_interval=0') expect(chef_run).to render_file(file.name).with_content('qpid_reconnect_interval=0')
end end
it 'has qpid_reconnect' do it 'has qpid_reconnect' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_reconnect=true') expect(chef_run).to render_file(file.name).with_content('qpid_reconnect=true')
end end
it 'has qpid_heartbeat' do it 'has qpid_heartbeat' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_heartbeat=60') expect(chef_run).to render_file(file.name).with_content('qpid_heartbeat=60')
end end
it 'has qpid_protocol' do it 'has qpid_protocol' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_protocol=tcp') expect(chef_run).to render_file(file.name).with_content('qpid_protocol=tcp')
end end
it 'has qpid_tcp_nodelay' do it 'has qpid_tcp_nodelay' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_tcp_nodelay=true') expect(chef_run).to render_file(file.name).with_content('qpid_tcp_nodelay=true')
end end
it 'has notification_driver' do it 'has notification_driver' do
expect(@chef_run).to render_file(@file.name).with_content('notification_driver=cinder.test_driver') expect(chef_run).to render_file(file.name).with_content('notification_driver=cinder.test_driver')
end end
it 'has notification_topics' do it 'has notification_topics' do
expect(@chef_run).to render_file(@file.name).with_content('notification_topics=qpid_topic') expect(chef_run).to render_file(file.name).with_content('notification_topics=qpid_topic')
end end
end end
describe 'lvm settings' do describe 'lvm settings' do
before do before do
@chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) do |n| node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.lvm.LVMISCSIDriver'
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.lvm.LVMISCSIDriver' node.set['openstack']['block-storage']['volume']['volume_group'] = 'test-group'
n.set['openstack']['block-storage']['volume']['volume_group'] = 'test-group' node.set['openstack']['block-storage']['volume']['volume_clear_size'] = 100
n.set['openstack']['block-storage']['volume']['volume_clear_size'] = 100 node.set['openstack']['block-storage']['volume']['volume_clear'] = 'none'
n.set['openstack']['block-storage']['volume']['volume_clear'] = 'none'
end
@chef_run.converge 'openstack-block-storage::cinder-common'
end end
it 'has volume_group' do it 'has volume_group' do
expect(@chef_run).to render_file(@file.name).with_content('volume_group=test-group') expect(chef_run).to render_file(file.name).with_content('volume_group=test-group')
end end
it 'has volume_clear_size' do it 'has volume_clear_size' do
expect(@chef_run).to render_file(@file.name).with_content('volume_clear_size=100') expect(chef_run).to render_file(file.name).with_content('volume_clear_size=100')
end end
it 'has volume_clear' do it 'has volume_clear' do
expect(@chef_run).to render_file(@file.name).with_content('volume_clear=none') expect(chef_run).to render_file(file.name).with_content('volume_clear=none')
end end
end end
describe 'solidfire settings' do describe 'solidfire settings' do
before do before do
@chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) do |n| node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.solidfire.SolidFire'
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.solidfire.SolidFire' node.set['openstack']['block-storage']['solidfire']['sf_emulate'] = 'test'
n.set['openstack']['block-storage']['solidfire']['sf_emulate'] = 'test' node.set['openstack']['block-storage']['solidfire']['san_ip'] = '203.0.113.10'
n.set['openstack']['block-storage']['solidfire']['san_ip'] = '203.0.113.10' node.set['openstack']['block-storage']['solidfire']['san_login'] = 'solidfire_admin'
n.set['openstack']['block-storage']['solidfire']['san_login'] = 'solidfire_admin'
end
@chef_run.converge 'openstack-block-storage::cinder-common'
end end
it 'has solidfire sf_emulate set' do it 'has solidfire sf_emulate set' do
expect(@chef_run).to render_file(@file.name).with_content('sf_emulate_512=test') expect(chef_run).to render_file(file.name).with_content('sf_emulate_512=test')
end end
it 'has solidfire san_ip set' do it 'has solidfire san_ip set' do
expect(@chef_run).to render_file(@file.name).with_content('san_ip=203.0.113.10') expect(chef_run).to render_file(file.name).with_content('san_ip=203.0.113.10')
end end
it 'has solidfire san_login' do it 'has solidfire san_login' do
expect(@chef_run).to render_file(@file.name).with_content('san_login=solidfire_admin') expect(chef_run).to render_file(file.name).with_content('san_login=solidfire_admin')
end end
it 'has solidfire password' do it 'has solidfire password' do
expect(@chef_run).to render_file(@file.name).with_content('san_password=solidfire_testpass') expect(chef_run).to render_file(file.name).with_content('san_password=solidfire_testpass')
end end
it 'does not have iscsi_ip_prefix not specified' do it 'does not have iscsi_ip_prefix not specified' do
expect(@chef_run).to_not render_file(@file.name).with_content('iscsi_ip_prefix') expect(chef_run).to_not render_file(file.name).with_content('iscsi_ip_prefix')
end end
it 'does have iscsi_ip_prefix when specified' do it 'does have iscsi_ip_prefix when specified' do
@chef_run.node.set['openstack']['block-storage']['solidfire']['iscsi_ip_prefix'] = '203.0.113.*' chef_run.node.set['openstack']['block-storage']['solidfire']['iscsi_ip_prefix'] = '203.0.113.*'
expect(@chef_run).to render_file(@file.name).with_content('iscsi_ip_prefix=203.0.113.*') expect(chef_run).to render_file(file.name).with_content('iscsi_ip_prefix=203.0.113.*')
end end
end end
describe 'emc settings' do describe 'emc settings' do
before do before do
@chef_run.node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.emc.emc_smis_iscsi.EMCSMISISCSIDriver' node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.emc.emc_smis_iscsi.EMCSMISISCSIDriver'
@chef_run.node.set['openstack']['block-storage']['emc']['iscsi_target_prefix'] = 'test.prefix' node.set['openstack']['block-storage']['emc']['iscsi_target_prefix'] = 'test.prefix'
@chef_run.node.set['openstack']['block-storage']['emc']['cinder_emc_config_file'] = '/etc/test/config.file' node.set['openstack']['block-storage']['emc']['cinder_emc_config_file'] = '/etc/test/config.file'
@chef_run.converge 'openstack-block-storage::cinder-common'
end end
it 'has emc iscsi_target_prefix' do it 'has emc iscsi_target_prefix' do
expect(@chef_run).to render_file(@file.name).with_content('iscsi_target_prefix=test.prefix') expect(chef_run).to render_file(file.name).with_content('iscsi_target_prefix=test.prefix')
end end
it 'has cinder_emc_config_file' do it 'has cinder_emc_config_file' do
expect(@chef_run).to render_file(@file.name).with_content('cinder_emc_config_file=/etc/test/config.file') expect(chef_run).to render_file(file.name).with_content('cinder_emc_config_file=/etc/test/config.file')
end end
end end
describe 'vmware vmdk settings' do describe 'vmware vmdk settings' do
before do before do
@chef_run.node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver' chef_run.node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver'
@chef_run.converge 'openstack-block-storage::cinder-common' chef_run.converge 'openstack-block-storage::cinder-common'
end end
[ [
@@ -326,38 +307,33 @@ describe 'openstack-block-storage::cinder-common' do
/^vmware_max_objects_retrieval = 100$/ /^vmware_max_objects_retrieval = 100$/
].each do |content| ].each do |content|
it "has a #{content.source[1...-1]} line" do it "has a #{content.source[1...-1]} line" do
expect(@chef_run).to render_file(@file.name).with_content(content) expect(chef_run).to render_file(file.name).with_content(content)
end end
end end
it 'has no wsdl_location line' do it 'has no wsdl_location line' do
expect(@chef_run).not_to render_file(@file.name).with_content('vmware_wsdl_location = ') expect(chef_run).not_to render_file(file.name).with_content('vmware_wsdl_location = ')
end end
it 'has wsdl_location line' do it 'has wsdl_location line' do
chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) do |n| node.set['openstack']['block-storage']['vmware']['vmware_wsdl_location'] = 'http://127.0.0.1/wsdl'
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver'
n.set['openstack']['block-storage']['vmware']['vmware_wsdl_location'] = 'http://127.0.0.1/wsdl' expect(chef_run).to render_file(file.name).with_content('vmware_wsdl_location = http://127.0.0.1/wsdl')
end
filename = '/etc/cinder/cinder.conf'
chef_run.converge 'openstack-block-storage::cinder-common'
expect(chef_run).to render_file(filename).with_content('vmware_wsdl_location = http://127.0.0.1/wsdl')
end end
end end
end end
describe '/var/lock/cinder' do describe '/var/lock/cinder' do
before do let(:dir) { chef_run.directory('/var/lock/cinder') }
@dir = @chef_run.directory '/var/lock/cinder'
end
it 'has proper owner' do it 'has proper owner' do
expect(@dir.owner).to eq('cinder') expect(dir.owner).to eq('cinder')
expect(@dir.group).to eq('cinder') expect(dir.group).to eq('cinder')
end end
it 'has proper modes' do it 'has proper modes' do
expect(sprintf('%o', @dir.mode)).to eq '700' expect(sprintf('%o', dir.mode)).to eq '700'
end
end end
end end
end end

View File

@@ -2,9 +2,7 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::client' do describe 'openstack-block-storage::client' do
describe 'redhat' do describe 'redhat' do
let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) } let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) }
let(:node) { runner.node } let(:node) { runner.node }
let(:chef_run) do let(:chef_run) do

View File

@@ -2,9 +2,7 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::client' do describe 'openstack-block-storage::client' do
describe 'ubuntu' do describe 'ubuntu' do
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) } let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
let(:node) { runner.node } let(:node) { runner.node }
let(:chef_run) do let(:chef_run) do

View File

@@ -5,19 +5,17 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::identity_registration' do describe 'openstack-block-storage::identity_registration' do
before do describe 'ubuntu' do
block_storage_stubs let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS let(:node) { runner.node }
@chef_run.converge 'openstack-block-storage::identity_registration' let(:chef_run) { runner.converge(described_recipe) }
end
include_context 'block-storage-stubs'
it 'registers cinder volume service' do it 'registers cinder volume service' do
resource = @chef_run.find_resource( expect(chef_run).to create_service_openstack_identity_register(
'openstack-identity_register',
'Register Cinder Volume Service' 'Register Cinder Volume Service'
).to_hash ).with(
expect(resource).to include(
auth_uri: 'http://127.0.0.1:35357/v2.0', auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token', bootstrap_token: 'bootstrap-token',
service_name: 'cinder', service_name: 'cinder',
@@ -26,34 +24,15 @@ describe 'openstack-block-storage::identity_registration' do
endpoint_region: 'RegionOne', endpoint_region: 'RegionOne',
endpoint_adminurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s', endpoint_adminurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s',
endpoint_internalurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s', endpoint_internalurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s',
endpoint_publicurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s', endpoint_publicurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s'
action: [:create_service]
) )
end end
it 'overrides cinder volume service region' do context 'registers volume endpoint' do
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| it 'with default values' do
n.set['openstack']['block-storage']['region'] = 'serviceRegion' expect(chef_run).to create_endpoint_openstack_identity_register(
end
@chef_run.converge 'openstack-block-storage::identity_registration'
resource = @chef_run.find_resource(
'openstack-identity_register',
'Register Cinder Volume Service'
).to_hash
expect(resource).to include(
endpoint_region: 'serviceRegion',
action: [:create_service]
)
end
it 'registers cinder volume endpoint' do
resource = @chef_run.find_resource(
'openstack-identity_register',
'Register Cinder Volume Endpoint' 'Register Cinder Volume Endpoint'
).to_hash ).with(
expect(resource).to include(
auth_uri: 'http://127.0.0.1:35357/v2.0', auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token', bootstrap_token: 'bootstrap-token',
service_name: 'cinder', service_name: 'cinder',
@@ -62,57 +41,41 @@ describe 'openstack-block-storage::identity_registration' do
endpoint_region: 'RegionOne', endpoint_region: 'RegionOne',
endpoint_adminurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s', endpoint_adminurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s',
endpoint_internalurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s', endpoint_internalurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s',
endpoint_publicurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s', endpoint_publicurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s'
action: [:create_endpoint]
) )
end end
it 'overrides cinder volume endpoint region' do it 'with custom region override' do
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| node.set['openstack']['block-storage']['region'] = 'volumeRegion'
n.set['openstack']['block-storage']['region'] = 'volumeRegion' expect(chef_run).to create_endpoint_openstack_identity_register(
end
@chef_run.converge 'openstack-block-storage::identity_registration'
resource = @chef_run.find_resource(
'openstack-identity_register',
'Register Cinder Volume Endpoint' 'Register Cinder Volume Endpoint'
).to_hash ).with(endpoint_region: 'volumeRegion')
end
expect(resource).to include(
endpoint_region: 'volumeRegion',
action: [:create_endpoint]
)
end end
it 'registers service user' do it 'registers service user' do
resource = @chef_run.find_resource( expect(chef_run).to create_user_openstack_identity_register(
'openstack-identity_register',
'Register Cinder Service User' 'Register Cinder Service User'
).to_hash ).with(
expect(resource).to include(
auth_uri: 'http://127.0.0.1:35357/v2.0', auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token', bootstrap_token: 'bootstrap-token',
tenant_name: 'service', tenant_name: 'service',
user_name: 'cinder', user_name: 'cinder',
user_pass: 'cinder-pass', user_pass: 'cinder-pass',
user_enabled: true, user_enabled: true
action: [:create_user]
) )
end end
it 'grants admin role to service user for service tenant' do it 'grants admin role to service user for service tenant' do
resource = @chef_run.find_resource( expect(chef_run).to grant_role_openstack_identity_register(
'openstack-identity_register',
'Grant service Role to Cinder Service User for Cinder Service Tenant' 'Grant service Role to Cinder Service User for Cinder Service Tenant'
).to_hash ).with(
expect(resource).to include(
auth_uri: 'http://127.0.0.1:35357/v2.0', auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token', bootstrap_token: 'bootstrap-token',
tenant_name: 'service', tenant_name: 'service',
user_name: 'cinder', user_name: 'cinder',
role_name: 'admin', role_name: 'admin'
action: [:grant_role]
) )
end end
end end
end

View File

@@ -5,33 +5,35 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::scheduler' do describe 'openstack-block-storage::scheduler' do
before { block_storage_stubs }
describe 'redhat' do describe 'redhat' do
before do let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS let(:node) { runner.node }
@chef_run.converge 'openstack-block-storage::scheduler' let(:chef_run) { runner.converge(described_recipe) }
end
include_context 'block-storage-stubs'
it 'installs cinder scheduler packages' do it 'installs cinder scheduler packages' do
expect(@chef_run).to upgrade_package 'openstack-cinder' expect(chef_run).to upgrade_package 'openstack-cinder'
end
it 'starts cinder scheduler' do
expect(chef_run).to start_service 'openstack-cinder-scheduler'
end
it 'starts cinder scheduler on boot' do
expect(chef_run).to enable_service 'openstack-cinder-scheduler'
end end
it 'does not upgrade stevedore' do it 'does not upgrade stevedore' do
chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS
chef_run.converge 'openstack-block-storage::scheduler'
expect(chef_run).not_to upgrade_python_pip 'stevedore' expect(chef_run).not_to upgrade_python_pip 'stevedore'
end end
it 'installs mysql python packages by default' do it 'installs mysql python packages by default' do
expect(@chef_run).to upgrade_package 'MySQL-python' expect(chef_run).to upgrade_package 'MySQL-python'
end end
it 'installs db2 python packages if explicitly told' do it 'installs db2 python packages if explicitly told' do
chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS
node = chef_run.node
node.set['openstack']['db']['block-storage']['service_type'] = 'db2' node.set['openstack']['db']['block-storage']['service_type'] = 'db2'
chef_run.converge 'openstack-block-storage::scheduler'
['python-ibm-db', 'python-ibm-db-sa'].each do |pkg| ['python-ibm-db', 'python-ibm-db-sa'].each do |pkg|
expect(chef_run).to upgrade_package pkg expect(chef_run).to upgrade_package pkg
@@ -39,21 +41,10 @@ describe 'openstack-block-storage::scheduler' do
end end
it 'installs postgresql python packages if explicitly told' do it 'installs postgresql python packages if explicitly told' do
chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS
node = chef_run.node
node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql' node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql'
chef_run.converge 'openstack-block-storage::scheduler'
expect(chef_run).to upgrade_package 'python-psycopg2' expect(chef_run).to upgrade_package 'python-psycopg2'
expect(chef_run).not_to upgrade_package 'MySQL-python' expect(chef_run).not_to upgrade_package 'MySQL-python'
end end
it 'starts cinder scheduler' do
expect(@chef_run).to start_service 'openstack-cinder-scheduler'
end
it 'starts cinder scheduler on boot' do
expect(@chef_run).to enable_service 'openstack-cinder-scheduler'
end
end end
end end

View File

@@ -5,44 +5,38 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::scheduler' do describe 'openstack-block-storage::scheduler' do
before { block_storage_stubs }
describe 'suse' do describe 'suse' do
before do let(:runner) { ChefSpec::Runner.new(SUSE_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::SUSE_OPTS let(:node) { runner.node }
@chef_run.converge 'openstack-block-storage::scheduler' let(:chef_run) { runner.converge(described_recipe) }
end
include_context 'block-storage-stubs'
it 'installs cinder scheduler packages' do it 'installs cinder scheduler packages' do
expect(@chef_run).to upgrade_package 'openstack-cinder-scheduler' expect(chef_run).to upgrade_package 'openstack-cinder-scheduler'
end
it 'starts cinder scheduler' do
expect(chef_run).to start_service 'openstack-cinder-scheduler'
end
it 'starts cinder scheduler on boot' do
expect(chef_run).to enable_service 'openstack-cinder-scheduler'
end end
it 'does not upgrade stevedore' do it 'does not upgrade stevedore' do
chef_run = ::ChefSpec::Runner.new ::SUSE_OPTS
chef_run.converge 'openstack-block-storage::scheduler'
expect(chef_run).not_to upgrade_python_pip 'stevedore' expect(chef_run).not_to upgrade_python_pip 'stevedore'
end end
it 'installs mysql python packages by default' do it 'installs mysql python packages by default' do
expect(@chef_run).to upgrade_package 'python-mysql' expect(chef_run).to upgrade_package 'python-mysql'
end end
it 'installs postgresql python packages if explicitly told' do it 'installs postgresql python packages if explicitly told' do
chef_run = ::ChefSpec::Runner.new ::SUSE_OPTS
node = chef_run.node
node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql' node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql'
chef_run.converge 'openstack-block-storage::scheduler'
expect(chef_run).to upgrade_package 'python-psycopg2' expect(chef_run).to upgrade_package 'python-psycopg2'
expect(chef_run).not_to upgrade_package 'python-mysql' expect(chef_run).not_to upgrade_package 'python-mysql'
end end
it 'starts cinder scheduler' do
expect(@chef_run).to start_service 'openstack-cinder-scheduler'
end
it 'starts cinder scheduler on boot' do
expect(@chef_run).to enable_service 'openstack-cinder-scheduler'
end
end end
end end

View File

@@ -5,66 +5,49 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::scheduler' do describe 'openstack-block-storage::scheduler' do
before { block_storage_stubs }
describe 'ubuntu' do describe 'ubuntu' do
before do let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| let(:node) { runner.node }
n.set['openstack']['block-storage']['syslog']['use'] = true let(:chef_run) { runner.converge(described_recipe) }
end
@chef_run.converge 'openstack-block-storage::scheduler'
end
expect_runs_openstack_common_logging_recipe include_context 'block-storage-stubs'
include_examples 'common-logging'
it 'does not run logging recipe' do expect_creates_cinder_conf 'service[cinder-scheduler]', 'cinder', 'cinder'
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
chef_run.converge 'openstack-block-storage::scheduler'
expect(chef_run).not_to include_recipe 'openstack-common::logging'
end
it 'installs cinder scheduler packages' do it 'installs cinder scheduler packages' do
expect(@chef_run).to upgrade_package 'cinder-scheduler' expect(chef_run).to upgrade_package 'cinder-scheduler'
end
it 'starts cinder scheduler' do
expect(chef_run).to start_service 'cinder-scheduler'
end
it 'starts cinder scheduler on boot' do
expect(chef_run).to enable_service 'cinder-scheduler'
end end
it 'installs mysql python packages by default' do it 'installs mysql python packages by default' do
expect(@chef_run).to upgrade_package 'python-mysqldb' expect(chef_run).to upgrade_package 'python-mysqldb'
end end
it 'installs postgresql python packages if explicitly told' do it 'installs postgresql python packages if explicitly told' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
node = chef_run.node
node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql' node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql'
chef_run.converge 'openstack-block-storage::scheduler'
expect(chef_run).to upgrade_package 'python-psycopg2' expect(chef_run).to upgrade_package 'python-psycopg2'
expect(chef_run).not_to upgrade_package 'python-mysqldb' expect(chef_run).not_to upgrade_package 'python-mysqldb'
end end
it 'starts cinder scheduler' do
expect(@chef_run).to start_service 'cinder-scheduler'
end
it 'starts cinder scheduler on boot' do
expect(@chef_run).to enable_service 'cinder-scheduler'
end
it 'does not run logging recipe' do
expect(@chef_run).to enable_service 'cinder-scheduler'
end
it 'does not setup cron when no metering' do it 'does not setup cron when no metering' do
expect(@chef_run.cron('cinder-volume-usage-audit')).to be_nil expect(chef_run.cron('cinder-volume-usage-audit')).to be_nil
end end
it 'creates cron metering default' do it 'creates cron metering default' do
::Chef::Recipe.any_instance.stub(:search) ::Chef::Recipe.any_instance.stub(:search)
.with(:node, 'roles:os-block-storage-scheduler') .with(:node, 'roles:os-block-storage-scheduler')
.and_return([OpenStruct.new(name: 'fauxhai.local')]) .and_return([OpenStruct.new(name: 'fauxhai.local')])
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| node.set['openstack']['telemetry'] = true
n.set['openstack']['telemetry'] = true
end
chef_run.converge 'openstack-block-storage::scheduler'
cron = chef_run.cron 'cinder-volume-usage-audit' cron = chef_run.cron 'cinder-volume-usage-audit'
bin_str = '/usr/bin/cinder-volume-usage-audit > /var/log/cinder/audit.log' bin_str = '/usr/bin/cinder-volume-usage-audit > /var/log/cinder/audit.log'
expect(cron.command).to match(/#{bin_str}/) expect(cron.command).to match(/#{bin_str}/)
@@ -82,21 +65,17 @@ describe 'openstack-block-storage::scheduler' do
::Chef::Recipe.any_instance.stub(:search) ::Chef::Recipe.any_instance.stub(:search)
.with(:node, 'roles:os-block-storage-scheduler') .with(:node, 'roles:os-block-storage-scheduler')
.and_return([OpenStruct.new(name: 'foobar')]) .and_return([OpenStruct.new(name: 'foobar')])
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| node.set['openstack']['telemetry'] = true
n.set['openstack']['telemetry'] = true
crontests.each do |k, v| crontests.each do |k, v|
n.set['openstack']['block-storage']['cron'][k.to_s] = v node.set['openstack']['block-storage']['cron'][k.to_s] = v
end end
n.set['openstack']['block-storage']['user'] = 'foobar' node.set['openstack']['block-storage']['user'] = 'foobar'
end
chef_run.converge 'openstack-block-storage::scheduler'
cron = chef_run.cron 'cinder-volume-usage-audit' cron = chef_run.cron 'cinder-volume-usage-audit'
crontests.each do |k, v| crontests.each do |k, v|
expect(cron.send(k)).to eq v expect(cron.send(k)).to eq v
end end
expect(cron.action).to include :delete expect(cron.action).to include :delete
end end
expect_creates_cinder_conf 'service[cinder-scheduler]', 'cinder', 'cinder'
end end
end end

View File

@@ -5,102 +5,124 @@
require 'chefspec' require 'chefspec'
require 'chefspec/berkshelf' require 'chefspec/berkshelf'
require 'chef/application' require 'chef/application'
require_relative 'support/matcher'
::LOG_LEVEL = :fatal LOG_LEVEL = :fatal
::SUSE_OPTS = { SUSE_OPTS = {
platform: 'suse', platform: 'suse',
version: '11.03', version: '11.03',
log_level: ::LOG_LEVEL log_level: LOG_LEVEL
} }
::REDHAT_OPTS = { REDHAT_OPTS = {
platform: 'redhat', platform: 'redhat',
version: '6.3', version: '6.3',
log_level: ::LOG_LEVEL log_level: LOG_LEVEL
} }
::UBUNTU_OPTS = { UBUNTU_OPTS = {
platform: 'ubuntu', platform: 'ubuntu',
version: '12.04', version: '12.04',
log_level: ::LOG_LEVEL log_level: LOG_LEVEL
} }
def block_storage_stubs # rubocop:disable MethodLength shared_context 'block-storage-stubs' do
::Chef::Recipe.any_instance.stub(:rabbit_servers) before do
Chef::Recipe.any_instance.stub(:rabbit_servers)
.and_return('1.1.1.1:5672,2.2.2.2:5672') .and_return('1.1.1.1:5672,2.2.2.2:5672')
::Chef::Recipe.any_instance.stub(:get_password) Chef::Recipe.any_instance.stub(:get_password)
.with('service', anything) .with('service', anything)
.and_return('') .and_return('')
::Chef::Recipe.any_instance.stub(:get_password) Chef::Recipe.any_instance.stub(:get_password)
.with('db', anything) .with('db', anything)
.and_return('') .and_return('')
::Chef::Recipe.any_instance.stub(:secret) Chef::Recipe.any_instance.stub(:secret)
.with('secrets', 'openstack_identity_bootstrap_token') .with('secrets', 'openstack_identity_bootstrap_token')
.and_return('bootstrap-token') .and_return('bootstrap-token')
::Chef::Recipe.any_instance.stub(:secret) Chef::Recipe.any_instance.stub(:secret)
.with('secrets', 'rbd_secret_uuid') .with('secrets', 'rbd_secret_uuid')
.and_return('b0ff3bba-e07b-49b1-beed-09a45552b1ad') .and_return('b0ff3bba-e07b-49b1-beed-09a45552b1ad')
::Chef::Recipe.any_instance.stub(:get_password) Chef::Recipe.any_instance.stub(:get_password)
.with('user', 'guest') .with('user', 'guest')
.and_return('mq-pass') .and_return('mq-pass')
::Chef::Recipe.any_instance.stub(:get_password) Chef::Recipe.any_instance.stub(:get_password)
.with('user', 'solidfire_admin') .with('user', 'solidfire_admin')
.and_return('solidfire_testpass') .and_return('solidfire_testpass')
::Chef::Recipe.any_instance.stub(:get_password) Chef::Recipe.any_instance.stub(:get_password)
.with('service', 'netapp')
.and_return 'netapp-pass'
Chef::Recipe.any_instance.stub(:get_password)
.with('service', 'openstack-block-storage') .with('service', 'openstack-block-storage')
.and_return('cinder-pass') .and_return('cinder-pass')
::Chef::Recipe.any_instance.stub(:get_password) Chef::Recipe.any_instance.stub(:get_password)
.with('service', 'openstack_image_cephx_key') .with('service', 'openstack_image_cephx_key')
.and_return('cephx-key') .and_return('cephx-key')
::Chef::Recipe.any_instance.stub(:get_password) Chef::Recipe.any_instance.stub(:get_password)
.with('user', 'admin') .with('user', 'admin')
.and_return('emc_test_pass') .and_return('emc_test_pass')
::Chef::Application.stub(:fatal!) Chef::Application.stub(:fatal!)
end
end
shared_examples 'common-logging' do
context 'when syslog.use is true' do
before do
node.set['openstack']['block-storage']['syslog']['use'] = true
end
it 'runs logging recipe if node attributes say to' do
expect(chef_run).to include_recipe 'openstack-common::logging'
end
end
context 'when syslog.use is false' do
before do
node.set['openstack']['block-storage']['syslog']['use'] = false
end
it 'runs logging recipe if node attributes say to' do
expect(chef_run).to_not include_recipe 'openstack-common::logging'
end
end
end end
def expect_runs_openstack_common_logging_recipe def expect_runs_openstack_common_logging_recipe
it 'runs logging recipe if node attributes say to' do it 'runs logging recipe if node attributes say to' do
expect(@chef_run).to include_recipe 'openstack-common::logging' expect(chef_run).to include_recipe 'openstack-common::logging'
end end
end end
def expect_creates_cinder_conf(service, user, group, action = :restart) # rubocop:disable MethodLength def expect_creates_cinder_conf(service, user, group, action = :restart) # rubocop:disable MethodLength
describe 'cinder.conf' do describe 'cinder.conf' do
before do let(:file) { chef_run.template('/etc/cinder/cinder.conf') }
@file = @chef_run.template '/etc/cinder/cinder.conf'
end
it 'has proper owner' do it 'has proper owner' do
expect(@file.owner).to eq(user) expect(file.owner).to eq(user)
expect(@file.group).to eq(group) expect(file.group).to eq(group)
end end
it 'has proper modes' do it 'has proper modes' do
expect(sprintf('%o', @file.mode)).to eq '644' expect(sprintf('%o', file.mode)).to eq '644'
end end
it 'notifies service restart' do it 'notifies service restart' do
expect(@file).to notify(service).to(action) expect(file).to notify(service).to(action)
end end
end end
end end
def expect_creates_policy_json(service, user, group, action = :restart) # rubocop:disable MethodLength def expect_creates_policy_json(service, user, group, action = :restart) # rubocop:disable MethodLength
describe 'policy.json' do describe 'policy.json' do
before do let(:file) { chef_run.template('/etc/cinder/policy.json') }
@file = @chef_run.template '/etc/cinder/policy.json'
end
it 'has proper owner' do it 'has proper owner' do
expect(@file.owner).to eq(user) expect(file.owner).to eq(user)
expect(@file.group).to eq(group) expect(file.group).to eq(group)
end end
it 'has proper modes' do it 'has proper modes' do
expect(sprintf('%o', @file.mode)).to eq '644' expect(sprintf('%o', file.mode)).to eq '644'
end end
it 'notifies service restart' do it 'notifies service restart' do
expect(@file).to notify(service).to(action) expect(file).to notify(service).to(action)
end end
end end
end end

View File

@@ -1,7 +0,0 @@
# encoding: UTF-8
#
# Cookbook Name:: openstack-block-storage
def upgrade_python_pip(pkgname)
ChefSpec::Matchers::ResourceMatcher.new(:python_pip, :upgrade, pkgname)
end

View File

@@ -5,79 +5,77 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::volume' do describe 'openstack-block-storage::volume' do
before { block_storage_stubs }
describe 'redhat' do describe 'redhat' do
before do let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS let(:node) { runner.node }
@chef_run.converge 'openstack-block-storage::volume' let(:chef_run) { runner.converge(described_recipe) }
end
include_context 'block-storage-stubs'
it 'installs mysql python packages by default' do it 'installs mysql python packages by default' do
expect(@chef_run).to upgrade_package 'MySQL-python' expect(chef_run).to upgrade_package('MySQL-python')
end end
it 'installs db2 python packages if explicitly told' do it 'installs db2 python packages if explicitly told' do
chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS
node = chef_run.node
node.set['openstack']['db']['block-storage']['service_type'] = 'db2' node.set['openstack']['db']['block-storage']['service_type'] = 'db2'
chef_run.converge 'openstack-block-storage::volume'
['python-ibm-db', 'python-ibm-db-sa'].each do |pkg| ['python-ibm-db', 'python-ibm-db-sa'].each do |pkg|
expect(chef_run).to upgrade_package pkg expect(chef_run).to upgrade_package(pkg)
end end
end end
it 'installs postgresql python packages if explicitly told' do it 'installs postgresql python packages if explicitly told' do
chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS
node = chef_run.node
node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql' node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql'
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).to upgrade_package 'python-psycopg2' expect(chef_run).to upgrade_package('python-psycopg2')
expect(chef_run).not_to upgrade_package 'MySQL-python' expect(chef_run).not_to upgrade_package('MySQL-python')
end end
it 'installs cinder iscsi packages' do it 'installs cinder iscsi packages' do
expect(@chef_run).to upgrade_package 'scsi-target-utils' expect(chef_run).to upgrade_package('scsi-target-utils')
end end
it 'starts cinder volume' do it 'starts cinder volume' do
expect(@chef_run).to start_service 'openstack-cinder-volume' expect(chef_run).to start_service('openstack-cinder-volume')
end end
it 'starts cinder volume on boot' do it 'starts cinder volume on boot' do
expected = 'openstack-cinder-volume' expect(chef_run).to enable_service('openstack-cinder-volume')
expect(@chef_run).to enable_service expected
end end
context 'ISCSI' do
let(:file) { chef_run.template('/etc/tgt/targets.conf') }
it 'starts iscsi target on boot' do it 'starts iscsi target on boot' do
expect(@chef_run).to enable_service 'tgtd' expect(chef_run).to enable_service('tgtd')
end
it 'installs nfs packages' do
chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS do |n|
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.netapp.nfs.NetAppDirect7modeNfsDriver'
end
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).to upgrade_package 'nfs-utils'
expect(chef_run).to upgrade_package 'nfs-utils-lib'
end
it 'installs emc packages' do
chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS do |n|
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.emc.emc_smis_iscsi.EMCSMISISCSIDriver'
end
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).to upgrade_package 'pywbem'
end end
it 'has redhat include' do it 'has redhat include' do
file = '/etc/tgt/targets.conf' expect(chef_run).to render_file(file.name).with_content(
'include /var/lib/cinder/volumes/*')
expect(chef_run).not_to render_file(file.name).with_content(
'include /etc/tgt/conf.d/*.conf')
end
end
expect(@chef_run).to render_file(file).with_content('include /var/lib/cinder/volumes/*') context 'NFS Driver' do
expect(@chef_run).not_to render_file(file).with_content('include /etc/tgt/conf.d/*.conf') before do
node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.netapp.nfs.NetAppDirect7modeNfsDriver'
end
it 'installs nfs packages' do
expect(chef_run).to upgrade_package('nfs-utils')
expect(chef_run).to upgrade_package('nfs-utils-lib')
end
end
context 'EMC ISCSI Driver' do
before do
node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.emc.emc_smis_iscsi.EMCSMISISCSIDriver'
end
it 'installs emc packages' do
expect(chef_run).to upgrade_package('pywbem')
end
end end
end end
end end

View File

@@ -5,72 +5,71 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::volume' do describe 'openstack-block-storage::volume' do
before { block_storage_stubs }
describe 'suse' do describe 'suse' do
before do let(:runner) { ChefSpec::Runner.new(SUSE_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::SUSE_OPTS let(:node) { runner.node }
@chef_run.converge 'openstack-block-storage::volume' let(:chef_run) { runner.converge(described_recipe) }
end
include_context 'block-storage-stubs'
it 'installs cinder volume packages' do it 'installs cinder volume packages' do
expect(@chef_run).to upgrade_package 'openstack-cinder-volume' expect(chef_run).to upgrade_package('openstack-cinder-volume')
end end
it 'installs mysql python packages by default' do it 'installs mysql python packages by default' do
expect(@chef_run).to upgrade_package 'python-mysql' expect(chef_run).to upgrade_package('python-mysql')
end end
it 'installs postgresql python packages if explicitly told' do it 'installs postgresql python packages if explicitly told' do
chef_run = ::ChefSpec::Runner.new ::SUSE_OPTS
node = chef_run.node
node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql' node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql'
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).to upgrade_package 'python-psycopg2' expect(chef_run).to upgrade_package('python-psycopg2')
expect(chef_run).not_to upgrade_package 'python-mysql' expect(chef_run).not_to upgrade_package('python-mysql')
end end
it 'installs cinder iscsi packages' do it 'installs cinder iscsi packages' do
expect(@chef_run).to upgrade_package 'tgt' expect(chef_run).to upgrade_package('tgt')
end end
it 'starts cinder volume' do it 'starts cinder volume' do
expect(@chef_run).to start_service 'openstack-cinder-volume' expect(chef_run).to start_service('openstack-cinder-volume')
end end
it 'starts cinder volume on boot' do it 'starts cinder volume on boot' do
expected = 'openstack-cinder-volume' expect(chef_run).to enable_service('openstack-cinder-volume')
expect(@chef_run).to enable_service expected
end end
context 'ISCSI' do
let(:file) { chef_run.template('/etc/tgt/targets.conf') }
it 'starts iscsi target on boot' do it 'starts iscsi target on boot' do
expect(@chef_run).to enable_service 'tgtd' expect(chef_run).to enable_service('tgtd')
end
it 'installs nfs packages' do
chef_run = ::ChefSpec::Runner.new ::SUSE_OPTS do |n|
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.netapp.nfs.NetAppDirect7modeNfsDriver'
end
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).to upgrade_package 'nfs-utils'
expect(chef_run).not_to upgrade_package 'nfs-utils-lib'
end
it 'installs emc packages' do
chef_run = ::ChefSpec::Runner.new ::SUSE_OPTS do |n|
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.emc.emc_smis_iscsi.EMCSMISISCSIDriver'
end
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).to upgrade_package 'python-pywbem'
end end
it 'has suse include' do it 'has suse include' do
file = '/etc/tgt/targets.conf' expect(chef_run).to render_file(file.name).with_content('include /var/lib/cinder/volumes/*')
expect(chef_run).not_to render_file(file.name).with_content('include /etc/tgt/conf.d/*.conf')
end
end
expect(@chef_run).to render_file(file).with_content('include /var/lib/cinder/volumes/*') context 'NFS Driver' do
expect(@chef_run).not_to render_file(file).with_content('include /etc/tgt/conf.d/*.conf') before do
node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.netapp.nfs.NetAppDirect7modeNfsDriver'
end
it 'installs nfs packages' do
expect(chef_run).to upgrade_package('nfs-utils')
expect(chef_run).not_to upgrade_package('nfs-utils-lib')
end
end
context 'EMC ISCSI Driver' do
before do
node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.emc.emc_smis_iscsi.EMCSMISISCSIDriver'
end
it 'installs emc packages' do
expect(chef_run).to upgrade_package('python-pywbem')
end
end end
end end
end end

View File

@@ -5,303 +5,256 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-block-storage::volume' do describe 'openstack-block-storage::volume' do
before { block_storage_stubs }
describe 'ubuntu' do describe 'ubuntu' do
before do let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| let(:node) { runner.node }
n.set['openstack']['block-storage']['syslog']['use'] = true let(:chef_run) { runner.converge(described_recipe) }
end
@chef_run.converge 'openstack-block-storage::volume'
end
expect_runs_openstack_common_logging_recipe include_context 'block-storage-stubs'
include_examples 'common-logging'
it 'does not run logging recipe' do expect_creates_cinder_conf('service[cinder-volume]', 'cinder', 'cinder')
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).not_to include_recipe 'openstack-common::logging'
end
it 'installs cinder volume packages' do it 'installs cinder volume packages' do
expect(@chef_run).to upgrade_package 'cinder-volume' expect(chef_run).to upgrade_package 'cinder-volume'
end
it 'starts cinder volume' do
expect(chef_run).to start_service 'cinder-volume'
end
it 'starts cinder volume on boot' do
expect(chef_run).to enable_service 'cinder-volume'
end
it 'starts iscsi target on boot' do
expect(chef_run).to enable_service 'tgt'
end end
it 'installs mysql python packages by default' do it 'installs mysql python packages by default' do
expect(@chef_run).to upgrade_package 'python-mysqldb' expect(chef_run).to upgrade_package 'python-mysqldb'
end end
it 'installs postgresql python packages if explicitly told' do it 'installs postgresql python packages if explicitly told' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
node = chef_run.node
node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql' node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql'
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).to upgrade_package 'python-psycopg2' expect(chef_run).to upgrade_package 'python-psycopg2'
expect(chef_run).not_to upgrade_package 'python-mysqldb' expect(chef_run).not_to upgrade_package 'python-mysqldb'
end end
it 'installs cinder iscsi packages' do it 'installs cinder iscsi packages' do
expect(@chef_run).to upgrade_package 'tgt' expect(chef_run).to upgrade_package 'tgt'
end end
it 'installs emc packages' do it 'installs emc packages' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.emc.emc_smis_iscsi.EMCSMISISCSIDriver'
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.emc.emc_smis_iscsi.EMCSMISISCSIDriver'
end
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).to upgrade_package 'python-pywbem' expect(chef_run).to upgrade_package 'python-pywbem'
end end
it 'installs nfs packages' do context 'NetApp Driver' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| describe 'NFS' do
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.netapp.nfs.NetAppDirect7modeNfsDriver' before do
node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.netapp.nfs.NetAppDirect7modeNfsDriver'
end end
chef_run.converge 'openstack-block-storage::volume'
it 'installs nfs packages' do
expect(chef_run).to upgrade_package 'nfs-common' expect(chef_run).to upgrade_package 'nfs-common'
end end
it 'creates the nfs mount point' do it 'creates the nfs mount point' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.netapp.nfs.NetAppDirect7modeNfsDriver'
end
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).to create_directory '/mnt/cinder-volumes' expect(chef_run).to create_directory '/mnt/cinder-volumes'
end end
end
describe 'ISCSI' do
before do
node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.netapp.iscsi.NetAppISCSIDriver'
end
it 'configures netapp dfm password' do it 'configures netapp dfm password' do
::Chef::Recipe.any_instance.stub(:get_password).with('service', 'netapp')
.and_return 'netapp-pass'
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.netapp.iscsi.NetAppISCSIDriver'
end
chef_run.converge 'openstack-block-storage::volume'
n = chef_run.node['openstack']['block-storage']['netapp']['dfm_password'] n = chef_run.node['openstack']['block-storage']['netapp']['dfm_password']
expect(n).to eq 'netapp-pass' expect(n).to eq 'netapp-pass'
end end
describe 'RBD Ceph as block-storage backend' do
before do
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.rbd.RBDDriver'
n.set['openstack']['block-storage']['rbd_secret_name'] = 'rbd_secret_uuid'
# TODO: Remove work around once https://github.com/customink/fauxhai/pull/77 merges
n.set['cpu']['total'] = 1
end end
@chef_run.converge 'openstack-block-storage::volume' end
@filename = '/etc/ceph/ceph.client.cinder.keyring'
@file = @chef_run.template(@filename) context 'Ceph (RBD) Driver' do
let(:file) { chef_run.template('/etc/ceph/ceph.client.cinder.keyring') }
before do
node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.rbd.RBDDriver'
node.set['openstack']['block-storage']['rbd_secret_name'] = 'rbd_secret_uuid'
end end
it 'fetches the rbd_uuid_secret' do it 'fetches the rbd_uuid_secret' do
n = @chef_run.node['openstack']['block-storage']['rbd_secret_uuid'] n = chef_run.node['openstack']['block-storage']['rbd_secret_uuid']
expect(n).to eq 'b0ff3bba-e07b-49b1-beed-09a45552b1ad' expect(n).to eq 'b0ff3bba-e07b-49b1-beed-09a45552b1ad'
end end
it 'includes the ceph_client recipe' do it 'includes the ceph_client recipe' do
expect(@chef_run).to include_recipe('openstack-common::ceph_client') expect(chef_run).to include_recipe('openstack-common::ceph_client')
end end
it 'installs the needed ceph packages by default' do it 'installs the needed ceph packages by default' do
%w{ python-ceph ceph-common }.each do |pkg| %w{ python-ceph ceph-common }.each do |pkg|
expect(@chef_run).to install_package(pkg) expect(chef_run).to install_package(pkg)
end end
end end
it 'honors package option platform overrides for cinder_ceph_packages' do it 'honors package option platform overrides for python-ceph' do
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| node.set['openstack']['block-storage']['rbd_secret_name'] = 'rbd_secret_uuid'
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.rbd.RBDDriver' node.set['openstack']['block-storage']['platform']['package_overrides'] = '--override1 --override2'
n.set['openstack']['block-storage']['rbd_secret_name'] = 'rbd_secret_uuid'
n.set['openstack']['block-storage']['platform']['package_overrides'] = '--override1 --override2'
end
@chef_run.converge 'openstack-block-storage::volume'
%w{ python-ceph ceph-common }.each do |pkg| %w{ python-ceph ceph-common }.each do |pkg|
expect(@chef_run).to install_package(pkg).with(options: '--override1 --override2') expect(chef_run).to install_package(pkg).with(options: '--override1 --override2')
end end
end end
it 'honors package name platform overrides for cinder_ceph_packages' do it 'honors package name platform overrides for python-ceph' do
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| node.set['openstack']['block-storage']['rbd_secret_name'] = 'rbd_secret_uuid'
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.rbd.RBDDriver' node.set['openstack']['block-storage']['platform']['cinder_ceph_packages'] = ['my-ceph', 'my-other-ceph']
n.set['openstack']['block-storage']['rbd_secret_name'] = 'rbd_secret_uuid'
n.set['openstack']['block-storage']['platform']['cinder_ceph_packages'] = ['my-ceph', 'my-other-ceph']
end
@chef_run.converge 'openstack-block-storage::volume'
%w{my-ceph my-other-ceph}.each do |pkg| %w{my-ceph my-other-ceph}.each do |pkg|
expect(@chef_run).to install_package(pkg) expect(chef_run).to install_package(pkg)
end end
end end
it 'creates a cephx client keyring correctly' do it 'creates a cephx client keyring correctly' do
[/^\[client\.cinder\]$/, [/^\[client\.cinder\]$/,
/^ key = cephx-key$/].each do |content| /^ key = cephx-key$/].each do |content|
expect(@chef_run).to render_file(@filename).with_content(content) expect(chef_run).to render_file(file.name).with_content(content)
end end
expect(@chef_run).to create_template(@filename).with(cookbook: 'openstack-common') expect(chef_run).to create_template(file.name).with(cookbook: 'openstack-common')
expect(@file.owner).to eq('cinder') expect(file.owner).to eq('cinder')
expect(@file.group).to eq('cinder') expect(file.group).to eq('cinder')
expect(sprintf('%o', @file.mode)).to eq '600' expect(sprintf('%o', file.mode)).to eq '600'
end end
end end
context 'Storewize Driver' do
let(:file) { chef_run.template('/etc/cinder/cinder.conf') }
before do
node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.storwize_svc.StorwizeSVCDriver'
end
it 'configures storewize private key' do it 'configures storewize private key' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.storwize_svc.StorwizeSVCDriver'
end
chef_run.converge 'openstack-block-storage::volume'
san_key = chef_run.file chef_run.node['openstack']['block-storage']['san']['san_private_key'] san_key = chef_run.file chef_run.node['openstack']['block-storage']['san']['san_private_key']
expect(san_key.mode).to eq('0400') expect(san_key.mode).to eq('0400')
end end
it 'configures storewize with iscsi' do context 'ISCSI' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| before do
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.storwize_svc.StorwizeSVCDriver' node.set['openstack']['block-storage']['storwize']['storwize_svc_connection_protocol'] = 'iSCSI'
n.set['openstack']['block-storage']['storwize']['storwize_svc_connection_protocol'] = 'iSCSI'
end end
conf = '/etc/cinder/cinder.conf'
chef_run.converge 'openstack-block-storage::volume'
it 'configures storewize with iscsi' do
# Test that the FC specific options are not set when connected via iSCSI # Test that the FC specific options are not set when connected via iSCSI
expect(chef_run).not_to render_file(conf).with_content('storwize_svc_multipath_enabled') expect(chef_run).not_to render_file(file.name).with_content('storwize_svc_multipath_enabled')
end
end
context 'FC' do
before do
node.set['openstack']['block-storage']['storwize']['storwize_svc_connection_protocol'] = 'FC'
end end
it 'configures storewize with fc' do it 'configures storewize with fc' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.storwize_svc.StorwizeSVCDriver'
n.set['openstack']['block-storage']['storwize']['storwize_svc_connection_protocol'] = 'FC'
end
conf = '/etc/cinder/cinder.conf'
chef_run.converge 'openstack-block-storage::volume'
# Test that the iSCSI specific options are not set when connected via FC # Test that the iSCSI specific options are not set when connected via FC
expect(chef_run).not_to render_file(conf).with_content('storwize_svc_iscsi_chap_enabled') expect(chef_run).not_to render_file(file.name).with_content('storwize_svc_iscsi_chap_enabled')
end end
it 'starts cinder volume' do
expect(@chef_run).to start_service 'cinder-volume'
end end
it 'starts cinder volume on boot' do
expect(@chef_run).to enable_service 'cinder-volume'
end
expect_creates_cinder_conf 'service[cinder-volume]', 'cinder', 'cinder'
it 'starts iscsi target on boot' do
expect(@chef_run).to enable_service 'tgt'
end end
describe 'targets.conf' do describe 'targets.conf' do
before do let(:file) { chef_run.template('/etc/tgt/targets.conf') }
@file = @chef_run.template '/etc/tgt/targets.conf'
end
it 'has proper modes' do it 'has proper modes' do
expect(sprintf('%o', @file.mode)).to eq '600' expect(sprintf('%o', file.mode)).to eq '600'
end end
it 'notifies iscsi restart' do it 'notifies iscsi restart' do
expect(@file).to notify('service[iscsitarget]').to(:restart) expect(file).to notify('service[iscsitarget]').to(:restart)
end end
it 'has ubuntu include' do it 'has ubuntu include' do
expect(@chef_run).to render_file(@file.name).with_content('include /etc/tgt/conf.d/*.conf') expect(chef_run).to render_file(file.name).with_content('include /etc/tgt/conf.d/*.conf')
expect(@chef_run).not_to render_file(@file.name).with_content('include /var/lib/cinder/volumes/*') expect(chef_run).not_to render_file(file.name).with_content('include /var/lib/cinder/volumes/*')
end end
end end
describe 'create_vg' do describe 'create_vg' do
let(:file) { chef_run.template('/etc/init.d/cinder-group-active') }
before do before do
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.lvm.LVMISCSIDriver'
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.lvm.LVMISCSIDriver' node.set['openstack']['block-storage']['volume']['create_volume_group'] = true
n.set['openstack']['block-storage']['volume']['create_volume_group'] = true
end
stub_command('vgs cinder-volumes').and_return(false) stub_command('vgs cinder-volumes').and_return(false)
@filename = '/etc/init.d/cinder-group-active'
@chef_run.converge 'openstack-block-storage::volume'
@file = @chef_run.template(@filename)
end end
it 'cinder vg active' do it 'cinder vg active' do
expect(@chef_run).to enable_service 'cinder-group-active' expect(chef_run).to enable_service 'cinder-group-active'
end end
it 'create volume group' do it 'create volume group' do
volume_size = @chef_run.node['openstack']['block-storage']['volume']['volume_group_size'] volume_size = chef_run.node['openstack']['block-storage']['volume']['volume_group_size']
seek_count = volume_size.to_i * 1024 seek_count = volume_size.to_i * 1024
group_name = @chef_run.node['openstack']['block-storage']['volume']['volume_group'] group_name = chef_run.node['openstack']['block-storage']['volume']['volume_group']
path = @chef_run.node['openstack']['block-storage']['volume']['state_path'] path = chef_run.node['openstack']['block-storage']['volume']['state_path']
vg_file = "#{path}/#{group_name}.img" vg_file = "#{path}/#{group_name}.img"
cmd = "dd if=/dev/zero of=#{vg_file} bs=1M seek=#{seek_count} count=0; vgcreate cinder-volumes $(losetup --show -f #{vg_file})" cmd = "dd if=/dev/zero of=#{vg_file} bs=1M seek=#{seek_count} count=0; vgcreate cinder-volumes $(losetup --show -f #{vg_file})"
expect(@chef_run).to run_execute(cmd) expect(chef_run).to run_execute(cmd)
end end
it 'notifies cinder group active start' do it 'notifies cinder group active start' do
expect(@file).to notify('service[cinder-group-active]').to(:start) expect(file).to notify('service[cinder-group-active]').to(:start)
end end
it 'creates cinder group active template file' do it 'creates cinder group active template file' do
expect(@chef_run).to create_template(@filename) expect(chef_run).to create_template(file.name)
end end
end end
describe 'cinder_emc_config.xml' do describe 'cinder_emc_config.xml' do
let(:file) { chef_run.template('/etc/cinder/cinder_emc_config.xml') }
before do before do
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.emc.emc_smis_iscsi.EMCSMISISCSIDriver'
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.emc.emc_smis_iscsi.EMCSMISISCSIDriver'
end
@chef_run.converge 'openstack-block-storage::volume'
@filename = '/etc/cinder/cinder_emc_config.xml'
@file = @chef_run.template(@filename)
end end
it 'creates cinder emc config file' do it 'creates cinder emc config file' do
expect(@chef_run).to create_template(@filename) expect(chef_run).to create_template(file.name)
end end
it 'has proper modes' do it 'has proper modes' do
expect(sprintf('%o', @file.mode)).to eq('644') expect(sprintf('%o', file.mode)).to eq('644')
end end
it 'has StorageType' do it 'has StorageType' do
expect(@chef_run).to render_file(@file.name).with_content('<StorageType>0</StorageType>') expect(chef_run).to render_file(file.name).with_content('<StorageType>0</StorageType>')
end end
it 'has EcomServerIp' do it 'has EcomServerIp' do
expect(@chef_run).to render_file(@file.name).with_content('<EcomServerIp>127.0.0.1</EcomServerIp>') expect(chef_run).to render_file(file.name).with_content('<EcomServerIp>127.0.0.1</EcomServerIp>')
end end
it 'has EcomServerPort' do it 'has EcomServerPort' do
expect(@chef_run).to render_file(@file.name).with_content('<EcomServerPort>5988</EcomServerPort>') expect(chef_run).to render_file(file.name).with_content('<EcomServerPort>5988</EcomServerPort>')
end end
it 'has EcomUserName' do it 'has EcomUserName' do
expect(@chef_run).to render_file(@file.name).with_content('<EcomUserName>admin</EcomUserName>') expect(chef_run).to render_file(file.name).with_content('<EcomUserName>admin</EcomUserName>')
end end
it 'has EcomPassword' do it 'has EcomPassword' do
expect(@chef_run).to render_file(@file.name).with_content('<EcomPassword>emc_test_pass</EcomPassword>') expect(chef_run).to render_file(file.name).with_content('<EcomPassword>emc_test_pass</EcomPassword>')
end end
it 'does not have MaskingView when not specified' do it 'does not have MaskingView when not specified' do
expect(@chef_run).not_to render_file(@file.name).with_content('<MaskingView>') expect(chef_run).not_to render_file(file.name).with_content('<MaskingView>')
end end
it 'has MaskingView when specified' do it 'has MaskingView when specified' do
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| node.set['openstack']['block-storage']['emc']['MaskingView'] = 'testMaskingView'
n.set['openstack']['block-storage']['emc']['MaskingView'] = 'testMaskingView'
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.emc.emc_smis_iscsi.EMCSMISISCSIDriver'
end
@chef_run.converge 'openstack-block-storage::volume'
expect(@chef_run).to render_file(@file.name).with_content('<MaskingView>testMaskingView</MaskingView>') expect(chef_run).to render_file(file.name).with_content('<MaskingView>testMaskingView</MaskingView>')
end end
end end
end end