azure 0.6.4 → 0.7.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env_sample +11 -0
- data/.gitignore +4 -1
- data/.travis.yml +3 -1
- data/ChangeLog.txt +17 -1
- data/LICENSE.txt +202 -0
- data/README.md +58 -20
- data/Rakefile +27 -35
- data/azure.gemspec +17 -13
- data/bin/pfxer +35 -0
- data/lib/azure.rb +8 -0
- data/lib/azure/base_management/base_management_service.rb +24 -26
- data/lib/azure/base_management/management_http_request.rb +17 -14
- data/lib/azure/base_management/serialization.rb +1 -0
- data/lib/azure/blob/auth/shared_access_signature.rb +141 -0
- data/lib/azure/blob/blob_service.rb +221 -217
- data/lib/azure/cloud_service_management/cloud_service_management_service.rb +27 -30
- data/lib/azure/cloud_service_management/serialization.rb +1 -0
- data/lib/azure/core.rb +17 -15
- data/lib/azure/core/configuration.rb +7 -0
- data/lib/azure/core/http/http_error.rb +1 -1
- data/lib/azure/core/http/http_request.rb +4 -1
- data/lib/azure/core/utility.rb +16 -1
- data/lib/azure/queue/queue_service.rb +13 -13
- data/lib/azure/service/cors.rb +11 -0
- data/lib/azure/service/cors_rule.rb +15 -0
- data/lib/azure/service/serialization.rb +69 -10
- data/lib/azure/service/storage_service.rb +10 -6
- data/lib/azure/service/storage_service_properties.rb +8 -3
- data/lib/azure/service_bus/brokered_message.rb +1 -1
- data/lib/azure/service_bus/relay.rb +88 -0
- data/lib/azure/service_bus/serialization.rb +1 -0
- data/lib/azure/service_bus/service_bus_service.rb +70 -4
- data/lib/azure/sql_database_management/serialization.rb +1 -0
- data/lib/azure/sql_database_management/sql_database_management_service.rb +22 -22
- data/lib/azure/storage_management/serialization.rb +34 -14
- data/lib/azure/storage_management/storage_account.rb +9 -1
- data/lib/azure/storage_management/storage_management_service.rb +74 -32
- data/lib/azure/table/batch.rb +6 -6
- data/lib/azure/table/table_service.rb +13 -13
- data/lib/azure/version.rb +3 -3
- data/lib/azure/virtual_machine_image_management/serialization.rb +19 -0
- data/lib/azure/virtual_machine_image_management/virtual_machine_image.rb +1 -1
- data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +30 -7
- data/lib/azure/virtual_machine_management/serialization.rb +32 -12
- data/lib/azure/virtual_machine_management/virtual_machine.rb +1 -0
- data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +92 -81
- data/lib/azure/virtual_network_management/serialization.rb +12 -5
- data/lib/azure/virtual_network_management/virtual_network.rb +1 -0
- data/lib/azure/virtual_network_management/virtual_network_management_service.rb +11 -11
- data/test/fixtures/get_storage_account_properties.xml +6 -4
- data/test/fixtures/{list_images.xml → list_os_images.xml} +1 -1
- data/test/fixtures/list_storage_accounts.xml +2 -0
- data/test/fixtures/list_vm_images.xml +21 -0
- data/test/fixtures/metrics.xml +2 -2
- data/test/fixtures/sb_default_create_relay_response.xml +15 -0
- data/test/fixtures/storage_service_keys.xml +8 -0
- data/test/fixtures/storage_service_properties.xml +35 -3
- data/test/fixtures/updated_storage_accounts.xml +2 -0
- data/test/fixtures/virtual_machine.xml +3 -1
- data/test/integration/affinity_group/Affinity_test.rb +1 -1
- data/test/integration/affinity_group/Create_Affinity_test.rb +8 -7
- data/test/integration/affinity_group/Delete_Affinity_test.rb +3 -3
- data/test/integration/affinity_group/List_Affinity_test.rb +1 -1
- data/test/integration/affinity_group/Update_Affinity_test.rb +9 -8
- data/test/integration/cloud_service/Cloud_Create_test.rb +3 -2
- data/test/integration/cloud_service/Cloud_Delete_test.rb +5 -4
- data/test/integration/database/create_sql_server_firewall_test.rb +1 -1
- data/test/integration/database/create_sql_server_test.rb +1 -1
- data/test/integration/database/delete_sql_server_firewall_test.rb +1 -1
- data/test/integration/database/delete_sql_server_test.rb +1 -1
- data/test/integration/database/list_sql_server_firewall_test.rb +1 -1
- data/test/integration/database/list_sql_servers_test.rb +1 -1
- data/test/integration/database/reset_password_sql_server_test.rb +1 -1
- data/test/integration/service_bus/queues_test.rb +22 -22
- data/test/integration/service_bus/relay_test.rb +132 -0
- data/test/integration/storage_management/storage_management_test.rb +58 -33
- data/test/integration/test_helper.rb +11 -15
- data/test/integration/vm/VM_Create_test.rb +17 -18
- data/test/integration/vm/VM_Delete_test.rb +2 -4
- data/test/integration/vm/VM_Operations_test.rb +1 -2
- data/test/integration/vnet/Virtual_Network_Create_test.rb +9 -15
- data/test/integration/vnet/Virtual_Network_list_test.rb +4 -9
- data/test/support/name_generator.rb +8 -0
- data/test/support/virtual_network_helper.rb +2 -2
- data/test/test_helper.rb +13 -24
- data/test/unit/affinity_group/affinity_group_test.rb +10 -13
- data/test/unit/affinity_group/serialization_test.rb +7 -8
- data/test/unit/base_management/location_test.rb +1 -2
- data/test/unit/blob/auth/shared_access_signature_test.rb +71 -0
- data/test/unit/blob/blob_service_test.rb +393 -371
- data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +16 -16
- data/test/unit/core/auth/shared_key_lite_test.rb +4 -4
- data/test/unit/core/auth/shared_key_test.rb +2 -2
- data/test/unit/core/http/http_error_test.rb +10 -5
- data/test/unit/core/http/http_request_test.rb +72 -25
- data/test/unit/database/serialization_test.rb +7 -7
- data/test/unit/database/sql_database_server_service_test.rb +43 -47
- data/test/unit/service/serialization_test.rb +40 -9
- data/test/unit/service/storage_service_test.rb +13 -11
- data/test/unit/storage_management/serialization_test.rb +26 -14
- data/test/unit/storage_management/storage_management_service_test.rb +48 -62
- data/test/unit/virtual_machine_image_management/serialization_test.rb +20 -5
- data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +78 -29
- data/test/unit/virtual_machine_management/serialization_test.rb +112 -43
- data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +123 -100
- data/test/unit/vnet/serialization_test.rb +7 -7
- data/test/unit/vnet/virtual_network_management_service_test.rb +1 -1
- metadata +70 -16
- data/test/fixtures/certificate.pem +0 -21
@@ -17,19 +17,34 @@ require 'test_helper'
|
|
17
17
|
describe Azure::VirtualMachineImageManagement::Serialization do
|
18
18
|
subject { Azure::VirtualMachineImageManagement::Serialization }
|
19
19
|
|
20
|
-
let(:virtual_machine_images_from_xml) { Fixtures['list_images'] }
|
21
|
-
|
22
20
|
describe '#virtual_machine_images_from_xml' do
|
21
|
+
let(:os_images_xml) { Fixtures['list_os_images'] }
|
23
22
|
|
24
23
|
it 'accepts an XML string' do
|
25
|
-
subject.virtual_machine_images_from_xml Nokogiri::XML(
|
24
|
+
subject.virtual_machine_images_from_xml Nokogiri::XML(os_images_xml)
|
26
25
|
end
|
27
26
|
|
28
27
|
it 'returns an Array of VirtualMachineImageService instances' do
|
29
|
-
results = subject.virtual_machine_images_from_xml Nokogiri::XML(
|
28
|
+
results = subject.virtual_machine_images_from_xml Nokogiri::XML(os_images_xml)
|
30
29
|
results.must_be_kind_of Array
|
31
|
-
results[0].must_be_kind_of
|
30
|
+
results[0].must_be_kind_of VirtualMachineImage
|
32
31
|
results.count.must_equal 12
|
33
32
|
end
|
34
33
|
end
|
34
|
+
|
35
|
+
describe '#virtual_machine_vm_images_from_xml' do
|
36
|
+
let(:vm_images_xml) { Fixtures['list_vm_images'] }
|
37
|
+
|
38
|
+
it 'accepts an XML string' do
|
39
|
+
subject.virtual_machine_vm_images_from_xml Nokogiri::XML(vm_images_xml)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns an Array of VirtualMachineImageService instances' do
|
43
|
+
results = subject.virtual_machine_vm_images_from_xml Nokogiri::XML(vm_images_xml)
|
44
|
+
results.must_be_kind_of Array
|
45
|
+
results[0].must_be_kind_of VirtualMachineImage
|
46
|
+
results.count.must_equal 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
35
50
|
end
|
data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb
CHANGED
@@ -18,48 +18,97 @@ describe Azure::VirtualMachineImageManagementService do
|
|
18
18
|
|
19
19
|
subject { Azure::VirtualMachineImageManagementService.new }
|
20
20
|
|
21
|
-
let(:
|
22
|
-
let(:
|
23
|
-
let(:
|
24
|
-
let(:
|
25
|
-
let(:
|
21
|
+
let(:os_image_request_path) { '/services/images' }
|
22
|
+
let(:vm_image_request_path) { '/services/vmimages' }
|
23
|
+
let(:os_images_xml) { Fixtures['list_os_images'] }
|
24
|
+
let(:vm_images_xml) { Fixtures['list_vm_images'] }
|
25
|
+
let(:verb) { :get }
|
26
|
+
let(:os_images_response) do
|
26
27
|
response = mock
|
27
|
-
response.stubs(:body).returns(
|
28
|
-
response
|
28
|
+
response.stubs(:body).returns(os_images_xml)
|
29
|
+
Nokogiri::XML response.body
|
29
30
|
end
|
30
|
-
let(:
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
let(:vm_images_response) do
|
32
|
+
response = mock
|
33
|
+
response.stubs(:body).returns(vm_images_xml)
|
34
|
+
Nokogiri::XML response.body
|
34
35
|
end
|
35
36
|
|
36
|
-
|
37
|
+
before {
|
38
|
+
Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
|
39
|
+
}
|
37
40
|
|
41
|
+
describe '#list_os_images' do
|
42
|
+
let(:verb) { :get }
|
38
43
|
before do
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
44
|
+
os_images_request = mock
|
45
|
+
Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
|
46
|
+
verb,
|
47
|
+
os_image_request_path,
|
48
|
+
nil
|
49
|
+
).returns(os_images_request)
|
50
|
+
os_images_request.expects(:call).returns(os_images_response)
|
45
51
|
end
|
46
52
|
|
47
|
-
it '
|
48
|
-
subject.
|
53
|
+
it 'returns a list of os images from server' do
|
54
|
+
os_images = subject.list_os_images
|
55
|
+
os_images.must_be_kind_of Array
|
56
|
+
image_klass = VirtualMachineImage
|
57
|
+
os_images.length.must_equal 12
|
58
|
+
image = os_images.first
|
59
|
+
image.must_be_kind_of image_klass
|
60
|
+
image.image_type.must_equal 'OS'
|
49
61
|
end
|
62
|
+
end
|
50
63
|
|
51
|
-
|
52
|
-
|
53
|
-
|
64
|
+
describe '#list_vm_images' do
|
65
|
+
let(:verb) { :get }
|
66
|
+
before do
|
67
|
+
vm_images_request = mock
|
68
|
+
Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
|
69
|
+
verb,
|
70
|
+
vm_image_request_path,
|
71
|
+
nil
|
72
|
+
).returns(vm_images_request)
|
73
|
+
vm_images_request.expects(:call).returns(vm_images_response)
|
54
74
|
end
|
55
75
|
|
56
|
-
it 'returns a list of
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
image_klass =
|
61
|
-
|
76
|
+
it 'returns a list of vm images from server' do
|
77
|
+
vm_images = subject.list_vm_images
|
78
|
+
vm_images.must_be_kind_of Array
|
79
|
+
vm_images.length.must_equal 1
|
80
|
+
image_klass = VirtualMachineImage
|
81
|
+
image = vm_images.first
|
82
|
+
image.must_be_kind_of image_klass
|
83
|
+
image.image_type.must_equal 'VM'
|
62
84
|
end
|
63
85
|
end
|
64
86
|
|
87
|
+
describe '#list_images' do
|
88
|
+
let(:verb) { :get }
|
89
|
+
before do
|
90
|
+
vm_images_request = mock
|
91
|
+
Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
|
92
|
+
verb,
|
93
|
+
vm_image_request_path,
|
94
|
+
nil
|
95
|
+
).returns(vm_images_request)
|
96
|
+
vm_images_request.expects(:call).returns(vm_images_response)
|
97
|
+
os_images_request = mock
|
98
|
+
Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
|
99
|
+
verb,
|
100
|
+
os_image_request_path,
|
101
|
+
nil
|
102
|
+
).returns(os_images_request)
|
103
|
+
os_images_request.expects(:call).returns(os_images_response)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'returns a list of virtual machine images' do
|
107
|
+
images = subject.list_virtual_machine_images
|
108
|
+
images.must_be_kind_of Array
|
109
|
+
images.length.must_equal 13
|
110
|
+
images.last.image_type.must_equal 'VM'
|
111
|
+
images.first.image_type.must_equal 'OS'
|
112
|
+
end
|
113
|
+
end
|
65
114
|
end
|
@@ -15,6 +15,8 @@
|
|
15
15
|
require 'test_helper'
|
16
16
|
|
17
17
|
describe Azure::VirtualMachineManagement::Serialization do
|
18
|
+
include Azure::Core::Utility
|
19
|
+
|
18
20
|
subject { Azure::VirtualMachineManagement::Serialization }
|
19
21
|
|
20
22
|
let(:vm_xml) { Nokogiri::XML(Fixtures['virtual_machine']) }
|
@@ -46,25 +48,25 @@ describe Azure::VirtualMachineManagement::Serialization do
|
|
46
48
|
virtual_machine = subject.virtual_machines_from_xml(vm_xml, csn).first
|
47
49
|
virtual_machine.tcp_endpoints.must_be_kind_of Array
|
48
50
|
virtual_machine.tcp_endpoints.must_include(
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
name: 'SSH',
|
52
|
+
vip: '137.116.17.187',
|
53
|
+
public_port: '22',
|
54
|
+
local_port: '22',
|
55
|
+
protocol: 'tcp'
|
54
56
|
)
|
55
57
|
virtual_machine.tcp_endpoints.must_include(
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
name: 'tcp-port-80',
|
59
|
+
vip: '137.117.17.187',
|
60
|
+
public_port: '80',
|
61
|
+
local_port: '80',
|
62
|
+
protocol: 'tcp'
|
61
63
|
)
|
62
64
|
virtual_machine.tcp_endpoints.must_include(
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
name: 'tcp-port-3889',
|
66
|
+
vip: '137.116.17.187',
|
67
|
+
public_port: '3889',
|
68
|
+
local_port: '3889',
|
69
|
+
protocol: 'tcp'
|
68
70
|
)
|
69
71
|
end
|
70
72
|
|
@@ -107,30 +109,40 @@ describe Azure::VirtualMachineManagement::Serialization do
|
|
107
109
|
describe '#deployment_to_xml' do
|
108
110
|
let(:params) do
|
109
111
|
{
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
vm_name: 'virtual-machine-name',
|
113
|
+
vm_user: 'username',
|
114
|
+
image: 'linux_image',
|
115
|
+
password: 'password',
|
116
|
+
location: 'West US',
|
117
|
+
certificate: {fingerprint: 'CFB8C256D2986559C630547F2D0'}
|
115
118
|
}
|
116
119
|
end
|
117
120
|
|
118
121
|
let(:options) do
|
119
122
|
{
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
123
|
+
storage_account_name: 'storageaccountname',
|
124
|
+
cloud_service_name: 'cloud-service-name',
|
125
|
+
tcp_endpoints: '80,3389:3390,85:85',
|
126
|
+
availability_set_name: 'aval-set',
|
127
|
+
winrm_https_port: '5988',
|
128
|
+
winrm_transport: %w(http https),
|
129
|
+
reserved_ip_name: 'AnAwesomeIP'
|
126
130
|
}
|
127
131
|
end
|
128
132
|
|
133
|
+
let(:image) do
|
134
|
+
Azure::VirtualMachineImageManagement::VirtualMachineImage.new do |i|
|
135
|
+
i.name = 'windows-instance'
|
136
|
+
i.os_type = 'Linux'
|
137
|
+
i.image_type = 'OS'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
129
141
|
it 'returns an VirtualMachine object with correct tcp endpoints' do
|
130
142
|
params[:certificate] = {fingerprint: 'CFB8C256D2986559C630547F2D0'}
|
131
143
|
options[:os_type] = 'Windows'
|
132
144
|
options[:existing_ports] = ['5985']
|
133
|
-
result = subject.deployment_to_xml params, options
|
145
|
+
result = subject.deployment_to_xml params, image, options
|
134
146
|
doc = Nokogiri::XML(result)
|
135
147
|
endpoints = doc.css('Deployment RoleList ConfigurationSet InputEndpoints InputEndpoint')
|
136
148
|
tcp_endpoints = []
|
@@ -144,45 +156,65 @@ describe Azure::VirtualMachineManagement::Serialization do
|
|
144
156
|
doc.css('Deployment RoleList AvailabilitySetName').text.must_equal 'aval-set'
|
145
157
|
result.must_be_kind_of String
|
146
158
|
tcp_endpoints.must_include(
|
147
|
-
|
148
|
-
|
149
|
-
|
159
|
+
name: 'TCP-PORT-80',
|
160
|
+
public_port: '80',
|
161
|
+
local_port: '80'
|
150
162
|
)
|
151
163
|
tcp_endpoints.must_include(
|
152
|
-
|
153
|
-
|
154
|
-
|
164
|
+
name: 'TCP-PORT-3390',
|
165
|
+
public_port: '3390',
|
166
|
+
local_port: '3389'
|
155
167
|
)
|
156
168
|
tcp_endpoints.must_include(
|
157
|
-
|
158
|
-
|
159
|
-
|
169
|
+
name: 'TCP-PORT-85',
|
170
|
+
public_port: '85',
|
171
|
+
local_port: '85'
|
160
172
|
)
|
161
173
|
tcp_endpoints.must_include(
|
162
|
-
|
163
|
-
|
164
|
-
|
174
|
+
name: 'PowerShell',
|
175
|
+
public_port: '5988',
|
176
|
+
local_port: '5986'
|
165
177
|
)
|
166
178
|
end
|
179
|
+
|
180
|
+
it 'returns a VirtualMachine object with it the vhds media_link that includes seconds and milliseconds' do
|
181
|
+
now = Time.now
|
182
|
+
Timecop.freeze(now) do
|
183
|
+
result = subject.deployment_to_xml params, image, options
|
184
|
+
doc = Nokogiri::XML(result)
|
185
|
+
media_link_uri = URI.parse(doc.css('Deployment RoleList OSVirtualHardDisk MediaLink').text)
|
186
|
+
disk_time_name = /disk_(.*?)\.vhd/.match(media_link_uri.path).captures.first
|
187
|
+
disk_time_name.must_equal now.strftime('%Y_%m_%d_%H_%M_%S_%L')
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'returns a VirtualMachine object with the correct reserved IP' do
|
192
|
+
now = Time.now
|
193
|
+
Timecop.freeze(now) do
|
194
|
+
result = subject.deployment_to_xml params, image, options
|
195
|
+
doc = Nokogiri::XML(result)
|
196
|
+
doc.css('ReservedIPName').text.must_equal "AnAwesomeIP"
|
197
|
+
end
|
198
|
+
end
|
167
199
|
end
|
168
200
|
|
169
201
|
describe '#add_data_disk_to_xml' do
|
170
202
|
|
171
203
|
let(:options) do
|
172
204
|
{
|
173
|
-
|
205
|
+
disk_size: 100
|
174
206
|
}
|
175
207
|
end
|
176
208
|
let(:media_link) { 'https://sta.blob.managment.core.net/vhds/1234.vhd' }
|
177
209
|
|
178
210
|
before do
|
179
|
-
Loggerx.expects(:puts).returns(nil).at_least(0)
|
211
|
+
Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
|
180
212
|
@vm = Azure::VirtualMachineManagement::VirtualMachine.new
|
181
213
|
@vm.data_disks = []
|
182
214
|
@vm.media_link = media_link
|
183
215
|
end
|
184
216
|
|
185
|
-
it 'returns an xml for newly created data disk' do
|
217
|
+
it 'returns an xml for newly created data disk' do
|
186
218
|
result = subject.add_data_disk_to_xml(@vm, options)
|
187
219
|
doc = Nokogiri::XML(result)
|
188
220
|
disk_size = doc.css('DataVirtualHardDisk LogicalDiskSizeInGB').text
|
@@ -219,7 +251,7 @@ describe Azure::VirtualMachineManagement::Serialization do
|
|
219
251
|
let(:preferred_port) { '22' }
|
220
252
|
before do
|
221
253
|
subject.class.send(:public, *subject.class.private_instance_methods)
|
222
|
-
Loggerx.expects(:puts).returns(nil).at_least(0)
|
254
|
+
Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
|
223
255
|
end
|
224
256
|
|
225
257
|
it 'returns random port number when preferred port is in use' do
|
@@ -244,4 +276,41 @@ describe Azure::VirtualMachineManagement::Serialization do
|
|
244
276
|
assert_operator result.to_i, :<=, 65535
|
245
277
|
end
|
246
278
|
end
|
279
|
+
|
280
|
+
describe "#role_to_xml" do
|
281
|
+
|
282
|
+
let(:params) do
|
283
|
+
{:certificate => {:fingerprint => "fingerprint"},
|
284
|
+
:vm_name => "aVMName",
|
285
|
+
:vm_user => "nocturnal_flying_echolocating_mammal_man"}
|
286
|
+
end
|
287
|
+
|
288
|
+
let(:image) do
|
289
|
+
Azure::VirtualMachineImageManagement::VirtualMachineImage.new do |i|
|
290
|
+
i.name = 'windows-instance'
|
291
|
+
i.os_type = 'Linux'
|
292
|
+
i.image_type = 'OS'
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
let(:options) do
|
297
|
+
{:virtual_network_name => "aNetworkName",
|
298
|
+
:subnet_name => "someSubnet",
|
299
|
+
:storage_account_name => "storage",
|
300
|
+
:vm_size => "Small",
|
301
|
+
:os_type => "Linux"}
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should return a valid role containing a static vnet ip address if provided in options" do
|
305
|
+
options[:static_virtual_network_ipaddress] = "1.2.3.4"
|
306
|
+
result = subject.role_to_xml(params, image, options)
|
307
|
+
result.css('StaticVirtualNetworkIPAddress').text.must_equal "1.2.3.4"
|
308
|
+
end
|
309
|
+
|
310
|
+
it "should return a valid role containing a custom data section if provided in params" do
|
311
|
+
params[:custom_data] = 'blahblahblah'
|
312
|
+
result = subject.role_to_xml(params, image, options)
|
313
|
+
result.css('CustomData').text.must_equal "blahblahblah"
|
314
|
+
end
|
315
|
+
end
|
247
316
|
end
|
@@ -23,21 +23,21 @@ describe Azure::VirtualMachineManagementService do
|
|
23
23
|
|
24
24
|
let(:params) do
|
25
25
|
{
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
vm_name: 'instance1',
|
27
|
+
vm_user: 'root',
|
28
|
+
image: '5112500ae3b842c8b9c604889f8753c3__OpenLogic-CentOS-63APR20130415',
|
29
|
+
password: 'root',
|
30
|
+
location: 'West US'
|
31
31
|
}
|
32
32
|
end
|
33
33
|
|
34
34
|
let(:windows_params) do
|
35
35
|
{
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
vm_name: 'instance1',
|
37
|
+
vm_user: 'administrator',
|
38
|
+
image: 'a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-201304.01-en.us-127GB.vhd',
|
39
|
+
password: 'Admin123',
|
40
|
+
location: 'West US'
|
41
41
|
}
|
42
42
|
end
|
43
43
|
|
@@ -50,32 +50,45 @@ 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
|
-
let(:windows_images_xml) { Fixtures['list_images'] }
|
54
|
-
let(:images_request_path) { '/services/images' }
|
55
53
|
let(:mock_request) { mock }
|
56
|
-
let(:
|
54
|
+
let(:os_image_response_body) do
|
57
55
|
response = mock
|
58
|
-
response.stubs(:body).returns(
|
56
|
+
response.stubs(:body).returns(Fixtures['list_os_images'])
|
57
|
+
Nokogiri::XML response.body
|
58
|
+
end
|
59
|
+
let(:vm_image_response_body) do
|
60
|
+
response = mock
|
61
|
+
response.stubs(:body).returns(Fixtures['list_vm_images'])
|
59
62
|
Nokogiri::XML response.body
|
60
63
|
end
|
61
64
|
|
62
65
|
before do
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
images_request_path,
|
68
|
-
nil
|
66
|
+
Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
|
67
|
+
:get,
|
68
|
+
'/services/images',
|
69
|
+
nil
|
69
70
|
).returns(mock_request)
|
70
|
-
mock_request.expects(:call).returns(
|
71
|
+
mock_request.expects(:call).returns(os_image_response_body).at_least(0)
|
72
|
+
vm_request = mock
|
73
|
+
Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
|
74
|
+
:get,
|
75
|
+
'/services/vmimages',
|
76
|
+
nil
|
77
|
+
).returns(vm_request)
|
78
|
+
vm_request.expects(:call).returns(vm_image_response_body).at_least(0)
|
71
79
|
end
|
72
80
|
|
73
81
|
describe '#list_virtual_machines' do
|
82
|
+
before do
|
83
|
+
Azure::Loggerx.stubs(:info).returns(nil)
|
84
|
+
Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
|
85
|
+
end
|
86
|
+
|
74
87
|
let(:request_path) { '/services/hostedservices' }
|
75
88
|
let(:cloud_services_xml) { Fixtures['list_cloud_services'] }
|
76
89
|
let(:virtual_machine_xml) { Fixtures['virtual_machine'] }
|
77
90
|
let(:deployment_error_xml) { Fixtures['deployment_error'] }
|
78
|
-
let(:
|
91
|
+
let(:verb) { :get }
|
79
92
|
let(:mock_cloud_service_request) { mock }
|
80
93
|
let(:cloud_service_response) do
|
81
94
|
cloud_service_response = mock
|
@@ -96,11 +109,11 @@ describe Azure::VirtualMachineManagementService do
|
|
96
109
|
let(:virtual_machine_response_body) { Nokogiri::XML virtual_machine_response.body }
|
97
110
|
|
98
111
|
before do
|
99
|
-
ManagementHttpRequest.stubs(:new).with(
|
112
|
+
Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(verb, request_path, nil).returns(mock_cloud_service_request)
|
100
113
|
mock_cloud_service_request.expects(:call).returns(cloud_service_response_body)
|
101
|
-
ManagementHttpRequest.stubs(:new).with(
|
114
|
+
Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(verb, anything).returns(mock_virtual_machine_request)
|
102
115
|
mock_virtual_machine_request.stubs(:warn=).returns(true).twice
|
103
|
-
mock_virtual_machine_request.expects(:call).twice.returns(virtual_machine_response_body).returns(Nokogiri::XML
|
116
|
+
mock_virtual_machine_request.expects(:call).twice.returns(virtual_machine_response_body).returns(Nokogiri::XML deployment_error_response.body)
|
104
117
|
end
|
105
118
|
|
106
119
|
it 'assembles a URI for the request' do
|
@@ -116,6 +129,7 @@ describe Azure::VirtualMachineManagementService do
|
|
116
129
|
virtual_machine.deployment_name.must_equal 'deployment-name'
|
117
130
|
virtual_machine.ipaddress.must_equal '137.116.17.187'
|
118
131
|
virtual_machine.virtual_network_name.must_equal 'test-virtual-network'
|
132
|
+
virtual_machine.subnet.must_equal 'test-subnet'
|
119
133
|
end
|
120
134
|
|
121
135
|
it 'returns a list of virtual machines for the subscription' do
|
@@ -129,25 +143,25 @@ describe Azure::VirtualMachineManagementService do
|
|
129
143
|
virtual_machine = subject.list_virtual_machines.first
|
130
144
|
virtual_machine.tcp_endpoints.must_be_kind_of Array
|
131
145
|
virtual_machine.tcp_endpoints.must_include(
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
146
|
+
name: 'SSH',
|
147
|
+
vip: '137.116.17.187',
|
148
|
+
public_port: '22',
|
149
|
+
local_port: '22',
|
150
|
+
protocol: 'tcp'
|
137
151
|
)
|
138
152
|
virtual_machine.tcp_endpoints.must_include(
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
153
|
+
name: 'tcp-port-80',
|
154
|
+
vip: '137.117.17.187',
|
155
|
+
public_port: '80',
|
156
|
+
local_port: '80',
|
157
|
+
protocol: 'tcp'
|
144
158
|
)
|
145
159
|
virtual_machine.tcp_endpoints.must_include(
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
160
|
+
name: 'tcp-port-3889',
|
161
|
+
vip: '137.116.17.187',
|
162
|
+
public_port: '3889',
|
163
|
+
local_port: '3889',
|
164
|
+
protocol: 'tcp'
|
151
165
|
)
|
152
166
|
end
|
153
167
|
end
|
@@ -155,12 +169,14 @@ describe Azure::VirtualMachineManagementService do
|
|
155
169
|
describe '#get_virtual_machine' do
|
156
170
|
|
157
171
|
before do
|
172
|
+
Azure::Loggerx.stubs(:info).returns(nil)
|
173
|
+
Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
|
158
174
|
virtual_machine = VirtualMachine.new do |vm|
|
159
175
|
vm.vm_name = 'instance-name'
|
160
176
|
vm.cloud_service_name = 'cloud-service-1'
|
161
177
|
end
|
162
178
|
Azure::VirtualMachineManagementService.any_instance.stubs(
|
163
|
-
|
179
|
+
:list_virtual_machines
|
164
180
|
).returns([virtual_machine])
|
165
181
|
end
|
166
182
|
|
@@ -183,24 +199,26 @@ describe Azure::VirtualMachineManagementService do
|
|
183
199
|
end
|
184
200
|
|
185
201
|
describe '#create_virtual_machine' do
|
186
|
-
let(:
|
202
|
+
let(:verb) { :get }
|
187
203
|
|
188
204
|
before do
|
205
|
+
Azure::Loggerx.stubs(:info).returns(nil)
|
206
|
+
Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
|
189
207
|
mock_request = mock
|
190
|
-
ManagementHttpRequest.stubs(:new).with(
|
191
|
-
|
192
|
-
|
193
|
-
|
208
|
+
Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
|
209
|
+
verb,
|
210
|
+
location_request_path,
|
211
|
+
nil
|
194
212
|
).returns(mock_request)
|
195
213
|
mock_request.expects(:call).returns(location_response_body).at_least(0)
|
196
214
|
Azure::CloudServiceManagementService.any_instance.stubs(:create_cloud_service)
|
197
215
|
Azure::CloudServiceManagementService.any_instance.stubs(:upload_certificate)
|
198
216
|
Azure::StorageManagementService.any_instance.stubs(:create_storage_account)
|
199
217
|
mock_request = mock
|
200
|
-
ManagementHttpRequest.expects(:new).with(
|
201
|
-
|
202
|
-
|
203
|
-
|
218
|
+
Azure::BaseManagement::ManagementHttpRequest.expects(:new).with(
|
219
|
+
:post,
|
220
|
+
anything,
|
221
|
+
anything
|
204
222
|
).returns(mock_request)
|
205
223
|
mock_request.expects(:call).returns(nil)
|
206
224
|
virtual_machine = VirtualMachine.new do |vm|
|
@@ -208,7 +226,7 @@ describe Azure::VirtualMachineManagementService do
|
|
208
226
|
vm.ipaddress = '192.168.1.1'
|
209
227
|
end
|
210
228
|
Azure::VirtualMachineManagementService.stubs(
|
211
|
-
|
229
|
+
:get_virtual_machine
|
212
230
|
).returns(virtual_machine)
|
213
231
|
end
|
214
232
|
|
@@ -225,9 +243,9 @@ describe Azure::VirtualMachineManagementService do
|
|
225
243
|
|
226
244
|
it 'should set options hash with valid cloud service name.' do
|
227
245
|
options = {
|
228
|
-
|
229
|
-
|
230
|
-
|
246
|
+
storage_account_name: 'storage_account_name',
|
247
|
+
deployment_name: 'unique_deployment_name',
|
248
|
+
tcp_endpoints: '80,3889:3889'
|
231
249
|
}
|
232
250
|
subject.create_virtual_machine(params, options)
|
233
251
|
csn = options[:cloud_service_name]
|
@@ -240,24 +258,25 @@ describe Azure::VirtualMachineManagementService do
|
|
240
258
|
|
241
259
|
describe '#create_virtual_machine with invalid parameters for windows machine' do
|
242
260
|
let(:virtual_machine_xml) { Fixtures['virtual_machine'] }
|
243
|
-
let(:
|
261
|
+
let(:verb) { :get }
|
244
262
|
|
245
263
|
before do
|
264
|
+
windows_params[:cloud_service_name] = 'cloud-service-1'
|
246
265
|
mock_request = mock
|
247
|
-
ManagementHttpRequest.stubs(:new).with(
|
248
|
-
|
249
|
-
|
250
|
-
|
266
|
+
Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
|
267
|
+
verb,
|
268
|
+
location_request_path,
|
269
|
+
nil
|
251
270
|
).returns(mock_request)
|
252
271
|
mock_request.expects(:call).returns(location_response_body).at_least(0)
|
253
272
|
Azure::CloudServiceManagementService.any_instance.stubs(:create_cloud_service)
|
254
273
|
Azure::CloudServiceManagementService.any_instance.stubs(:upload_certificate)
|
255
274
|
Azure::StorageManagementService.any_instance.stubs(:create_storage_account)
|
256
275
|
mock_request = mock
|
257
|
-
ManagementHttpRequest.expects(:new).with(
|
258
|
-
|
259
|
-
|
260
|
-
|
276
|
+
Azure::BaseManagement::ManagementHttpRequest.expects(:new).with(
|
277
|
+
:post,
|
278
|
+
anything,
|
279
|
+
anything
|
261
280
|
).returns(mock_request).at_least(0)
|
262
281
|
mock_request.expects(:call).returns(nil).at_least(0)
|
263
282
|
virtual_machine_obj = VirtualMachine.new do |virtual_machine|
|
@@ -265,7 +284,7 @@ describe Azure::VirtualMachineManagementService do
|
|
265
284
|
virtual_machine.ipaddress = '192.168.1.1'
|
266
285
|
end
|
267
286
|
Azure::VirtualMachineManagementService.any_instance.stubs(
|
268
|
-
|
287
|
+
:get_virtual_machine
|
269
288
|
).returns(virtual_machine_obj)
|
270
289
|
end
|
271
290
|
|
@@ -288,16 +307,16 @@ describe Azure::VirtualMachineManagementService do
|
|
288
307
|
end
|
289
308
|
|
290
309
|
it 'self-signed certificate is generated by vm and used for the virtual machine when certificate path is not given.' do
|
291
|
-
options = {
|
310
|
+
options = {winrm_transport: %w(https http)}
|
292
311
|
virtual_machine = subject.create_virtual_machine(windows_params, options)
|
293
312
|
virtual_machine.wont_be_nil
|
294
313
|
end
|
295
314
|
|
296
315
|
it 'throws error when certificate path is not invalid.' do
|
297
316
|
options = {
|
298
|
-
|
299
|
-
|
300
|
-
|
317
|
+
winrm_transport: %w(https http),
|
318
|
+
private_key_file: 'f:/invalid_path/private_key',
|
319
|
+
certificate_file: 'f:/invalid_path/certificate.pem'
|
301
320
|
}
|
302
321
|
virtual_machine = subject.create_virtual_machine(windows_params, options)
|
303
322
|
assert_match(/No such file or directory -*/, virtual_machine)
|
@@ -305,9 +324,9 @@ describe Azure::VirtualMachineManagementService do
|
|
305
324
|
|
306
325
|
it 'should not throws certificate error when wirnm_transport is http' do
|
307
326
|
options = {
|
308
|
-
|
309
|
-
|
310
|
-
|
327
|
+
winrm_transport: ['http'],
|
328
|
+
private_key_file: 'f:/invalid_path/private_key',
|
329
|
+
certificate_file: 'f:/invalid_path/certificate.pem'
|
311
330
|
}
|
312
331
|
virtual_machine = subject.create_virtual_machine(windows_params, options)
|
313
332
|
virtual_machine.must_be_kind_of VirtualMachine
|
@@ -344,45 +363,56 @@ describe Azure::VirtualMachineManagementService do
|
|
344
363
|
assert_match(/Persistentvmrole not enabled for "West Europe"*/, msg)
|
345
364
|
end
|
346
365
|
|
347
|
-
it 'vm_size
|
366
|
+
it 'warns if vm_size is not in the correct case' do
|
348
367
|
options = {
|
349
|
-
|
368
|
+
vm_size: 'extralarge'
|
350
369
|
}
|
351
|
-
|
352
|
-
|
370
|
+
out, err = capture_io do
|
371
|
+
msg = subject.create_virtual_machine(params, options)
|
372
|
+
end
|
373
|
+
error_msg = "'extralarge' specified for parameter 'vm_size' is not in the list of valid VM role sizes."
|
374
|
+
assert_match(/#{error_msg}*/, out)
|
353
375
|
end
|
354
376
|
|
355
|
-
it '
|
377
|
+
it 'warns when wrong role size is given' do
|
356
378
|
options = {
|
357
|
-
|
379
|
+
vm_size: 'wrong size'
|
358
380
|
}
|
359
|
-
|
360
|
-
|
361
|
-
|
381
|
+
out, err = capture_io do
|
382
|
+
virtual_machine = subject.create_virtual_machine(params, options)
|
383
|
+
end
|
384
|
+
error_msg = "'wrong size' specified for parameter 'vm_size' is not in the list of valid VM role sizes."
|
385
|
+
assert_match(/#{error_msg}*/, out)
|
362
386
|
end
|
363
387
|
|
364
|
-
it 'should
|
388
|
+
it 'should warn if role size is empty' do
|
365
389
|
options = {
|
366
|
-
|
390
|
+
vm_size: ''
|
367
391
|
}
|
368
|
-
|
392
|
+
out, err = capture_io do
|
393
|
+
subject.create_virtual_machine(params, options)
|
394
|
+
end
|
395
|
+
error_msg = "'' specified for parameter 'vm_size' is not in the list of valid VM role sizes."
|
396
|
+
assert_match(/#{error_msg}*/, out)
|
369
397
|
end
|
370
398
|
end
|
371
399
|
|
372
|
-
describe '#
|
400
|
+
describe '#get_image' do
|
373
401
|
|
374
402
|
before do
|
403
|
+
Azure::Loggerx.stubs(:info).returns(nil)
|
404
|
+
Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
|
375
405
|
subject.class.send(:public, *subject.class.private_instance_methods)
|
376
406
|
end
|
377
407
|
|
378
408
|
it 'returns os type of given virtual machine image' do
|
379
|
-
result = subject.
|
380
|
-
result.must_equal 'Linux'
|
409
|
+
result = subject.get_image 'RightImage-CentOS-6.2-x64-v5.8.8.1'
|
410
|
+
result.os_type.must_equal 'Linux'
|
381
411
|
end
|
382
412
|
|
383
413
|
it 'errors if the virtual machine image does not exist' do
|
384
414
|
exception = assert_raises(RuntimeError) do
|
385
|
-
subject.
|
415
|
+
subject.get_image 'invalid-image-name'
|
386
416
|
end
|
387
417
|
error_msg = 'The virtual machine image source is not valid'
|
388
418
|
assert_match(/#{error_msg}/i, exception.message)
|
@@ -392,6 +422,8 @@ describe Azure::VirtualMachineManagementService do
|
|
392
422
|
describe '#add_role' do
|
393
423
|
|
394
424
|
before do
|
425
|
+
Azure::Loggerx.stubs(:info).returns(nil)
|
426
|
+
Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
|
395
427
|
windows_params[:cloud_service_name] = 'cloud-service-1'
|
396
428
|
end
|
397
429
|
|
@@ -415,26 +447,17 @@ describe Azure::VirtualMachineManagementService do
|
|
415
447
|
|
416
448
|
it 'throws error when certificate path is not invalid.' do
|
417
449
|
options = {
|
418
|
-
|
419
|
-
|
420
|
-
|
450
|
+
winrm_transport: %w(https http),
|
451
|
+
private_key_file: 'f:/invalid_path/private_key',
|
452
|
+
certificate_file: 'f:/invalid_path/certificate.pem'
|
421
453
|
}
|
422
454
|
exception = assert_raises(RuntimeError) do
|
423
455
|
subject.add_role(windows_params, options)
|
424
456
|
end
|
425
|
-
error_msg = 'No such file or directory
|
457
|
+
error_msg = 'No such file or directory'
|
426
458
|
assert_match(/#{error_msg}/i, exception.message)
|
427
459
|
end
|
428
460
|
|
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
461
|
end
|
439
462
|
|
440
463
|
end
|