 1858c025b2
			
		
	
	1858c025b2
	
	
	
		
			
			* 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
		
			
				
	
	
		
			205 lines
		
	
	
		
			7.5 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			205 lines
		
	
	
		
			7.5 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| # encoding: UTF-8
 | |
| require_relative 'spec_helper'
 | |
| require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'uri'
 | |
| require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'endpoints'
 | |
| 
 | |
| describe 'openstack-common::default' do
 | |
|   describe 'Openstack endpoints' do
 | |
|     let(:runner) { ChefSpec::SoloRunner.new(CHEFSPEC_OPTS) }
 | |
|     let(:node) { runner.node }
 | |
|     let(:chef_run) { runner.converge(described_recipe) }
 | |
|     let(:subject) { Object.new.extend(Openstack) }
 | |
| 
 | |
|     %w(public internal admin).each do |ep_type|
 | |
|       describe "#{ep_type}_endpoint" do
 | |
|         it 'fails with a NoMethodError when no openstack.endpoints in node attrs' do
 | |
|           allow(subject).to receive(:node).and_return({})
 | |
|           expect do
 | |
|             subject.send("#{ep_type}_endpoint", 'someservice')
 | |
|           end.to raise_error(NoMethodError)
 | |
|         end
 | |
| 
 | |
|         it 'fails with a NoMethodError when no endpoint was found' do
 | |
|           allow(subject).to receive(:node).and_return(node)
 | |
|           expect do
 | |
|             subject.send("#{ep_type}_endpoint", 'someservice')
 | |
|           end.to raise_error(NoMethodError)
 | |
|         end
 | |
| 
 | |
|         it 'handles a URI needing escaped' do
 | |
|           uri_hash = {
 | |
|             'openstack' => {
 | |
|               'endpoints' => {
 | |
|                 'compute-api' => {
 | |
|                   ep_type => {
 | |
|                     'uri' => 'http://localhost:8080/v2/%(tenant_id)s'
 | |
|                   }
 | |
|                 }
 | |
|               }
 | |
|             }
 | |
|           }
 | |
|           allow(subject).to receive(:node).and_return(uri_hash)
 | |
|           expect(
 | |
|             subject.send("#{ep_type}_endpoint", 'compute-api').path
 | |
|           ).to eq('/v2/%25(tenant_id)s')
 | |
|         end
 | |
| 
 | |
|         it 'returns endpoint URI object when uri key in endpoint hash' do
 | |
|           uri_hash = {
 | |
|             'openstack' => {
 | |
|               'endpoints' => {
 | |
|                 'compute-api' => {
 | |
|                   ep_type => {
 | |
|                     'uri' => 'http://localhost:1234/path'
 | |
|                   }
 | |
|                 }
 | |
|               }
 | |
|             }
 | |
|           }
 | |
|           allow(subject).to receive(:node).and_return(uri_hash)
 | |
|           expect(
 | |
|             subject.send("#{ep_type}_endpoint", 'compute-api').port
 | |
|           ).to eq(1234)
 | |
|         end
 | |
| 
 | |
|         it 'returns endpoint URI string when uri key in endpoint hash and host also in hash' do
 | |
|           uri_hash = {
 | |
|             'openstack' => {
 | |
|               'endpoints' => {
 | |
|                 'compute-api' => {
 | |
|                   ep_type => {
 | |
|                     'uri' => 'http://localhost',
 | |
|                     'host' => 'ignored'
 | |
|                   }
 | |
|                 }
 | |
|               }
 | |
|             }
 | |
|           }
 | |
|           allow(subject).to receive(:node).and_return(uri_hash)
 | |
|           expect(subject.send("#{ep_type}_endpoint", 'compute-api').to_s).to eq('http://localhost')
 | |
|         end
 | |
| 
 | |
|         it 'returns endpoint URI object when uri key not in endpoint hash but host is in hash' do
 | |
|           subject.should_receive(:uri_from_hash).with('host' => 'localhost', 'port' => '1234')
 | |
|           uri_hash = {
 | |
|             'openstack' => {
 | |
|               'endpoints' => {
 | |
|                 'compute-api' => {
 | |
|                   ep_type => {
 | |
|                     'host' => 'localhost',
 | |
|                     'port' => '1234'
 | |
|                   }
 | |
|                 }
 | |
|               }
 | |
|             }
 | |
|           }
 | |
|           allow(subject).to receive(:node).and_return(uri_hash)
 | |
|           subject.send("#{ep_type}_endpoint", 'compute-api')
 | |
|         end
 | |
|       end
 | |
|     end
 | |
| 
 | |
|     describe '#db' do
 | |
|       it 'returns nil when no openstack.db not in node attrs' do
 | |
|         allow(subject).to receive(:node).and_return({})
 | |
|         expect(subject.db('nonexisting')).to be_nil
 | |
|       end
 | |
| 
 | |
|       it 'returns nil when no such service was found' do
 | |
|         allow(subject).to receive(:node).and_return(chef_run.node)
 | |
|         expect(subject.db('nonexisting')).to be_nil
 | |
|       end
 | |
| 
 | |
|       it 'returns db info hash when service found' do
 | |
|         allow(subject).to receive(:node).and_return(chef_run.node)
 | |
|         expect(subject.db('compute')['host']).to eq('127.0.0.1')
 | |
|         expect(subject.db('compute').key?('uri')).to be_falsey
 | |
|       end
 | |
|     end
 | |
| 
 | |
|     describe '#db_uri' do
 | |
|       it 'returns nil when no openstack.db not in node attrs' do
 | |
|         allow(subject).to receive(:node).and_return({})
 | |
|         expect(subject.db_uri('nonexisting', 'user', 'pass')).to be_nil
 | |
|       end
 | |
| 
 | |
|       it 'returns nil when no such service was found' do
 | |
|         allow(subject).to receive(:node).and_return(chef_run.node)
 | |
|         expect(
 | |
|           subject.db_uri('nonexisting', 'user', 'pass')
 | |
|         ).to be_nil
 | |
|       end
 | |
| 
 | |
|       it 'returns compute db info hash when service found for default mysql' do
 | |
|         allow(subject).to receive(:node).and_return(chef_run.node)
 | |
|         expected = 'mysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
 | |
|         expect(
 | |
|           subject.db_uri('compute', 'user', 'pass')
 | |
|         ).to eq(expected)
 | |
|       end
 | |
| 
 | |
|       it 'returns network db info hash when service found for sqlite with options' do
 | |
|         node.set['openstack']['db']['service_type'] = 'sqlite'
 | |
|         node.set['openstack']['db']['options'] = { 'sqlite' => '?options' }
 | |
|         node.set['openstack']['db']['network']['path'] = 'path'
 | |
|         allow(subject).to receive(:node).and_return(chef_run.node)
 | |
|         expected = 'sqlite:///path?options'
 | |
|         expect(
 | |
|           subject.db_uri('network', 'user', 'pass')
 | |
|         ).to eq(expected)
 | |
|       end
 | |
| 
 | |
|       it 'returns compute db info hash when service found for mariadb' do
 | |
|         node.set['openstack']['db']['service_type'] = 'mariadb'
 | |
|         allow(subject).to receive(:node).and_return(chef_run.node)
 | |
|         expected = 'mysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
 | |
|         expect(
 | |
|           subject.db_uri('compute', 'user', 'pass')
 | |
|         ).to eq(expected)
 | |
|       end
 | |
| 
 | |
|       %w(galera percona-cluster).each do |db|
 | |
|         it "returns compute db info hash when service found for #{db}" do
 | |
|           node.set['openstack']['db']['service_type'] = db
 | |
|           allow(subject).to receive(:node).and_return(chef_run.node)
 | |
|           expected = 'mysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
 | |
|           expect(
 | |
|             subject.db_uri('compute', 'user', 'pass')
 | |
|           ).to eq(expected)
 | |
|         end
 | |
|       end
 | |
| 
 | |
|       it 'returns compute slave db info hash when service found for default mysql' do
 | |
|         node.set['openstack']['endpoints']['db']['enabled_slave'] = true
 | |
|         allow(subject).to receive(:node).and_return(chef_run.node)
 | |
|         expected = 'mysql://user:pass@127.0.0.1:3316/nova?charset=utf8'
 | |
|         expect(
 | |
|           subject.db_uri('compute', 'user', 'pass', true)
 | |
|         ).to eq(expected)
 | |
|       end
 | |
| 
 | |
|       it 'returns image slave db info hash when service found for mariadb' do
 | |
|         node.set['openstack']['db']['service_type'] = 'mariadb'
 | |
|         node.set['openstack']['endpoints']['db']['enabled_slave'] = true
 | |
|         allow(subject).to receive(:node).and_return(chef_run.node)
 | |
|         expected = 'mysql://user:pass@127.0.0.1:3316/glance?charset=utf8'
 | |
|         expect(
 | |
|           subject.db_uri('image', 'user', 'pass', true)
 | |
|         ).to eq(expected)
 | |
|       end
 | |
| 
 | |
|       %w(galera percona-cluster).each do |db|
 | |
|         it "returns network slave db info hash when service found for #{db}" do
 | |
|           node.set['openstack']['db']['service_type'] = db
 | |
|           node.set['openstack']['endpoints']['db']['enabled_slave'] = true
 | |
|           allow(subject).to receive(:node).and_return(chef_run.node)
 | |
|           expected = 'mysql://user:pass@127.0.0.1:3316/neutron?charset=utf8'
 | |
|           expect(
 | |
|             subject.db_uri('network', 'user', 'pass', true)
 | |
|           ).to eq(expected)
 | |
|         end
 | |
|       end
 | |
|     end
 | |
|   end
 | |
| end
 |