Skip to content

Commit

Permalink
Merge pull request fog#3837 from zhitongLBN/rework_openstack_mock_sna…
Browse files Browse the repository at this point in the history
…pshots

rework mock openstack snapshot to have same behavior as servers...
  • Loading branch information
geemus committed Feb 9, 2016
2 parents 9cd7ffc + 57db292 commit 3691afd
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 33 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -895,3 +895,4 @@
* Обоев Рулон ибн Хаттаб <[email protected]>
* 应俊 <[email protected]>
* Raul Roa <[email protected]>
* zhitongLBN <[email protected]>
3 changes: 2 additions & 1 deletion lib/fog/openstack/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ def self.data
'cores' => 20,
'ram' => 51200
},
:volumes => {}
:volumes => {},
:snapshots => {}
}
end
end
Expand Down
33 changes: 20 additions & 13 deletions lib/fog/openstack/requests/compute/create_volume_snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,27 @@ def create_volume_snapshot(volume_id, name, description, force=false)

class Mock
def create_volume_snapshot(volume_id, name, description, force=false)
response = Excon::Response.new
response.status = 202
response.body = {
"snapshot"=> {
"status"=>"creating",
"display_name"=>name,
"created_at"=>Time.now,
"display_description"=>description,
"volume_id"=>volume_id,
"id"=>"5",
"size"=>1
volume_response = get_volume_details(volume_id)
volume = volume_response.data[:body]['volume']
unless volume.nil?
response = Excon::Response.new
data = {
"status" => "availble",
"name" => name,
"created_at" => Time.now,
"description" => description,
"volume_id" => volume_id,
"id" => Fog::Mock.random_numbers(2),
"size" => volume['size']
}
}
response

self.data[:snapshots][data['id']] = data
response.body = { "snapshot" => data }
response.status = 202
response
else
raise Fog::Compute::OpenStack::NotFound
end
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/fog/openstack/requests/compute/delete_snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class Mock
def delete_snapshot(snapshot_id)
response = Excon::Response.new
response.status = 204
if list_snapshots_detail.body['snapshots'].find { |_| _['id'] == snapshot_id }
self.data[:snapshots].delete(snapshot_id)
else
raise Fog::Compute::OpenStack::NotFound
end
response
end
end
Expand Down
21 changes: 8 additions & 13 deletions lib/fog/openstack/requests/compute/get_snapshot_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@ def get_snapshot_details(snapshot_id)
class Mock
def get_snapshot_details(snapshot_id)
response = Excon::Response.new
response.status = 200
response.body = {
'snapshot' => {
'id' => '1',
'display_name' => Fog::Mock.random_letters(rand(8) + 5),
'display_description' => Fog::Mock.random_letters(rand(12) + 10),
'size' => 3,
'volume_id' => '4',
'status' => 'online',
'created_at' => Time.now
}
}
response
if snapshot = list_snapshots_detail.body['snapshots'].find{
|_| _['id'] == snapshot_id }
response.status = 200
response.body = { 'snapshot' => snapshot }
response
else
raise Fog::Compute::OpenStack::NotFound
end
end
end
end
Expand Down
5 changes: 2 additions & 3 deletions lib/fog/openstack/requests/compute/list_snapshots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ class Mock
def list_snapshots(options = true)
response = Excon::Response.new
response.status = 200
response.body = {
'snapshots' => [get_snapshot_details.body["snapshot"]]
}
snapshots = self.data[:snapshots].values
response.body = { 'snapshots' => snapshots }
response
end
end
Expand Down
5 changes: 2 additions & 3 deletions lib/fog/openstack/requests/compute/list_snapshots_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ class Mock
def list_snapshots_detail(options = {})
response = Excon::Response.new
response.status = 200
response.body = {
'snapshots' => [get_snapshot_details.body["snapshot"]]
}
snapshots = self.data[:snapshots].values
response.body = { 'snapshots' => snapshots }
response
end
end
Expand Down

0 comments on commit 3691afd

Please sign in to comment.