azurex 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/Gemfile +1 -1
  4. data/README.md +2 -0
  5. data/lib/azure.rb +3 -0
  6. data/lib/azure/base_management/management_http_request.rb +3 -3
  7. data/lib/azure/cloud_service_management/cloud_service_management_service.rb +1 -9
  8. data/lib/azure/core/utility.rb +0 -71
  9. data/lib/azure/storage_management/serialization.rb +9 -12
  10. data/lib/azure/storage_management/storage_account.rb +1 -0
  11. data/lib/azure/storage_management/storage_management_service.rb +15 -18
  12. data/lib/azure/version.rb +1 -1
  13. data/lib/azure/virtual_machine_image_management/serialization.rb +15 -1
  14. data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +31 -2
  15. data/lib/azure/virtual_machine_management/serialization.rb +1 -1
  16. data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +4 -4
  17. data/lib/core_ext/ip_addr.rb +48 -0
  18. data/lib/core_ext/string.rb +27 -0
  19. data/test/fixtures/get_storage_account_properties.xml +6 -4
  20. data/test/fixtures/list_storage_accounts.xml +2 -0
  21. data/test/fixtures/list_vmimages.xml +86 -0
  22. data/test/fixtures/updated_storage_accounts.xml +2 -0
  23. data/test/integration/affinity_group/Create_Affinity_test.rb +1 -1
  24. data/test/integration/cloud_service/Cloud_Delete_test.rb +2 -2
  25. data/test/integration/storage_management/storage_management_test.rb +40 -33
  26. data/test/integration/vm/VM_Delete_test.rb +1 -1
  27. data/test/integration/vm_image/virtual_machine_image_test.rb +1 -1
  28. data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +4 -4
  29. data/test/unit/core_ext/string_test.rb +11 -0
  30. data/test/unit/storage_management/serialization_test.rb +12 -13
  31. data/test/unit/storage_management/storage_management_service_test.rb +26 -40
  32. data/test/unit/virtual_machine_image_management/serialization_test.rb +17 -1
  33. data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +113 -8
  34. data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +17 -0
  35. metadata +6 -2
@@ -92,14 +92,16 @@ describe Azure::StorageManagementService do
92
92
  subject.get_storage_account 'storage1'
93
93
  end
94
94
 
95
- it "returns true if found storage account with given name" do
96
- result = subject.get_storage_account 'storage1'
97
- result.must_equal true
95
+ it "returns storage account instance" do
96
+ storage_account_name = 'storage1'
97
+ result = subject.get_storage_account storage_account_name
98
+ result.must_be_kind_of Azure::StorageManagement::StorageAccount
99
+ result.name.must_equal storage_account_name
98
100
  end
99
101
 
100
102
  it "returns false if storage account with given name doesn't exists" do
101
103
  result = subject.get_storage_account 'storage3'
102
- result.must_equal false
104
+ result.must_equal nil
103
105
  end
104
106
  end
105
107
 
@@ -149,15 +151,12 @@ describe Azure::StorageManagementService do
149
151
  describe "#update_storage_account" do
150
152
  let(:updated_accounts_xml) { Fixtures["updated_storage_accounts"] }
151
153
  let(:no_options_specified) { 'No options specified' }
152
- let(:update_storage_account_req) { Fixtures["update_storage_account"] }
153
-
154
- let(:updated_storage_account_mock_request){ mock() }
155
- let(:updated_storage_account_response) {
154
+ let(:sa_response) {
156
155
  updated_storage_account_response = mock()
157
156
  updated_storage_account_response.stubs(:body).returns(updated_accounts_xml)
158
157
  updated_storage_account_response
158
+ Nokogiri::XML updated_storage_account_response.body
159
159
  }
160
- let(:updated_storage_account_response_body) {Nokogiri::XML updated_storage_account_response.body}
161
160
 
162
161
  let(:update_request) {
163
162
  update_request = mock()
@@ -168,8 +167,6 @@ describe Azure::StorageManagementService do
168
167
  before {
169
168
  ManagementHttpRequest.stubs(:new).with(method, request_path, nil).returns(mock_request)
170
169
  mock_request.expects(:call).returns(response_body)
171
-
172
- Azure::StorageManagement::Serialization.stubs(:update_storage_account).returns(update_storage_account_req)
173
170
  }
174
171
 
175
172
  let(:options) { {
@@ -183,13 +180,6 @@ describe Azure::StorageManagementService do
183
180
  }
184
181
  }
185
182
 
186
- it "checks if nil options is provided" do
187
- exception = assert_raises RuntimeError do
188
- subject.update_storage_account 'storage2', nil
189
- end
190
- assert_match no_options_specified, exception.message
191
- end
192
-
193
183
  it "checks if empty options is provided" do
194
184
  exception = assert_raises RuntimeError do
195
185
  subject.update_storage_account 'storage2', Hash.new
@@ -203,26 +193,20 @@ describe Azure::StorageManagementService do
203
193
  end
204
194
 
205
195
  it "updates the specified account" do
206
- ManagementHttpRequest.stubs(:new).with(:put, "#{request_path}/storage2", update_storage_account_req).returns(update_request)
207
- update_request.expects(:call).returns('')
208
-
196
+ ManagementHttpRequest.stubs(:new).with(
197
+ :put,
198
+ "#{request_path}/storage2",
199
+ Fixtures['update_storage_account']
200
+ ).returns(update_request)
201
+ update_request.expects(:call)
209
202
  subject.update_storage_account 'storage2', options
210
-
211
- ManagementHttpRequest.stubs(:new).with(method, request_path, nil).returns(updated_storage_account_mock_request)
212
- updated_storage_account_mock_request.expects(:call).returns(updated_storage_account_response_body)
213
-
214
- accounts = subject.list_storage_accounts
215
-
216
- accounts.each { |account|
217
- next unless account.name == 'storage2'
218
-
219
- account.name.must_equal 'storage2'
220
- account.label.must_equal options[:label]
221
- account.geo_replication_enabled.must_equal "#{options[:geo_replication_enabled]}"
222
-
223
- account.extended_properties.each { |prop|
224
- prop[:value].must_equal "#{options[:extended_properties][:"#{prop[:name]}"]}"
225
- }
203
+ mock_request.expects(:call).returns(sa_response)
204
+ storage_account = subject.list_storage_accounts.last
205
+ storage_account.name.must_equal 'storage2'
206
+ storage_account.label.must_equal options[:label]
207
+ storage_account.geo_replication_enabled.must_equal "#{options[:geo_replication_enabled]}"
208
+ storage_account.extended_properties.each { |prop|
209
+ prop[:value].must_equal "#{options[:extended_properties][:"#{prop[:name]}"]}"
226
210
  }
227
211
  end
228
212
  end
@@ -253,9 +237,11 @@ describe Azure::StorageManagementService do
253
237
  }
254
238
 
255
239
  it 'returns the label as a Base64 decoded string' do
256
- account = subject.get_storage_account_properties(account_name)
257
- account.label.must_be_kind_of(String)
258
- account.label.must_equal(label)
240
+ storage_account = subject.get_storage_account_properties(account_name)
241
+ storage_account.label.must_be_kind_of(String)
242
+ storage_account.label.must_equal(label)
243
+ storage_account.account_type.must_equal 'Standard_GRS'
244
+ storage_account.geo_primary_region.must_equal 'West US'
259
245
  end
260
246
  end
261
247
  end
@@ -18,6 +18,7 @@ describe Azure::VirtualMachineImageManagement::Serialization do
18
18
  subject { Azure::VirtualMachineImageManagement::Serialization }
19
19
 
20
20
  let(:virtual_machine_images_from_xml) { Fixtures['list_images'] }
21
+ let(:virtual_machine_vmimages_from_xml) { Fixtures['list_vmimages'] }
21
22
 
22
23
  describe '#virtual_machine_images_from_xml' do
23
24
 
@@ -28,8 +29,23 @@ describe Azure::VirtualMachineImageManagement::Serialization do
28
29
  it 'returns an Array of VirtualMachineImageService instances' do
29
30
  results = subject.virtual_machine_images_from_xml Nokogiri::XML(virtual_machine_images_from_xml)
30
31
  results.must_be_kind_of Array
31
- results[0].must_be_kind_of Azure::VirtualMachineImageManagement::VirtualMachineImage
32
+ results.first.must_be_kind_of Azure::VirtualMachineImageManagement::VirtualMachineImage
32
33
  results.count.must_equal 12
33
34
  end
35
+
36
+ it 'parses an OSImage node correctly' do
37
+ results = subject.virtual_machine_images_from_xml Nokogiri::XML(virtual_machine_images_from_xml)
38
+ results.first.name.must_equal 'RightImage-CentOS-6.2-x64-v5.8.8.1'
39
+ results.first.os_type.must_equal 'Linux'
40
+ results.first.category.must_equal 'RightScale with Linux'
41
+ end
42
+
43
+ it 'parses an VMImage node correctly' do
44
+ results = subject.virtual_machine_vmimages_from_xml Nokogiri::XML(virtual_machine_vmimages_from_xml)
45
+ results.first.name.must_equal 'name-of-image'
46
+ results.first.os_type.must_equal 'operating-system-of-image'
47
+ results.first.category.must_equal 'category-of-image'
48
+ end
49
+
34
50
  end
35
51
  end
@@ -18,48 +18,153 @@ describe Azure::VirtualMachineImageManagementService do
18
18
 
19
19
  subject { Azure::VirtualMachineImageManagementService.new }
20
20
 
21
- let(:request_path) { '/services/images' }
21
+ let(:public_request_path) { '/services/images' }
22
+ let(:private_request_path) { '/services/vmimages' }
22
23
  let(:images_xml) { Fixtures['list_images'] }
24
+ let(:vmimages_xml) { Fixtures['list_vmimages'] }
23
25
  let(:method) { :get }
24
26
  let(:mock_request) { mock }
25
- let(:response) do
27
+ let(:mock_request2) { mock }
28
+
29
+ let(:public_response) do
26
30
  response = mock
27
31
  response.stubs(:body).returns(images_xml)
28
32
  response
29
33
  end
30
- let(:response_body) { Nokogiri::XML response.body }
34
+ let(:public_response_body) { Nokogiri::XML public_response.body }
35
+
36
+ let(:private_response) do
37
+ response = mock
38
+ response.stubs(:body).returns(vmimages_xml)
39
+ response
40
+ end
41
+ let(:private_response_body) { Nokogiri::XML private_response.body }
31
42
 
32
43
  before do
33
44
  Loggerx.expects(:puts).returns(nil).at_least(0)
34
45
  end
35
46
 
36
- describe '#list_virtual_machine_images' do
47
+ describe '#list_public_virtual_machine_images' do
37
48
 
38
49
  before do
39
50
  ManagementHttpRequest.stubs(:new).with(
40
51
  method,
41
- request_path,
52
+ public_request_path,
42
53
  nil
43
54
  ).returns(mock_request)
44
- mock_request.expects(:call).returns(response_body)
55
+ mock_request.expects(:call).returns(public_response_body)
45
56
  end
46
57
 
47
58
  it 'assembles a URI for the request' do
48
- subject.list_virtual_machine_images
59
+ subject.list_public_virtual_machine_images
49
60
  end
50
61
 
51
62
  it 'sets the properties of the virtual machine images' do
52
- virtual_machine_image = subject.list_virtual_machine_images.first
63
+ virtual_machine_image = subject.list_public_virtual_machine_images.first
53
64
  virtual_machine_image.name.must_equal 'RightImage-CentOS-6.2-x64-v5.8.8.1'
54
65
  end
55
66
 
56
67
  it 'returns a list of virtual machine images from server' do
68
+ results = subject.list_public_virtual_machine_images
69
+ results.must_be_kind_of Array
70
+ results.length.must_equal 12
71
+ image_klass = Azure::VirtualMachineImageManagement::VirtualMachineImage
72
+ results.first.must_be_kind_of image_klass
73
+ end
74
+ end
75
+
76
+ describe '#list_private_virtual_machine_images' do
77
+
78
+ before do
79
+ ManagementHttpRequest.stubs(:new).with(
80
+ method,
81
+ private_request_path,
82
+ nil
83
+ ).returns(mock_request)
84
+ mock_request.expects(:call).returns(private_response_body)
85
+ end
86
+
87
+ it 'assembles a URI for the request' do
88
+ subject.list_private_virtual_machine_images
89
+ end
90
+
91
+ it 'sets the properties of the virtual machine images' do
92
+ virtual_machine_image = subject.list_private_virtual_machine_images.first
93
+ virtual_machine_image.name.must_equal 'name-of-image'
94
+ end
95
+
96
+ it 'returns a list of virtual machine images from server' do
97
+ results = subject.list_private_virtual_machine_images
98
+ results.must_be_kind_of Array
99
+ results.length.must_equal 2
100
+ image_klass = Azure::VirtualMachineImageManagement::VirtualMachineImage
101
+ results.first.must_be_kind_of image_klass
102
+ end
103
+
104
+ end
105
+
106
+ describe '#list_virtual_machine_images' do
107
+
108
+ before do
109
+ ManagementHttpRequest.stubs(:new).with(
110
+ method,
111
+ public_request_path,
112
+ nil
113
+ ).returns(mock_request)
114
+
115
+
116
+ ManagementHttpRequest.stubs(:new).with(
117
+ method,
118
+ private_request_path,
119
+ nil
120
+ ).returns(mock_request2)
121
+
122
+ end
123
+
124
+ it 'returns a list of virtual machine images from server when no type is specified' do
125
+ mock_request.expects(:call).returns(public_response_body)
126
+ mock_request2.expects(:call).returns(private_response_body)
127
+
57
128
  results = subject.list_virtual_machine_images
58
129
  results.must_be_kind_of Array
130
+ results.length.must_equal 14
131
+ image_klass = Azure::VirtualMachineImageManagement::VirtualMachineImage
132
+ results.first.must_be_kind_of image_klass
133
+ end
134
+
135
+ it 'returns a list of virtual machine images from server when :all is specified' do
136
+ mock_request.expects(:call).returns(public_response_body)
137
+ mock_request2.expects(:call).returns(private_response_body)
138
+
139
+ results = subject.list_virtual_machine_images :all
140
+ results.must_be_kind_of Array
141
+ results.length.must_equal 14
142
+ image_klass = Azure::VirtualMachineImageManagement::VirtualMachineImage
143
+ results.first.must_be_kind_of image_klass
144
+ end
145
+
146
+ it 'returns a list of virtual machine images from server when :public is specified' do
147
+ mock_request.expects(:call).returns(public_response_body)
148
+ mock_request2.expects(:call).never
149
+
150
+ results = subject.list_virtual_machine_images :public
151
+ results.must_be_kind_of Array
59
152
  results.length.must_equal 12
60
153
  image_klass = Azure::VirtualMachineImageManagement::VirtualMachineImage
61
154
  results.first.must_be_kind_of image_klass
62
155
  end
156
+
157
+ it 'returns a list of virtual machine images from server when :private is specified' do
158
+ mock_request.expects(:call).never
159
+ mock_request2.expects(:call).returns(private_response_body)
160
+
161
+ results = subject.list_virtual_machine_images :private
162
+ results.must_be_kind_of Array
163
+ results.length.must_equal 2
164
+ image_klass = Azure::VirtualMachineImageManagement::VirtualMachineImage
165
+ results.first.must_be_kind_of image_klass
166
+ end
167
+
63
168
  end
64
169
 
65
170
  end
@@ -50,6 +50,7 @@ describe Azure::VirtualMachineManagementService do
50
50
  end
51
51
  let(:location_response_body) { Nokogiri::XML location_response.body }
52
52
  let(:mock_virtual_machine_request) { mock }
53
+
53
54
  let(:windows_images_xml) { Fixtures['list_images'] }
54
55
  let(:images_request_path) { '/services/images' }
55
56
  let(:mock_request) { mock }
@@ -59,6 +60,15 @@ describe Azure::VirtualMachineManagementService do
59
60
  Nokogiri::XML response.body
60
61
  end
61
62
 
63
+ let(:vm_images_xml) { Fixtures['list_vmimages'] }
64
+ let(:vmimages_request_path) { '/services/vmimages' }
65
+ let(:vmmock_request) { mock }
66
+ let(:vm_response_body) do
67
+ response = mock
68
+ response.stubs(:body).returns(vm_images_xml)
69
+ Nokogiri::XML response.body
70
+ end
71
+
62
72
  before do
63
73
  Loggerx.stubs(:info).returns(nil)
64
74
  Loggerx.expects(:puts).returns(nil).at_least(0)
@@ -68,6 +78,13 @@ describe Azure::VirtualMachineManagementService do
68
78
  nil
69
79
  ).returns(mock_request)
70
80
  mock_request.expects(:call).returns(os_response_body).at_least(0)
81
+
82
+ ManagementHttpRequest.stubs(:new).with(
83
+ :get,
84
+ vmimages_request_path,
85
+ nil
86
+ ).returns(vmmock_request)
87
+ vmmock_request.expects(:call).returns(vm_response_body).at_least(0)
71
88
  end
72
89
 
73
90
  describe '#list_virtual_machines' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azurex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Microsoft Corporation
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-25 00:00:00.000000000 Z
12
+ date: 2014-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -252,6 +252,8 @@ files:
252
252
  - lib/azure/virtual_network_management/serialization.rb
253
253
  - lib/azure/virtual_network_management/virtual_network.rb
254
254
  - lib/azure/virtual_network_management/virtual_network_management_service.rb
255
+ - lib/core_ext/ip_addr.rb
256
+ - lib/core_ext/string.rb
255
257
  - test/fixtures/32px-fulls-black.jpg
256
258
  - test/fixtures/affinity_group.xml
257
259
  - test/fixtures/all_containers.xml
@@ -295,6 +297,7 @@ files:
295
297
  - test/fixtures/list_storage_account_single.xml
296
298
  - test/fixtures/list_storage_accounts.xml
297
299
  - test/fixtures/list_virtual_networks.xml
300
+ - test/fixtures/list_vmimages.xml
298
301
  - test/fixtures/logging.xml
299
302
  - test/fixtures/management_certificate.pem
300
303
  - test/fixtures/messages.xml
@@ -427,6 +430,7 @@ files:
427
430
  - test/unit/core/http/http_request_test.rb
428
431
  - test/unit/core/http/http_response_test.rb
429
432
  - test/unit/core/http/retry_policy_test.rb
433
+ - test/unit/core_ext/string_test.rb
430
434
  - test/unit/database/serialization_test.rb
431
435
  - test/unit/database/sql_database_server_service_test.rb
432
436
  - test/unit/service/serialization_test.rb