Replace mocha by rspec-mocks
puppetlabs_spec_helper recommends rspec-mocks instead of mocha[1] and
it uses rspec-mocks by default instead of mocha since v 5.0.0[2]
This is the prep work to adapt to that migration.
[1] https://github.com/puppetlabs/puppetlabs_spec_helper/#mock_with
[2] 493f0cbc1c
Closes-Bug: #2004135
Change-Id: Idfb4d8344af472aec0c6bbdd9b3600eedd17eb46
This commit is contained in:
parent
7b51c9178a
commit
0f8158a399
@ -78,18 +78,18 @@ shared_examples_for 'prefetch the resources' do
|
||||
it 'should correctly prefetch the existing resource' do
|
||||
existing = resources[0]
|
||||
non_existing = resources[1]
|
||||
resource = mock
|
||||
resource = double
|
||||
r = []
|
||||
r << existing
|
||||
|
||||
catalog = Puppet::Resource::Catalog.new
|
||||
r.each { |res| catalog.add_resource(res) }
|
||||
m_value = mock
|
||||
m_first = mock
|
||||
resource.expects(:values).returns(m_value)
|
||||
m_value.expects(:first).returns(m_first)
|
||||
m_first.expects(:catalog).returns(catalog)
|
||||
m_first.expects(:class).returns(described_class.resource_type)
|
||||
m_value = double
|
||||
m_first = double
|
||||
expect(resource).to receive(:values).and_return(m_value)
|
||||
expect(m_value).to receive(:first).and_return(m_first)
|
||||
expect(m_first).to receive(:catalog).and_return(catalog)
|
||||
expect(m_first).to receive(:class).and_return(described_class.resource_type)
|
||||
described_class.prefetch(resource)
|
||||
|
||||
# found and not found
|
||||
|
@ -17,6 +17,8 @@ RSpec.configure do |c|
|
||||
|
||||
c.module_path = File.join(fixture_path, 'modules')
|
||||
c.manifest_dir = File.join(fixture_path, 'manifests')
|
||||
|
||||
c.mock_with :rspec
|
||||
end
|
||||
|
||||
RSpec::Matchers.define :be_absent do
|
||||
|
@ -50,12 +50,12 @@ describe Puppet::Type.type(:keystone_domain).provider(:openstack) do
|
||||
|
||||
describe '#create' do
|
||||
it 'creates a domain' do
|
||||
entry = mock
|
||||
provider.expects(:keystone_conf_default_domain_id_entry).returns(entry)
|
||||
entry = double
|
||||
expect(provider).to receive(:keystone_conf_default_domain_id_entry).and_return(entry)
|
||||
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('domain', 'create', '--format', 'shell', ['domain_one', '--enable', '--description', 'Domain One'])
|
||||
.returns('id="1cb05cfed7c24279be884ba4f6520262"
|
||||
.and_return('id="1cb05cfed7c24279be884ba4f6520262"
|
||||
name="domain_one"
|
||||
description="Domain One"
|
||||
enabled=True
|
||||
@ -67,11 +67,11 @@ enabled=True
|
||||
|
||||
describe '#destroy' do
|
||||
it 'destroys a domain' do
|
||||
entry = mock
|
||||
provider.expects(:keystone_conf_default_domain_id_entry).returns(entry)
|
||||
described_class.expects(:openstack)
|
||||
entry = double
|
||||
expect(provider).to receive(:keystone_conf_default_domain_id_entry).and_return(entry)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('domain', 'set', ['domain_one', '--disable'])
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('domain', 'delete', 'domain_one')
|
||||
|
||||
provider.destroy
|
||||
@ -82,9 +82,9 @@ enabled=True
|
||||
|
||||
describe '#instances' do
|
||||
it 'finds every domain' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('domain', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Name","Description","Enabled"
|
||||
.and_return('"ID","Name","Description","Enabled"
|
||||
"1cb05cfed7c24279be884ba4f6520262","domain_one","Domain One",True
|
||||
')
|
||||
instances = described_class.instances
|
||||
@ -105,17 +105,17 @@ enabled=True
|
||||
|
||||
context 'default_domain_id defined in keystone.conf' do
|
||||
it 'creates a default domain' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('domain', 'create', '--format', 'shell',
|
||||
['new_default', '--enable', '--description', 'New default domain.'])
|
||||
.returns('id="1cb05cfed7c24279be884ba4f6520262"
|
||||
.and_return('id="1cb05cfed7c24279be884ba4f6520262"
|
||||
name="domain_one"
|
||||
description="Domain One"
|
||||
enabled=True
|
||||
')
|
||||
entry = mock
|
||||
provider.expects(:keystone_conf_default_domain_id_entry).returns(entry)
|
||||
entry.expects(:create).returns(nil)
|
||||
entry = double
|
||||
expect(provider).to receive(:keystone_conf_default_domain_id_entry).and_return(entry)
|
||||
expect(entry).to receive(:create).and_return(nil)
|
||||
provider.create
|
||||
expect(provider.exists?).to be_truthy
|
||||
end
|
||||
@ -124,18 +124,18 @@ enabled=True
|
||||
|
||||
describe '#destroy default' do
|
||||
it 'destroys a default domain' do
|
||||
entry = mock
|
||||
provider.expects(:keystone_conf_default_domain_id_entry).returns(entry)
|
||||
entry = double
|
||||
expect(provider).to receive(:keystone_conf_default_domain_id_entry).and_return(entry)
|
||||
|
||||
described_class.expects(:default_domain_id).returns('1cb05cfed7c24279be884ba4f6520262')
|
||||
provider.expects(:is_default).returns(:true)
|
||||
provider.expects(:id).times(3).returns('1cb05cfed7c24279be884ba4f6520262')
|
||||
expect(described_class).to receive(:default_domain_id).and_return('1cb05cfed7c24279be884ba4f6520262')
|
||||
expect(provider).to receive(:is_default).and_return(:true)
|
||||
expect(provider).to receive(:id).exactly(3).times.and_return('1cb05cfed7c24279be884ba4f6520262')
|
||||
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('domain', 'set', ['domain_one', '--disable'])
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('domain', 'delete', 'domain_one')
|
||||
entry.expects(:destroy)
|
||||
expect(entry).to receive(:destroy)
|
||||
provider.destroy
|
||||
expect(provider.exists?).to be_falsey
|
||||
end
|
||||
@ -153,17 +153,17 @@ enabled=True
|
||||
end
|
||||
|
||||
it 'changes the description' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('domain', 'set', ['domain_one', '--description', 'new description'])
|
||||
provider.description = 'new description'
|
||||
provider.flush
|
||||
end
|
||||
|
||||
it 'changes is_default' do
|
||||
entry = mock
|
||||
provider.expects(:keystone_conf_default_domain_id_entry).returns(entry)
|
||||
provider.expects(:id).times(3).returns('current_default_domain')
|
||||
entry.expects(:create)
|
||||
entry = double
|
||||
expect(provider).to receive(:keystone_conf_default_domain_id_entry).and_return(entry)
|
||||
expect(provider).to receive(:id).exactly(3).times.and_return('current_default_domain')
|
||||
expect(entry).to receive(:create)
|
||||
|
||||
provider.is_default=(:true)
|
||||
provider.flush
|
||||
|
@ -35,7 +35,7 @@ describe provider_class do
|
||||
})
|
||||
config_provider = Puppet::Type.type(:keystone_config).provider(:openstackconfig)
|
||||
keystone_config = config_provider.new(config)
|
||||
keystone_config.class.expects(:file_path).at_least_once.returns(tmpfile)
|
||||
expect(keystone_config.class).to receive(:file_path).at_least(1).times.and_return(tmpfile)
|
||||
keystone_config.create
|
||||
|
||||
@domain = Puppet::Type::Keystone_domain_config.new(
|
||||
|
@ -39,30 +39,30 @@ describe Puppet::Type.type(:keystone_endpoint).provider(:openstack) do
|
||||
|
||||
describe '#create' do
|
||||
before(:each) do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('endpoint', 'create', '--format', 'shell',
|
||||
['service_id1', 'admin', 'http://127.0.0.1:5002', '--region', 'region'])
|
||||
.returns('admin_url="http://127.0.0.1:5002"
|
||||
.and_return('admin_url="http://127.0.0.1:5002"
|
||||
id="endpoint1_id"
|
||||
region="region"
|
||||
')
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('endpoint', 'create', '--format', 'shell',
|
||||
['service_id1', 'internal', 'http://127.0.0.1:5001', '--region', 'region'])
|
||||
.returns('internal_url="http://127.0.0.1:5001"
|
||||
.and_return('internal_url="http://127.0.0.1:5001"
|
||||
id="endpoint2_id"
|
||||
region="region"
|
||||
')
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('endpoint', 'create', '--format', 'shell',
|
||||
['service_id1', 'public', 'http://127.0.0.1:5000', '--region', 'region'])
|
||||
.returns('public_url="http://127.0.0.1:5000"
|
||||
.and_return('public_url="http://127.0.0.1:5000"
|
||||
id="endpoint3_id"
|
||||
region="region"
|
||||
')
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('service', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Name","Type"
|
||||
.and_return('"ID","Name","Type"
|
||||
"service_id1","endpoint","type_one"
|
||||
')
|
||||
end
|
||||
@ -96,11 +96,11 @@ region="region"
|
||||
describe '#destroy' do
|
||||
it 'destroys an endpoint' do
|
||||
provider.instance_variable_get('@property_hash')[:id] = 'endpoint1_id,endpoint2_id,endpoint3_id'
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('endpoint', 'delete', 'endpoint1_id')
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('endpoint', 'delete', 'endpoint2_id')
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('endpoint', 'delete', 'endpoint3_id')
|
||||
provider.destroy
|
||||
expect(provider.exists?).to be_falsey
|
||||
@ -120,9 +120,9 @@ region="region"
|
||||
describe '#instances' do
|
||||
context 'basic' do
|
||||
it 'finds every tenant' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('endpoint', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Region","Service Name","Service Type","Enabled","Interface","URL"
|
||||
.and_return('"ID","Region","Service Name","Service Type","Enabled","Interface","URL"
|
||||
"endpoint1_id","RegionOne","keystone","identity",True,"admin","http://127.0.0.1:5002"
|
||||
"endpoint2_id","RegionOne","keystone","identity",True,"internal","https://127.0.0.1:5001"
|
||||
"endpoint3_id","RegionOne","keystone","identity",True,"public","https://127.0.0.1:5000"
|
||||
@ -133,9 +133,9 @@ region="region"
|
||||
end
|
||||
context 'many different region' do
|
||||
it 'should not mix up the endpoints' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('endpoint', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Region","Service Name","Service Type","Enabled","Interface","URL"
|
||||
.and_return('"ID","Region","Service Name","Service Type","Enabled","Interface","URL"
|
||||
"endpoint1_id","RegionOne","keystone","identity",True,"admin","http://One-127.0.0.1:5002"
|
||||
"endpoint2_id","RegionOne","keystone","identity",True,"internal","https://One-127.0.0.1:5001"
|
||||
"endpoint3_id","RegionOne","keystone","identity",True,"public","https://One-127.0.0.1:5000"
|
||||
@ -216,9 +216,9 @@ region="region"
|
||||
describe '#prefetch' do
|
||||
context 'working: fq or nfq and matching resource' do
|
||||
before(:each) do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('endpoint', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Region","Service Name","Service Type","Enabled","Interface","URL"
|
||||
.and_return('"ID","Region","Service Name","Service Type","Enabled","Interface","URL"
|
||||
"endpoint1_id","RegionOne","keystone","identity",True,"admin","http://127.0.0.1:5002"
|
||||
"endpoint2_id","RegionOne","keystone","identity",True,"internal","https://127.0.0.1:5001"
|
||||
"endpoint3_id","RegionOne","keystone","identity",True,"public","https://127.0.0.1:5000"
|
||||
@ -257,9 +257,9 @@ region="region"
|
||||
context 'not working' do
|
||||
context 'too many type' do
|
||||
before(:each) do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('endpoint', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Region","Service Name","Service Type","Enabled","Interface","URL"
|
||||
.and_return('"ID","Region","Service Name","Service Type","Enabled","Interface","URL"
|
||||
"endpoint1_id","RegionOne","keystone","identity",True,"admin","http://127.0.0.1:5002"
|
||||
"endpoint2_id","RegionOne","keystone","identity",True,"internal","https://127.0.0.1:5001"
|
||||
"endpoint3_id","RegionOne","keystone","identity",True,"public","https://127.0.0.1:5000"
|
||||
@ -271,18 +271,18 @@ region="region"
|
||||
it "should fail as it's not possible to get the right type here" do
|
||||
existing = Puppet::Type.type(:keystone_endpoint)
|
||||
.new(:title => 'RegionOne/keystone', :ensure => :present)
|
||||
resource = mock
|
||||
resource = double
|
||||
r = []
|
||||
r << existing
|
||||
|
||||
catalog = Puppet::Resource::Catalog.new
|
||||
r.each { |res| catalog.add_resource(res) }
|
||||
m_value = mock
|
||||
m_first = mock
|
||||
resource.expects(:values).returns(m_value)
|
||||
m_value.expects(:first).returns(m_first)
|
||||
m_first.expects(:catalog).returns(catalog)
|
||||
m_first.expects(:class).returns(described_class.resource_type)
|
||||
m_value = double
|
||||
m_first = double
|
||||
expect(resource).to receive(:values).and_return(m_value)
|
||||
expect(m_value).to receive(:first).and_return(m_first)
|
||||
expect(m_first).to receive(:catalog).and_return(catalog)
|
||||
expect(m_first).to receive(:class).and_return(described_class.resource_type)
|
||||
expect { described_class.prefetch(resource) }
|
||||
.to raise_error(Puppet::Error,
|
||||
/endpoint matching RegionOne\/keystone: identity identityv3/)
|
||||
@ -292,34 +292,34 @@ region="region"
|
||||
|
||||
context 'not any type but existing service' do
|
||||
before(:each) do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('endpoint', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Region","Service Name","Service Type","Enabled","Interface","URL"
|
||||
.and_return('"ID","Region","Service Name","Service Type","Enabled","Interface","URL"
|
||||
"endpoint1_id","RegionOne","keystone","identity",True,"admin","http://127.0.0.1:5002"
|
||||
"endpoint2_id","RegionOne","keystone","identity",True,"internal","https://127.0.0.1:5001"
|
||||
"endpoint3_id","RegionOne","keystone","identity",True,"public","https://127.0.0.1:5000"
|
||||
')
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('service', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Name","Type"
|
||||
.and_return('"ID","Name","Type"
|
||||
"service1_id","keystonev3","identity"
|
||||
')
|
||||
end
|
||||
it 'should be successful' do
|
||||
existing = Puppet::Type.type(:keystone_endpoint)
|
||||
.new(:title => 'RegionOne/keystonev3', :ensure => :present)
|
||||
resource = mock
|
||||
resource = double
|
||||
r = []
|
||||
r << existing
|
||||
|
||||
catalog = Puppet::Resource::Catalog.new
|
||||
r.each { |res| catalog.add_resource(res) }
|
||||
m_value = mock
|
||||
m_first = mock
|
||||
resource.expects(:values).returns(m_value)
|
||||
m_value.expects(:first).returns(m_first)
|
||||
m_first.expects(:catalog).returns(catalog)
|
||||
m_first.expects(:class).returns(described_class.resource_type)
|
||||
m_value = double
|
||||
m_first = double
|
||||
expect(resource).to receive(:values).and_return(m_value)
|
||||
expect(m_value).to receive(:first).and_return(m_first)
|
||||
expect(m_first).to receive(:catalog).and_return(catalog)
|
||||
expect(m_first).to receive(:class).and_return(described_class.resource_type)
|
||||
|
||||
expect { described_class.prefetch(resource) }.not_to raise_error
|
||||
expect(existing.provider.ensure).to eq(:absent)
|
||||
@ -340,11 +340,11 @@ region="region"
|
||||
end
|
||||
context '#update a missing endpoint' do
|
||||
it 'creates an endpoint' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('endpoint', 'create', '--format', 'shell',
|
||||
['service_id_1', 'admin', 'http://127.0.0.1:4999',
|
||||
'--region', 'region'])
|
||||
.returns(<<-eoo
|
||||
.and_return(<<-eoo
|
||||
enabled="True"
|
||||
id="endpoint1_id"
|
||||
interface="internal"
|
||||
@ -357,14 +357,14 @@ url="http://127.0.0.1:5001"
|
||||
eoo
|
||||
)
|
||||
|
||||
provider.expects(:property_flush)
|
||||
.times(5)
|
||||
.returns({:admin_url => 'http://127.0.0.1:4999'})
|
||||
provider.expects(:property_hash)
|
||||
.twice
|
||||
.returns({:id => ',endpoint2_id,endpoint3_id'})
|
||||
provider.expects(:service_id)
|
||||
.returns('service_id_1')
|
||||
expect(provider).to receive(:property_flush)
|
||||
.exactly(5).times
|
||||
.and_return({:admin_url => 'http://127.0.0.1:4999'})
|
||||
expect(provider).to receive(:property_hash)
|
||||
.exactly(2).times
|
||||
.and_return({:id => ',endpoint2_id,endpoint3_id'})
|
||||
expect(provider).to receive(:service_id)
|
||||
.and_return('service_id_1')
|
||||
provider.flush
|
||||
expect(provider.exists?).to be_truthy
|
||||
expect(provider.id).to eq('endpoint1_id,endpoint2_id,endpoint3_id')
|
||||
@ -373,15 +373,15 @@ url="http://127.0.0.1:5001"
|
||||
|
||||
context 'adjust a url' do
|
||||
it 'update the url' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('endpoint', 'set',
|
||||
['endpoint1_id', '--url=http://127.0.0.1:4999'])
|
||||
provider.expects(:property_flush)
|
||||
.times(4)
|
||||
.returns({:admin_url => 'http://127.0.0.1:4999'})
|
||||
provider.expects(:property_hash)
|
||||
.twice
|
||||
.returns({:id => 'endpoint1_id,endpoint2_id,endpoint3_id'})
|
||||
expect(provider).to receive(:property_flush)
|
||||
.exactly(4).times
|
||||
.and_return({:admin_url => 'http://127.0.0.1:4999'})
|
||||
expect(provider).to receive(:property_hash)
|
||||
.exactly(2).times
|
||||
.and_return({:id => 'endpoint1_id,endpoint2_id,endpoint3_id'})
|
||||
provider.flush
|
||||
expect(provider.exists?).to be_truthy
|
||||
expect(provider.id).to eq('endpoint1_id,endpoint2_id,endpoint3_id')
|
||||
|
@ -29,7 +29,7 @@ describe Puppet::Type.type(:keystone_identity_provider).provider(:openstack) do
|
||||
before(:example) { set_env }
|
||||
describe '#create success' do
|
||||
it 'creates an identity provider' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with(
|
||||
'identity provider', 'create',
|
||||
'--format', 'shell', [
|
||||
@ -41,8 +41,8 @@ describe Puppet::Type.type(:keystone_identity_provider).provider(:openstack) do
|
||||
'idp_one'
|
||||
]
|
||||
)
|
||||
.once
|
||||
.returns(
|
||||
.exactly(1).times
|
||||
.and_return(
|
||||
<<-EOR
|
||||
description="Nice id provider"
|
||||
enabled="True"
|
||||
@ -55,8 +55,8 @@ EOR
|
||||
end
|
||||
end
|
||||
describe '#create failure' do
|
||||
it 'fails with an helpfull message when hitting remote-id duplicate.' do
|
||||
described_class.expects(:openstack)
|
||||
it 'fails with an helpful message when hitting remote-id duplicate.' do
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with(
|
||||
'identity provider', 'create',
|
||||
'--format', 'shell', [
|
||||
@ -68,10 +68,10 @@ EOR
|
||||
'idp_one'
|
||||
]
|
||||
)
|
||||
.once
|
||||
.raises(Puppet::ExecutionFailure,
|
||||
'openstack Conflict occurred attempting to' \
|
||||
' store identity_provider')
|
||||
.exactly(1).times
|
||||
.and_raise(Puppet::ExecutionFailure,
|
||||
'openstack Conflict occurred attempting to' \
|
||||
' store identity_provider')
|
||||
expect { provider.create }
|
||||
.to raise_error(Puppet::Error::OpenstackDuplicateRemoteId)
|
||||
end
|
||||
@ -88,7 +88,7 @@ EOR
|
||||
}
|
||||
end
|
||||
it 'create a resource whit remote id in a file' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with(
|
||||
'identity provider', 'create',
|
||||
'--format', 'shell', [
|
||||
@ -98,8 +98,8 @@ EOR
|
||||
'idp_one'
|
||||
]
|
||||
)
|
||||
.once
|
||||
.returns(
|
||||
.exactly(1).times
|
||||
.and_return(
|
||||
<<-EOR
|
||||
description="Nice id provider"
|
||||
enabled="True"
|
||||
@ -116,7 +116,7 @@ EOR
|
||||
describe '#destroy' do
|
||||
it 'destroy an identity provider' do
|
||||
provider.instance_variable_get('@property_hash')[:id] = 'idp_one'
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with(
|
||||
'identity provider', 'delete', 'idp_one'
|
||||
)
|
||||
@ -127,26 +127,26 @@ EOR
|
||||
|
||||
describe '#instances' do
|
||||
it 'finds every identity provider' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with(
|
||||
'identity provider', 'list',
|
||||
'--quiet', '--format', 'csv', []
|
||||
)
|
||||
.once
|
||||
.returns(
|
||||
.exactly(1).times
|
||||
.and_return(
|
||||
<<-EOR
|
||||
"ID","Enabled","Description"
|
||||
"idp_one",True,""
|
||||
"idp_two",False,"Idp two description"
|
||||
EOR
|
||||
)
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with(
|
||||
'identity provider', 'show',
|
||||
'--format', 'shell', 'idp_one'
|
||||
)
|
||||
.once
|
||||
.returns(
|
||||
.exactly(1).times
|
||||
.and_return(
|
||||
<<-EOR
|
||||
description="None"
|
||||
enabled="True"
|
||||
@ -154,13 +154,13 @@ id="idp_one"
|
||||
remote_ids="entityid_idp1, http://entityid_idp2/saml/meta, 3"
|
||||
EOR
|
||||
)
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with(
|
||||
'identity provider', 'show',
|
||||
'--format', 'shell', 'idp_two'
|
||||
)
|
||||
.once
|
||||
.returns(
|
||||
.exactly(1).times
|
||||
.and_return(
|
||||
<<-EOR
|
||||
description="Idp two description"
|
||||
enabled="False"
|
||||
@ -179,8 +179,8 @@ EOR
|
||||
describe '#update' do
|
||||
context 'remote_ids' do
|
||||
it 'changes the remote_ids' do
|
||||
provider.expects(:id).returns('1234')
|
||||
described_class.expects(:openstack)
|
||||
expect(provider).to receive(:id).and_return('1234')
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with(
|
||||
'identity provider', 'set',
|
||||
[
|
||||
@ -189,41 +189,41 @@ EOR
|
||||
'1234'
|
||||
]
|
||||
)
|
||||
.once
|
||||
.exactly(1).times
|
||||
provider.remote_ids = ['entityid_idp1', 'http://entityid_idp2/saml/meta']
|
||||
end
|
||||
end
|
||||
context 'with remote_id_file' do
|
||||
it 'changes the remote_id_file' do
|
||||
provider.expects(:id).returns('1234')
|
||||
described_class.expects(:openstack)
|
||||
expect(provider).to receive(:id).and_return('1234')
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with(
|
||||
'identity provider', 'set',
|
||||
['--remote-id-file', '/tmp/new_file', '1234']
|
||||
)
|
||||
.once
|
||||
.exactly(1).times
|
||||
provider.remote_id_file = '/tmp/new_file'
|
||||
end
|
||||
end
|
||||
context 'enabled' do
|
||||
it 'changes the enable to true' do
|
||||
provider.expects(:id).returns('1234')
|
||||
described_class.expects(:openstack)
|
||||
expect(provider).to receive(:id).and_return('1234')
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with(
|
||||
'identity provider', 'set',
|
||||
['--enable', '1234']
|
||||
)
|
||||
.once
|
||||
.exactly(1).times
|
||||
provider.enabled = :true
|
||||
end
|
||||
it 'changes the enable to false' do
|
||||
provider.expects(:id).returns('1234')
|
||||
described_class.expects(:openstack)
|
||||
expect(provider).to receive(:id).and_return('1234')
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with(
|
||||
'identity provider', 'set',
|
||||
['--disable', '1234']
|
||||
)
|
||||
.once
|
||||
.exactly(1).times
|
||||
provider.enabled = :false
|
||||
end
|
||||
end
|
||||
@ -247,9 +247,9 @@ EOR
|
||||
existing
|
||||
end
|
||||
it 'fill the resource with the right provider' do
|
||||
described_class.expects(:instances)
|
||||
.once
|
||||
.returns([found_resource])
|
||||
expect(described_class).to receive(:instances)
|
||||
.exactly(1).times
|
||||
.and_return([found_resource])
|
||||
expect(resources_catalog['idp_one'].provider).to be_absent
|
||||
described_class.prefetch(resources_catalog)
|
||||
expect(resources_catalog['idp_one'].provider).not_to be_absent
|
||||
|
@ -35,9 +35,9 @@ describe provider_class do
|
||||
|
||||
describe '#create' do
|
||||
it 'creates a role' do
|
||||
provider.class.expects(:openstack)
|
||||
expect(provider.class).to receive(:openstack)
|
||||
.with('role', 'create', '--format', 'shell', 'foo')
|
||||
.returns('name="foo"')
|
||||
.and_return('name="foo"')
|
||||
provider.create
|
||||
expect(provider.exists?).to be_truthy
|
||||
end
|
||||
@ -45,7 +45,7 @@ describe provider_class do
|
||||
|
||||
describe '#destroy' do
|
||||
it 'destroys a role' do
|
||||
provider.class.expects(:openstack)
|
||||
expect(provider.class).to receive(:openstack)
|
||||
.with('role', 'delete', [])
|
||||
provider.destroy
|
||||
expect(provider.exists?).to be_falsey
|
||||
@ -64,9 +64,9 @@ describe provider_class do
|
||||
|
||||
describe '#instances' do
|
||||
it 'finds every role' do
|
||||
provider.class.expects(:openstack)
|
||||
expect(provider.class).to receive(:openstack)
|
||||
.with('role', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Name"
|
||||
.and_return('"ID","Name"
|
||||
"1cb05cfed7c24279be884ba4f6520262","foo"
|
||||
'
|
||||
)
|
||||
|
@ -38,10 +38,10 @@ describe provider_class do
|
||||
|
||||
describe '#create' do
|
||||
before(:each) do
|
||||
provider_class.expects(:openstack)
|
||||
expect(provider_class).to receive(:openstack)
|
||||
.with('service', 'create', '--format', 'shell',
|
||||
['type_one', '--name', 'service_one', '--description', 'Service One'])
|
||||
.returns('description="Service One"
|
||||
.and_return('description="Service One"
|
||||
enabled="True"
|
||||
id="8f0dd4c0abc44240998fbb3f5089ecbf"
|
||||
name="service_one"
|
||||
@ -75,7 +75,7 @@ type="type_one"
|
||||
end
|
||||
describe '#destroy' do
|
||||
it 'destroys a service' do
|
||||
provider_class.expects(:openstack)
|
||||
expect(provider_class).to receive(:openstack)
|
||||
.with('service', 'delete', [])
|
||||
provider.destroy
|
||||
expect(provider.exists?).to be_falsey
|
||||
@ -91,9 +91,9 @@ type="type_one"
|
||||
|
||||
describe '#instances' do
|
||||
it 'finds every service' do
|
||||
provider_class.expects(:openstack)
|
||||
expect(provider_class).to receive(:openstack)
|
||||
.with('service', 'list', '--quiet', '--format', 'csv', '--long')
|
||||
.returns('"ID","Name","Type","Description"
|
||||
.and_return('"ID","Name","Type","Description"
|
||||
"8f0dd4c0abc44240998fbb3f5089ecbf","service_one","type_one","Service One"
|
||||
')
|
||||
instances = provider_class.instances
|
||||
@ -106,9 +106,9 @@ type="type_one"
|
||||
before(:each) do
|
||||
# This call done by self.instance in prefetch in what make the
|
||||
# resource exists.
|
||||
provider_class.expects(:openstack)
|
||||
expect(provider_class).to receive(:openstack)
|
||||
.with('service', 'list', '--quiet', '--format', 'csv', '--long')
|
||||
.returns('"ID","Name","Type","Description"
|
||||
.and_return('"ID","Name","Type","Description"
|
||||
"8f0dd4c0abc44240998fbb3f5089ecbf","service_1","type_1",""
|
||||
')
|
||||
end
|
||||
|
@ -35,28 +35,28 @@ describe Puppet::Provider::Keystone do
|
||||
|
||||
describe '#domain_id_from_name' do
|
||||
it 'should list all domains when requesting a domain name from an ID' do
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('domain', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Name","Enabled","Description"
|
||||
.and_return('"ID","Name","Enabled","Description"
|
||||
"someid","SomeName",True,"default domain"
|
||||
')
|
||||
expect(klass.domain_id_from_name('SomeName')).to eq('someid')
|
||||
end
|
||||
it 'should lookup a domain when not found in the hash' do
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('domain', 'show', '--format', 'shell', 'NewName')
|
||||
.returns('
|
||||
.and_return('
|
||||
name="NewName"
|
||||
id="newid"
|
||||
')
|
||||
expect(klass.domain_id_from_name('NewName')).to eq('newid')
|
||||
end
|
||||
it 'should print an error when there is no such domain' do
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('domain', 'show', '--format', 'shell', 'doesnotexist')
|
||||
.returns('
|
||||
.and_return('
|
||||
')
|
||||
klass.expects(:err)
|
||||
expect(klass).to receive(:err)
|
||||
.with('Could not find domain with name [doesnotexist]')
|
||||
expect(klass.domain_id_from_name('doesnotexist')).to eq(nil)
|
||||
end
|
||||
@ -75,18 +75,18 @@ id="newid"
|
||||
end
|
||||
|
||||
it 'should be false if the project does not exist' do
|
||||
klass.expects(:request_timeout).returns(0)
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:request_timeout).and_return(0)
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('project', 'show', '--format', 'shell', ['no_project', '--domain', 'Default'])
|
||||
.once
|
||||
.raises(Puppet::ExecutionFailure, "Execution of '/usr/bin/openstack project show --format shell no_project' returned 1: No project with a name or ID of 'no_project' exists.")
|
||||
.exactly(1).times
|
||||
.and_raise(Puppet::ExecutionFailure, "Execution of '/usr/bin/openstack project show --format shell no_project' returned 1: No project with a name or ID of 'no_project' exists.")
|
||||
expect(klass.fetch_project('no_project', 'Default')).to be_falsey
|
||||
end
|
||||
|
||||
it 'should return the project' do
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('project', 'show', '--format', 'shell', ['The Project', '--domain', 'Default'])
|
||||
.returns('
|
||||
.and_return('
|
||||
name="The Project"
|
||||
id="the_project_id"
|
||||
')
|
||||
@ -107,18 +107,18 @@ id="the_project_id"
|
||||
end
|
||||
|
||||
it 'should be false if the user does not exist' do
|
||||
klass.expects(:request_timeout).returns(0)
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:request_timeout).and_return(0)
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('user', 'show', '--format', 'shell', ['no_user', '--domain', 'Default'])
|
||||
.once
|
||||
.raises(Puppet::ExecutionFailure, "Execution of '/usr/bin/openstack user show --format shell no_user' returned 1: No user with a name or ID of 'no_user' exists.")
|
||||
.exactly(1).times
|
||||
.and_raise(Puppet::ExecutionFailure, "Execution of '/usr/bin/openstack user show --format shell no_user' returned 1: No user with a name or ID of 'no_user' exists.")
|
||||
expect(klass.fetch_user('no_user', 'Default')).to be_falsey
|
||||
end
|
||||
|
||||
it 'should return the user' do
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('user', 'show', '--format', 'shell', ['The User', '--domain', 'Default'])
|
||||
.returns('
|
||||
.and_return('
|
||||
name="The User"
|
||||
id="the_user_id"
|
||||
')
|
||||
@ -137,14 +137,14 @@ id="the_user_id"
|
||||
home = ENV['HOME']
|
||||
ENV.clear
|
||||
mock = {'OS_AUTH_URL' => 'http://127.0.0.1:5001'}
|
||||
klass.expects(:get_os_vars_from_rcfile).with("#{home}/openrc").returns(mock)
|
||||
expect(klass).to receive(:get_os_vars_from_rcfile).with("#{home}/openrc").and_return(mock)
|
||||
expect(klass.get_auth_url).to eq('http://127.0.0.1:5001')
|
||||
end
|
||||
|
||||
it 'should use auth_endpoint when nothing else is available' do
|
||||
ENV.clear
|
||||
mock = 'http://127.0.0.1:5001'
|
||||
klass.expects(:auth_endpoint).returns(mock)
|
||||
expect(klass).to receive(:auth_endpoint).and_return(mock)
|
||||
expect(klass.get_auth_url).to eq('http://127.0.0.1:5001')
|
||||
end
|
||||
end
|
||||
@ -157,11 +157,11 @@ id="the_user_id"
|
||||
end
|
||||
|
||||
it 'should return the name only when the provided domain is the default domain id' do
|
||||
klass.expects(:default_domain_id)
|
||||
.returns('default')
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:default_domain_id)
|
||||
.and_return('default')
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('domain', 'show', '--format', 'shell', 'Default')
|
||||
.returns('
|
||||
.and_return('
|
||||
name="Default"
|
||||
id="default"
|
||||
')
|
||||
@ -169,11 +169,11 @@ id="default"
|
||||
end
|
||||
|
||||
it 'should return the name and domain when the provided domain is not the default domain id' do
|
||||
klass.expects(:default_domain_id)
|
||||
.returns('default')
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:default_domain_id)
|
||||
.and_return('default')
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('domain', 'show', '--format', 'shell', 'Other Domain')
|
||||
.returns('
|
||||
.and_return('
|
||||
name="Other Domain"
|
||||
id="other_domain_id"
|
||||
')
|
||||
@ -181,11 +181,11 @@ id="other_domain_id"
|
||||
end
|
||||
|
||||
it 'should return the name only if the domain cannot be fetched' do
|
||||
klass.expects(:default_domain_id)
|
||||
.returns('default')
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:default_domain_id)
|
||||
.and_return('default')
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('domain', 'show', '--format', 'shell', 'Unknown Domain')
|
||||
.returns('')
|
||||
.and_return('')
|
||||
expect(klass.set_domain_for_name('name', 'Unknown Domain')).to eq('name')
|
||||
end
|
||||
end
|
||||
@ -196,22 +196,22 @@ id="other_domain_id"
|
||||
end
|
||||
|
||||
it 'should list all domains when requesting a domain name from an ID' do
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('domain', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Name","Enabled","Description"
|
||||
.and_return('"ID","Name","Enabled","Description"
|
||||
"somename","SomeName",True,"default domain"
|
||||
')
|
||||
expect(klass.domain_name_from_id('somename')).to eq('SomeName')
|
||||
end
|
||||
it 'should lookup a domain when not found in the hash' do
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('domain', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Name","Enabled","Description"
|
||||
.and_return('"ID","Name","Enabled","Description"
|
||||
"somename","SomeName",True,"default domain"
|
||||
')
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('domain', 'show', '--format', 'shell', 'another')
|
||||
.returns('
|
||||
.and_return('
|
||||
name="AnOther"
|
||||
id="another"
|
||||
')
|
||||
@ -219,16 +219,16 @@ id="another"
|
||||
expect(klass.domain_name_from_id('another')).to eq('AnOther')
|
||||
end
|
||||
it 'should print an error when there is no such domain' do
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('domain', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Name","Enabled","Description"
|
||||
.and_return('"ID","Name","Enabled","Description"
|
||||
"somename","SomeName",True,"default domain"
|
||||
')
|
||||
klass.expects(:openstack)
|
||||
expect(klass).to receive(:openstack)
|
||||
.with('domain', 'show', '--format', 'shell', 'doesnotexist')
|
||||
.returns('
|
||||
.and_return('
|
||||
')
|
||||
klass.expects(:err)
|
||||
expect(klass).to receive(:err)
|
||||
.with('Could not find domain with id [doesnotexist]')
|
||||
expect(klass.domain_name_from_id('doesnotexist')).to eq(nil)
|
||||
end
|
||||
|
@ -31,9 +31,9 @@ describe provider_class do
|
||||
|
||||
def before_hook(domainlist, provider_class)
|
||||
if domainlist
|
||||
provider_class.expects(:openstack).once
|
||||
expect(provider_class).to receive(:openstack).exactly(1).times
|
||||
.with('domain', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Name","Enabled","Description"
|
||||
.and_return('"ID","Name","Enabled","Description"
|
||||
"domain_one_id","domain_one",True,"project_one domain"
|
||||
"domain_two_id","domain_two",True,"domain_two domain"
|
||||
"another_domain_id","another_domain",True,"another domain"
|
||||
@ -66,9 +66,9 @@ describe provider_class do
|
||||
|
||||
describe '#create', :domainlist => false do
|
||||
it 'creates a tenant' do
|
||||
provider.class.expects(:openstack)
|
||||
expect(provider.class).to receive(:openstack)
|
||||
.with('project', 'create', '--format', 'shell', ['project_one', '--enable', '--description', 'Project One', '--domain', 'Default'])
|
||||
.returns('description="Project One"
|
||||
.and_return('description="Project One"
|
||||
enabled="True"
|
||||
name="project_one"
|
||||
id="project_one"
|
||||
@ -82,7 +82,7 @@ domain_id="domain_one_id"
|
||||
describe '#destroy', :domainlist => false do
|
||||
it 'destroys a tenant' do
|
||||
provider.instance_variable_get('@property_hash')[:id] = 'my-project-id'
|
||||
provider.class.expects(:openstack)
|
||||
expect(provider.class).to receive(:openstack)
|
||||
.with('project', 'delete', 'my-project-id')
|
||||
provider.destroy
|
||||
expect(provider.exists?).to be_falsey
|
||||
@ -97,9 +97,9 @@ domain_id="domain_one_id"
|
||||
|
||||
describe '#instances', :domainlist => true do
|
||||
it 'finds every tenant' do
|
||||
provider_class.expects(:openstack)
|
||||
expect(provider_class).to receive(:openstack)
|
||||
.with('project', 'list', '--quiet', '--format', 'csv', '--long')
|
||||
.returns('"ID","Name","Domain ID","Description","Enabled"
|
||||
.and_return('"ID","Name","Domain ID","Description","Enabled"
|
||||
"1cb05cfed7c24279be884ba4f6520262","project_one","domain_one_id","Project One",True
|
||||
"2cb05cfed7c24279be884ba4f6520262","project_one","domain_two_id","Project One, domain Two",True
|
||||
')
|
||||
@ -113,12 +113,12 @@ domain_id="domain_one_id"
|
||||
|
||||
describe '#prefetch' do
|
||||
before(:each) do
|
||||
provider_class.expects(:domain_name_from_id).with('default').returns('Default')
|
||||
provider_class.expects(:domain_name_from_id).with('domain_two_id').returns('domain_two')
|
||||
expect(provider_class).to receive(:domain_name_from_id).with('default').and_return('Default')
|
||||
expect(provider_class).to receive(:domain_name_from_id).with('domain_two_id').and_return('domain_two')
|
||||
# There are one for self.instance and one for each Puppet::Type.type calls.
|
||||
provider.class.expects(:openstack)
|
||||
expect(provider.class).to receive(:openstack)
|
||||
.with('project', 'list', '--quiet', '--format', 'csv', '--long')
|
||||
.returns('"ID","Name","Domain ID","Description","Enabled"
|
||||
.and_return('"ID","Name","Domain ID","Description","Enabled"
|
||||
"1cb05cfed7c24279be884ba4f6520262","project_one","default","A project",True
|
||||
"2cb05cfed7c24279be884ba4f6520262","project_one","domain_two_id","A domain_two",True
|
||||
')
|
||||
@ -134,20 +134,20 @@ domain_id="domain_one_id"
|
||||
context '.enable' do
|
||||
describe '-> false' do
|
||||
it 'properly set enable to false' do
|
||||
provider_class.expects(:openstack)
|
||||
expect(provider_class).to receive(:openstack)
|
||||
.with('project', 'set', ['37b7086693ec482389799da5dc546fa4', '--disable'])
|
||||
.returns('""')
|
||||
provider.expects(:id).returns('37b7086693ec482389799da5dc546fa4')
|
||||
.and_return('""')
|
||||
expect(provider).to receive(:id).and_return('37b7086693ec482389799da5dc546fa4')
|
||||
provider.enabled = :false
|
||||
provider.flush
|
||||
end
|
||||
end
|
||||
describe '-> true' do
|
||||
it 'properly set enable to true' do
|
||||
provider_class.expects(:openstack)
|
||||
expect(provider_class).to receive(:openstack)
|
||||
.with('project', 'set', ['37b7086693ec482389799da5dc546fa4', '--enable'])
|
||||
.returns('""')
|
||||
provider.expects(:id).returns('37b7086693ec482389799da5dc546fa4')
|
||||
.and_return('""')
|
||||
expect(provider).to receive(:id).and_return('37b7086693ec482389799da5dc546fa4')
|
||||
provider.enabled = :true
|
||||
provider.flush
|
||||
end
|
||||
@ -155,24 +155,24 @@ domain_id="domain_one_id"
|
||||
end
|
||||
context '.description' do
|
||||
it 'change the description' do
|
||||
provider_class.expects(:openstack)
|
||||
expect(provider_class).to receive(:openstack)
|
||||
.with('project', 'set', ['37b7086693ec482389799da5dc546fa4',
|
||||
'--description=new description'])
|
||||
.returns('""')
|
||||
provider.expects(:id).returns('37b7086693ec482389799da5dc546fa4')
|
||||
provider.expects(:resource).returns(:description => 'new description')
|
||||
.and_return('""')
|
||||
expect(provider).to receive(:id).and_return('37b7086693ec482389799da5dc546fa4')
|
||||
expect(provider).to receive(:resource).and_return(:description => 'new description')
|
||||
provider.description = 'new description'
|
||||
provider.flush
|
||||
end
|
||||
end
|
||||
context '.enable/description' do
|
||||
it 'properly change the enable and the description' do
|
||||
provider_class.expects(:openstack)
|
||||
expect(provider_class).to receive(:openstack)
|
||||
.with('project', 'set', ['37b7086693ec482389799da5dc546fa4', '--disable',
|
||||
'--description=new description'])
|
||||
.returns('""')
|
||||
provider.expects(:id).returns('37b7086693ec482389799da5dc546fa4')
|
||||
provider.expects(:resource).returns(:description => 'new description')
|
||||
.and_return('""')
|
||||
expect(provider).to receive(:id).and_return('37b7086693ec482389799da5dc546fa4')
|
||||
expect(provider).to receive(:resource).and_return(:description => 'new description')
|
||||
provider.enabled = :false
|
||||
provider.description = 'new description'
|
||||
provider.flush
|
||||
@ -185,9 +185,9 @@ domain_id="domain_one_id"
|
||||
describe '#create' do
|
||||
describe 'with domain in resource', :domainlist => false do
|
||||
before(:each) do
|
||||
provider_class.expects(:openstack)
|
||||
expect(provider_class).to receive(:openstack)
|
||||
.with('project', 'create', '--format', 'shell', ['project_one', '--enable', '--description', 'Project One', '--domain', 'domain_one'])
|
||||
.returns('description="Project One"
|
||||
.and_return('description="Project One"
|
||||
enabled="True"
|
||||
name="project_one"
|
||||
id="project-id"
|
||||
@ -234,13 +234,13 @@ domain_id="domain_one_id"
|
||||
|
||||
describe '#prefetch' do
|
||||
before(:each) do
|
||||
provider_class.expects(:domain_name_from_id)
|
||||
.with('domain_one_id').returns('domain_one')
|
||||
provider_class.expects(:domain_name_from_id)
|
||||
.with('domain_two_id').returns('domain_two')
|
||||
provider_class.expects(:openstack)
|
||||
expect(provider_class).to receive(:domain_name_from_id)
|
||||
.with('domain_one_id').and_return('domain_one')
|
||||
expect(provider_class).to receive(:domain_name_from_id)
|
||||
.with('domain_two_id').and_return('domain_two')
|
||||
expect(provider_class).to receive(:openstack)
|
||||
.with('project', 'list', '--quiet', '--format', 'csv', '--long')
|
||||
.returns('"ID","Name","Domain ID","Description","Enabled"
|
||||
.and_return('"ID","Name","Domain ID","Description","Enabled"
|
||||
"1cb05cfed7c24279be884ba4f6520262","name","domain_one_id","A project_one",True
|
||||
"2cb05cfed7c24279be884ba4f6520262","project_one","domain_two_id","A domain_two",True
|
||||
')
|
||||
|
@ -43,9 +43,9 @@ describe Puppet::Type.type(:keystone_user).provider(:openstack) do
|
||||
describe 'when managing a user' do
|
||||
describe '#create' do
|
||||
it 'creates a user' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('user', 'create', '--format', 'shell', ['user1', '--enable', '--password', 'secret', '--email', 'user1@example.com', '--domain', 'domain1'])
|
||||
.returns('email="user1@example.com"
|
||||
.and_return('email="user1@example.com"
|
||||
enabled="True"
|
||||
id="user1_id"
|
||||
name="user1"
|
||||
@ -58,8 +58,8 @@ username="user1"
|
||||
|
||||
describe '#destroy' do
|
||||
it 'destroys a user' do
|
||||
provider.expects(:id).returns('my-user-id')
|
||||
described_class.expects(:openstack)
|
||||
expect(provider).to receive(:id).and_return('my-user-id')
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('user', 'delete', 'my-user-id')
|
||||
provider.destroy
|
||||
end
|
||||
@ -68,20 +68,20 @@ username="user1"
|
||||
describe '#exists' do
|
||||
context 'when user does not exist' do
|
||||
it 'should detect it' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('domain', 'list', '--quiet', '--format', 'csv', [])
|
||||
.returns('"ID","Name","Enabled","Description"
|
||||
.and_return('"ID","Name","Enabled","Description"
|
||||
"default","Default",True,"default"
|
||||
"domain1_id","domain1",True,"domain1"
|
||||
"domain2_id","domain2",True,"domain2"
|
||||
"domain3_id","domain3",True,"domain3"
|
||||
')
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('user', 'show', '--format', 'shell',
|
||||
['user1', '--domain', 'domain1_id'])
|
||||
.once
|
||||
.raises(Puppet::ExecutionFailure,
|
||||
"No user with a name or ID of 'user1' exists.")
|
||||
.exactly(1).times
|
||||
.and_raise(Puppet::ExecutionFailure,
|
||||
"No user with a name or ID of 'user1' exists.")
|
||||
expect(provider.exists?).to be_falsey
|
||||
end
|
||||
end
|
||||
@ -91,20 +91,20 @@ username="user1"
|
||||
context '.enable' do
|
||||
describe '-> false' do
|
||||
it 'properly set enable to false' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('user', 'set', ['--disable', '37b7086693ec482389799da5dc546fa4'])
|
||||
.returns('""')
|
||||
provider.expects(:id).returns('37b7086693ec482389799da5dc546fa4')
|
||||
.and_return('""')
|
||||
expect(provider).to receive(:id).and_return('37b7086693ec482389799da5dc546fa4')
|
||||
provider.enabled = :false
|
||||
provider.flush
|
||||
end
|
||||
end
|
||||
describe '-> true' do
|
||||
it 'properly set enable to true' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('user', 'set', ['--enable', '37b7086693ec482389799da5dc546fa4'])
|
||||
.returns('""')
|
||||
provider.expects(:id).returns('37b7086693ec482389799da5dc546fa4')
|
||||
.and_return('""')
|
||||
expect(provider).to receive(:id).and_return('37b7086693ec482389799da5dc546fa4')
|
||||
provider.enabled = :true
|
||||
provider.flush
|
||||
end
|
||||
@ -112,24 +112,24 @@ username="user1"
|
||||
end
|
||||
context '.description' do
|
||||
it 'change the description' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('user', 'set', ['--description', 'new description',
|
||||
'37b7086693ec482389799da5dc546fa4'])
|
||||
.returns('""')
|
||||
provider.expects(:id).returns('37b7086693ec482389799da5dc546fa4')
|
||||
provider.expects(:resource).returns(:description => 'new description')
|
||||
.and_return('""')
|
||||
expect(provider).to receive(:id).and_return('37b7086693ec482389799da5dc546fa4')
|
||||
expect(provider).to receive(:resource).and_return(:description => 'new description')
|
||||
provider.description = 'new description'
|
||||
provider.flush
|
||||
end
|
||||
end
|
||||
context '.email' do
|
||||
it 'change the mail' do
|
||||
described_class.expects(:openstack)
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('user', 'set', ['--email', 'new email',
|
||||
'37b7086693ec482389799da5dc546fa4'])
|
||||
.returns('""')
|
||||
provider.expects(:id).returns('37b7086693ec482389799da5dc546fa4')
|
||||
provider.expects(:resource).returns(:email => 'new email')
|
||||
.and_return('""')
|
||||
expect(provider).to receive(:id).and_return('37b7086693ec482389799da5dc546fa4')
|
||||
expect(provider).to receive(:resource).and_return(:email => 'new email')
|
||||
provider.email = 'new email'
|
||||
provider.flush
|
||||
end
|
||||
@ -164,25 +164,25 @@ username="user1"
|
||||
mock_creds.username = 'user_one'
|
||||
mock_creds.user_id = 'user1_id'
|
||||
mock_creds.user_domain_name = 'Default'
|
||||
Puppet::Provider::Openstack::CredentialsV3.expects(:new).returns(mock_creds)
|
||||
expect(Puppet::Provider::Openstack::CredentialsV3).to receive(:new).and_return(mock_creds)
|
||||
|
||||
Puppet::Provider::Openstack.expects(:openstack)
|
||||
expect(Puppet::Provider::Openstack).to receive(:openstack)
|
||||
.with('token', 'issue', ['--format', 'value'])
|
||||
.returns('2015-05-14T04:06:05Z
|
||||
.and_return('2015-05-14T04:06:05Z
|
||||
e664a386befa4a30878dcef20e79f167
|
||||
8dce2ae9ecd34c199d2877bf319a3d06
|
||||
ac43ec53d5a74a0b9f51523ae41a29f0
|
||||
')
|
||||
provider.expects(:id).returns('user1_id')
|
||||
expect(provider).to receive(:id).and_return('user1_id')
|
||||
password = provider.password
|
||||
expect(password).to eq('pass_one')
|
||||
end
|
||||
|
||||
it 'fails the password check' do
|
||||
Puppet::Provider::Openstack.expects(:openstack)
|
||||
expect(Puppet::Provider::Openstack).to receive(:openstack)
|
||||
.with('token', 'issue', ['--format', 'value'])
|
||||
.raises(Puppet::ExecutionFailure, 'HTTP 401 invalid authentication')
|
||||
provider.expects(:id).returns('user1_id')
|
||||
.and_raise(Puppet::ExecutionFailure, 'HTTP 401 invalid authentication')
|
||||
expect(provider).to receive(:id).and_return('user1_id')
|
||||
password = provider.password
|
||||
expect(password).to eq(nil)
|
||||
end
|
||||
@ -222,9 +222,9 @@ ac43ec53d5a74a0b9f51523ae41a29f0
|
||||