azure 0.7.1 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +31 -0
  3. data/azure.gemspec +2 -1
  4. data/lib/azure.rb +1 -0
  5. data/lib/azure/base_management/management_http_request.rb +3 -12
  6. data/lib/azure/blob/auth/shared_access_signature.rb +4 -0
  7. data/lib/azure/blob/blob_service.rb +2 -2
  8. data/lib/azure/client_services.rb +13 -13
  9. data/lib/azure/core/http/http_request.rb +3 -14
  10. data/lib/azure/core/service.rb +2 -1
  11. data/lib/azure/http_client.rb +1 -17
  12. data/lib/azure/http_response_helper.rb +38 -0
  13. data/lib/azure/sql_database_management/serialization.rb +4 -0
  14. data/lib/azure/sql_database_management/sql_database_management_service.rb +10 -9
  15. data/lib/azure/version.rb +1 -1
  16. data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +2 -2
  17. data/lib/azure/virtual_machine_management/serialization.rb +21 -12
  18. data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +8 -3
  19. metadata +17 -199
  20. data/test/fixtures/32px-fulls-black.jpg +0 -0
  21. data/test/fixtures/affinity_group.xml +0 -33
  22. data/test/fixtures/all_containers.xml +0 -20
  23. data/test/fixtures/all_tables.xml +0 -22
  24. data/test/fixtures/container_acl.xml +0 -11
  25. data/test/fixtures/create_sql_database_server.xml +0 -2
  26. data/test/fixtures/create_storage_desc_error.xml +0 -5
  27. data/test/fixtures/create_storage_extendedprop_error.xml +0 -8
  28. data/test/fixtures/create_storage_extendedpropname_error.xml +0 -6
  29. data/test/fixtures/create_storage_full_error.xml +0 -6
  30. data/test/fixtures/create_storage_label_error.xml +0 -5
  31. data/test/fixtures/create_storage_location_error.xml +0 -5
  32. data/test/fixtures/create_storage_name_error.xml +0 -6
  33. data/test/fixtures/create_table_response_entry.xml +0 -15
  34. data/test/fixtures/delete_storage_container_error.xml +0 -5
  35. data/test/fixtures/delete_storage_error.xml +0 -5
  36. data/test/fixtures/deployment_error.xml +0 -5
  37. data/test/fixtures/empty_xml_file +0 -0
  38. data/test/fixtures/get_storage_account_error.xml +0 -5
  39. data/test/fixtures/get_storage_account_properties.xml +0 -34
  40. data/test/fixtures/get_storage_account_properties_new.xml +0 -32
  41. data/test/fixtures/http_error.xml +0 -5
  42. data/test/fixtures/insert_entity_response_entry.xml +0 -25
  43. data/test/fixtures/list_affinity_groups.xml +0 -22
  44. data/test/fixtures/list_blobs.xml +0 -121
  45. data/test/fixtures/list_block_all_with_none_committed.xml +0 -22
  46. data/test/fixtures/list_blocks_all.xml +0 -23
  47. data/test/fixtures/list_blocks_committed.xml +0 -13
  48. data/test/fixtures/list_cloud_services.xml +0 -39
  49. data/test/fixtures/list_containers.xml +0 -38
  50. data/test/fixtures/list_firewall_management_endpoint.xml +0 -27
  51. data/test/fixtures/list_locations.xml +0 -212
  52. data/test/fixtures/list_os_images.xml +0 -110
  53. data/test/fixtures/list_page_ranges.xml +0 -11
  54. data/test/fixtures/list_sql_database.xml +0 -24
  55. data/test/fixtures/list_sql_server_firewall.xml +0 -23
  56. data/test/fixtures/list_storage_account_single.xml +0 -25
  57. data/test/fixtures/list_storage_accounts.xml +0 -48
  58. data/test/fixtures/list_virtual_networks.xml +0 -91
  59. data/test/fixtures/list_vm_images.xml +0 -21
  60. data/test/fixtures/logging.xml +0 -11
  61. data/test/fixtures/management_certificate.pem +0 -55
  62. data/test/fixtures/management_certificate.pfx +0 -0
  63. data/test/fixtures/management_certificate.publishsettings +0 -12
  64. data/test/fixtures/messages.xml +0 -12
  65. data/test/fixtures/metrics.xml +0 -10
  66. data/test/fixtures/privatekey.key +0 -28
  67. data/test/fixtures/query_entities_empty_response.xml +0 -7
  68. data/test/fixtures/query_entities_response.xml +0 -45
  69. data/test/fixtures/queue_service_properties.xml +0 -22
  70. data/test/fixtures/queue_service_properties_original.xml +0 -19
  71. data/test/fixtures/queues.xml +0 -16
  72. data/test/fixtures/retention_policy.xml +0 -5
  73. data/test/fixtures/sb_default_create_queue_response.xml +0 -23
  74. data/test/fixtures/sb_default_create_relay_response.xml +0 -15
  75. data/test/fixtures/sb_default_create_topic_response.xml +0 -18
  76. data/test/fixtures/sb_get_access_token_response.txt +0 -1
  77. data/test/fixtures/sb_queues_runtime_peek_message_response_headers.txt +0 -9
  78. data/test/fixtures/storage_service_keys.xml +0 -8
  79. data/test/fixtures/storage_service_properties.xml +0 -55
  80. data/test/fixtures/update_storage_account.xml +0 -16
  81. data/test/fixtures/update_storage_error.xml +0 -5
  82. data/test/fixtures/updated_storage_accounts.xml +0 -55
  83. data/test/fixtures/virtual_machine.xml +0 -116
  84. data/test/fixtures/windows_virtual_machine.xml +0 -106
  85. data/test/integration/affinity_group/Affinity_test.rb +0 -55
  86. data/test/integration/affinity_group/Create_Affinity_test.rb +0 -64
  87. data/test/integration/affinity_group/Delete_Affinity_test.rb +0 -56
  88. data/test/integration/affinity_group/List_Affinity_test.rb +0 -41
  89. data/test/integration/affinity_group/Update_Affinity_test.rb +0 -87
  90. data/test/integration/blob/blob_gb18030_test.rb +0 -199
  91. data/test/integration/blob/blob_metadata_test.rb +0 -75
  92. data/test/integration/blob/blob_pages_test.rb +0 -119
  93. data/test/integration/blob/blob_properties_test.rb +0 -77
  94. data/test/integration/blob/block_blob_test.rb +0 -303
  95. data/test/integration/blob/container/container_acl_test.rb +0 -69
  96. data/test/integration/blob/container/container_metadata_test.rb +0 -50
  97. data/test/integration/blob/container/create_container_test.rb +0 -60
  98. data/test/integration/blob/container/delete_container_test.rb +0 -39
  99. data/test/integration/blob/container/get_container_properties_test.rb +0 -48
  100. data/test/integration/blob/container/list_containers_test.rb +0 -79
  101. data/test/integration/blob/container/root_container_test.rb +0 -55
  102. data/test/integration/blob/copy_blob_test.rb +0 -113
  103. data/test/integration/blob/create_blob_snapshot_test.rb +0 -80
  104. data/test/integration/blob/create_page_blob_test.rb +0 -83
  105. data/test/integration/blob/delete_blob_test.rb +0 -159
  106. data/test/integration/blob/get_blob_test.rb +0 -65
  107. data/test/integration/blob/informative_errors_test.rb +0 -39
  108. data/test/integration/blob/lease/acquire_lease_test.rb +0 -36
  109. data/test/integration/blob/lease/break_lease_test.rb +0 -40
  110. data/test/integration/blob/lease/release_lease_test.rb +0 -40
  111. data/test/integration/blob/lease/renew_lease_test.rb +0 -42
  112. data/test/integration/blob/list_blobs_test.rb +0 -113
  113. data/test/integration/cloud_service/Cloud_Create_test.rb +0 -45
  114. data/test/integration/cloud_service/Cloud_Delete_test.rb +0 -45
  115. data/test/integration/database/create_sql_server_firewall_test.rb +0 -81
  116. data/test/integration/database/create_sql_server_test.rb +0 -53
  117. data/test/integration/database/delete_sql_server_firewall_test.rb +0 -63
  118. data/test/integration/database/delete_sql_server_test.rb +0 -44
  119. data/test/integration/database/list_sql_server_firewall_test.rb +0 -44
  120. data/test/integration/database/list_sql_servers_test.rb +0 -44
  121. data/test/integration/database/reset_password_sql_server_test.rb +0 -53
  122. data/test/integration/location/Location_List_test.rb +0 -38
  123. data/test/integration/location/RoleSize_List_test.rb +0 -34
  124. data/test/integration/queue/clear_messages_test.rb +0 -42
  125. data/test/integration/queue/create_message_test.rb +0 -75
  126. data/test/integration/queue/create_queue_test.rb +0 -50
  127. data/test/integration/queue/delete_message_test.rb +0 -67
  128. data/test/integration/queue/delete_queue_test.rb +0 -45
  129. data/test/integration/queue/informative_errors_test.rb +0 -42
  130. data/test/integration/queue/list_messages_encoded_test.rb +0 -79
  131. data/test/integration/queue/list_messages_test.rb +0 -79
  132. data/test/integration/queue/list_queues_test.rb +0 -43
  133. data/test/integration/queue/peek_messages_test.rb +0 -59
  134. data/test/integration/queue/queue_gb18030_test.rb +0 -131
  135. data/test/integration/queue/queue_metadata_test.rb +0 -40
  136. data/test/integration/queue/update_message_test.rb +0 -74
  137. data/test/integration/service_bus/informative_errors_test.rb +0 -37
  138. data/test/integration/service_bus/queues_scenario_test.rb +0 -200
  139. data/test/integration/service_bus/queues_test.rb +0 -266
  140. data/test/integration/service_bus/relay_test.rb +0 -132
  141. data/test/integration/service_bus/rules_test.rb +0 -145
  142. data/test/integration/service_bus/sb_queue_gb18030_test.rb +0 -182
  143. data/test/integration/service_bus/scenario_test.rb +0 -101
  144. data/test/integration/service_bus/subscriptions_test.rb +0 -211
  145. data/test/integration/service_bus/topics_scenario_test.rb +0 -406
  146. data/test/integration/service_bus/topics_test.rb +0 -129
  147. data/test/integration/storage_management/storage_management_test.rb +0 -185
  148. data/test/integration/table/create_table_test.rb +0 -36
  149. data/test/integration/table/delete_entity_batch_test.rb +0 -107
  150. data/test/integration/table/delete_entity_test.rb +0 -94
  151. data/test/integration/table/delete_table_test.rb +0 -40
  152. data/test/integration/table/get_table_test.rb +0 -37
  153. data/test/integration/table/informative_errors_test.rb +0 -39
  154. data/test/integration/table/insert_entity_batch_test.rb +0 -100
  155. data/test/integration/table/insert_entity_test.rb +0 -88
  156. data/test/integration/table/insert_or_merge_entity_batch_test.rb +0 -159
  157. data/test/integration/table/insert_or_merge_entity_test.rb +0 -143
  158. data/test/integration/table/insert_or_replace_entity_batch_test.rb +0 -152
  159. data/test/integration/table/insert_or_replace_entity_test.rb +0 -137
  160. data/test/integration/table/merge_entity_batch_test.rb +0 -128
  161. data/test/integration/table/merge_entity_test.rb +0 -113
  162. data/test/integration/table/query_entities_test.rb +0 -196
  163. data/test/integration/table/query_tables_test.rb +0 -43
  164. data/test/integration/table/query_test.rb +0 -251
  165. data/test/integration/table/table_acl_test.rb +0 -52
  166. data/test/integration/table/table_gb18030_test.rb +0 -355
  167. data/test/integration/table/update_entity_batch_test.rb +0 -149
  168. data/test/integration/table/update_entity_test.rb +0 -131
  169. data/test/integration/test_helper.rb +0 -40
  170. data/test/integration/vm/VM_Create_test.rb +0 -262
  171. data/test/integration/vm/VM_Delete_test.rb +0 -53
  172. data/test/integration/vm/VM_Operations_test.rb +0 -172
  173. data/test/integration/vm_image/virtual_machine_disk_test.rb +0 -37
  174. data/test/integration/vm_image/virtual_machine_image_test.rb +0 -37
  175. data/test/integration/vnet/Virtual_Network_Create_test.rb +0 -116
  176. data/test/integration/vnet/Virtual_Network_list_test.rb +0 -48
  177. data/test/support/env.rb +0 -19
  178. data/test/support/fixtures.rb +0 -36
  179. data/test/support/name_generator.rb +0 -168
  180. data/test/support/stubs.rb +0 -42
  181. data/test/support/virtual_machine_name_generator.rb +0 -102
  182. data/test/support/virtual_network_helper.rb +0 -73
  183. data/test/test_helper.rb +0 -47
  184. data/test/unit/affinity_group/affinity_group_test.rb +0 -189
  185. data/test/unit/affinity_group/serialization_test.rb +0 -87
  186. data/test/unit/base_management/base_management_service_test.rb +0 -19
  187. data/test/unit/base_management/location_test.rb +0 -56
  188. data/test/unit/base_management/role_size_test.rb +0 -50
  189. data/test/unit/blob/auth/shared_access_signature_test.rb +0 -71
  190. data/test/unit/blob/blob_service_test.rb +0 -1970
  191. data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +0 -94
  192. data/test/unit/cloud_service_management/serialization_test.rb +0 -169
  193. data/test/unit/config/azure_test.rb +0 -131
  194. data/test/unit/config/client_test.rb +0 -37
  195. data/test/unit/core/auth/shared_key_lite_test.rb +0 -51
  196. data/test/unit/core/auth/shared_key_test.rb +0 -58
  197. data/test/unit/core/auth/signer_test.rb +0 -30
  198. data/test/unit/core/http/http_error_test.rb +0 -61
  199. data/test/unit/core/http/http_request_test.rb +0 -138
  200. data/test/unit/core/http/http_response_test.rb +0 -20
  201. data/test/unit/core/http/retry_policy_test.rb +0 -23
  202. data/test/unit/core/utility_test.rb +0 -122
  203. data/test/unit/database/serialization_test.rb +0 -94
  204. data/test/unit/database/sql_database_server_service_test.rb +0 -341
  205. data/test/unit/http_client_test.rb +0 -74
  206. data/test/unit/service/serialization_test.rb +0 -533
  207. data/test/unit/service/storage_service_test.rb +0 -297
  208. data/test/unit/storage_management/serialization_test.rb +0 -244
  209. data/test/unit/storage_management/storage_management_service_test.rb +0 -247
  210. data/test/unit/table/edmtype_test.rb +0 -108
  211. data/test/unit/virtual_machine_image_management/serialization_test.rb +0 -50
  212. data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +0 -114
  213. data/test/unit/virtual_machine_management/serialization_test.rb +0 -316
  214. data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +0 -480
  215. data/test/unit/vnet/serialization_test.rb +0 -187
  216. data/test/unit/vnet/virtual_network_management_service_test.rb +0 -131
@@ -1,316 +0,0 @@
1
- #-------------------------------------------------------------------------
2
- # Copyright 2013 Microsoft Open Technologies, Inc.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- #--------------------------------------------------------------------------
15
- require 'test_helper'
16
-
17
- describe Azure::VirtualMachineManagement::Serialization do
18
- include Azure::Core::Utility
19
-
20
- subject { Azure::VirtualMachineManagement::Serialization }
21
-
22
- let(:vm_xml) { Nokogiri::XML(Fixtures['virtual_machine']) }
23
- let(:csn) { 'cloud-service-1' }
24
-
25
- describe '#virtual_machines_from_xml' do
26
-
27
- it 'accepts an XML string' do
28
- subject.virtual_machines_from_xml(vm_xml, csn)
29
- end
30
-
31
- it 'returns an Array of VirtualMachine instances' do
32
- result = subject.virtual_machines_from_xml(vm_xml, csn).first
33
- result.must_be_kind_of Azure::VirtualMachineManagement::VirtualMachine
34
- end
35
-
36
- it "returns a virtual_machine, with it's attribute populated" do
37
- virtual_machine = subject.virtual_machines_from_xml(vm_xml, csn).first
38
- virtual_machine.vm_name.must_equal 'instance-name'
39
- virtual_machine.role_size.must_equal 'Small'
40
- virtual_machine.hostname.must_equal 'host-name'
41
- virtual_machine.cloud_service_name.must_equal 'cloud-service-1'
42
- virtual_machine.deployment_name.must_equal 'deployment-name'
43
- virtual_machine.ipaddress.must_equal '137.116.17.187'
44
- virtual_machine.availability_set_name.must_equal 'vm-availability'
45
- end
46
-
47
- it "returns a virtual_machine, with it's tcp_endpoints attribute" do
48
- virtual_machine = subject.virtual_machines_from_xml(vm_xml, csn).first
49
- virtual_machine.tcp_endpoints.must_be_kind_of Array
50
- virtual_machine.tcp_endpoints.must_include(
51
- name: 'SSH',
52
- vip: '137.116.17.187',
53
- public_port: '22',
54
- local_port: '22',
55
- protocol: 'tcp'
56
- )
57
- virtual_machine.tcp_endpoints.must_include(
58
- name: 'tcp-port-80',
59
- vip: '137.117.17.187',
60
- public_port: '80',
61
- local_port: '80',
62
- protocol: 'tcp'
63
- )
64
- virtual_machine.tcp_endpoints.must_include(
65
- name: 'tcp-port-3889',
66
- vip: '137.116.17.187',
67
- public_port: '3889',
68
- local_port: '3889',
69
- protocol: 'tcp'
70
- )
71
- end
72
-
73
- end
74
-
75
- describe '#shutdown_virtual_machine_to_xml' do
76
-
77
- it 'returns an xml for virtual machine shutdown' do
78
- result = subject.shutdown_virtual_machine_to_xml
79
- result.must_be_kind_of String
80
- doc = Nokogiri::XML(result)
81
- doc.css('OperationType').text.must_equal 'ShutdownRoleOperation'
82
- doc.css('PostShutdownAction').text.must_equal 'StoppedDeallocated'
83
- end
84
-
85
- end
86
-
87
- describe '#start_virtual_machine_to_xml' do
88
-
89
- it 'returns an xml for start virtual machine' do
90
- result = subject.start_virtual_machine_to_xml
91
- result.must_be_kind_of String
92
- doc = Nokogiri::XML(result)
93
- doc.css('OperationType').text.must_equal 'StartRoleOperation'
94
- end
95
-
96
- end
97
-
98
- describe '#restart_virtual_machine_to_xml' do
99
-
100
- it 'returns an xml for restart virtual machine' do
101
- result = subject.restart_virtual_machine_to_xml
102
- result.must_be_kind_of String
103
- doc = Nokogiri::XML(result)
104
- doc.css('OperationType').text.must_equal 'RestartRoleOperation'
105
- end
106
-
107
- end
108
-
109
- describe '#deployment_to_xml' do
110
- let(:params) do
111
- {
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'}
118
- }
119
- end
120
-
121
- let(:options) do
122
- {
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'
130
- }
131
- end
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
-
141
- it 'returns an VirtualMachine object with correct tcp endpoints' do
142
- params[:certificate] = {fingerprint: 'CFB8C256D2986559C630547F2D0'}
143
- options[:os_type] = 'Windows'
144
- options[:existing_ports] = ['5985']
145
- result = subject.deployment_to_xml params, image, options
146
- doc = Nokogiri::XML(result)
147
- endpoints = doc.css('Deployment RoleList ConfigurationSet InputEndpoints InputEndpoint')
148
- tcp_endpoints = []
149
- endpoints.each do |endpoint|
150
- ep = {}
151
- ep[:name] = xml_content(endpoint, 'Name')
152
- ep[:public_port] = xml_content(endpoint, 'Port')
153
- ep[:local_port] = xml_content(endpoint, 'LocalPort')
154
- tcp_endpoints << ep
155
- end
156
- doc.css('Deployment RoleList AvailabilitySetName').text.must_equal 'aval-set'
157
- result.must_be_kind_of String
158
- tcp_endpoints.must_include(
159
- name: 'TCP-PORT-80',
160
- public_port: '80',
161
- local_port: '80'
162
- )
163
- tcp_endpoints.must_include(
164
- name: 'TCP-PORT-3390',
165
- public_port: '3390',
166
- local_port: '3389'
167
- )
168
- tcp_endpoints.must_include(
169
- name: 'TCP-PORT-85',
170
- public_port: '85',
171
- local_port: '85'
172
- )
173
- tcp_endpoints.must_include(
174
- name: 'PowerShell',
175
- public_port: '5988',
176
- local_port: '5986'
177
- )
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
199
- end
200
-
201
- describe '#add_data_disk_to_xml' do
202
-
203
- let(:options) do
204
- {
205
- disk_size: 100
206
- }
207
- end
208
- let(:media_link) { 'https://sta.blob.managment.core.net/vhds/1234.vhd' }
209
-
210
- before do
211
- Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
212
- @vm = Azure::VirtualMachineManagement::VirtualMachine.new
213
- @vm.data_disks = []
214
- @vm.media_link = media_link
215
- end
216
-
217
- it 'returns an xml for newly created data disk' do
218
- result = subject.add_data_disk_to_xml(@vm, options)
219
- doc = Nokogiri::XML(result)
220
- disk_size = doc.css('DataVirtualHardDisk LogicalDiskSizeInGB').text
221
- media_link = doc.css('DataVirtualHardDisk MediaLink').text
222
- disk_name = doc.css('DataVirtualHardDisk DiskName').text
223
- result.must_be_kind_of String
224
- disk_size.must_equal options[:disk_size].to_s
225
- media_link.wont_be_empty
226
- disk_name.must_be_empty
227
- end
228
-
229
- it 'returns an xml for existing data disk' do
230
- options[:import] = true
231
- options[:disk_name] = 'disk_name'
232
- result = subject.add_data_disk_to_xml(@vm, options)
233
- doc = Nokogiri::XML(result)
234
- media_link = doc.css('DataVirtualHardDisk MediaLink').text
235
- disk_name = doc.css('DataVirtualHardDisk DiskName').text
236
- result.must_be_kind_of String
237
- media_link.must_be_empty
238
- disk_name.wont_be_empty
239
- end
240
-
241
- it 'raise error when disk name is empty' do
242
- options[:import] = true
243
- exception = assert_raises(RuntimeError) do
244
- subject.add_data_disk_to_xml(@vm, options)
245
- end
246
- assert_match(/The data disk name is not valid/i, exception.message)
247
- end
248
- end
249
-
250
- describe '#assign_random_port' do
251
- let(:preferred_port) { '22' }
252
- before do
253
- subject.class.send(:public, *subject.class.private_instance_methods)
254
- Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
255
- end
256
-
257
- it 'returns random port number when preferred port is in use' do
258
- result = subject.assign_random_port(preferred_port, [preferred_port])
259
- assert_operator result.to_i, :>=, 10000
260
- assert_operator result.to_i, :<=, 65535
261
- end
262
-
263
- it 'returns preferred port number when used ports is nil' do
264
- result = subject.assign_random_port(preferred_port, nil)
265
- result.must_equal preferred_port
266
- end
267
-
268
- it 'returns preferred port number when used ports is empty' do
269
- result = subject.assign_random_port(preferred_port, [])
270
- result.must_equal preferred_port
271
- end
272
-
273
- it 'returns random port number when preferred port is in use' do
274
- result = subject.assign_random_port(preferred_port, ['1', preferred_port])
275
- assert_operator result.to_i, :>=, 10000
276
- assert_operator result.to_i, :<=, 65535
277
- end
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
316
- end
@@ -1,480 +0,0 @@
1
- #-------------------------------------------------------------------------
2
- # Copyright 2013 Microsoft Open Technologies, Inc.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- #--------------------------------------------------------------------------
15
- require 'test_helper'
16
-
17
- describe Azure::VirtualMachineManagementService do
18
- VirtualMachine = Azure::VirtualMachineManagement::VirtualMachine
19
-
20
- subject do
21
- Azure::VirtualMachineManagementService.new
22
- end
23
-
24
- let(:params) do
25
- {
26
- vm_name: 'instance1',
27
- vm_user: 'root',
28
- image: '5112500ae3b842c8b9c604889f8753c3__OpenLogic-CentOS-63APR20130415',
29
- password: 'root',
30
- location: 'West US'
31
- }
32
- end
33
-
34
- let(:windows_params) do
35
- {
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
- }
42
- end
43
-
44
- let(:location_request_path) { '/locations' }
45
- let(:locations_xml) { Fixtures['list_locations'] }
46
- let(:location_response) do
47
- response = mock
48
- response.stubs(:body).returns(locations_xml)
49
- response
50
- end
51
- let(:location_response_body) { Nokogiri::XML location_response.body }
52
- let(:mock_virtual_machine_request) { mock }
53
- let(:mock_request) { mock }
54
- let(:os_image_response_body) do
55
- response = mock
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'])
62
- Nokogiri::XML response.body
63
- end
64
-
65
- before do
66
- Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
67
- :get,
68
- '/services/images',
69
- anything
70
- ).returns(mock_request)
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
- anything
77
- ).returns(vm_request)
78
- vm_request.expects(:call).returns(vm_image_response_body).at_least(0)
79
- end
80
-
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
-
87
- let(:request_path) { '/services/hostedservices' }
88
- let(:cloud_services_xml) { Fixtures['list_cloud_services'] }
89
- let(:virtual_machine_xml) { Fixtures['virtual_machine'] }
90
- let(:deployment_error_xml) { Fixtures['deployment_error'] }
91
- let(:verb) { :get }
92
- let(:mock_cloud_service_request) { mock }
93
- let(:cloud_service_response) do
94
- cloud_service_response = mock
95
- cloud_service_response.stubs(:body).returns(cloud_services_xml)
96
- cloud_service_response
97
- end
98
- let(:virtual_machine_response) do
99
- virtual_machine_response = mock
100
- virtual_machine_response.stubs(:body).returns(virtual_machine_xml)
101
- virtual_machine_response
102
- end
103
- let(:deployment_error_response) do
104
- http_error_response = mock
105
- http_error_response.stubs(:body).returns(deployment_error_xml)
106
- http_error_response
107
- end
108
- let(:cloud_service_response_body) { Nokogiri::XML cloud_service_response.body }
109
- let(:virtual_machine_response_body) { Nokogiri::XML virtual_machine_response.body }
110
-
111
- before do
112
- Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(verb, request_path, anything).returns(mock_cloud_service_request)
113
- mock_cloud_service_request.expects(:call).returns(cloud_service_response_body)
114
- Azure::BaseManagement::ManagementHttpRequest.stubs(:new)
115
- .with(verb, regexp_matches(/\/services\/hostedservices\/(.+)\/deploymentslots\/production/), anything)
116
- .returns(mock_virtual_machine_request)
117
- mock_virtual_machine_request.stubs(:warn=).returns(true).twice
118
- mock_virtual_machine_request.expects(:call).twice.returns(virtual_machine_response_body).returns(Nokogiri::XML deployment_error_response.body)
119
- end
120
-
121
- it 'assembles a URI for the request' do
122
- subject.list_virtual_machines
123
- end
124
-
125
- it "returns a virtual_machine, with it's attribute populated" do
126
- virtual_machine = subject.list_virtual_machines.first
127
- virtual_machine.vm_name.must_equal 'instance-name'
128
- virtual_machine.role_size.must_equal 'Small'
129
- virtual_machine.hostname.must_equal 'host-name'
130
- virtual_machine.cloud_service_name.must_equal 'cloud-service-1'
131
- virtual_machine.deployment_name.must_equal 'deployment-name'
132
- virtual_machine.ipaddress.must_equal '137.116.17.187'
133
- virtual_machine.virtual_network_name.must_equal 'test-virtual-network'
134
- virtual_machine.subnet.must_equal 'test-subnet'
135
- virtual_machine.static_virtual_network_ipaddress.must_equal '100.65.164.123'
136
- end
137
-
138
- it 'returns a list of virtual machines for the subscription' do
139
- results = subject.list_virtual_machines
140
- results.must_be_kind_of Array
141
- results.length.must_equal 1
142
- results.first.must_be_kind_of VirtualMachine
143
- end
144
-
145
- it "returns a virtual_machine, with it's tcp_endpoints attribute" do
146
- virtual_machine = subject.list_virtual_machines.first
147
- virtual_machine.tcp_endpoints.must_be_kind_of Array
148
- virtual_machine.tcp_endpoints.must_include(
149
- name: 'SSH',
150
- vip: '137.116.17.187',
151
- public_port: '22',
152
- local_port: '22',
153
- protocol: 'tcp'
154
- )
155
- virtual_machine.tcp_endpoints.must_include(
156
- name: 'tcp-port-80',
157
- vip: '137.117.17.187',
158
- public_port: '80',
159
- local_port: '80',
160
- protocol: 'tcp'
161
- )
162
- virtual_machine.tcp_endpoints.must_include(
163
- name: 'tcp-port-3889',
164
- vip: '137.116.17.187',
165
- public_port: '3889',
166
- local_port: '3889',
167
- protocol: 'tcp'
168
- )
169
- end
170
- end
171
-
172
- describe '#get_virtual_machine' do
173
-
174
- before do
175
- Azure::Loggerx.stubs(:info).returns(nil)
176
- Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
177
- virtual_machine = VirtualMachine.new do |vm|
178
- vm.vm_name = 'instance-name'
179
- vm.cloud_service_name = 'cloud-service-1'
180
- end
181
- Azure::VirtualMachineManagementService.any_instance.stubs(
182
- :list_virtual_machines
183
- ).returns([virtual_machine])
184
- end
185
-
186
- it 'return nil if virtual machine and cloud server does not exist ' do
187
- virtual_machine = subject.get_virtual_machine 'name', 'cloud-service'
188
- virtual_machine.must_equal nil
189
- end
190
-
191
- it 'return nil if virtual machine or cloud server does not exist ' do
192
- vm = subject.get_virtual_machine 'name', 'cloud-service-1'
193
- vm.must_equal nil
194
- vm = subject.get_virtual_machine 'name2', 'cloud_service_name'
195
- vm.must_equal nil
196
- end
197
-
198
- it 'return virtual machine instance if virtual machine name and cloud server name are valid ' do
199
- vm = subject.get_virtual_machine 'instance-name', 'cloud-service-1'
200
- vm.must_be_kind_of VirtualMachine
201
- end
202
- end
203
-
204
- describe '#create_virtual_machine' do
205
- let(:verb) { :get }
206
-
207
- before do
208
- Azure::Loggerx.expects(:error_with_exit).returns(nil).at_least(0)
209
- mock_request = mock
210
- Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
211
- verb,
212
- location_request_path,
213
- anything
214
- ).returns(mock_request)
215
- mock_request.expects(:call).returns(location_response_body).at_least(0)
216
- Azure::CloudServiceManagementService.any_instance.stubs(:create_cloud_service)
217
- Azure::CloudServiceManagementService.any_instance.stubs(:upload_certificate)
218
- Azure::StorageManagementService.any_instance.stubs(:create_storage_account)
219
- mock_request = mock
220
- Azure::BaseManagement::ManagementHttpRequest.expects(:new).with(
221
- :post,
222
- anything,
223
- anything
224
- ).returns(mock_request)
225
- mock_request.expects(:call).returns(nil)
226
- virtual_machine = VirtualMachine.new do |vm|
227
- vm.vm_name = 'instance-name'
228
- vm.ipaddress = '192.168.1.1'
229
- end
230
- Azure::VirtualMachineManagementService.stubs(
231
- :get_virtual_machine
232
- ).returns(virtual_machine)
233
- end
234
-
235
- it 'should set options hash with valid cloud_service_name, deployment_name, storage_account_name.' do
236
- options = {}
237
- subject.create_virtual_machine(params, options)
238
- csn = options[:cloud_service_name]
239
- csn.wont_be_nil
240
- options[:storage_account_name].wont_be_nil
241
- options[:deployment_name].wont_be_nil
242
- options[:os_type].must_equal 'Linux'
243
- assert_match(/^#{params[:vm_name] + '-service'}*/, csn)
244
- end
245
-
246
- it 'should set options hash with valid cloud service name.' do
247
- options = {
248
- storage_account_name: 'storage_account_name',
249
- deployment_name: 'unique_deployment_name',
250
- tcp_endpoints: '80,3889:3889'
251
- }
252
- subject.create_virtual_machine(params, options)
253
- csn = options[:cloud_service_name]
254
- csn.wont_be_nil
255
- assert_match(/^#{params[:vm_name] + '-service-'}*/, csn)
256
- options[:os_type].must_equal 'Linux'
257
- end
258
-
259
- end
260
-
261
- describe '#create_virtual_machine with invalid parameters for windows machine' do
262
- let(:virtual_machine_xml) { Fixtures['virtual_machine'] }
263
- let(:verb) { :get }
264
-
265
- before do
266
- windows_params[:cloud_service_name] = 'cloud-service-1'
267
- mock_request = mock
268
- Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
269
- verb,
270
- location_request_path,
271
- anything
272
- ).returns(mock_request)
273
- mock_request.expects(:call).returns(location_response_body).at_least(0)
274
- Azure::CloudServiceManagementService.any_instance.stubs(:create_cloud_service)
275
- Azure::CloudServiceManagementService.any_instance.stubs(:upload_certificate)
276
- Azure::StorageManagementService.any_instance.stubs(:create_storage_account)
277
- mock_request = mock
278
- Azure::BaseManagement::ManagementHttpRequest.expects(:new).with(
279
- :post,
280
- anything,
281
- anything
282
- ).returns(mock_request).at_least(0)
283
- mock_request.expects(:call).returns(nil).at_least(0)
284
- virtual_machine_obj = VirtualMachine.new do |virtual_machine|
285
- virtual_machine.vm_name = 'windows-instance'
286
- virtual_machine.ipaddress = '192.168.1.1'
287
- end
288
- Azure::VirtualMachineManagementService.any_instance.stubs(
289
- :get_virtual_machine
290
- ).returns(virtual_machine_obj)
291
- end
292
-
293
- it 'should set options os_type with windows.' do
294
- options = {}
295
- subject.create_virtual_machine(windows_params, options)
296
- csn = options[:cloud_service_name]
297
- csn.wont_be_nil
298
- options[:storage_account_name].wont_be_nil
299
- options[:deployment_name].wont_be_nil
300
- options[:os_type].must_equal 'Windows'
301
- assert_match(/^#{params[:vm_name] + '-service'}*/, csn)
302
- end
303
-
304
- it 'throws error when vm_user is not given' do
305
- windows_params.delete(:vm_user)
306
- options = {}
307
- ex = assert_raises(RuntimeError) {subject.create_virtual_machine(windows_params, options)}
308
- error_msg = "You did not provide a valid 'vm_user' value"
309
- assert_match(/#{error_msg}*/,ex.message)
310
- end
311
-
312
- it 'self-signed certificate is generated by vm and used for the virtual machine when certificate path is not given.' do
313
- options = {winrm_transport: %w(https http)}
314
- virtual_machine = subject.create_virtual_machine(windows_params, options)
315
- virtual_machine.wont_be_nil
316
- end
317
-
318
- it 'throws error when certificate path is not invalid.' do
319
- options = {
320
- winrm_transport: %w(https http),
321
- private_key_file: 'c:/invalid_path/private_key',
322
- certificate_file: 'c:/invalid_path/certificate.pem'
323
- }
324
- ex = assert_raises(RuntimeError) {subject.create_virtual_machine(windows_params, options)}
325
- error_msg = 'No such file or directory -'
326
- assert_match(/#{error_msg}*/,ex.message)
327
- end
328
-
329
- it 'should not throws certificate error when wirnm_transport is http' do
330
- options = {
331
- winrm_transport: ['http'],
332
- private_key_file: 'c:/invalid_path/private_key',
333
- certificate_file: 'c:/invalid_path/certificate.pem'
334
- }
335
- virtual_machine = subject.create_virtual_machine(windows_params, options)
336
- virtual_machine.must_be_kind_of VirtualMachine
337
- virtual_machine.wont_be_nil
338
- end
339
-
340
- it 'throws error when location is not given' do
341
- params.delete(:location)
342
- ex=assert_raises(RuntimeError){subject.create_virtual_machine(params)}
343
- error_msg = "You did not provide a valid 'location' value"
344
- assert_match(/#{error_msg}*/,ex.message)
345
- end
346
-
347
- it 'throws error when wrong location is given' do
348
- params.merge!(location: 'wrong location')
349
- ex = assert_raises(RuntimeError) {subject.create_virtual_machine(params)}
350
- error_msg = "Value 'wrong location' specified for parameter 'location' is invalid"
351
- assert_match(/#{error_msg}*/,ex.message)
352
- end
353
-
354
- it 'throws error when empty location is given' do
355
- params.merge!(location: nil)
356
- ex = assert_raises(RuntimeError) {subject.create_virtual_machine(params)}
357
- error_msg = "You did not provide a valid 'location' value"
358
- assert_match(/#{error_msg}*/,ex.message)
359
- end
360
-
361
- it 'location should be case insensitive' do
362
- params.merge!(location: 'west us')
363
- subject.create_virtual_machine(params)
364
- end
365
-
366
- it 'throw error when available_services has not persistentvmrole for given location' do
367
- params.merge!(location: 'West Europe')
368
- ex = assert_raises(RuntimeError) {subject.create_virtual_machine(params)}
369
- error_msg = 'Persistentvmrole not enabled for "West Europe"'
370
- assert_match(/#{error_msg}*/,ex.message)
371
- end
372
-
373
- it 'warns if vm_size is not in the correct case' do
374
- options = {
375
- vm_size: 'extralarge'
376
- }
377
-
378
- out, err = capture_io do
379
- msg = subject.create_virtual_machine(params, options)
380
- end
381
- error_msg = "'extralarge' specified for parameter 'vm_size' is not in the list of valid VM role sizes."
382
- assert_match(/#{error_msg}*/, out)
383
- end
384
-
385
- it 'warns when wrong role size is given' do
386
- options = {
387
- vm_size: 'wrong size'
388
- }
389
- out, err = capture_io do
390
- virtual_machine = subject.create_virtual_machine(params, options)
391
- end
392
- error_msg = "'wrong size' specified for parameter 'vm_size' is not in the list of valid VM role sizes."
393
- assert_match(/#{error_msg}*/, out)
394
- end
395
-
396
- it 'should warn if role size is empty' do
397
- options = {
398
- vm_size: ''
399
- }
400
- out, err = capture_io do
401
- subject.create_virtual_machine(params, options)
402
- end
403
- error_msg = "'' specified for parameter 'vm_size' is not in the list of valid VM role sizes."
404
- assert_match(/#{error_msg}*/, out)
405
- end
406
- end
407
-
408
- describe '#get_image' do
409
-
410
- before do
411
- Azure::Loggerx.stubs(:info).returns(nil)
412
- Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
413
- subject.class.send(:public, *subject.class.private_instance_methods)
414
- end
415
-
416
- it 'returns os type of given virtual machine image' do
417
- result = subject.get_image 'RightImage-CentOS-6.2-x64-v5.8.8.1'
418
- result.os_type.must_equal 'Linux'
419
- end
420
-
421
- it 'errors if the virtual machine image does not exist' do
422
- exception = assert_raises(RuntimeError) do
423
- subject.get_image 'invalid-image-name'
424
- end
425
- error_msg = 'The virtual machine image source is not valid'
426
- assert_match(/#{error_msg}/i, exception.message)
427
- end
428
- end
429
-
430
- describe '#add_role' do
431
-
432
- let(:verb) { :get }
433
-
434
- before do
435
- Azure::Loggerx.stubs(:info).returns(nil)
436
- Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
437
- windows_params[:cloud_service_name] = 'cloud-service-1'
438
- mock_request = mock
439
- Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
440
- verb,
441
- location_request_path,
442
- anything
443
- ).returns(mock_request)
444
- mock_request.expects(:call).returns(location_response_body).at_least(0)
445
- end
446
-
447
- it 'should throws error when cloud service name is empty' do
448
- windows_params.delete(:cloud_service_name)
449
- exception = assert_raises(RuntimeError) do
450
- subject.add_role(params)
451
- end
452
- error_msg = 'You did not provide a valid \'cloud_service_name\' value'
453
- assert_match(/#{error_msg}/i, exception.message)
454
- end
455
-
456
- it 'throws error when vm_user is not given' do
457
- windows_params.delete(:vm_user)
458
- exception = assert_raises(RuntimeError) do
459
- subject.add_role(windows_params)
460
- end
461
- error_msg = 'You did not provide a valid \'vm_user\' value'
462
- assert_match(/#{error_msg}/i, exception.message)
463
- end
464
-
465
- it 'throws error when certificate path is not invalid.' do
466
- options = {
467
- winrm_transport: %w(https http),
468
- private_key_file: 'c:/invalid_path/private_key',
469
- certificate_file: 'c:/invalid_path/certificate.pem'
470
- }
471
- exception = assert_raises(RuntimeError) do
472
- subject.add_role(windows_params, options)
473
- end
474
- error_msg = 'No such file or directory'
475
- assert_match(/#{error_msg}/i, exception.message)
476
- end
477
-
478
- end
479
-
480
- end