* version bump to 13.0.0 for mitaka release * removed suse support * removed general endpoint method, since we should be able to always specify which endpoint we need * removed fallbacks in specific_endpoint method, since this behaviour is not a very obvious one to the user and it should rather return an error than an unexpected result * dry public, internal and admin endpoint methods * removed obsolete private methods * adapted method calls for admin_endpoint in libraries/cli.rb * refactored set_endpoints_by_interface recipe to directly call address_for instead of address, since the recipe already checks for an existing attribute ..['bind_interface'] and therefore address would redirect to address_for anyways * moved the nested hash order for the public, internal and admin attributes to to be more clear and to break all existing calls to fix them during the refactoring process of all cookbooks e.g: node['openstack']['endpoints']['internal']['identity'] is now node['openstack']['endpoints']['identity']['internal'] and can be moved into the identity cookbook. This also streamlines these endpoint attributes with the bind_interface and host attributes * removed dependency on openstack-identity cookbooks by moving openrc recipe to opentack-identity (same for corrensponding specs and template) * removed address method and use the address (or hostname) defined in the endpoints hash directly (logic to set this attribute should rather be done in a wrapper (with a fitting method) instead of a static and predefined one) * removed set_endpoints_by_interface recipe since logic for defining the endpoints will be moved to wrapper cookbooks * added helper method merge_config_options for generation of config hashes used in service config templates * added template for openstack-service.conf.erb which can be used by all service cookbooks * deleted all endpoints attibutes, since these are moved to the service cookbooks for easier dependency handling Implements: blueprint cookbook-refactoring Change-Id: I0547182085eed91d05384fdd7734408a839a9a2c
158 lines
5.2 KiB
Ruby
158 lines
5.2 KiB
Ruby
# encoding: UTF-8
|
|
require_relative 'spec_helper'
|
|
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'cli'
|
|
|
|
describe 'openstack-common::default' do
|
|
describe 'Openstack CLI' do
|
|
let(:runner) { ChefSpec::SoloRunner.new(CHEFSPEC_OPTS) }
|
|
let(:node) { runner.node }
|
|
let(:chef_run) do
|
|
runner.converge(described_recipe)
|
|
end
|
|
let(:subject) { Object.new.extend(Openstack) }
|
|
|
|
include_context 'library-stubs'
|
|
|
|
describe 'openstack_command_env' do
|
|
before do
|
|
node.set['openstack']['endpoints']['identity']['admin'] = {
|
|
host: '127.0.0.1',
|
|
scheme: 'http',
|
|
path: '/v2.0',
|
|
port: '35357'
|
|
}
|
|
end
|
|
it 'returns cli enviroment' do
|
|
allow(subject).to receive(:get_password)
|
|
.with('user', 'name')
|
|
.and_return('pass')
|
|
|
|
expect(
|
|
subject.openstack_command_env('name', 'tenant')
|
|
).to eq(
|
|
'OS_USERNAME' => 'name',
|
|
'OS_PASSWORD' => 'pass',
|
|
'OS_TENANT_NAME' => 'tenant',
|
|
'OS_AUTH_URL' => 'http://127.0.0.1:35357/v2.0'
|
|
)
|
|
end
|
|
end
|
|
|
|
describe 'openstack_command' do
|
|
it 'runs openstack command' do
|
|
env =
|
|
{
|
|
'OS_USERNAME' => 'name',
|
|
'OS_PASSWORD' => 'pass',
|
|
'OS_TENANT_NAME' => 'tenant',
|
|
'OS_AUTH_URL' => 'http://127.0.0.1:35357/v2.0'
|
|
}
|
|
allow(subject).to receive(:shell_out).with(
|
|
['keystone', 'user-list'],
|
|
env: env
|
|
).and_return double('shell_out', exitstatus: 0, stdout: 'good', stderr: '')
|
|
|
|
result = subject.openstack_command('keystone', 'user-list', env)
|
|
expect(result).to eq('good')
|
|
end
|
|
|
|
it 'runs openstack command with args' do
|
|
env =
|
|
{
|
|
'OS_USERNAME' => 'name',
|
|
'OS_PASSWORD' => 'pass',
|
|
'OS_TENANT_NAME' => 'tenant',
|
|
'OS_AUTH_URL' => 'http://127.0.0.1:35357/v2.0'
|
|
}
|
|
allow(subject).to receive(:shell_out).with(
|
|
%w(keystone --key1 value1 --key2 value2 --key3 user-list),
|
|
env: env
|
|
).and_return double('shell_out', exitstatus: 0, stdout: 'good', stderr: '')
|
|
|
|
result = subject.openstack_command('keystone', 'user-list', env, 'key1' => 'value1', 'key2' => 'value2', 'key3' => '')
|
|
expect(result).to eq('good')
|
|
end
|
|
|
|
it 'runs openstack command with failure' do
|
|
env =
|
|
{
|
|
'OS_USERNAME' => 'name',
|
|
'OS_PASSWORD' => 'pass',
|
|
'OS_TENANT_NAME' => 'tenant',
|
|
'OS_AUTH_URL' => 'http://127.0.0.1:35357/v2.0'
|
|
}
|
|
allow(subject).to receive(:shell_out).with(
|
|
['keystone', 'user-list'],
|
|
env: env
|
|
).and_return double('shell_out', exitstatus: 123, stdout: 'fail', stderr: '')
|
|
|
|
# TODO: need to figure out why this won't work.
|
|
# expect(subject.openstack_command('keystone', 'user-list', env)).to fail
|
|
end
|
|
end
|
|
|
|
describe 'identity_uuid' do
|
|
it 'runs identity command to query uuid' do
|
|
env =
|
|
{
|
|
'OS_USERNAME' => 'name',
|
|
'OS_PASSWORD' => 'pass',
|
|
'OS_TENANT_NAME' => 'tenant',
|
|
'OS_AUTH_URL' => 'http://127.0.0.1:35357/v2.0'
|
|
}
|
|
allow(subject).to receive(:openstack_command).with('keystone', 'user-list', env, {})
|
|
allow(subject).to receive(:prettytable_to_array)
|
|
.and_return([{ 'name' => 'user1', 'id' => '1234567890ABCDEFGH' }])
|
|
|
|
result = subject.identity_uuid('user', 'name', 'user1', env)
|
|
expect(result).to eq('1234567890ABCDEFGH')
|
|
end
|
|
end
|
|
|
|
describe 'image_id' do
|
|
let(:env) do
|
|
{
|
|
'OS_USERNAME' => 'name',
|
|
'OS_PASSWORD' => 'pass',
|
|
'OS_TENANT_NAME' => 'tenant',
|
|
'OS_AUTH_URL' => 'http://127.0.0.1:35357/v2.0'
|
|
}
|
|
end
|
|
|
|
it 'runs glance command to query valid id' do
|
|
allow(subject).to receive(:openstack_command).with('glance', 'image-list', :env, {})
|
|
allow(subject).to receive(:prettytable_to_array)
|
|
.and_return([{ 'ID' => '87f38e15-9737-46cc-a612-7c67ee29a24f', 'Name' => 'cirros' }])
|
|
|
|
result = subject.image_id('cirros', :env)
|
|
expect(result).to eq('87f38e15-9737-46cc-a612-7c67ee29a24f')
|
|
end
|
|
|
|
it 'runs glance command to query invalid id' do
|
|
allow(subject).to receive(:openstack_command).with('glance', 'image-list', :env, {})
|
|
.and_raise("No image with a name or ID of 'test' exists. (1)")
|
|
|
|
expect { subject.image_id('test', :env) }.to raise_error(RuntimeError)
|
|
end
|
|
end
|
|
|
|
describe 'network_uuid' do
|
|
it 'runs network command to query uuid' do
|
|
env =
|
|
{
|
|
'OS_USERNAME' => 'name',
|
|
'OS_PASSWORD' => 'pass',
|
|
'OS_TENANT_NAME' => 'tenant',
|
|
'OS_AUTH_URL' => 'http://127.0.0.1:35357/v2.0'
|
|
}
|
|
allow(subject).to receive(:openstack_command).with('neutron', 'net-list', env, {})
|
|
allow(subject).to receive(:prettytable_to_array)
|
|
.and_return([{ 'name' => 'net1', 'id' => '1234567890ABCDEFGH' }])
|
|
|
|
result = subject.network_uuid('net', 'name', 'net1', env)
|
|
expect(result).to eq('1234567890ABCDEFGH')
|
|
end
|
|
end
|
|
end
|
|
end
|