diff --git a/lib/fog/slicehost.rb b/lib/fog/slicehost.rb index 9d78f1165..698f73738 100644 --- a/lib/fog/slicehost.rb +++ b/lib/fog/slicehost.rb @@ -1,6 +1,9 @@ module Fog module Slicehost + class Error < Fog::Errors::Error; end + class NotFound < Fog::Errors::NotFound; end + def self.new(options={}) unless @required @@ -79,15 +82,24 @@ module Fog headers['Content-Type'] = 'application/xml' end - response = @connection.request({ - :body => params[:body], - :expects => params[:expects], - :headers => headers.merge!(params[:headers] || {}), - :host => @host, - :method => params[:method], - :parser => params[:parser], - :path => params[:path] - }) + begin + response = @connection.request({ + :body => params[:body], + :expects => params[:expects], + :headers => headers.merge!(params[:headers] || {}), + :host => @host, + :method => params[:method], + :parser => params[:parser], + :path => params[:path] + }) + rescue Excon::Errors::Error => error + case error + when Excon::Errors::NotFound + raise Fog::Slicehost::NotFound + else + raise error + end + end response end diff --git a/tests/slicehost/helper.rb b/tests/slicehost/helper.rb index 11491aebf..d09715445 100644 --- a/tests/slicehost/helper.rb +++ b/tests/slicehost/helper.rb @@ -13,39 +13,4 @@ module Slicehost @@connections[service] end - module Formats - - BACKUP = { - 'date' => String, - 'id' => Integer, - 'name' => String, - 'slice-id' => Integer - } - - FLAVOR = { - 'id' => Integer, - 'name' => String, - 'price' => Integer, - 'ram' => Integer - } - - IMAGE = { - 'id' => Integer, - 'name' => String - } - - SLICE = { - 'addresses' => [String], - 'bw-in' => Float, - 'bw-out' => Float, - 'flavor-id' => Integer, - 'id' => Integer, - 'image-id' => Integer, - 'name' => String, - 'progress' => Integer, - 'status' => String - } - - end - end \ No newline at end of file diff --git a/tests/slicehost/requests/backup_tests.rb b/tests/slicehost/requests/backup_tests.rb new file mode 100644 index 000000000..e0afc5238 --- /dev/null +++ b/tests/slicehost/requests/backup_tests.rb @@ -0,0 +1,17 @@ +Shindo.tests('Slicehost | backup requests', ['slicehost']) do + + @backup_format = { + 'date' => String, + 'id' => Integer, + 'name' => String, + 'slice-id' => Integer + } + + tests('success') do + + tests('#get_backups').formats({ 'backups' => [@backup_format] }) do + Slicehost[:slices].get_backups.body + end + + end +end diff --git a/tests/slicehost/requests/create_slice_tests.rb b/tests/slicehost/requests/create_slice_tests.rb deleted file mode 100644 index 8bb95fee6..000000000 --- a/tests/slicehost/requests/create_slice_tests.rb +++ /dev/null @@ -1,14 +0,0 @@ -Shindo.tests('Slicehost#create_slice', 'slicehost') do - tests('success') do - - tests("#create_slice(1, 19, 'fogcreateslice')").formats(Slicehost::Formats::SLICE.merge('root-password' => String)) do - data = Slicehost[:slices].create_slice(1, 19, 'fogcreateslice').body - @id = data['id'] - data - end - - Fog.wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' } - Slicehost[:slices].delete_slice(@id) - - end -end diff --git a/tests/slicehost/requests/delete_slice_tests.rb b/tests/slicehost/requests/delete_slice_tests.rb deleted file mode 100644 index 10a94b122..000000000 --- a/tests/slicehost/requests/delete_slice_tests.rb +++ /dev/null @@ -1,20 +0,0 @@ -Shindo.tests('Slicehost#delete_slice', 'slicehost') do - tests('success') do - - @id = Slicehost[:slices].create_slice(1, 19, 'fogdeleteslice').body['id'] - - tests("#delete_slice(#{@id})").succeeds do - Fog.wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' } - Slicehost[:slices].delete_slice(@id) - end - - end - - tests('failure') do - - tests('delete_slice(0)').raises(Excon::Errors::NotFound) do - Slicehost[:slices].delete_slice(0) - end - - end -end diff --git a/tests/slicehost/requests/flavor_tests.rb b/tests/slicehost/requests/flavor_tests.rb new file mode 100644 index 000000000..4e87197ae --- /dev/null +++ b/tests/slicehost/requests/flavor_tests.rb @@ -0,0 +1,30 @@ +Shindo.tests('Slicehost | flavor requests', ['slicehost']) do + + @flavor_format = { + 'id' => Integer, + 'name' => String, + 'price' => Integer, + 'ram' => Integer + } + + tests('success') do + + tests('#get_flavor(1)').formats(@flavor_format) do + Slicehost[:slices].get_flavor(1).body + end + + tests('#get_flavors').formats({ 'flavors' => [@flavor_format] }) do + Slicehost[:slices].get_flavors.body + end + + end + + tests('failure') do + + tests('#get_flavor(0)').raises(Excon::Errors::Forbidden) do + Slicehost[:slices].get_flavor(0) + end + + end + +end diff --git a/tests/slicehost/requests/get_backups_tests.rb b/tests/slicehost/requests/get_backups_tests.rb deleted file mode 100644 index 549448d0b..000000000 --- a/tests/slicehost/requests/get_backups_tests.rb +++ /dev/null @@ -1,9 +0,0 @@ -Shindo.tests('Slicehost#get_backups', 'slicehost') do - tests('success') do - - tests('#get_backups').formats({ 'backups' => [Slicehost::Formats::BACKUP] }) do - Slicehost[:slices].get_backups.body - end - - end -end diff --git a/tests/slicehost/requests/get_flavor_tests.rb b/tests/slicehost/requests/get_flavor_tests.rb deleted file mode 100644 index 1934f7ae2..000000000 --- a/tests/slicehost/requests/get_flavor_tests.rb +++ /dev/null @@ -1,17 +0,0 @@ -Shindo.tests('Slicehost#get_flavor', 'slicehost') do - tests('success') do - - tests('#get_flavor(1)').formats(Slicehost::Formats::FLAVOR) do - Slicehost[:slices].get_flavor(1).body - end - - end - - tests('failure') do - - tests('#get_flavor(0)').raises(Excon::Errors::Forbidden) do - Slicehost[:slices].get_flavor(0) - end - - end -end diff --git a/tests/slicehost/requests/get_flavors_tests.rb b/tests/slicehost/requests/get_flavors_tests.rb deleted file mode 100644 index 3be22e4fd..000000000 --- a/tests/slicehost/requests/get_flavors_tests.rb +++ /dev/null @@ -1,9 +0,0 @@ -Shindo.tests('Slicehost#get_flavors', 'slicehost') do - tests('success') do - - tests('#get_flavors').formats({ 'flavors' => [Slicehost::Formats::FLAVOR] }) do - Slicehost[:slices].get_flavors.body - end - - end -end diff --git a/tests/slicehost/requests/get_image_tests.rb b/tests/slicehost/requests/get_image_tests.rb deleted file mode 100644 index 346ed7b4d..000000000 --- a/tests/slicehost/requests/get_image_tests.rb +++ /dev/null @@ -1,17 +0,0 @@ -Shindo.tests('Slicehost#get_image', 'slicehost') do - tests('success') do - - tests('#get_image(19)').formats(Slicehost::Formats::IMAGE) do - Slicehost[:slices].get_image(19).body - end - - end - - tests('failure') do - - tests('#get_image(0)').raises(Excon::Errors::Forbidden) do - Slicehost[:slices].get_image(0) - end - - end -end diff --git a/tests/slicehost/requests/get_images_tests.rb b/tests/slicehost/requests/get_images_tests.rb deleted file mode 100644 index c783552b3..000000000 --- a/tests/slicehost/requests/get_images_tests.rb +++ /dev/null @@ -1,9 +0,0 @@ -Shindo.tests('Slicehost#get_images', 'slicehost') do - tests('success') do - - tests('#get_images').formats({ 'images' => [Slicehost::Formats::IMAGE] }) do - Slicehost[:slices].get_images.body - end - - end -end diff --git a/tests/slicehost/requests/get_slice_tests.rb b/tests/slicehost/requests/get_slice_tests.rb deleted file mode 100644 index 444d1a2ff..000000000 --- a/tests/slicehost/requests/get_slice_tests.rb +++ /dev/null @@ -1,22 +0,0 @@ -Shindo.tests('Slicehost#get_slice', 'slicehost') do - tests('success') do - - @server = Slicehost[:slices].servers.create(:flavor_id => 1, :image_id => 19, :name => 'fogrebootslice') - - tests("#get_slice(#{@server.id})").formats(Slicehost::Formats::SLICE) do - Slicehost[:slices].get_slice(@server.id).body - end - - @server.wait_for { ready? } - @server.destroy - - end - - tests('failure') do - - tests('#get_slice(0)').raises(Excon::Errors::Forbidden) do - Slicehost[:slices].get_slice(0) - end - - end -end diff --git a/tests/slicehost/requests/get_slices_tests.rb b/tests/slicehost/requests/get_slices_tests.rb deleted file mode 100644 index 6889229b7..000000000 --- a/tests/slicehost/requests/get_slices_tests.rb +++ /dev/null @@ -1,9 +0,0 @@ -Shindo.tests('Slicehost#get_slices', 'slicehost') do - tests('success') do - - formats({'slices' => [Slicehost::Formats::SLICE]}) do - Slicehost[:slices].get_slices.body - end - - end -end diff --git a/tests/slicehost/requests/image_tests.rb b/tests/slicehost/requests/image_tests.rb new file mode 100644 index 000000000..3c37eb6f4 --- /dev/null +++ b/tests/slicehost/requests/image_tests.rb @@ -0,0 +1,28 @@ +Shindo.tests('Slicehost | image requests', ['slicehost']) do + + @image_format = { + 'id' => Integer, + 'name' => String + } + + tests('success') do + + tests('#get_image(19)').formats(@image_format) do + Slicehost[:slices].get_image(19).body + end + + tests('#get_images').formats({ 'images' => [@image_format] }) do + Slicehost[:slices].get_images.body + end + + end + + tests('failure') do + + tests('#get_image(0)').raises(Excon::Errors::Forbidden) do + Slicehost[:slices].get_image(0) + end + + end + +end diff --git a/tests/slicehost/requests/reboot_slice_tests.rb b/tests/slicehost/requests/reboot_slice_tests.rb deleted file mode 100644 index 8d4fae973..000000000 --- a/tests/slicehost/requests/reboot_slice_tests.rb +++ /dev/null @@ -1,23 +0,0 @@ -Shindo.tests('Slicehost#reboot_slice', 'slicehost') do - tests('success') do - - @server = Slicehost[:slices].servers.create(:flavor_id => 1, :image_id => 19, :name => 'fogrebootslice') - @server.wait_for { ready? } - - tests("#reboot_slice(#{@server.id})").formats(Slicehost::Formats::SLICE) do - Slicehost[:slices].reboot_slice(@server.id).body - end - - @server.wait_for { ready? } - @server.destroy - - end - - tests('failure') do - - tests('#reboot_slice(0)').raises(Excon::Errors::Forbidden) do - Slicehost[:slices].reboot_slice(0) - end - - end -end diff --git a/tests/slicehost/requests/slice_tests.rb b/tests/slicehost/requests/slice_tests.rb new file mode 100644 index 000000000..4f71f0b17 --- /dev/null +++ b/tests/slicehost/requests/slice_tests.rb @@ -0,0 +1,63 @@ +Shindo.tests('Slicehost | slice requests', ['slicehost']) do + + @slice_format = { + 'addresses' => [String], + 'bw-in' => Float, + 'bw-out' => Float, + 'flavor-id' => Integer, + 'id' => Integer, + 'image-id' => Integer, + 'name' => String, + 'progress' => Integer, + 'status' => String + } + + tests('success') do + + @slice_id = nil + + tests("#create_slice(1, 19, 'fogcreateslice')").formats(@slice_format.merge('root-password' => String)) do + data = Slicehost[:slices].create_slice(1, 19, 'fogcreateslice').body + @slice_id = data['id'] + data + end + + Slicehost[:slices].slices.get(@slice_id).wait_for { ready? } + + tests("#get_slice(#{@slice_id})").formats(@slice_format) do + Slicehost[:slices].get_slice(@slice_id).body + end + + tests("#get_slices").formats({'slices' => [@slice_format]}) do + Slicehost[:slices].get_slices.body + end + + tests("#reboot_slice(#{@slice_id})").formats(@slice_format) do + Slicehost[:slices].reboot_slice(@slice_id).body + end + + Slicehost[:slices].slices.get(@slice_id).wait_for { ready? } + + tests("#delete_slice(#{@slice_id})").succeeds do + Slicehost[:slices].delete_slice(@slice_id) + end + + end + + tests('failure') do + + tests('#get_slice(0)').raises(Excon::Errors::Forbidden) do + Slicehost[:slices].get_slice(0) + end + + tests('#reboot_slice(0)').raises(Excon::Errors::Forbidden) do + Slicehost[:slices].reboot_slice(0) + end + + tests('delete_slice(0)').raises(Fog::Slicehost::NotFound) do + Slicehost[:slices].delete_slice(0) + end + + end + +end