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
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 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'
}
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 include_context 'block-storage-stubs'
expect(@chef_run).to upgrade_package 'openstack-cinder'
it 'installs the openstack-cinder package' do
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'
}
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 include_context 'block-storage-stubs'
expect(@chef_run).to upgrade_package 'openstack-cinder'
it 'installs the openstack-cinder package' do
expect(chef_run).to upgrade_package 'openstack-cinder'
end
end end
end end

View File

@@ -5,359 +5,335 @@
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
@chef_run.converge 'openstack-block-storage::cinder-common'
end
it 'installs the cinder-common package' do runner.converge(described_recipe)
expect(@chef_run).to upgrade_package 'cinder-common'
end
describe '/etc/cinder' do
before do
@dir = @chef_run.directory '/etc/cinder'
end end
it 'has proper owner' do include_context 'block-storage-stubs'
expect(@dir.owner).to eq('cinder')
expect(@dir.group).to eq('cinder') it 'installs the cinder-common package' do
expect(chef_run).to upgrade_package 'cinder-common'
end end
it 'has proper modes' do describe '/etc/cinder' do
expect(sprintf('%o', @dir.mode)).to eq '750' let(:dir) { chef_run.directory('/etc/cinder') }
end
end
describe 'cinder.conf' do it 'has proper owner' do
before do expect(dir.owner).to eq('cinder')
@file = @chef_run.template '/etc/cinder/cinder.conf' expect(dir.group).to eq('cinder')
end
it 'has proper owner' do
expect(@file.owner).to eq('cinder')
expect(@file.group).to eq('cinder')
end
it 'has proper modes' do
expect(sprintf('%o', @file.mode)).to eq '644'
end
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('snapshot_name_template=snapshot-%s')
end
it 'has rpc_backend set' do
expect(@chef_run).to render_file(@file.name).with_content('rpc_backend=cinder.openstack.common.rpc.impl_kombu')
end
it 'has has volumes_dir set' do
expect(@chef_run).to render_file(@file.name).with_content('volumes_dir=/var/lib/cinder/volumes')
end
it 'has correct volume.driver set' do
expect(@chef_run).to render_file(@file.name).with_content('volume_driver=cinder.volume.drivers.lvm.LVMISCSIDriver')
end
it 'has rpc_thread_pool_size' do
expect(@chef_run).to render_file(@file.name).with_content('rpc_thread_pool_size=64')
end
it 'has rpc_conn_pool_size' do
expect(@chef_run).to render_file(@file.name).with_content('rpc_conn_pool_size=30')
end
it 'has rpc_response_timeout' do
expect(@chef_run).to render_file(@file.name).with_content('rpc_response_timeout=60')
end
it 'has rabbit_host' do
expect(@chef_run).to render_file(@file.name).with_content('rabbit_host=127.0.0.1')
end
it 'does not have rabbit_hosts' do
expect(@chef_run).not_to render_file(@file.name).with_content('rabbit_hosts=')
end
it 'does not have rabbit_ha_queues' do
expect(@chef_run).not_to render_file(@file.name).with_content('rabbit_ha_queues=')
end
it 'has log_file' do
expect(@chef_run).to render_file(@file.name).with_content('log_file = /var/log/cinder/cinder.log')
end
it 'has log_config when syslog is true' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
n.set['openstack']['block-storage']['syslog']['use'] = true
end 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') it 'has proper modes' do
expect(sprintf('%o', dir.mode)).to eq '750'
end
end end
it 'has rabbit_port' do describe 'cinder.conf' do
expect(@chef_run).to render_file(@file.name).with_content('rabbit_port=5672') let(:file) { chef_run.template('/etc/cinder/cinder.conf') }
end
it 'has rabbit_use_ssl' do it 'has proper owner' do
expect(@chef_run).to render_file(@file.name).with_content('rabbit_use_ssl=false') expect(file.owner).to eq('cinder')
end expect(file.group).to eq('cinder')
end
it 'has rabbit_userid' do it 'has proper modes' do
expect(@chef_run).to render_file(@file.name).with_content('rabbit_userid=guest') expect(sprintf('%o', file.mode)).to eq '644'
end end
it 'has rabbit_password' do it 'has name templates' 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('volume_name_template=volume-%s')
end expect(chef_run).to render_file(file.name).with_content('snapshot_name_template=snapshot-%s')
end
it 'has rabbit_virtual_host' do it 'has rpc_backend set' do
expect(@chef_run).to render_file(@file.name).with_content('rabbit_virtual_host=/') expect(chef_run).to render_file(file.name).with_content('rpc_backend=cinder.openstack.common.rpc.impl_kombu')
end end
it 'has rabbit notification_topics' do it 'has has volumes_dir set' 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('volumes_dir=/var/lib/cinder/volumes')
end end
describe 'rabbit ha' do it 'has correct volume.driver set' do
before do expect(chef_run).to render_file(file.name).with_content('volume_driver=cinder.volume.drivers.lvm.LVMISCSIDriver')
@chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) do |n| end
n.set['openstack']['mq']['block-storage']['rabbit']['ha'] = true
it 'has rpc_thread_pool_size' do
expect(chef_run).to render_file(file.name).with_content('rpc_thread_pool_size=64')
end
it 'has rpc_conn_pool_size' do
expect(chef_run).to render_file(file.name).with_content('rpc_conn_pool_size=30')
end
it 'has rpc_response_timeout' do
expect(chef_run).to render_file(file.name).with_content('rpc_response_timeout=60')
end
it 'has rabbit_host' do
expect(chef_run).to render_file(file.name).with_content('rabbit_host=127.0.0.1')
end
it 'does not have rabbit_hosts' do
expect(chef_run).not_to render_file(file.name).with_content('rabbit_hosts=')
end
it 'does not have rabbit_ha_queues' do
expect(chef_run).not_to render_file(file.name).with_content('rabbit_ha_queues=')
end
it 'has log_file' do
expect(chef_run).to render_file(file.name).with_content('log_file = /var/log/cinder/cinder.log')
end
it 'has log_config when syslog is true' do
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
it 'has rabbit_port' do
expect(chef_run).to render_file(file.name).with_content('rabbit_port=5672')
end
it 'has rabbit_use_ssl' do
expect(chef_run).to render_file(file.name).with_content('rabbit_use_ssl=false')
end
it 'has rabbit_userid' do
expect(chef_run).to render_file(file.name).with_content('rabbit_userid=guest')
end
it 'has rabbit_password' do
expect(chef_run).to render_file(file.name).with_content('rabbit_password=mq-pass')
end
it 'has rabbit_virtual_host' do
expect(chef_run).to render_file(file.name).with_content('rabbit_virtual_host=/')
end
it 'has rabbit notification_topics' do
expect(chef_run).to render_file(file.name).with_content('notification_topics=rabbit_topic')
end
describe 'rabbit ha' do
before do
node.set['openstack']['mq']['block-storage']['rabbit']['ha'] = true
end end
@chef_run.converge 'openstack-block-storage::cinder-common'
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
it 'has rabbit_ha_queues' do
expect(@chef_run).to render_file(@file.name).with_content('rabbit_ha_queues=True')
end
it 'does not have rabbit_host' do
expect(@chef_run).not_to render_file(@file.name).with_content('rabbit_host=127.0.0.1')
end
it 'does not have rabbit_port' do
expect(@chef_run).not_to render_file(@file.name).with_content('rabbit_port=5672')
end
end
describe 'qpid' do
before do
@chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) do |n|
n.set['openstack']['mq']['block-storage']['service_type'] = 'qpid'
n.set['openstack']['block-storage']['notification_driver'] = 'cinder.test_driver'
n.set['openstack']['mq']['block-storage']['qpid']['notification_topic'] = 'qpid_topic'
# we set username here since the attribute in common currently
# defaults to ''
n.set['openstack']['mq']['block-storage']['qpid']['username'] = 'guest'
end end
@chef_run.converge 'openstack-block-storage::cinder-common'
end
it 'has qpid_hostname' do it 'has rabbit_ha_queues' 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('rabbit_ha_queues=True')
end
it 'has qpid_port' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_port=5672')
end
it 'has qpid_username' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_username=guest')
end
it 'has qpid_password' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_password=mq-pass')
end
it 'has qpid_sasl_mechanisms' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_sasl_mechanisms=')
end
it 'has qpid_reconnect_timeout' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_reconnect_timeout=0')
end
it 'has qpid_reconnect_limit' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_reconnect_limit=0')
end
it 'has qpid_reconnect_interval_min' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_reconnect_interval_min=0')
end
it 'has qpid_reconnect_interval_max' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_reconnect_interval_max=0')
end
it 'has qpid_reconnect_interval' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_reconnect_interval=0')
end
it 'has qpid_reconnect' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_reconnect=true')
end
it 'has qpid_heartbeat' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_heartbeat=60')
end
it 'has qpid_protocol' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_protocol=tcp')
end
it 'has qpid_tcp_nodelay' do
expect(@chef_run).to render_file(@file.name).with_content('qpid_tcp_nodelay=true')
end
it 'has notification_driver' do
expect(@chef_run).to render_file(@file.name).with_content('notification_driver=cinder.test_driver')
end
it 'has notification_topics' do
expect(@chef_run).to render_file(@file.name).with_content('notification_topics=qpid_topic')
end
end
describe 'lvm settings' do
before do
@chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) do |n|
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.lvm.LVMISCSIDriver'
n.set['openstack']['block-storage']['volume']['volume_group'] = 'test-group'
n.set['openstack']['block-storage']['volume']['volume_clear_size'] = 100
n.set['openstack']['block-storage']['volume']['volume_clear'] = 'none'
end end
@chef_run.converge 'openstack-block-storage::cinder-common'
end
it 'has volume_group' do it 'does not have rabbit_host' do
expect(@chef_run).to render_file(@file.name).with_content('volume_group=test-group') expect(chef_run).not_to render_file(file.name).with_content('rabbit_host=127.0.0.1')
end
it 'has volume_clear_size' do
expect(@chef_run).to render_file(@file.name).with_content('volume_clear_size=100')
end
it 'has volume_clear' do
expect(@chef_run).to render_file(@file.name).with_content('volume_clear=none')
end
end
describe 'solidfire settings' do
before do
@chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) do |n|
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.solidfire.SolidFire'
n.set['openstack']['block-storage']['solidfire']['sf_emulate'] = 'test'
n.set['openstack']['block-storage']['solidfire']['san_ip'] = '203.0.113.10'
n.set['openstack']['block-storage']['solidfire']['san_login'] = 'solidfire_admin'
end end
@chef_run.converge 'openstack-block-storage::cinder-common'
end
it 'has solidfire sf_emulate set' do it 'does not have rabbit_port' do
expect(@chef_run).to render_file(@file.name).with_content('sf_emulate_512=test') expect(chef_run).not_to render_file(file.name).with_content('rabbit_port=5672')
end
it 'has solidfire san_ip set' do
expect(@chef_run).to render_file(@file.name).with_content('san_ip=203.0.113.10')
end
it 'has solidfire san_login' do
expect(@chef_run).to render_file(@file.name).with_content('san_login=solidfire_admin')
end
it 'has solidfire password' do
expect(@chef_run).to render_file(@file.name).with_content('san_password=solidfire_testpass')
end
it 'does not have iscsi_ip_prefix not specified' do
expect(@chef_run).to_not render_file(@file.name).with_content('iscsi_ip_prefix')
end
it 'does have iscsi_ip_prefix when specified' do
@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.*')
end
end
describe 'emc settings' do
before do
@chef_run.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'
@chef_run.node.set['openstack']['block-storage']['emc']['cinder_emc_config_file'] = '/etc/test/config.file'
@chef_run.converge 'openstack-block-storage::cinder-common'
end
it 'has emc iscsi_target_prefix' do
expect(@chef_run).to render_file(@file.name).with_content('iscsi_target_prefix=test.prefix')
end
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')
end
end
describe 'vmware vmdk settings' do
before do
@chef_run.node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver'
@chef_run.converge 'openstack-block-storage::cinder-common'
end
[
/^vmware_host_ip = $/,
/^vmware_host_username = $/,
/^vmware_host_password = $/,
/^vmware_api_retry_count = 10$/,
/^vmware_task_poll_interval = 5$/,
/^vmware_volume_folder = cinder-volumes/,
/^vmware_image_transfer_timeout_secs = 7200$/,
/^vmware_max_objects_retrieval = 100$/
].each do |content|
it "has a #{content.source[1...-1]} line" do
expect(@chef_run).to render_file(@file.name).with_content(content)
end end
end end
it 'has no wsdl_location line' do describe 'qpid' do
expect(@chef_run).not_to render_file(@file.name).with_content('vmware_wsdl_location = ') before do
end node.set['openstack']['mq']['block-storage']['service_type'] = 'qpid'
node.set['openstack']['block-storage']['notification_driver'] = 'cinder.test_driver'
it 'has wsdl_location line' do node.set['openstack']['mq']['block-storage']['qpid']['notification_topic'] = 'qpid_topic'
chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) do |n| # we set username here since the attribute in common currently
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver' # defaults to ''
n.set['openstack']['block-storage']['vmware']['vmware_wsdl_location'] = 'http://127.0.0.1/wsdl' node.set['openstack']['mq']['block-storage']['qpid']['username'] = 'guest'
end
it 'has qpid_hostname' do
expect(chef_run).to render_file(file.name).with_content('qpid_hostname=127.0.0.1')
end
it 'has qpid_port' do
expect(chef_run).to render_file(file.name).with_content('qpid_port=5672')
end
it 'has qpid_username' do
expect(chef_run).to render_file(file.name).with_content('qpid_username=guest')
end
it 'has qpid_password' do
expect(chef_run).to render_file(file.name).with_content('qpid_password=mq-pass')
end
it 'has qpid_sasl_mechanisms' do
expect(chef_run).to render_file(file.name).with_content('qpid_sasl_mechanisms=')
end
it 'has qpid_reconnect_timeout' do
expect(chef_run).to render_file(file.name).with_content('qpid_reconnect_timeout=0')
end
it 'has qpid_reconnect_limit' do
expect(chef_run).to render_file(file.name).with_content('qpid_reconnect_limit=0')
end
it 'has qpid_reconnect_interval_min' do
expect(chef_run).to render_file(file.name).with_content('qpid_reconnect_interval_min=0')
end
it 'has qpid_reconnect_interval_max' do
expect(chef_run).to render_file(file.name).with_content('qpid_reconnect_interval_max=0')
end
it 'has qpid_reconnect_interval' do
expect(chef_run).to render_file(file.name).with_content('qpid_reconnect_interval=0')
end
it 'has qpid_reconnect' do
expect(chef_run).to render_file(file.name).with_content('qpid_reconnect=true')
end
it 'has qpid_heartbeat' do
expect(chef_run).to render_file(file.name).with_content('qpid_heartbeat=60')
end
it 'has qpid_protocol' do
expect(chef_run).to render_file(file.name).with_content('qpid_protocol=tcp')
end
it 'has qpid_tcp_nodelay' do
expect(chef_run).to render_file(file.name).with_content('qpid_tcp_nodelay=true')
end
it 'has notification_driver' do
expect(chef_run).to render_file(file.name).with_content('notification_driver=cinder.test_driver')
end
it 'has notification_topics' do
expect(chef_run).to render_file(file.name).with_content('notification_topics=qpid_topic')
end
end
describe 'lvm settings' do
before do
node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.lvm.LVMISCSIDriver'
node.set['openstack']['block-storage']['volume']['volume_group'] = 'test-group'
node.set['openstack']['block-storage']['volume']['volume_clear_size'] = 100
node.set['openstack']['block-storage']['volume']['volume_clear'] = 'none'
end
it 'has volume_group' do
expect(chef_run).to render_file(file.name).with_content('volume_group=test-group')
end
it 'has volume_clear_size' do
expect(chef_run).to render_file(file.name).with_content('volume_clear_size=100')
end
it 'has volume_clear' do
expect(chef_run).to render_file(file.name).with_content('volume_clear=none')
end
end
describe 'solidfire settings' do
before do
node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.solidfire.SolidFire'
node.set['openstack']['block-storage']['solidfire']['sf_emulate'] = 'test'
node.set['openstack']['block-storage']['solidfire']['san_ip'] = '203.0.113.10'
node.set['openstack']['block-storage']['solidfire']['san_login'] = 'solidfire_admin'
end
it 'has solidfire sf_emulate set' do
expect(chef_run).to render_file(file.name).with_content('sf_emulate_512=test')
end
it 'has solidfire san_ip set' do
expect(chef_run).to render_file(file.name).with_content('san_ip=203.0.113.10')
end
it 'has solidfire san_login' do
expect(chef_run).to render_file(file.name).with_content('san_login=solidfire_admin')
end
it 'has solidfire password' do
expect(chef_run).to render_file(file.name).with_content('san_password=solidfire_testpass')
end
it 'does not have iscsi_ip_prefix not specified' do
expect(chef_run).to_not render_file(file.name).with_content('iscsi_ip_prefix')
end
it 'does have iscsi_ip_prefix when specified' do
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.*')
end
end
describe 'emc settings' do
before do
node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.emc.emc_smis_iscsi.EMCSMISISCSIDriver'
node.set['openstack']['block-storage']['emc']['iscsi_target_prefix'] = 'test.prefix'
node.set['openstack']['block-storage']['emc']['cinder_emc_config_file'] = '/etc/test/config.file'
end
it 'has emc iscsi_target_prefix' do
expect(chef_run).to render_file(file.name).with_content('iscsi_target_prefix=test.prefix')
end
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')
end
end
describe 'vmware vmdk settings' do
before do
chef_run.node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver'
chef_run.converge 'openstack-block-storage::cinder-common'
end
[
/^vmware_host_ip = $/,
/^vmware_host_username = $/,
/^vmware_host_password = $/,
/^vmware_api_retry_count = 10$/,
/^vmware_task_poll_interval = 5$/,
/^vmware_volume_folder = cinder-volumes/,
/^vmware_image_transfer_timeout_secs = 7200$/,
/^vmware_max_objects_retrieval = 100$/
].each do |content|
it "has a #{content.source[1...-1]} line" do
expect(chef_run).to render_file(file.name).with_content(content)
end
end
it 'has no wsdl_location line' do
expect(chef_run).not_to render_file(file.name).with_content('vmware_wsdl_location = ')
end
it 'has wsdl_location line' do
node.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 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
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,114 +5,77 @@
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
it 'registers cinder volume service' do include_context 'block-storage-stubs'
resource = @chef_run.find_resource(
'openstack-identity_register',
'Register Cinder Volume Service'
).to_hash
expect(resource).to include( it 'registers cinder volume service' do
auth_uri: 'http://127.0.0.1:35357/v2.0', expect(chef_run).to create_service_openstack_identity_register(
bootstrap_token: 'bootstrap-token', 'Register Cinder Volume Service'
service_name: 'cinder', ).with(
service_type: 'volume', auth_uri: 'http://127.0.0.1:35357/v2.0',
service_description: 'Cinder Volume Service', bootstrap_token: 'bootstrap-token',
endpoint_region: 'RegionOne', service_name: 'cinder',
endpoint_adminurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s', service_type: 'volume',
endpoint_internalurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s', service_description: 'Cinder Volume Service',
endpoint_publicurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s', endpoint_region: 'RegionOne',
action: [:create_service] endpoint_adminurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s',
) endpoint_internalurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s',
end endpoint_publicurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s'
)
it 'overrides cinder volume service region' do
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
n.set['openstack']['block-storage']['region'] = 'serviceRegion'
end 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( context 'registers volume endpoint' do
endpoint_region: 'serviceRegion', it 'with default values' do
action: [:create_service] expect(chef_run).to create_endpoint_openstack_identity_register(
) 'Register Cinder Volume Endpoint'
end ).with(
auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
service_name: 'cinder',
service_type: 'volume',
service_description: 'Cinder Volume Service',
endpoint_region: 'RegionOne',
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_publicurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s'
)
end
it 'registers cinder volume endpoint' do it 'with custom region override' do
resource = @chef_run.find_resource( node.set['openstack']['block-storage']['region'] = 'volumeRegion'
'openstack-identity_register', expect(chef_run).to create_endpoint_openstack_identity_register(
'Register Cinder Volume Endpoint' 'Register Cinder Volume Endpoint'
).to_hash ).with(endpoint_region: 'volumeRegion')
end
expect(resource).to include(
auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
service_name: 'cinder',
service_type: 'volume',
service_description: 'Cinder Volume Service',
endpoint_region: 'RegionOne',
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_publicurl: 'http://127.0.0.1:8776/v1/%(tenant_id)s',
action: [:create_endpoint]
)
end
it 'overrides cinder volume endpoint region' do
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
n.set['openstack']['block-storage']['region'] = 'volumeRegion'
end end
@chef_run.converge 'openstack-block-storage::identity_registration'
resource = @chef_run.find_resource(
'openstack-identity_register',
'Register Cinder Volume Endpoint'
).to_hash
expect(resource).to include( it 'registers service user' do
endpoint_region: 'volumeRegion', expect(chef_run).to create_user_openstack_identity_register(
action: [:create_endpoint] 'Register Cinder Service User'
) ).with(
end auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
tenant_name: 'service',
user_name: 'cinder',
user_pass: 'cinder-pass',
user_enabled: true
)
end
it 'registers service user' 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'
'Register Cinder Service User' ).with(
).to_hash auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
expect(resource).to include( tenant_name: 'service',
auth_uri: 'http://127.0.0.1:35357/v2.0', user_name: 'cinder',
bootstrap_token: 'bootstrap-token', role_name: 'admin'
tenant_name: 'service', )
user_name: 'cinder', end
user_pass: 'cinder-pass',
user_enabled: true,
action: [:create_user]
)
end
it 'grants admin role to service user for service tenant' do
resource = @chef_run.find_resource(
'openstack-identity_register',
'Grant service Role to Cinder Service User for Cinder Service Tenant'
).to_hash
expect(resource).to include(
auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
tenant_name: 'service',
user_name: 'cinder',
role_name: 'admin',
action: [:grant_role]
)
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| node.set['openstack']['block-storage']['cron'][k.to_s] = v
n.set['openstack']['block-storage']['cron'][k.to_s] = v
end
n.set['openstack']['block-storage']['user'] = 'foobar'
end end
chef_run.converge 'openstack-block-storage::scheduler' node.set['openstack']['block-storage']['user'] = 'foobar'
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
.and_return('1.1.1.1:5672,2.2.2.2:5672') Chef::Recipe.any_instance.stub(:rabbit_servers)
::Chef::Recipe.any_instance.stub(:get_password) .and_return('1.1.1.1:5672,2.2.2.2:5672')
.with('service', anything) Chef::Recipe.any_instance.stub(:get_password)
.and_return('') .with('service', anything)
::Chef::Recipe.any_instance.stub(:get_password) .and_return('')
.with('db', anything) Chef::Recipe.any_instance.stub(:get_password)
.and_return('') .with('db', anything)
::Chef::Recipe.any_instance.stub(:secret) .and_return('')
.with('secrets', 'openstack_identity_bootstrap_token') Chef::Recipe.any_instance.stub(:secret)
.and_return('bootstrap-token') .with('secrets', 'openstack_identity_bootstrap_token')
::Chef::Recipe.any_instance.stub(:secret) .and_return('bootstrap-token')
.with('secrets', 'rbd_secret_uuid') Chef::Recipe.any_instance.stub(:secret)
.and_return('b0ff3bba-e07b-49b1-beed-09a45552b1ad') .with('secrets', 'rbd_secret_uuid')
::Chef::Recipe.any_instance.stub(:get_password) .and_return('b0ff3bba-e07b-49b1-beed-09a45552b1ad')
.with('user', 'guest') Chef::Recipe.any_instance.stub(:get_password)
.and_return('mq-pass') .with('user', 'guest')
::Chef::Recipe.any_instance.stub(:get_password) .and_return('mq-pass')
.with('user', 'solidfire_admin') Chef::Recipe.any_instance.stub(:get_password)
.and_return('solidfire_testpass') .with('user', 'solidfire_admin')
::Chef::Recipe.any_instance.stub(:get_password) .and_return('solidfire_testpass')
.with('service', 'openstack-block-storage') Chef::Recipe.any_instance.stub(:get_password)
.and_return('cinder-pass') .with('service', 'netapp')
::Chef::Recipe.any_instance.stub(:get_password) .and_return 'netapp-pass'
.with('service', 'openstack_image_cephx_key') Chef::Recipe.any_instance.stub(:get_password)
.and_return('cephx-key') .with('service', 'openstack-block-storage')
::Chef::Recipe.any_instance.stub(:get_password) .and_return('cinder-pass')
.with('user', 'admin') Chef::Recipe.any_instance.stub(:get_password)
.and_return('emc_test_pass') .with('service', 'openstack_image_cephx_key')
::Chef::Application.stub(:fatal!) .and_return('cephx-key')
Chef::Recipe.any_instance.stub(:get_password)
.with('user', 'admin')
.and_return('emc_test_pass')
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
it 'starts iscsi target on boot' do context 'ISCSI' do
expect(@chef_run).to enable_service 'tgtd' let(:file) { chef_run.template('/etc/tgt/targets.conf') }
end it 'starts iscsi target on boot' do
expect(chef_run).to enable_service('tgtd')
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 end
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).to upgrade_package 'nfs-utils' it 'has redhat include' do
expect(chef_run).to upgrade_package 'nfs-utils-lib' expect(chef_run).to render_file(file.name).with_content(
end 'include /var/lib/cinder/volumes/*')
expect(chef_run).not_to render_file(file.name).with_content(
it 'installs emc packages' do 'include /etc/tgt/conf.d/*.conf')
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 end
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).to upgrade_package 'pywbem'
end end
it 'has redhat include' do context 'NFS Driver' do
file = '/etc/tgt/targets.conf' before do
node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.netapp.nfs.NetAppDirect7modeNfsDriver'
end
expect(@chef_run).to render_file(file).with_content('include /var/lib/cinder/volumes/*') it 'installs nfs packages' do
expect(@chef_run).not_to render_file(file).with_content('include /etc/tgt/conf.d/*.conf') 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
it 'starts iscsi target on boot' do context 'ISCSI' do
expect(@chef_run).to enable_service 'tgtd' let(:file) { chef_run.template('/etc/tgt/targets.conf') }
end it 'starts iscsi target on boot' do
expect(chef_run).to enable_service('tgtd')
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 end
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).to upgrade_package 'nfs-utils' it 'has suse include' do
expect(chef_run).not_to upgrade_package 'nfs-utils-lib' expect(chef_run).to render_file(file.name).with_content('include /var/lib/cinder/volumes/*')
end expect(chef_run).not_to render_file(file.name).with_content('include /etc/tgt/conf.d/*.conf')
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 end
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).to upgrade_package 'python-pywbem'
end end
it 'has suse include' do context 'NFS Driver' do
file = '/etc/tgt/targets.conf' before do
node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.netapp.nfs.NetAppDirect7modeNfsDriver'
end
expect(@chef_run).to render_file(file).with_content('include /var/lib/cinder/volumes/*') it 'installs nfs packages' do
expect(@chef_run).not_to render_file(file).with_content('include /etc/tgt/conf.d/*.conf') 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
end node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.netapp.nfs.NetAppDirect7modeNfsDriver'
chef_run.converge 'openstack-block-storage::volume'
expect(chef_run).to upgrade_package 'nfs-common'
end
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'
end
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']
expect(n).to eq 'netapp-pass'
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'
@filename = '/etc/ceph/ceph.client.cinder.keyring' it 'installs nfs packages' do
@file = @chef_run.template(@filename) expect(chef_run).to upgrade_package 'nfs-common'
end
it 'creates the nfs mount point' do
expect(chef_run).to create_directory '/mnt/cinder-volumes'
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
n = chef_run.node['openstack']['block-storage']['netapp']['dfm_password']
expect(n).to eq 'netapp-pass'
end
end
end
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
it 'configures storewize private key' do context 'Storewize Driver' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| let(:file) { chef_run.template('/etc/cinder/cinder.conf') }
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.storwize_svc.StorwizeSVCDriver' before do
node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.storwize_svc.StorwizeSVCDriver'
end end
chef_run.converge 'openstack-block-storage::volume'
san_key = chef_run.file chef_run.node['openstack']['block-storage']['san']['san_private_key'] it 'configures storewize private key' do
expect(san_key.mode).to eq('0400') san_key = chef_run.file chef_run.node['openstack']['block-storage']['san']['san_private_key']
end expect(san_key.mode).to eq('0400')
it 'configures storewize with iscsi' 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'] = 'iSCSI'
end end
conf = '/etc/cinder/cinder.conf'
chef_run.converge 'openstack-block-storage::volume'
# Test that the FC specific options are not set when connected via iSCSI context 'ISCSI' do
expect(chef_run).not_to render_file(conf).with_content('storwize_svc_multipath_enabled') before do
end node.set['openstack']['block-storage']['storwize']['storwize_svc_connection_protocol'] = 'iSCSI'
end
it 'configures storewize with fc' do it 'configures storewize with iscsi' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n| # Test that the FC specific options are not set when connected via iSCSI
n.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.storwize_svc.StorwizeSVCDriver' expect(chef_run).not_to render_file(file.name).with_content('storwize_svc_multipath_enabled')
n.set['openstack']['block-storage']['storwize']['storwize_svc_connection_protocol'] = 'FC' end
end 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 context 'FC' do
expect(chef_run).not_to render_file(conf).with_content('storwize_svc_iscsi_chap_enabled') before do
end node.set['openstack']['block-storage']['storwize']['storwize_svc_connection_protocol'] = 'FC'
end
it 'starts cinder volume' do it 'configures storewize with fc' do
expect(@chef_run).to start_service 'cinder-volume' # Test that the iSCSI specific options are not set when connected via FC
end expect(chef_run).not_to render_file(file.name).with_content('storwize_svc_iscsi_chap_enabled')
end
it 'starts cinder volume on boot' do end
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