steamcannon-deltacloud-core 0.0.7.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. data/COPYING +176 -0
  2. data/Rakefile +106 -0
  3. data/bin/deltacloudd +120 -0
  4. data/config.ru +5 -0
  5. data/deltacloud.rb +20 -0
  6. data/lib/deltacloud/base_driver/base_driver.rb +259 -0
  7. data/lib/deltacloud/base_driver/features.rb +173 -0
  8. data/lib/deltacloud/base_driver/mock_driver.rb +58 -0
  9. data/lib/deltacloud/base_driver.rb +20 -0
  10. data/lib/deltacloud/drivers/azure/azure_driver.rb +127 -0
  11. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +580 -0
  12. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +170 -0
  13. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +50 -0
  14. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +343 -0
  15. data/lib/deltacloud/drivers/gogrid/test.rb +13 -0
  16. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob1.yml +5 -0
  17. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob2.yml +5 -0
  18. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob3.yml +5 -0
  19. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob4.yml +5 -0
  20. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob5.yml +5 -0
  21. data/lib/deltacloud/drivers/mock/data/buckets/bucket1.yml +2 -0
  22. data/lib/deltacloud/drivers/mock/data/buckets/bucket2.yml +2 -0
  23. data/lib/deltacloud/drivers/mock/data/images/img1.yml +3 -0
  24. data/lib/deltacloud/drivers/mock/data/images/img2.yml +3 -0
  25. data/lib/deltacloud/drivers/mock/data/images/img3.yml +3 -0
  26. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +16 -0
  27. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +9 -0
  28. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +9 -0
  29. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap1.yml +4 -0
  30. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap2.yml +4 -0
  31. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap3.yml +4 -0
  32. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml +6 -0
  33. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol2.yml +6 -0
  34. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml +6 -0
  35. data/lib/deltacloud/drivers/mock/mock_driver.rb +356 -0
  36. data/lib/deltacloud/drivers/opennebula/cloud_client.rb +116 -0
  37. data/lib/deltacloud/drivers/opennebula/occi_client.rb +204 -0
  38. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +241 -0
  39. data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +130 -0
  40. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +290 -0
  41. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +258 -0
  42. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +85 -0
  43. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +166 -0
  44. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +295 -0
  45. data/lib/deltacloud/hardware_profile.rb +153 -0
  46. data/lib/deltacloud/helpers/application_helper.rb +122 -0
  47. data/lib/deltacloud/helpers/blob_stream.rb +51 -0
  48. data/lib/deltacloud/helpers/conversion_helper.rb +39 -0
  49. data/lib/deltacloud/helpers/hardware_profiles_helper.rb +35 -0
  50. data/lib/deltacloud/helpers.rb +5 -0
  51. data/lib/deltacloud/method_serializer.rb +85 -0
  52. data/lib/deltacloud/models/base_model.rb +59 -0
  53. data/lib/deltacloud/models/blob.rb +26 -0
  54. data/lib/deltacloud/models/bucket.rb +24 -0
  55. data/lib/deltacloud/models/image.rb +27 -0
  56. data/lib/deltacloud/models/instance.rb +38 -0
  57. data/lib/deltacloud/models/instance_profile.rb +48 -0
  58. data/lib/deltacloud/models/key.rb +35 -0
  59. data/lib/deltacloud/models/realm.rb +26 -0
  60. data/lib/deltacloud/models/storage_snapshot.rb +27 -0
  61. data/lib/deltacloud/models/storage_volume.rb +28 -0
  62. data/lib/deltacloud/state_machine.rb +84 -0
  63. data/lib/deltacloud/validation.rb +70 -0
  64. data/lib/drivers.rb +51 -0
  65. data/lib/sinatra/accept_media_types.rb +128 -0
  66. data/lib/sinatra/lazy_auth.rb +56 -0
  67. data/lib/sinatra/rabbit.rb +279 -0
  68. data/lib/sinatra/respond_to.rb +238 -0
  69. data/lib/sinatra/static_assets.rb +83 -0
  70. data/lib/sinatra/url_for.rb +53 -0
  71. data/public/favicon.ico +0 -0
  72. data/public/images/grid.png +0 -0
  73. data/public/images/logo-wide.png +0 -0
  74. data/public/images/rails.png +0 -0
  75. data/public/images/topbar-bg.png +0 -0
  76. data/public/javascripts/application.js +32 -0
  77. data/public/javascripts/jquery-1.4.2.min.js +154 -0
  78. data/public/stylesheets/compiled/application.css +613 -0
  79. data/public/stylesheets/compiled/ie.css +31 -0
  80. data/public/stylesheets/compiled/print.css +27 -0
  81. data/public/stylesheets/compiled/screen.css +456 -0
  82. data/server.rb +516 -0
  83. data/support/fedora/deltacloudd +68 -0
  84. data/support/fedora/rubygem-deltacloud-core.spec +91 -0
  85. data/tests/api_test.rb +37 -0
  86. data/tests/hardware_profiles_test.rb +120 -0
  87. data/tests/images_test.rb +111 -0
  88. data/tests/instance_states_test.rb +51 -0
  89. data/tests/instances_test.rb +222 -0
  90. data/tests/realms_test.rb +78 -0
  91. data/tests/url_for_test.rb +50 -0
  92. data/views/accounts/index.html.haml +11 -0
  93. data/views/accounts/show.html.haml +30 -0
  94. data/views/api/show.html.haml +15 -0
  95. data/views/api/show.xml.haml +5 -0
  96. data/views/blobs/show.html.haml +20 -0
  97. data/views/blobs/show.xml.haml +7 -0
  98. data/views/buckets/index.html.haml +33 -0
  99. data/views/buckets/index.xml.haml +10 -0
  100. data/views/buckets/new.html.haml +13 -0
  101. data/views/buckets/show.html.haml +19 -0
  102. data/views/buckets/show.xml.haml +8 -0
  103. data/views/docs/collection.html.haml +37 -0
  104. data/views/docs/collection.xml.haml +14 -0
  105. data/views/docs/index.html.haml +15 -0
  106. data/views/docs/index.xml.haml +5 -0
  107. data/views/docs/operation.html.haml +31 -0
  108. data/views/docs/operation.xml.haml +10 -0
  109. data/views/errors/auth_exception.html.haml +8 -0
  110. data/views/errors/auth_exception.xml.haml +2 -0
  111. data/views/errors/backend_error.html.haml +19 -0
  112. data/views/errors/backend_error.xml.haml +8 -0
  113. data/views/errors/not_found.html.haml +6 -0
  114. data/views/errors/not_found.xml.haml +2 -0
  115. data/views/errors/validation_failure.html.haml +11 -0
  116. data/views/errors/validation_failure.xml.haml +7 -0
  117. data/views/hardware_profiles/index.html.haml +25 -0
  118. data/views/hardware_profiles/index.xml.haml +4 -0
  119. data/views/hardware_profiles/show.html.haml +19 -0
  120. data/views/hardware_profiles/show.xml.haml +18 -0
  121. data/views/images/index.html.haml +30 -0
  122. data/views/images/index.xml.haml +8 -0
  123. data/views/images/show.html.haml +21 -0
  124. data/views/images/show.xml.haml +5 -0
  125. data/views/instance_states/show.html.haml +31 -0
  126. data/views/instance_states/show.png.erb +45 -0
  127. data/views/instance_states/show.xml.haml +8 -0
  128. data/views/instances/index.html.haml +30 -0
  129. data/views/instances/index.xml.haml +21 -0
  130. data/views/instances/new.html.haml +55 -0
  131. data/views/instances/show.html.haml +43 -0
  132. data/views/instances/show.xml.haml +49 -0
  133. data/views/keys/index.html.haml +26 -0
  134. data/views/keys/index.xml.haml +4 -0
  135. data/views/keys/new.html.haml +8 -0
  136. data/views/keys/show.html.haml +22 -0
  137. data/views/keys/show.xml.haml +20 -0
  138. data/views/layout.html.haml +26 -0
  139. data/views/realms/index.html.haml +29 -0
  140. data/views/realms/index.xml.haml +10 -0
  141. data/views/realms/show.html.haml +15 -0
  142. data/views/realms/show.xml.haml +9 -0
  143. data/views/root/index.html.haml +4 -0
  144. data/views/storage_snapshots/index.html.haml +20 -0
  145. data/views/storage_snapshots/index.xml.haml +9 -0
  146. data/views/storage_snapshots/show.html.haml +14 -0
  147. data/views/storage_snapshots/show.xml.haml +7 -0
  148. data/views/storage_volumes/index.html.haml +21 -0
  149. data/views/storage_volumes/index.xml.haml +23 -0
  150. data/views/storage_volumes/show.html.haml +20 -0
  151. data/views/storage_volumes/show.xml.haml +24 -0
  152. metadata +367 -0
@@ -0,0 +1,120 @@
1
+ require 'tests/common'
2
+
3
+ module DeltacloudUnitTest
4
+ class HardwareProfilesTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ def test_it_returns_hardware_profiles
12
+ do_xml_request '/api/hardware_profiles'
13
+ (last_xml_response/'hardware_profiles/hardware_profile').map.size.should > 0
14
+ end
15
+
16
+ def test_it_has_correct_attributes_set
17
+ do_xml_request '/api/hardware_profiles'
18
+ (last_xml_response/'hardware_profiles/hardware_profile').each do |profile|
19
+ profile.attributes.keys.sort.should == [ 'href', 'id' ]
20
+ end
21
+ end
22
+
23
+ def test_hardware_profiles_have_name
24
+ do_xml_request '/api/hardware_profiles'
25
+ (last_xml_response/'hardware_profiles/hardware_profile').each do |profile|
26
+ (profile/'name').text.should_not == nil
27
+ end
28
+ end
29
+
30
+ def test_hardware_profiles_have_unique_name
31
+ do_xml_request '/api/hardware_profiles'
32
+ names = []
33
+ (last_xml_response/'hardware_profiles/hardware_profile').each do |profile|
34
+ names << (profile/'name').text
35
+ end
36
+ names.should == names.uniq
37
+ end
38
+
39
+ def test_hardware_profiles_have_unique_id
40
+ do_xml_request '/api/hardware_profiles'
41
+ ids = []
42
+ (last_xml_response/'hardware_profiles/hardware_profile').each do |profile|
43
+ ids << profile['id']
44
+ end
45
+ ids.should == ids.uniq
46
+ end
47
+
48
+ def test_m1_xlarge_profile_has_correct_attributes
49
+ do_xml_request '/api/hardware_profiles'
50
+ profile = (last_xml_response/'hardware_profiles/hardware_profile[@id="m1-xlarge"]')
51
+ test_profile_properties(profile)
52
+ end
53
+
54
+ def test_it_returns_valid_hardware_profile
55
+ do_xml_request '/api/hardware_profiles/m1-xlarge'
56
+ profile = (last_xml_response/'hardware_profile')
57
+ test_profile_properties(profile)
58
+ end
59
+
60
+ def test_it_responses_to_json
61
+ do_request '/api/hardware_profiles', {}, false, { :format => :json }
62
+ JSON::parse(last_response.body).class.should == Hash
63
+ JSON::parse(last_response.body)['hardware_profiles'].class.should == Array
64
+
65
+ do_request '/api/hardware_profiles/m1-xlarge', {}, false, { :format => :json }
66
+ last_response.status.should == 200
67
+ JSON::parse(last_response.body).class.should == Hash
68
+ JSON::parse(last_response.body)['hardware_profile'].class.should == Hash
69
+ end
70
+
71
+ def test_it_responses_to_html
72
+ do_request '/api/hardware_profiles', {}, false, { :format => :html }
73
+ last_response.status.should == 200
74
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
75
+
76
+ do_request '/api/hardware_profiles/m1-xlarge', {}, false, { :format => :html }
77
+ last_response.status.should == 200
78
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
79
+ end
80
+
81
+ def test_it_returns_error_on_wrong_name
82
+ do_request '/api/hardware_profiles/m1-unknown-wrongname', {}, false, { :format => :html }
83
+ last_response.status.should == 404
84
+ do_xml_request '/api/hardware_profiles/m1-unknown-wrongname'
85
+ last_response.status.should == 404
86
+ do_request '/api/hardware_profiles/m1-unknown-wrongname', {}, false, { :format => :json }
87
+ last_response.status.should == 404
88
+ end
89
+
90
+ private
91
+
92
+ def test_profile_properties(profile)
93
+
94
+ (profile/'property').each do |properties|
95
+ properties.attributes.keys.sort.should == [ 'kind', 'name', 'unit', 'value' ]
96
+ end
97
+
98
+ (profile/'property[@name="architecture"]').first['kind'].should == 'fixed'
99
+ (profile/'property[@name="architecture"]').first['unit'].should == 'label'
100
+
101
+ (profile/'property[@name="memory"]').first['kind'].should == 'range'
102
+ (profile/'property[@name="memory"]').first['unit'].should == 'MB'
103
+ (profile/'property[@name="memory"]/range').size.should == 1
104
+ (profile/'property[@name="memory"]/range').first.attributes.keys.sort.should == [ 'first', 'last' ]
105
+
106
+ (profile/'property[@name="cpu"]').first['kind'].should == 'fixed'
107
+ (profile/'property[@name="cpu"]').first['unit'].should == 'count'
108
+
109
+ (profile/'property[@name="storage"]').first['kind'].should == 'enum'
110
+ (profile/'property[@name="storage"]').first['unit'].should == 'GB'
111
+ (profile/'property[@name="storage"]/enum').size.should == 1
112
+ (profile/'property[@name="storage"]/enum/entry').map.size.should == 3
113
+ (profile/'property[@name="storage"]/enum/entry').each do |entry|
114
+ entry.attributes.keys.should == [ 'value' ]
115
+ entry['value'].should_not == nil
116
+ end
117
+ end
118
+
119
+ end
120
+ end
@@ -0,0 +1,111 @@
1
+ require 'tests/common'
2
+
3
+ module DeltacloudUnitTest
4
+ class HardwareProfilesTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ def test_it_require_authentication
12
+ require_authentication?('/api/images').should == true
13
+ end
14
+
15
+ def test_it_returns_images
16
+ do_xml_request '/api/images', {}, true
17
+ (last_xml_response/'images/image').map.size.should > 0
18
+ end
19
+
20
+ def test_it_has_correct_attributes_set
21
+ do_xml_request '/api/images', {}, true
22
+ (last_xml_response/'images/image').each do |image|
23
+ image.attributes.keys.sort.should == [ 'href', 'id' ]
24
+ end
25
+ end
26
+
27
+ def test_img1_has_correct_attributes
28
+ do_xml_request '/api/images', {}, true
29
+ image = (last_xml_response/'images/image[@id="img1"]')
30
+ test_image_attributes(image)
31
+ end
32
+
33
+ def test_it_returns_valid_image
34
+ do_xml_request '/api/images/img1', {}, true
35
+ image = (last_xml_response/'image')
36
+ test_image_attributes(image)
37
+ end
38
+
39
+ def test_it_has_unique_ids
40
+ do_xml_request '/api/images', {}, true
41
+ ids = []
42
+ (last_xml_response/'images/image').each do |image|
43
+ ids << image['id'].to_s
44
+ end
45
+ ids.sort.should == ids.sort.uniq
46
+ end
47
+
48
+ def test_it_has_valid_urls
49
+ do_xml_request '/api/images', {}, true
50
+ ids = []
51
+ images = (last_xml_response/'images/image')
52
+ images.each do |image|
53
+ do_xml_request image['href'].to_s, {}, true
54
+ (last_xml_response/'image').first['href'].should == image['href'].to_s
55
+ end
56
+ end
57
+
58
+ def test_it_can_filter_using_owner_id
59
+ do_xml_request '/api/images', { :owner_id => 'mockuser' }, true
60
+ (last_xml_response/'images/image').size.should == 1
61
+ (last_xml_response/'images/image/owner_id').first.text.should == 'mockuser'
62
+ end
63
+
64
+ def test_it_can_filter_using_unknown_owner_id
65
+ do_xml_request '/api/images', { :architecture => 'unknown_user' }, true
66
+ (last_xml_response/'images/image').size.should == 0
67
+ end
68
+
69
+ def test_it_can_filter_using_architecture
70
+ do_xml_request '/api/images', { :architecture => 'x86_64' }, true
71
+ (last_xml_response/'images/image').size.should == 1
72
+ (last_xml_response/'images/image/architecture').first.text.should == 'x86_64'
73
+ end
74
+
75
+ def test_it_can_filter_using_unknown_architecture
76
+ do_xml_request '/api/images', { :architecture => 'unknown_arch' }, true
77
+ (last_xml_response/'images/image').size.should == 0
78
+ end
79
+
80
+ def test_it_responses_to_json
81
+ do_request '/api/images', {}, true, { :format => :json }
82
+ JSON::parse(last_response.body).class.should == Hash
83
+ JSON::parse(last_response.body)['images'].class.should == Array
84
+
85
+ do_request '/api/images/img1', {}, true, { :format => :json }
86
+ last_response.status.should == 200
87
+ JSON::parse(last_response.body).class.should == Hash
88
+ JSON::parse(last_response.body)['image'].class.should == Hash
89
+ end
90
+
91
+ def test_it_responses_to_html
92
+ do_request '/api/images', {}, true, { :format => :html }
93
+ last_response.status.should == 200
94
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
95
+
96
+ do_request '/api/images/img1', {}, true, { :format => :html }
97
+ last_response.status.should == 200
98
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
99
+ end
100
+
101
+ private
102
+
103
+ def test_image_attributes(image)
104
+ (image/'name').text.should_not nil
105
+ (image/'owner_id').text.should_not nil
106
+ (image/'description').text.should_not nil
107
+ (image/'architecture').text.should_not nil
108
+ end
109
+
110
+ end
111
+ end
@@ -0,0 +1,51 @@
1
+ require 'tests/common'
2
+
3
+ module DeltacloudUnitTest
4
+ class RealmsTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ def test_it_not_require_authentication
12
+ require_authentication?('/api/realms').should_not == true
13
+ end
14
+
15
+ def test_it_returns_instance_states
16
+ do_xml_request '/api/instance_states', {}, true
17
+ (last_xml_response/'states/state').map.size.should > 0
18
+ end
19
+
20
+ def test_each_state_has_transition
21
+ do_xml_request '/api/instance_states', {}, true
22
+ (last_xml_response/'states/state').each do |state|
23
+ next if state['name'].eql?('finish') # Finnish state doesn't have transitions
24
+ (state/'transition').map.size.should > 0
25
+ (state/'transition').each do |transition|
26
+ transition['to'].should_not == nil
27
+ end
28
+ end
29
+ end
30
+
31
+ def test_it_responses_to_json
32
+ do_request '/api/instance_states', {}, false, { :format => :json }
33
+ JSON::parse(last_response.body).class.should == Array
34
+ JSON::parse(last_response.body).first['transitions'].class.should == Array
35
+ JSON::parse(last_response.body).first['name'].should == 'start'
36
+ end
37
+
38
+ def test_it_responses_to_html
39
+ do_request '/api/instance_states', {}, false, { :format => :html }
40
+ last_response.status.should == 200
41
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
42
+ end
43
+
44
+ def test_it_responses_to_png
45
+ do_request '/api/instance_states', { :format => 'png' }, false
46
+ last_response.status.should == 200
47
+ last_response.headers['Content-Type'].should == 'image/png'
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,222 @@
1
+ require 'tests/common'
2
+
3
+ module DeltacloudUnitTest
4
+ class InstancesTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ def test_it_require_authentication
12
+ require_authentication?('/api/instances').should == true
13
+ end
14
+
15
+ def test_it_returns_instances
16
+ do_xml_request '/api/instances', {}, true
17
+ (last_xml_response/'instances/instance').map.size.should > 0
18
+ end
19
+
20
+ def test_it_has_correct_attributes_set
21
+ do_xml_request '/api/images', {}, true
22
+ (last_xml_response/'images/image').each do |image|
23
+ image.attributes.keys.sort.should == [ 'href', 'id' ]
24
+ end
25
+ end
26
+
27
+ def test_it_has_unique_ids
28
+ do_xml_request '/api/instances', {}, true
29
+ ids = []
30
+ (last_xml_response/'instances/instance').each do |image|
31
+ ids << image['id'].to_s
32
+ end
33
+ ids.sort.should == ids.sort.uniq
34
+ end
35
+
36
+ def test_inst1_has_correct_attributes
37
+ do_xml_request '/api/instances', {}, true
38
+ instance = (last_xml_response/'instances/instance[@id="inst1"]')
39
+ test_instance_attributes(instance)
40
+ end
41
+
42
+ def test_it_returns_valid_realm
43
+ do_xml_request '/api/instances/inst1', {}, true
44
+ instance = (last_xml_response/'instance')
45
+ test_instance_attributes(instance)
46
+ end
47
+
48
+ def test_it_responses_to_json
49
+ do_request '/api/instances', {}, true, { :format => :json }
50
+ JSON::parse(last_response.body).class.should == Hash
51
+ JSON::parse(last_response.body)['instances'].class.should == Array
52
+
53
+ do_request '/api/instances/inst1', {}, true, { :format => :json }
54
+ last_response.status.should == 200
55
+ JSON::parse(last_response.body).class.should == Hash
56
+ JSON::parse(last_response.body)['instance'].class.should == Hash
57
+ end
58
+
59
+ def test_it_responses_to_html
60
+ do_request '/api/instances', {}, true, { :format => :html }
61
+ last_response.status.should == 200
62
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
63
+
64
+ do_request '/api/instances/inst1', {}, true, { :format => :html }
65
+ last_response.status.should == 200
66
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
67
+ end
68
+
69
+ def test_it_create_a_new_instance_using_image_id
70
+ params = {
71
+ :image_id => 'img1'
72
+ }
73
+ header 'Accept', accept_header(:xml)
74
+ post '/api/instances', params, authenticate
75
+ last_response.status.should == 201
76
+ last_response.headers['Location'].should_not == nil
77
+ do_xml_request last_response.headers['Location'], {}, true
78
+ (last_xml_response/'instance/name').should_not == nil
79
+ add_created_instance (last_xml_response/'instance').first['id']
80
+ test_instance_attributes(last_xml_response/'instance')
81
+ end
82
+
83
+ def test_it_create_a_new_instance_using_image_id_and_name
84
+ params = {
85
+ :image_id => 'img1',
86
+ :name => "unit_test_instance1"
87
+ }
88
+ header 'Accept', accept_header(:xml)
89
+ post '/api/instances', params, authenticate(:format => :xml)
90
+ last_response.status.should == 201
91
+ last_response.headers['Location'].should_not == nil
92
+ do_xml_request last_response.headers['Location'], {}, true
93
+ (last_xml_response/'instance/name').text.should == 'unit_test_instance1'
94
+ add_created_instance (last_xml_response/'instance').first['id']
95
+ test_instance_attributes(last_xml_response/'instance')
96
+ end
97
+
98
+ def test_it_create_a_new_instance_using_image_id_and_name_and_hwp
99
+ params = {
100
+ :image_id => 'img1',
101
+ :name => "unit_test_instance1",
102
+ :hwp_id => "m1-xlarge"
103
+ }
104
+ header 'Accept', accept_header(:xml)
105
+ post '/api/instances', params, authenticate(:format => :xml)
106
+ last_response.status.should == 201
107
+ last_response.headers['Location'].should_not == nil
108
+ do_xml_request last_response.headers['Location'], {}, true
109
+ (last_xml_response/'instance/name').text.should == 'unit_test_instance1'
110
+ (last_xml_response/'instance/hardware_profile').first['id'].should == 'm1-xlarge'
111
+ add_created_instance (last_xml_response/'instance').first['id']
112
+ test_instance_attributes(last_xml_response/'instance')
113
+ end
114
+
115
+ def test_it_z0_stop_and_start_instance
116
+ $created_instances.each do |instance_id|
117
+ do_xml_request "/api/instances/#{instance_id}", {}, true
118
+ stop_url = (last_xml_response/'actions/link[@rel="stop"]').first['href']
119
+ stop_url.should_not == nil
120
+ post create_url(stop_url), { :format => 'xml' }, authenticate
121
+ last_response.status.should == 200
122
+ instance = Nokogiri::XML(last_response.body)
123
+ test_instance_attributes(instance)
124
+ (instance/'state').text.should == 'STOPPED'
125
+ do_xml_request "/api/instances/#{instance_id}", {}, true
126
+ start_url = (last_xml_response/'actions/link[@rel="start"]').first['href']
127
+ start_url.should_not == nil
128
+ post create_url(start_url), { :format => 'xml'}, authenticate
129
+ last_response.status.should == 200
130
+ instance = Nokogiri::XML(last_response.body)
131
+ test_instance_attributes(instance)
132
+ (instance/'state').text.should == 'RUNNING'
133
+ end
134
+ end
135
+
136
+ def test_z0_reboot_instance
137
+ $created_instances.each do |instance_id|
138
+ do_xml_request "/api/instances/#{instance_id}", {}, true
139
+ reboot_url = (last_xml_response/'actions/link[@rel="reboot"]').first['href']
140
+ reboot_url.should_not == nil
141
+ post create_url(reboot_url), { :format => "xml"}, authenticate
142
+ last_response.status.should == 200
143
+ instance = Nokogiri::XML(last_response.body)
144
+ test_instance_attributes(instance)
145
+ (instance/'state').text.should == 'RUNNING'
146
+ end
147
+ end
148
+
149
+ def test_z1_stop_created_instances
150
+ $created_instances.each do |instance_id|
151
+ do_xml_request "/api/instances/#{instance_id}", {}, true
152
+ stop_url = (last_xml_response/'actions/link[@rel="stop"]').first['href']
153
+ stop_url.should_not == nil
154
+ post create_url(stop_url), {}, authenticate
155
+ last_response.status.should == 200
156
+ instance = Nokogiri::XML(last_response.body)
157
+ test_instance_attributes(instance)
158
+ (instance/'state').text.should == 'STOPPED'
159
+ end
160
+ end
161
+
162
+ def test_z2_destroy_created_instances
163
+ $created_instances.each do |instance_id|
164
+ do_xml_request "/api/instances/#{instance_id}", {}, true
165
+ destroy_url = (last_xml_response/'actions/link[@rel="destroy"]').first['href']
166
+ destroy_url.should_not == nil
167
+ delete create_url(destroy_url), {}, authenticate
168
+ last_response.status.should == 302
169
+ do_xml_request last_response.headers['Location'], {}, true
170
+ (last_xml_response/'instances').should_not == nil
171
+ do_xml_request "/api/instances/#{instance_id}", {}, true
172
+ last_response.status.should == 404
173
+ end
174
+ end
175
+
176
+ private
177
+
178
+ def test_instance_attributes(instance)
179
+ (instance/'name').should_not == nil
180
+ (instance/'owner_id').should_not == nil
181
+ ['RUNNING', 'STOPPED'].include?((instance/'state').text).should == true
182
+
183
+ (instance/'public_addreses').should_not == nil
184
+ (instance/'public_addresses/address').map.size.should > 0
185
+ (instance/'public_addresses/address').first.text.should_not == ""
186
+
187
+ (instance/'private_addresses').should_not == nil
188
+ (instance/'private_addresses/address').map.size.should > 0
189
+ (instance/'private_addresses/address').first.text.should_not == ""
190
+
191
+ (instance/'actions/link').map.size.should > 0
192
+ (instance/'actions/link').each do |link|
193
+ link['href'].should_not == ""
194
+ link['rel'].should_not == ""
195
+ link['method'].should_not == ""
196
+ ['get', 'post', 'delete', 'put'].include?(link['method']).should == true
197
+ end
198
+
199
+ (instance/'image').size.should > 0
200
+ (instance/'image').first['href'].should_not == ""
201
+ (instance/'image').first['id'].should_not == ""
202
+ do_xml_request (instance/'image').first['href'], {}, true
203
+ (last_xml_response/'image').should_not == nil
204
+ (last_xml_response/'image').first['href'] == (instance/'image').first['href']
205
+
206
+ (instance/'realm').size.should > 0
207
+ (instance/'realm').first['href'].should_not == ""
208
+ (instance/'realm').first['id'].should_not == ""
209
+ do_xml_request (instance/'realm').first['href']
210
+ (last_xml_response/'realm').should_not == nil
211
+ (last_xml_response/'realm').first['href'] == (instance/'realm').first['href']
212
+
213
+ (instance/'hardware_profile').size.should > 0
214
+ (instance/'hardware_profile').first['href'].should_not == ""
215
+ (instance/'hardware_profile').first['id'].should_not == ""
216
+ do_xml_request (instance/'hardware_profile').first['href']
217
+ (last_xml_response/'hardware_profile').should_not == nil
218
+ (last_xml_response/'hardware_profile').first['href'] == (instance/'hardware_profile').first['href']
219
+ end
220
+
221
+ end
222
+ end
@@ -0,0 +1,78 @@
1
+ require 'tests/common'
2
+
3
+ module DeltacloudUnitTest
4
+ class RealmsTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ def test_it_not_require_authentication
12
+ require_authentication?('/api/realms').should_not == true
13
+ end
14
+
15
+ def test_it_returns_realms
16
+ do_xml_request '/api/realms', {}, true
17
+ (last_xml_response/'realms/realm').map.size.should > 0
18
+ end
19
+
20
+ def test_it_has_correct_attributes_set
21
+ do_xml_request '/api/realms', {}, true
22
+ (last_xml_response/'realms/realm').each do |realm|
23
+ realm.attributes.keys.sort.should == [ 'href', 'id' ]
24
+ end
25
+ end
26
+
27
+ def test_us_has_correct_attributes
28
+ do_xml_request '/api/realms', {}, true
29
+ realm = (last_xml_response/'realms/realm[@id="us"]')
30
+ test_realm_attributes(realm)
31
+ end
32
+
33
+ def test_it_returns_valid_realm
34
+ do_xml_request '/api/realms/us', {}, true
35
+ realm = (last_xml_response/'realm')
36
+ test_realm_attributes(realm)
37
+ end
38
+
39
+ def test_it_has_unique_ids
40
+ do_xml_request '/api/realms', {}, true
41
+ ids = []
42
+ (last_xml_response/'realms/realm').each do |realm|
43
+ ids << realm['id'].to_s
44
+ end
45
+ ids.sort.should == ids.sort.uniq
46
+ end
47
+
48
+ def test_it_responses_to_json
49
+ do_request '/api/realms', {}, false, { :format => :json }
50
+ JSON::parse(last_response.body).class.should == Hash
51
+ JSON::parse(last_response.body)['realms'].class.should == Array
52
+
53
+ do_request '/api/realms/us', {}, false, { :format => :json }
54
+ last_response.status.should == 200
55
+ JSON::parse(last_response.body).class.should == Hash
56
+ JSON::parse(last_response.body)['realm'].class.should == Hash
57
+ end
58
+
59
+ def test_it_responses_to_html
60
+ do_request '/api/realms', {}, false, { :format => :html }
61
+ last_response.status.should == 200
62
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
63
+
64
+ do_request '/api/realms/us', {}, false, { :format => :html }
65
+ last_response.status.should == 200
66
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
67
+ end
68
+
69
+ private
70
+
71
+ def test_realm_attributes(realm)
72
+ (realm/'name').should_not == nil
73
+ (realm/'limit').should_not == nil
74
+ ['AVAILABLE'].include?((realm/'state').text).should == true
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,50 @@
1
+ require 'tests/common'
2
+
3
+ module DeltacloudUnitTest
4
+ class UrlForTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ def test_it_works_for_root
12
+ verify_url_for("/", "/")
13
+ end
14
+
15
+ def test_it_works_for_root_absolute
16
+ verify_url_for("/", "http://localhost/", :full)
17
+ end
18
+
19
+ def test_it_works_with_spaces
20
+ verify_url_for("/url with spaces", "/url%20with%20spaces")
21
+ end
22
+
23
+ def test_it_works_when_given_absolute
24
+ verify_url_for("http://test.com", "http://test.com")
25
+ end
26
+
27
+ def test_it_works_when_not_at_root_context
28
+ verify_url_for("/", "context/", :path_only, {}, {"SCRIPT_NAME" => "context"})
29
+ end
30
+
31
+ def verify_url_for(url, expected_url, mode=:path_only, params={}, rack_env={})
32
+ # generate a unique url for each test
33
+ test_url = "/url_for_test/#{expected_url.hash}/#{Time.now.to_i}"
34
+ # Create our sinatra test endpoint
35
+ self.class.create_test_url_content(test_url, url, mode)
36
+
37
+ # verify the generated url matches what we expect
38
+ get test_url, params, rack_env
39
+ last_response.body.should == expected_url
40
+ end
41
+
42
+ def self.create_test_url_content(test_url, url_content, mode)
43
+ get test_url do
44
+ content_type "text/plain"
45
+ url_for(url_content, mode)
46
+ end
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,11 @@
1
+ %h1 Accounts
2
+
3
+ %table
4
+ %thead
5
+ %tr
6
+ %th ID
7
+ %tbody
8
+ - @accounts.each do |account|
9
+ %tr
10
+ %td
11
+ = link_to account, account
@@ -0,0 +1,30 @@
1
+ %h1
2
+ = @account[:id]
3
+
4
+ %h2 Instances
5
+
6
+ %table
7
+ %thead
8
+ %tr
9
+ %th Instance ID
10
+ %tbody
11
+ - @account[:instance_ids].each do |instance_id|
12
+ %tr
13
+ %td
14
+ = link_to instance_id, instance_url( instance_id )
15
+
16
+ %h2 Images
17
+
18
+ %table
19
+ %thead
20
+ %tr
21
+ %th Image ID
22
+ %th Description
23
+ %tbody
24
+ %tbody
25
+ - @images.each do |image|
26
+ %tr
27
+ %td
28
+ = link_to image[:id], image_url( image[:id] )
29
+ %td
30
+ = image[:description]