deltacloud-core 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test.rb DELETED
@@ -1,8 +0,0 @@
1
- require 'rubygems'
2
- require 'AWS'
3
- require 'ap'
4
-
5
- client = AWS::EC2::Base.new(:access_key_id => "AKIAJ5XGZSACLBSBMUIA" ,
6
- :secret_access_key => "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")
7
-
8
- print client.describe_addresses
@@ -1,37 +0,0 @@
1
- require 'tests/common'
2
-
3
- module DeltacloudUnitTest
4
- class ApiTest < Test::Unit::TestCase
5
- include Rack::Test::Methods
6
-
7
- def app
8
- Sinatra::Application
9
- end
10
-
11
- def test_it_returns_entry_points
12
- do_xml_request '/api'
13
- (last_xml_response/'/api/link').map.size.should > 0
14
- end
15
-
16
- def test_it_has_correct_attributes_set
17
- do_xml_request '/api'
18
- (last_xml_response/'/api/link').each do |link|
19
- link.attributes.keys.sort.should == [ 'href', 'rel' ]
20
- end
21
- end
22
-
23
- def test_it_responses_to_html
24
- do_request '/api', {}, false, { :format => :html }
25
- last_response.status.should == 200
26
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
27
- end
28
-
29
- def test_it_responses_to_json
30
- do_request '/api', {}, false, { :format => :json }
31
- last_response.status.should == 200
32
- JSON::parse(last_response.body).class.should == Hash
33
- JSON::parse(last_response.body)['api'].class.should == Hash
34
- end
35
-
36
- end
37
- end
@@ -1,120 +0,0 @@
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
@@ -1,111 +0,0 @@
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
@@ -1,51 +0,0 @@
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
@@ -1,222 +0,0 @@
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