azure 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.txt +7 -0
- data/README.md +52 -35
- data/lib/azure/base_management/management_http_request.rb +1 -1
- data/lib/azure/cloud_service_management/cloud_service.rb +1 -1
- data/lib/azure/cloud_service_management/cloud_service_management_service.rb +8 -10
- data/lib/azure/cloud_service_management/serialization.rb +9 -8
- data/lib/azure/storage_management/storage_management_service.rb +2 -2
- data/lib/azure/version.rb +1 -1
- data/lib/azure/virtual_machine_image_management/serialization.rb +4 -6
- data/lib/azure/virtual_machine_image_management/virtual_machine_disk.rb +0 -2
- data/lib/azure/virtual_machine_image_management/virtual_machine_image.rb +0 -2
- data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +4 -9
- data/lib/azure/virtual_machine_management/serialization.rb +19 -4
- data/lib/azure/virtual_machine_management/virtual_machine.rb +1 -0
- data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +118 -68
- data/test/integration/cloud_service/Cloud_Create_test.rb +44 -0
- data/test/integration/cloud_service/Cloud_Delete_test.rb +44 -0
- data/test/integration/vm/VM_Create_test.rb +56 -10
- data/test/integration/vm/VM_Operations_test.rb +3 -4
- data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +30 -30
- data/test/unit/cloud_service_management/serialization_test.rb +20 -20
- data/test/unit/virtual_machine_image_management/serialization_test.rb +6 -6
- data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +20 -20
- data/test/unit/virtual_machine_management/serialization_test.rb +26 -14
- data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +80 -75
- metadata +4 -2
@@ -120,12 +120,16 @@ describe Azure::VirtualMachineManagement::Serialization do
|
|
120
120
|
storage_account_name: 'storageaccountname',
|
121
121
|
cloud_service_name: 'cloud-service-name',
|
122
122
|
tcp_endpoints: '80,3389:3390,85:85',
|
123
|
-
availability_set_name: 'aval-set'
|
123
|
+
availability_set_name: 'aval-set',
|
124
|
+
winrm_https_port: '5988',
|
125
|
+
winrm_transport: ['http','https']
|
124
126
|
}
|
125
127
|
end
|
126
128
|
|
127
129
|
it 'returns an VirtualMachine object with correct tcp endpoints' do
|
128
130
|
params[:certificate] = {fingerprint: 'CFB8C256D2986559C630547F2D0'}
|
131
|
+
options[:os_type] = 'Windows'
|
132
|
+
options[:existing_ports] = ['5985']
|
129
133
|
result = subject.deployment_to_xml params, options
|
130
134
|
doc = Nokogiri::XML(result)
|
131
135
|
endpoints = doc.css('Deployment RoleList ConfigurationSet InputEndpoints InputEndpoint')
|
@@ -154,28 +158,37 @@ describe Azure::VirtualMachineManagement::Serialization do
|
|
154
158
|
public_port: '85',
|
155
159
|
local_port: '85'
|
156
160
|
)
|
161
|
+
tcp_endpoints.must_include(
|
162
|
+
name: 'PowerShell',
|
163
|
+
public_port: '5988',
|
164
|
+
local_port: '5986'
|
165
|
+
)
|
157
166
|
end
|
158
167
|
end
|
159
168
|
|
160
169
|
describe '#add_data_disk_to_xml' do
|
161
170
|
|
162
171
|
let(:options) do
|
163
|
-
{
|
172
|
+
{
|
173
|
+
disk_size: 100,
|
174
|
+
}
|
164
175
|
end
|
165
176
|
let(:media_link) { 'https://sta.blob.managment.core.net/vhds/1234.vhd' }
|
166
|
-
|
177
|
+
|
167
178
|
before do
|
168
179
|
Loggerx.expects(:puts).returns(nil).at_least(0)
|
180
|
+
@vm = Azure::VirtualMachineManagement::VirtualMachine.new
|
181
|
+
@vm.data_disks = []
|
182
|
+
@vm.media_link = media_link
|
169
183
|
end
|
170
184
|
|
171
|
-
it 'returns an xml for newly created data disk' do
|
172
|
-
result = subject.add_data_disk_to_xml(
|
185
|
+
it 'returns an xml for newly created data disk' do
|
186
|
+
result = subject.add_data_disk_to_xml(@vm, options)
|
173
187
|
doc = Nokogiri::XML(result)
|
174
188
|
disk_size = doc.css('DataVirtualHardDisk LogicalDiskSizeInGB').text
|
175
189
|
media_link = doc.css('DataVirtualHardDisk MediaLink').text
|
176
190
|
disk_name = doc.css('DataVirtualHardDisk DiskName').text
|
177
191
|
result.must_be_kind_of String
|
178
|
-
doc.css('DataVirtualHardDisk Lun').text.must_equal lun.to_s
|
179
192
|
disk_size.must_equal options[:disk_size].to_s
|
180
193
|
media_link.wont_be_empty
|
181
194
|
disk_name.must_be_empty
|
@@ -184,12 +197,11 @@ describe Azure::VirtualMachineManagement::Serialization do
|
|
184
197
|
it 'returns an xml for existing data disk' do
|
185
198
|
options[:import] = true
|
186
199
|
options[:disk_name] = 'disk_name'
|
187
|
-
result = subject.add_data_disk_to_xml(
|
200
|
+
result = subject.add_data_disk_to_xml(@vm, options)
|
188
201
|
doc = Nokogiri::XML(result)
|
189
202
|
media_link = doc.css('DataVirtualHardDisk MediaLink').text
|
190
203
|
disk_name = doc.css('DataVirtualHardDisk DiskName').text
|
191
204
|
result.must_be_kind_of String
|
192
|
-
doc.css('DataVirtualHardDisk Lun').text.must_equal lun.to_s
|
193
205
|
media_link.must_be_empty
|
194
206
|
disk_name.wont_be_empty
|
195
207
|
end
|
@@ -197,36 +209,36 @@ describe Azure::VirtualMachineManagement::Serialization do
|
|
197
209
|
it 'raise error when disk name is empty' do
|
198
210
|
options[:import] = true
|
199
211
|
exception = assert_raises(RuntimeError) do
|
200
|
-
subject.add_data_disk_to_xml(
|
212
|
+
subject.add_data_disk_to_xml(@vm, options)
|
201
213
|
end
|
202
214
|
assert_match(/The data disk name is not valid/i, exception.message)
|
203
215
|
end
|
204
216
|
end
|
205
217
|
|
206
|
-
describe '#
|
218
|
+
describe '#assign_random_port' do
|
207
219
|
let(:preferred_port) { '22' }
|
208
220
|
before do
|
209
221
|
subject.class.send(:public, *subject.class.private_instance_methods)
|
210
222
|
Loggerx.expects(:puts).returns(nil).at_least(0)
|
211
223
|
end
|
212
224
|
|
213
|
-
it 'returns
|
225
|
+
it 'returns random port number when preferred port is in use' do
|
214
226
|
result = subject.assign_random_port(preferred_port, [preferred_port])
|
215
227
|
assert_operator result.to_i, :>=, 10000
|
216
228
|
assert_operator result.to_i, :<=, 65535
|
217
229
|
end
|
218
230
|
|
219
|
-
it 'returns
|
231
|
+
it 'returns preferred port number when used ports is nil' do
|
220
232
|
result = subject.assign_random_port(preferred_port, nil)
|
221
233
|
result.must_equal preferred_port
|
222
234
|
end
|
223
235
|
|
224
|
-
it 'returns
|
236
|
+
it 'returns preferred port number when used ports is empty' do
|
225
237
|
result = subject.assign_random_port(preferred_port, [])
|
226
238
|
result.must_equal preferred_port
|
227
239
|
end
|
228
240
|
|
229
|
-
it 'returns
|
241
|
+
it 'returns random port number when preferred port is in use' do
|
230
242
|
result = subject.assign_random_port(preferred_port, ['1', preferred_port])
|
231
243
|
assert_operator result.to_i, :>=, 10000
|
232
244
|
assert_operator result.to_i, :<=, 65535
|
@@ -21,11 +21,7 @@ describe Azure::VirtualMachineManagementService do
|
|
21
21
|
Azure::VirtualMachineManagementService.new
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
Loggerx.stubs(:info).returns(nil)
|
26
|
-
end
|
27
|
-
|
28
|
-
let(:params)do
|
24
|
+
let(:params) do
|
29
25
|
{
|
30
26
|
vm_name: 'instance1',
|
31
27
|
vm_user: 'root',
|
@@ -35,7 +31,7 @@ describe Azure::VirtualMachineManagementService do
|
|
35
31
|
}
|
36
32
|
end
|
37
33
|
|
38
|
-
let(:windows_params)do
|
34
|
+
let(:windows_params) do
|
39
35
|
{
|
40
36
|
vm_name: 'instance1',
|
41
37
|
vm_user: 'administrator',
|
@@ -53,56 +49,58 @@ describe Azure::VirtualMachineManagementService do
|
|
53
49
|
response
|
54
50
|
end
|
55
51
|
let(:location_response_body) { Nokogiri::XML location_response.body }
|
52
|
+
let(:mock_virtual_machine_request) { mock }
|
53
|
+
let(:windows_images_xml) { Fixtures['list_images'] }
|
54
|
+
let(:images_request_path) { '/services/images' }
|
55
|
+
let(:mock_request) { mock }
|
56
|
+
let(:os_response_body) do
|
57
|
+
response = mock
|
58
|
+
response.stubs(:body).returns(windows_images_xml)
|
59
|
+
Nokogiri::XML response.body
|
60
|
+
end
|
61
|
+
|
62
|
+
before do
|
63
|
+
Loggerx.stubs(:info).returns(nil)
|
64
|
+
Loggerx.expects(:puts).returns(nil).at_least(0)
|
65
|
+
ManagementHttpRequest.stubs(:new).with(
|
66
|
+
:get,
|
67
|
+
images_request_path,
|
68
|
+
nil
|
69
|
+
).returns(mock_request)
|
70
|
+
mock_request.expects(:call).returns(os_response_body).at_least(0)
|
71
|
+
end
|
56
72
|
|
57
73
|
describe '#list_virtual_machines' do
|
58
74
|
let(:request_path) { '/services/hostedservices' }
|
59
75
|
let(:cloud_services_xml) { Fixtures['list_cloud_services'] }
|
60
76
|
let(:virtual_machine_xml) { Fixtures['virtual_machine'] }
|
61
77
|
let(:deployment_error_xml) { Fixtures['deployment_error'] }
|
62
|
-
let(:virtual_networks_xml) { Fixtures['list_virtual_networks'] }
|
63
|
-
|
64
78
|
let(:method) { :get }
|
65
|
-
|
66
79
|
let(:mock_cloud_service_request) { mock }
|
67
|
-
let(:mock_virtual_machine_request) { mock }
|
68
|
-
let(:mock_virtual_network_request) { mock }
|
69
|
-
|
70
80
|
let(:cloud_service_response) do
|
71
81
|
cloud_service_response = mock
|
72
82
|
cloud_service_response.stubs(:body).returns(cloud_services_xml)
|
73
83
|
cloud_service_response
|
74
84
|
end
|
75
|
-
|
76
85
|
let(:virtual_machine_response) do
|
77
86
|
virtual_machine_response = mock
|
78
87
|
virtual_machine_response.stubs(:body).returns(virtual_machine_xml)
|
79
88
|
virtual_machine_response
|
80
89
|
end
|
81
|
-
|
82
90
|
let(:deployment_error_response) do
|
83
91
|
http_error_response = mock
|
84
92
|
http_error_response.stubs(:body).returns(deployment_error_xml)
|
85
93
|
http_error_response
|
86
94
|
end
|
87
|
-
|
88
|
-
let(:virtual_networks_response) do
|
89
|
-
virtual_networks_response = mock
|
90
|
-
virtual_networks_response.stubs(:body).returns(virtual_networks_xml)
|
91
|
-
virtual_networks_response
|
92
|
-
end
|
93
|
-
|
94
95
|
let(:cloud_service_response_body) { Nokogiri::XML cloud_service_response.body }
|
95
96
|
let(:virtual_machine_response_body) { Nokogiri::XML virtual_machine_response.body }
|
96
|
-
let(:virtual_networks_response_body) { Nokogiri::XML virtual_networks_response.body }
|
97
97
|
|
98
98
|
before do
|
99
99
|
ManagementHttpRequest.stubs(:new).with(method, request_path, nil).returns(mock_cloud_service_request)
|
100
100
|
mock_cloud_service_request.expects(:call).returns(cloud_service_response_body)
|
101
|
-
ManagementHttpRequest.stubs(:new).with(method,
|
101
|
+
ManagementHttpRequest.stubs(:new).with(method, anything).returns(mock_virtual_machine_request)
|
102
102
|
mock_virtual_machine_request.stubs(:warn=).returns(true).twice
|
103
|
-
ManagementHttpRequest.stubs(:new).with(method, '/services/hostedservices/cloud-service-2/deploymentslots/production').returns(mock_virtual_machine_request)
|
104
103
|
mock_virtual_machine_request.expects(:call).twice.returns(virtual_machine_response_body).returns(Nokogiri::XML deployment_error_response.body)
|
105
|
-
ManagementHttpRequest.stubs(:new).with(method, '/services/networking/virtualnetwork', nil).returns(mock_virtual_network_request)
|
106
104
|
end
|
107
105
|
|
108
106
|
it 'assembles a URI for the request' do
|
@@ -157,9 +155,9 @@ describe Azure::VirtualMachineManagementService do
|
|
157
155
|
describe '#get_virtual_machine' do
|
158
156
|
|
159
157
|
before do
|
160
|
-
virtual_machine = VirtualMachine.new do |
|
161
|
-
|
162
|
-
|
158
|
+
virtual_machine = VirtualMachine.new do |vm|
|
159
|
+
vm.vm_name = 'instance-name'
|
160
|
+
vm.cloud_service_name = 'cloud-service-1'
|
163
161
|
end
|
164
162
|
Azure::VirtualMachineManagementService.any_instance.stubs(
|
165
163
|
:list_virtual_machines
|
@@ -172,38 +170,22 @@ describe Azure::VirtualMachineManagementService do
|
|
172
170
|
end
|
173
171
|
|
174
172
|
it 'return nil if virtual machine or cloud server does not exist ' do
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
173
|
+
vm = subject.get_virtual_machine 'name', 'cloud-service-1'
|
174
|
+
vm.must_equal nil
|
175
|
+
vm = subject.get_virtual_machine 'name2', 'cloud_service_name'
|
176
|
+
vm.must_equal nil
|
179
177
|
end
|
180
178
|
|
181
179
|
it 'return virtual machine instance if virtual machine name and cloud server name are valid ' do
|
182
|
-
|
183
|
-
|
180
|
+
vm = subject.get_virtual_machine 'instance-name', 'cloud-service-1'
|
181
|
+
vm.must_be_kind_of VirtualMachine
|
184
182
|
end
|
185
183
|
end
|
186
184
|
|
187
185
|
describe '#create_virtual_machine' do
|
188
|
-
let(:images_request_path) { '/services/images' }
|
189
|
-
let(:images_xml) { Fixtures['list_images'] }
|
190
|
-
let(:virtual_machine_xml) { Fixtures['virtual_machine'] }
|
191
186
|
let(:method) { :get }
|
192
|
-
let(:mock_request) { mock }
|
193
|
-
|
194
|
-
let(:os_response_body) do
|
195
|
-
response = mock
|
196
|
-
response.stubs(:body).returns(images_xml)
|
197
|
-
Nokogiri::XML response.body
|
198
|
-
end
|
199
187
|
|
200
188
|
before do
|
201
|
-
ManagementHttpRequest.stubs(:new).with(
|
202
|
-
method,
|
203
|
-
images_request_path,
|
204
|
-
nil
|
205
|
-
).returns(mock_request)
|
206
|
-
mock_request.expects(:call).returns(os_response_body)
|
207
189
|
mock_request = mock
|
208
190
|
ManagementHttpRequest.stubs(:new).with(
|
209
191
|
method,
|
@@ -257,24 +239,10 @@ describe Azure::VirtualMachineManagementService do
|
|
257
239
|
end
|
258
240
|
|
259
241
|
describe '#create_virtual_machine with invalid parameters for windows machine' do
|
260
|
-
let(:images_request_path) { '/services/images' }
|
261
|
-
let(:windows_images_xml) { Fixtures['list_images'] }
|
262
242
|
let(:virtual_machine_xml) { Fixtures['virtual_machine'] }
|
263
243
|
let(:method) { :get }
|
264
|
-
let(:mock_request) { mock }
|
265
|
-
let(:os_response_body) do
|
266
|
-
response = mock
|
267
|
-
response.stubs(:body).returns(windows_images_xml)
|
268
|
-
Nokogiri::XML response.body
|
269
|
-
end
|
270
244
|
|
271
245
|
before do
|
272
|
-
ManagementHttpRequest.stubs(:new).with(
|
273
|
-
method,
|
274
|
-
images_request_path,
|
275
|
-
nil
|
276
|
-
).returns(mock_request)
|
277
|
-
mock_request.expects(:call).returns(os_response_body)
|
278
246
|
mock_request = mock
|
279
247
|
ManagementHttpRequest.stubs(:new).with(
|
280
248
|
method,
|
@@ -285,7 +253,6 @@ describe Azure::VirtualMachineManagementService do
|
|
285
253
|
Azure::CloudServiceManagementService.any_instance.stubs(:create_cloud_service)
|
286
254
|
Azure::CloudServiceManagementService.any_instance.stubs(:upload_certificate)
|
287
255
|
Azure::StorageManagementService.any_instance.stubs(:create_storage_account)
|
288
|
-
Loggerx.expects(:puts).returns(nil).at_least(0)
|
289
256
|
mock_request = mock
|
290
257
|
ManagementHttpRequest.expects(:new).with(
|
291
258
|
:post,
|
@@ -403,19 +370,9 @@ describe Azure::VirtualMachineManagementService do
|
|
403
370
|
end
|
404
371
|
|
405
372
|
describe '#get_os_type' do
|
406
|
-
let(:images_xml) { Fixtures['list_images'] }
|
407
|
-
let(:mock_request) { mock }
|
408
|
-
let(:response) do
|
409
|
-
response = mock
|
410
|
-
response.stubs(:body).returns(images_xml)
|
411
|
-
response
|
412
|
-
end
|
413
|
-
let(:response_body) { Nokogiri::XML response.body }
|
414
373
|
|
415
374
|
before do
|
416
|
-
ManagementHttpRequest.any_instance.expects(:call).returns response_body
|
417
375
|
subject.class.send(:public, *subject.class.private_instance_methods)
|
418
|
-
Loggerx.expects(:puts).returns(nil).at_least(0)
|
419
376
|
end
|
420
377
|
|
421
378
|
it 'returns os type of given virtual machine image' do
|
@@ -432,4 +389,52 @@ describe Azure::VirtualMachineManagementService do
|
|
432
389
|
end
|
433
390
|
end
|
434
391
|
|
392
|
+
describe '#add_role' do
|
393
|
+
|
394
|
+
before do
|
395
|
+
windows_params[:cloud_service_name] = 'cloud-service-1'
|
396
|
+
end
|
397
|
+
|
398
|
+
it 'should throws error when cloud service name is empty' do
|
399
|
+
windows_params.delete(:cloud_service_name)
|
400
|
+
exception = assert_raises(RuntimeError) do
|
401
|
+
subject.add_role(params)
|
402
|
+
end
|
403
|
+
error_msg = 'You did not provide a valid \'cloud_service_name\' value'
|
404
|
+
assert_match(/#{error_msg}/i, exception.message)
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'throws error when vm_user is not given' do
|
408
|
+
windows_params.delete(:vm_user)
|
409
|
+
exception = assert_raises(RuntimeError) do
|
410
|
+
subject.add_role(windows_params)
|
411
|
+
end
|
412
|
+
error_msg = 'You did not provide a valid \'vm_user\' value'
|
413
|
+
assert_match(/#{error_msg}/i, exception.message)
|
414
|
+
end
|
415
|
+
|
416
|
+
it 'throws error when certificate path is not invalid.' do
|
417
|
+
options = {
|
418
|
+
winrm_transport: %w(https http),
|
419
|
+
private_key_file: 'f:/invalid_path/private_key' ,
|
420
|
+
certificate_file: 'f:/invalid_path/certificate.pem'
|
421
|
+
}
|
422
|
+
exception = assert_raises(RuntimeError) do
|
423
|
+
subject.add_role(windows_params, options)
|
424
|
+
end
|
425
|
+
error_msg = 'No such file or directory -'
|
426
|
+
assert_match(/#{error_msg}/i, exception.message)
|
427
|
+
end
|
428
|
+
|
429
|
+
it 'throws error when wrong role size is given' do
|
430
|
+
options = { vm_size: 'wrong size' }
|
431
|
+
exception = assert_raises(RuntimeError) do
|
432
|
+
subject.add_role(windows_params, options)
|
433
|
+
end
|
434
|
+
error_msg = "wrong size' specified for parameter 'vm_size' is invalid."
|
435
|
+
assert_match(/#{error_msg}*/, exception.message)
|
436
|
+
end
|
437
|
+
|
438
|
+
end
|
439
|
+
|
435
440
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: azure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
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-
|
12
|
+
date: 2014-05-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -333,6 +333,8 @@ files:
|
|
333
333
|
- test/integration/blob/lease/release_lease_test.rb
|
334
334
|
- test/integration/blob/lease/renew_lease_test.rb
|
335
335
|
- test/integration/blob/list_blobs_test.rb
|
336
|
+
- test/integration/cloud_service/Cloud_Create_test.rb
|
337
|
+
- test/integration/cloud_service/Cloud_Delete_test.rb
|
336
338
|
- test/integration/database/create_sql_server_firewall_test.rb
|
337
339
|
- test/integration/database/create_sql_server_test.rb
|
338
340
|
- test/integration/database/delete_sql_server_firewall_test.rb
|