Skip to content

Commit

Permalink
Merge pull request #368 from danielparks/cinderv2-default
Browse files Browse the repository at this point in the history
(#367) Use Cinder v2 API if available
  • Loading branch information
ggiamarchi committed May 15, 2019
2 parents b831cb9 + 7c50899 commit dfe13b1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
3 changes: 2 additions & 1 deletion source/lib/vagrant-openstack-provider/client/cinder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def initialize
end

def get_all_volumes(env)
volumes_json = get(env, "#{@session.endpoints[:volume]}/volumes/detail")
endpoint = @session.endpoints[:volumev2] || @session.endpoints[:volume]
volumes_json = get(env, "#{endpoint}/volumes/detail")
JSON.parse(volumes_json)['volumes'].map do |volume|
name = volume['display_name']
name = volume['name'] if name.nil? # To be compatible with cinder api v1 and v2
Expand Down
61 changes: 58 additions & 3 deletions source/spec/vagrant-openstack-provider/client/cinder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
before :each do
session.token = '123456'
session.project_id = 'a1b2c3'
session.endpoints = { volume: 'http://cinder' }
@cinder_client = VagrantPlugins::Openstack.cinder
end

describe 'get_all_volumes' do
context 'on api v1' do
context 'on api v1 on volume' do
before :each do
session.endpoints = { volume: 'http://cinder' }
end
it 'returns volumes with details' do
stub_request(:get, 'http://cinder/volumes/detail')
.with(
Expand Down Expand Up @@ -82,7 +84,11 @@
end
end

context 'on api v2' do
context 'on api v2 on volume' do
before :each do
session.endpoints = { volume: 'http://cinder' }
end

it 'returns volumes with details' do
stub_request(:get, 'http://cinder/volumes/detail')
.with(
Expand Down Expand Up @@ -126,5 +132,54 @@
Volume.new('654', 'vol-02', '4', 'in-use', 'false', 'inst-01', '/dev/vdc')]
end
end

context 'on api v2 on volumev2' do
before :each do
session.endpoints = { volume: 'http://cinder', volumev2: 'http://cinderv2' }
end

it 'returns volumes with details' do
stub_request(:get, 'http://cinderv2/volumes/detail')
.with(
headers:
{
'Accept' => 'application/json',
'X-Auth-Token' => '123456'
})
.to_return(
status: 200,
body: '
{
"volumes": [
{
"id": "987",
"name": "vol-01",
"size": "2",
"status": "available",
"bootable": "true",
"attachments": []
},
{
"id": "654",
"name": "vol-02",
"size": "4",
"status": "in-use",
"bootable": "false",
"attachments": [
{
"server_id": "inst-01",
"device": "/dev/vdc"
}
]
}
]
}')

volumes = @cinder_client.get_all_volumes(env)

expect(volumes).to eq [Volume.new('987', 'vol-01', '2', 'available', 'true', nil, nil),
Volume.new('654', 'vol-02', '4', 'in-use', 'false', 'inst-01', '/dev/vdc')]
end
end
end
end

0 comments on commit dfe13b1

Please sign in to comment.