juliusl-azure-sdk-for-ruby 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env_sample +11 -0
- data/.gitignore +15 -0
- data/.travis.yml +13 -0
- data/ChangeLog.txt +56 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +202 -0
- data/README.md +630 -0
- data/Rakefile +121 -0
- data/azure.gemspec +47 -0
- data/bin/pfxer +35 -0
- data/lib/azure.rb +60 -0
- data/lib/azure/base_management/affinity_group.rb +32 -0
- data/lib/azure/base_management/base_management_service.rb +245 -0
- data/lib/azure/base_management/location.rb +27 -0
- data/lib/azure/base_management/management_http_request.rb +175 -0
- data/lib/azure/base_management/serialization.rb +135 -0
- data/lib/azure/base_management/sql_management_http_request.rb +45 -0
- data/lib/azure/blob/auth/shared_access_signature.rb +141 -0
- data/lib/azure/blob/blob.rb +32 -0
- data/lib/azure/blob/blob_service.rb +1427 -0
- data/lib/azure/blob/block.rb +31 -0
- data/lib/azure/blob/container.rb +32 -0
- data/lib/azure/blob/serialization.rb +285 -0
- data/lib/azure/cloud_service_management/cloud_service.rb +38 -0
- data/lib/azure/cloud_service_management/cloud_service_management_service.rb +137 -0
- data/lib/azure/cloud_service_management/serialization.rb +118 -0
- data/lib/azure/core.rb +41 -0
- data/lib/azure/core/auth/authorizer.rb +36 -0
- data/lib/azure/core/auth/shared_key.rb +110 -0
- data/lib/azure/core/auth/shared_key_lite.rb +48 -0
- data/lib/azure/core/auth/signer.rb +52 -0
- data/lib/azure/core/configuration.rb +218 -0
- data/lib/azure/core/error.rb +22 -0
- data/lib/azure/core/filtered_service.rb +44 -0
- data/lib/azure/core/http/debug_filter.rb +36 -0
- data/lib/azure/core/http/http_error.rb +88 -0
- data/lib/azure/core/http/http_filter.rb +53 -0
- data/lib/azure/core/http/http_request.rb +160 -0
- data/lib/azure/core/http/http_response.rb +140 -0
- data/lib/azure/core/http/retry_policy.rb +74 -0
- data/lib/azure/core/http/signer_filter.rb +34 -0
- data/lib/azure/core/service.rb +63 -0
- data/lib/azure/core/signed_service.rb +43 -0
- data/lib/azure/core/utility.rb +242 -0
- data/lib/azure/queue/message.rb +30 -0
- data/lib/azure/queue/queue.rb +29 -0
- data/lib/azure/queue/queue_service.rb +568 -0
- data/lib/azure/queue/serialization.rb +106 -0
- data/lib/azure/service/access_policy.rb +26 -0
- data/lib/azure/service/cors.rb +11 -0
- data/lib/azure/service/cors_rule.rb +15 -0
- data/lib/azure/service/enumeration_results.rb +21 -0
- data/lib/azure/service/logging.rb +32 -0
- data/lib/azure/service/metrics.rb +31 -0
- data/lib/azure/service/retention_policy.rb +25 -0
- data/lib/azure/service/serialization.rb +299 -0
- data/lib/azure/service/signed_identifier.rb +30 -0
- data/lib/azure/service/storage_service.rb +83 -0
- data/lib/azure/service/storage_service_properties.rb +37 -0
- data/lib/azure/service_bus/action.rb +21 -0
- data/lib/azure/service_bus/auth/wrap_service.rb +89 -0
- data/lib/azure/service_bus/auth/wrap_signer.rb +69 -0
- data/lib/azure/service_bus/brokered_message.rb +124 -0
- data/lib/azure/service_bus/brokered_message_serializer.rb +159 -0
- data/lib/azure/service_bus/correlation_filter.rb +45 -0
- data/lib/azure/service_bus/empty_rule_action.rb +30 -0
- data/lib/azure/service_bus/false_filter.rb +38 -0
- data/lib/azure/service_bus/filter.rb +21 -0
- data/lib/azure/service_bus/interval.rb +104 -0
- data/lib/azure/service_bus/queue.rb +230 -0
- data/lib/azure/service_bus/relay.rb +88 -0
- data/lib/azure/service_bus/resource.rb +109 -0
- data/lib/azure/service_bus/rule.rb +98 -0
- data/lib/azure/service_bus/rule_aspect.rb +34 -0
- data/lib/azure/service_bus/serialization.rb +161 -0
- data/lib/azure/service_bus/service_bus_service.rb +895 -0
- data/lib/azure/service_bus/sql_filter.rb +50 -0
- data/lib/azure/service_bus/sql_rule_action.rb +50 -0
- data/lib/azure/service_bus/subscription.rb +184 -0
- data/lib/azure/service_bus/topic.rb +187 -0
- data/lib/azure/service_bus/true_filter.rb +38 -0
- data/lib/azure/sql_database_management/serialization.rb +112 -0
- data/lib/azure/sql_database_management/sql_database.rb +31 -0
- data/lib/azure/sql_database_management/sql_database_management_service.rb +200 -0
- data/lib/azure/storage_management/serialization.rb +204 -0
- data/lib/azure/storage_management/storage_account.rb +48 -0
- data/lib/azure/storage_management/storage_management_service.rb +208 -0
- data/lib/azure/table/auth/shared_key.rb +92 -0
- data/lib/azure/table/auth/shared_key_lite.rb +44 -0
- data/lib/azure/table/batch.rb +330 -0
- data/lib/azure/table/batch_response.rb +118 -0
- data/lib/azure/table/edmtype.rb +127 -0
- data/lib/azure/table/entity.rb +31 -0
- data/lib/azure/table/guid.rb +24 -0
- data/lib/azure/table/query.rb +112 -0
- data/lib/azure/table/serialization.rb +108 -0
- data/lib/azure/table/table_service.rb +560 -0
- data/lib/azure/version.rb +31 -0
- data/lib/azure/virtual_machine_image_management/serialization.rb +70 -0
- data/lib/azure/virtual_machine_image_management/virtual_machine_disk.rb +25 -0
- data/lib/azure/virtual_machine_image_management/virtual_machine_image.rb +25 -0
- data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +89 -0
- data/lib/azure/virtual_machine_management/serialization.rb +459 -0
- data/lib/azure/virtual_machine_management/virtual_machine.rb +44 -0
- data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +554 -0
- data/lib/azure/virtual_network_management/serialization.rb +193 -0
- data/lib/azure/virtual_network_management/virtual_network.rb +37 -0
- data/lib/azure/virtual_network_management/virtual_network_management_service.rb +109 -0
- data/test/fixtures/32px-fulls-black.jpg +0 -0
- data/test/fixtures/affinity_group.xml +33 -0
- data/test/fixtures/all_containers.xml +20 -0
- data/test/fixtures/all_tables.xml +22 -0
- data/test/fixtures/container_acl.xml +11 -0
- data/test/fixtures/create_sql_database_server.xml +2 -0
- data/test/fixtures/create_storage_desc_error.xml +5 -0
- data/test/fixtures/create_storage_extendedprop_error.xml +8 -0
- data/test/fixtures/create_storage_extendedpropname_error.xml +6 -0
- data/test/fixtures/create_storage_full_error.xml +6 -0
- data/test/fixtures/create_storage_label_error.xml +5 -0
- data/test/fixtures/create_storage_location_error.xml +5 -0
- data/test/fixtures/create_storage_name_error.xml +6 -0
- data/test/fixtures/create_table_response_entry.xml +15 -0
- data/test/fixtures/delete_storage_container_error.xml +5 -0
- data/test/fixtures/delete_storage_error.xml +5 -0
- data/test/fixtures/deployment_error.xml +5 -0
- data/test/fixtures/empty_xml_file +0 -0
- data/test/fixtures/get_storage_account_error.xml +5 -0
- data/test/fixtures/get_storage_account_properties.xml +34 -0
- data/test/fixtures/get_storage_account_properties_new.xml +32 -0
- data/test/fixtures/http_error.xml +5 -0
- data/test/fixtures/insert_entity_response_entry.xml +25 -0
- data/test/fixtures/list_affinity_groups.xml +22 -0
- data/test/fixtures/list_blobs.xml +121 -0
- data/test/fixtures/list_block_all_with_none_committed.xml +22 -0
- data/test/fixtures/list_blocks_all.xml +23 -0
- data/test/fixtures/list_blocks_committed.xml +13 -0
- data/test/fixtures/list_cloud_services.xml +39 -0
- data/test/fixtures/list_containers.xml +38 -0
- data/test/fixtures/list_firewall_management_endpoint.xml +27 -0
- data/test/fixtures/list_locations.xml +212 -0
- data/test/fixtures/list_os_images.xml +110 -0
- data/test/fixtures/list_page_ranges.xml +11 -0
- data/test/fixtures/list_sql_database.xml +36 -0
- data/test/fixtures/list_sql_server_firewall.xml +23 -0
- data/test/fixtures/list_storage_account_single.xml +25 -0
- data/test/fixtures/list_storage_accounts.xml +48 -0
- data/test/fixtures/list_virtual_networks.xml +92 -0
- data/test/fixtures/list_vm_images.xml +21 -0
- data/test/fixtures/logging.xml +11 -0
- data/test/fixtures/messages.xml +12 -0
- data/test/fixtures/metrics.xml +10 -0
- data/test/fixtures/privatekey.key +28 -0
- data/test/fixtures/query_entities_empty_response.xml +7 -0
- data/test/fixtures/query_entities_response.xml +45 -0
- data/test/fixtures/queue_service_properties.xml +22 -0
- data/test/fixtures/queue_service_properties_original.xml +19 -0
- data/test/fixtures/queues.xml +16 -0
- data/test/fixtures/retention_policy.xml +5 -0
- data/test/fixtures/sb_default_create_queue_response.xml +23 -0
- data/test/fixtures/sb_default_create_relay_response.xml +15 -0
- data/test/fixtures/sb_default_create_topic_response.xml +18 -0
- data/test/fixtures/sb_get_access_token_response.txt +1 -0
- data/test/fixtures/sb_queues_runtime_peek_message_response_headers.txt +9 -0
- data/test/fixtures/storage_service_keys.xml +8 -0
- data/test/fixtures/storage_service_properties.xml +55 -0
- data/test/fixtures/update_storage_account.xml +16 -0
- data/test/fixtures/update_storage_error.xml +5 -0
- data/test/fixtures/updated_storage_accounts.xml +55 -0
- data/test/fixtures/virtual_machine.xml +116 -0
- data/test/fixtures/windows_virtual_machine.xml +106 -0
- data/test/integration/affinity_group/Affinity_test.rb +55 -0
- data/test/integration/affinity_group/Create_Affinity_test.rb +64 -0
- data/test/integration/affinity_group/Delete_Affinity_test.rb +56 -0
- data/test/integration/affinity_group/List_Affinity_test.rb +41 -0
- data/test/integration/affinity_group/Update_Affinity_test.rb +83 -0
- data/test/integration/blob/blob_gb18030_test.rb +199 -0
- data/test/integration/blob/blob_metadata_test.rb +75 -0
- data/test/integration/blob/blob_pages_test.rb +119 -0
- data/test/integration/blob/blob_properties_test.rb +77 -0
- data/test/integration/blob/block_blob_test.rb +254 -0
- data/test/integration/blob/container/container_acl_test.rb +69 -0
- data/test/integration/blob/container/container_metadata_test.rb +50 -0
- data/test/integration/blob/container/create_container_test.rb +60 -0
- data/test/integration/blob/container/delete_container_test.rb +39 -0
- data/test/integration/blob/container/get_container_properties_test.rb +48 -0
- data/test/integration/blob/container/list_containers_test.rb +79 -0
- data/test/integration/blob/container/root_container_test.rb +54 -0
- data/test/integration/blob/copy_blob_test.rb +113 -0
- data/test/integration/blob/create_blob_snapshot_test.rb +80 -0
- data/test/integration/blob/create_page_blob_test.rb +83 -0
- data/test/integration/blob/delete_blob_test.rb +159 -0
- data/test/integration/blob/get_blob_test.rb +65 -0
- data/test/integration/blob/informative_errors_test.rb +39 -0
- data/test/integration/blob/lease/acquire_lease_test.rb +36 -0
- data/test/integration/blob/lease/break_lease_test.rb +40 -0
- data/test/integration/blob/lease/release_lease_test.rb +40 -0
- data/test/integration/blob/lease/renew_lease_test.rb +42 -0
- data/test/integration/blob/list_blobs_test.rb +113 -0
- data/test/integration/cloud_service/Cloud_Create_test.rb +45 -0
- data/test/integration/cloud_service/Cloud_Delete_test.rb +45 -0
- data/test/integration/database/create_sql_server_firewall_test.rb +86 -0
- data/test/integration/database/create_sql_server_test.rb +53 -0
- data/test/integration/database/delete_sql_server_firewall_test.rb +70 -0
- data/test/integration/database/delete_sql_server_test.rb +58 -0
- data/test/integration/database/list_sql_server_firewall_test.rb +45 -0
- data/test/integration/database/list_sql_servers_test.rb +44 -0
- data/test/integration/database/reset_password_sql_server_test.rb +55 -0
- data/test/integration/location/Location_List_test.rb +39 -0
- data/test/integration/location/RoleSize_List_test.rb +35 -0
- data/test/integration/queue/clear_messages_test.rb +42 -0
- data/test/integration/queue/create_message_test.rb +75 -0
- data/test/integration/queue/create_queue_test.rb +50 -0
- data/test/integration/queue/delete_message_test.rb +67 -0
- data/test/integration/queue/delete_queue_test.rb +45 -0
- data/test/integration/queue/informative_errors_test.rb +42 -0
- data/test/integration/queue/list_messages_encoded_test.rb +79 -0
- data/test/integration/queue/list_messages_test.rb +79 -0
- data/test/integration/queue/list_queues_test.rb +44 -0
- data/test/integration/queue/peek_messages_test.rb +59 -0
- data/test/integration/queue/queue_gb18030_test.rb +131 -0
- data/test/integration/queue/queue_metadata_test.rb +40 -0
- data/test/integration/queue/update_message_test.rb +74 -0
- data/test/integration/service_bus/informative_errors_test.rb +37 -0
- data/test/integration/service_bus/queues_scenario_test.rb +200 -0
- data/test/integration/service_bus/queues_test.rb +266 -0
- data/test/integration/service_bus/relay_test.rb +132 -0
- data/test/integration/service_bus/rules_test.rb +145 -0
- data/test/integration/service_bus/sb_queue_gb18030_test.rb +182 -0
- data/test/integration/service_bus/scenario_test.rb +101 -0
- data/test/integration/service_bus/subscriptions_test.rb +211 -0
- data/test/integration/service_bus/topics_scenario_test.rb +406 -0
- data/test/integration/service_bus/topics_test.rb +129 -0
- data/test/integration/storage_management/storage_management_test.rb +185 -0
- data/test/integration/table/create_table_test.rb +36 -0
- data/test/integration/table/delete_entity_batch_test.rb +107 -0
- data/test/integration/table/delete_entity_test.rb +94 -0
- data/test/integration/table/delete_table_test.rb +40 -0
- data/test/integration/table/get_table_test.rb +37 -0
- data/test/integration/table/informative_errors_test.rb +39 -0
- data/test/integration/table/insert_entity_batch_test.rb +100 -0
- data/test/integration/table/insert_entity_test.rb +88 -0
- data/test/integration/table/insert_or_merge_entity_batch_test.rb +159 -0
- data/test/integration/table/insert_or_merge_entity_test.rb +143 -0
- data/test/integration/table/insert_or_replace_entity_batch_test.rb +152 -0
- data/test/integration/table/insert_or_replace_entity_test.rb +137 -0
- data/test/integration/table/merge_entity_batch_test.rb +128 -0
- data/test/integration/table/merge_entity_test.rb +113 -0
- data/test/integration/table/query_entities_test.rb +195 -0
- data/test/integration/table/query_tables_test.rb +43 -0
- data/test/integration/table/query_test.rb +251 -0
- data/test/integration/table/table_acl_test.rb +52 -0
- data/test/integration/table/table_gb18030_test.rb +355 -0
- data/test/integration/table/update_entity_batch_test.rb +149 -0
- data/test/integration/table/update_entity_test.rb +131 -0
- data/test/integration/test_helper.rb +38 -0
- data/test/integration/vm/VM_Create_test.rb +262 -0
- data/test/integration/vm/VM_Delete_test.rb +53 -0
- data/test/integration/vm/VM_Operations_test.rb +172 -0
- data/test/integration/vm_image/virtual_machine_disk_test.rb +37 -0
- data/test/integration/vm_image/virtual_machine_image_test.rb +37 -0
- data/test/integration/vnet/Virtual_Network_Create_test.rb +116 -0
- data/test/integration/vnet/Virtual_Network_list_test.rb +48 -0
- data/test/support/env.rb +19 -0
- data/test/support/fixtures.rb +36 -0
- data/test/support/name_generator.rb +168 -0
- data/test/support/stubs.rb +42 -0
- data/test/support/virtual_machine_name_generator.rb +102 -0
- data/test/support/virtual_network_helper.rb +73 -0
- data/test/test_helper.rb +44 -0
- data/test/unit/affinity_group/affinity_group_test.rb +189 -0
- data/test/unit/affinity_group/serialization_test.rb +87 -0
- data/test/unit/base_management/location_test.rb +56 -0
- data/test/unit/base_management/role_size_test.rb +50 -0
- data/test/unit/blob/auth/shared_access_signature_test.rb +71 -0
- data/test/unit/blob/blob_service_test.rb +1969 -0
- data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +94 -0
- data/test/unit/cloud_service_management/serialization_test.rb +169 -0
- data/test/unit/core/auth/shared_key_lite_test.rb +51 -0
- data/test/unit/core/auth/shared_key_test.rb +58 -0
- data/test/unit/core/auth/signer_test.rb +30 -0
- data/test/unit/core/http/http_error_test.rb +62 -0
- data/test/unit/core/http/http_request_test.rb +113 -0
- data/test/unit/core/http/http_response_test.rb +45 -0
- data/test/unit/core/http/retry_policy_test.rb +23 -0
- data/test/unit/core/utility_test.rb +122 -0
- data/test/unit/database/serialization_test.rb +97 -0
- data/test/unit/database/sql_database_server_service_test.rb +284 -0
- data/test/unit/service/serialization_test.rb +533 -0
- data/test/unit/service/storage_service_test.rb +293 -0
- data/test/unit/storage_management/serialization_test.rb +244 -0
- data/test/unit/storage_management/storage_management_service_test.rb +247 -0
- data/test/unit/table/edmtype_test.rb +108 -0
- data/test/unit/virtual_machine_image_management/serialization_test.rb +50 -0
- data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +114 -0
- data/test/unit/virtual_machine_management/serialization_test.rb +316 -0
- data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +478 -0
- data/test/unit/vnet/serialization_test.rb +187 -0
- data/test/unit/vnet/virtual_network_management_service_test.rb +131 -0
- metadata +512 -0
@@ -0,0 +1,316 @@
|
|
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
|
@@ -0,0 +1,478 @@
|
|
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
|
+
nil
|
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
|
+
nil
|
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, nil).returns(mock_cloud_service_request)
|
113
|
+
mock_cloud_service_request.expects(:call).returns(cloud_service_response_body)
|
114
|
+
Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(verb, anything).returns(mock_virtual_machine_request)
|
115
|
+
mock_virtual_machine_request.stubs(:warn=).returns(true).twice
|
116
|
+
mock_virtual_machine_request.expects(:call).twice.returns(virtual_machine_response_body).returns(Nokogiri::XML deployment_error_response.body)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'assembles a URI for the request' do
|
120
|
+
subject.list_virtual_machines
|
121
|
+
end
|
122
|
+
|
123
|
+
it "returns a virtual_machine, with it's attribute populated" do
|
124
|
+
virtual_machine = subject.list_virtual_machines.first
|
125
|
+
virtual_machine.vm_name.must_equal 'instance-name'
|
126
|
+
virtual_machine.role_size.must_equal 'Small'
|
127
|
+
virtual_machine.hostname.must_equal 'host-name'
|
128
|
+
virtual_machine.cloud_service_name.must_equal 'cloud-service-1'
|
129
|
+
virtual_machine.deployment_name.must_equal 'deployment-name'
|
130
|
+
virtual_machine.ipaddress.must_equal '137.116.17.187'
|
131
|
+
virtual_machine.virtual_network_name.must_equal 'test-virtual-network'
|
132
|
+
virtual_machine.subnet.must_equal 'test-subnet'
|
133
|
+
virtual_machine.static_virtual_network_ipaddress.must_equal '100.65.164.123'
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'returns a list of virtual machines for the subscription' do
|
137
|
+
results = subject.list_virtual_machines
|
138
|
+
results.must_be_kind_of Array
|
139
|
+
results.length.must_equal 1
|
140
|
+
results.first.must_be_kind_of VirtualMachine
|
141
|
+
end
|
142
|
+
|
143
|
+
it "returns a virtual_machine, with it's tcp_endpoints attribute" do
|
144
|
+
virtual_machine = subject.list_virtual_machines.first
|
145
|
+
virtual_machine.tcp_endpoints.must_be_kind_of Array
|
146
|
+
virtual_machine.tcp_endpoints.must_include(
|
147
|
+
name: 'SSH',
|
148
|
+
vip: '137.116.17.187',
|
149
|
+
public_port: '22',
|
150
|
+
local_port: '22',
|
151
|
+
protocol: 'tcp'
|
152
|
+
)
|
153
|
+
virtual_machine.tcp_endpoints.must_include(
|
154
|
+
name: 'tcp-port-80',
|
155
|
+
vip: '137.117.17.187',
|
156
|
+
public_port: '80',
|
157
|
+
local_port: '80',
|
158
|
+
protocol: 'tcp'
|
159
|
+
)
|
160
|
+
virtual_machine.tcp_endpoints.must_include(
|
161
|
+
name: 'tcp-port-3889',
|
162
|
+
vip: '137.116.17.187',
|
163
|
+
public_port: '3889',
|
164
|
+
local_port: '3889',
|
165
|
+
protocol: 'tcp'
|
166
|
+
)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe '#get_virtual_machine' do
|
171
|
+
|
172
|
+
before do
|
173
|
+
Azure::Loggerx.stubs(:info).returns(nil)
|
174
|
+
Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
|
175
|
+
virtual_machine = VirtualMachine.new do |vm|
|
176
|
+
vm.vm_name = 'instance-name'
|
177
|
+
vm.cloud_service_name = 'cloud-service-1'
|
178
|
+
end
|
179
|
+
Azure::VirtualMachineManagementService.any_instance.stubs(
|
180
|
+
:list_virtual_machines
|
181
|
+
).returns([virtual_machine])
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'return nil if virtual machine and cloud server does not exist ' do
|
185
|
+
virtual_machine = subject.get_virtual_machine 'name', 'cloud-service'
|
186
|
+
virtual_machine.must_equal nil
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'return nil if virtual machine or cloud server does not exist ' do
|
190
|
+
vm = subject.get_virtual_machine 'name', 'cloud-service-1'
|
191
|
+
vm.must_equal nil
|
192
|
+
vm = subject.get_virtual_machine 'name2', 'cloud_service_name'
|
193
|
+
vm.must_equal nil
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'return virtual machine instance if virtual machine name and cloud server name are valid ' do
|
197
|
+
vm = subject.get_virtual_machine 'instance-name', 'cloud-service-1'
|
198
|
+
vm.must_be_kind_of VirtualMachine
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe '#create_virtual_machine' do
|
203
|
+
let(:verb) { :get }
|
204
|
+
|
205
|
+
before do
|
206
|
+
Azure::Loggerx.expects(:error_with_exit).returns(nil).at_least(0)
|
207
|
+
mock_request = mock
|
208
|
+
Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
|
209
|
+
verb,
|
210
|
+
location_request_path,
|
211
|
+
nil
|
212
|
+
).returns(mock_request)
|
213
|
+
mock_request.expects(:call).returns(location_response_body).at_least(0)
|
214
|
+
Azure::CloudServiceManagementService.any_instance.stubs(:create_cloud_service)
|
215
|
+
Azure::CloudServiceManagementService.any_instance.stubs(:upload_certificate)
|
216
|
+
Azure::StorageManagementService.any_instance.stubs(:create_storage_account)
|
217
|
+
mock_request = mock
|
218
|
+
Azure::BaseManagement::ManagementHttpRequest.expects(:new).with(
|
219
|
+
:post,
|
220
|
+
anything,
|
221
|
+
anything
|
222
|
+
).returns(mock_request)
|
223
|
+
mock_request.expects(:call).returns(nil)
|
224
|
+
virtual_machine = VirtualMachine.new do |vm|
|
225
|
+
vm.vm_name = 'instance-name'
|
226
|
+
vm.ipaddress = '192.168.1.1'
|
227
|
+
end
|
228
|
+
Azure::VirtualMachineManagementService.stubs(
|
229
|
+
:get_virtual_machine
|
230
|
+
).returns(virtual_machine)
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'should set options hash with valid cloud_service_name, deployment_name, storage_account_name.' do
|
234
|
+
options = {}
|
235
|
+
subject.create_virtual_machine(params, options)
|
236
|
+
csn = options[:cloud_service_name]
|
237
|
+
csn.wont_be_nil
|
238
|
+
options[:storage_account_name].wont_be_nil
|
239
|
+
options[:deployment_name].wont_be_nil
|
240
|
+
options[:os_type].must_equal 'Linux'
|
241
|
+
assert_match(/^#{params[:vm_name] + '-service'}*/, csn)
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'should set options hash with valid cloud service name.' do
|
245
|
+
options = {
|
246
|
+
storage_account_name: 'storage_account_name',
|
247
|
+
deployment_name: 'unique_deployment_name',
|
248
|
+
tcp_endpoints: '80,3889:3889'
|
249
|
+
}
|
250
|
+
subject.create_virtual_machine(params, options)
|
251
|
+
csn = options[:cloud_service_name]
|
252
|
+
csn.wont_be_nil
|
253
|
+
assert_match(/^#{params[:vm_name] + '-service-'}*/, csn)
|
254
|
+
options[:os_type].must_equal 'Linux'
|
255
|
+
end
|
256
|
+
|
257
|
+
end
|
258
|
+
|
259
|
+
describe '#create_virtual_machine with invalid parameters for windows machine' do
|
260
|
+
let(:virtual_machine_xml) { Fixtures['virtual_machine'] }
|
261
|
+
let(:verb) { :get }
|
262
|
+
|
263
|
+
before do
|
264
|
+
windows_params[:cloud_service_name] = 'cloud-service-1'
|
265
|
+
mock_request = mock
|
266
|
+
Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
|
267
|
+
verb,
|
268
|
+
location_request_path,
|
269
|
+
nil
|
270
|
+
).returns(mock_request)
|
271
|
+
mock_request.expects(:call).returns(location_response_body).at_least(0)
|
272
|
+
Azure::CloudServiceManagementService.any_instance.stubs(:create_cloud_service)
|
273
|
+
Azure::CloudServiceManagementService.any_instance.stubs(:upload_certificate)
|
274
|
+
Azure::StorageManagementService.any_instance.stubs(:create_storage_account)
|
275
|
+
mock_request = mock
|
276
|
+
Azure::BaseManagement::ManagementHttpRequest.expects(:new).with(
|
277
|
+
:post,
|
278
|
+
anything,
|
279
|
+
anything
|
280
|
+
).returns(mock_request).at_least(0)
|
281
|
+
mock_request.expects(:call).returns(nil).at_least(0)
|
282
|
+
virtual_machine_obj = VirtualMachine.new do |virtual_machine|
|
283
|
+
virtual_machine.vm_name = 'windows-instance'
|
284
|
+
virtual_machine.ipaddress = '192.168.1.1'
|
285
|
+
end
|
286
|
+
Azure::VirtualMachineManagementService.any_instance.stubs(
|
287
|
+
:get_virtual_machine
|
288
|
+
).returns(virtual_machine_obj)
|
289
|
+
end
|
290
|
+
|
291
|
+
it 'should set options os_type with windows.' do
|
292
|
+
options = {}
|
293
|
+
subject.create_virtual_machine(windows_params, options)
|
294
|
+
csn = options[:cloud_service_name]
|
295
|
+
csn.wont_be_nil
|
296
|
+
options[:storage_account_name].wont_be_nil
|
297
|
+
options[:deployment_name].wont_be_nil
|
298
|
+
options[:os_type].must_equal 'Windows'
|
299
|
+
assert_match(/^#{params[:vm_name] + '-service'}*/, csn)
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'throws error when vm_user is not given' do
|
303
|
+
windows_params.delete(:vm_user)
|
304
|
+
options = {}
|
305
|
+
ex = assert_raises(RuntimeError) {subject.create_virtual_machine(windows_params, options)}
|
306
|
+
error_msg = "You did not provide a valid 'vm_user' value"
|
307
|
+
assert_match(/#{error_msg}*/,ex.message)
|
308
|
+
end
|
309
|
+
|
310
|
+
it 'self-signed certificate is generated by vm and used for the virtual machine when certificate path is not given.' do
|
311
|
+
options = {winrm_transport: %w(https http)}
|
312
|
+
virtual_machine = subject.create_virtual_machine(windows_params, options)
|
313
|
+
virtual_machine.wont_be_nil
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'throws error when certificate path is not invalid.' do
|
317
|
+
options = {
|
318
|
+
winrm_transport: %w(https http),
|
319
|
+
private_key_file: 'f:/invalid_path/private_key',
|
320
|
+
certificate_file: 'f:/invalid_path/certificate.pem'
|
321
|
+
}
|
322
|
+
ex = assert_raises(RuntimeError) {subject.create_virtual_machine(windows_params, options)}
|
323
|
+
error_msg = 'No such file or directory -'
|
324
|
+
assert_match(/#{error_msg}*/,ex.message)
|
325
|
+
end
|
326
|
+
|
327
|
+
it 'should not throws certificate error when wirnm_transport is http' do
|
328
|
+
options = {
|
329
|
+
winrm_transport: ['http'],
|
330
|
+
private_key_file: 'f:/invalid_path/private_key',
|
331
|
+
certificate_file: 'f:/invalid_path/certificate.pem'
|
332
|
+
}
|
333
|
+
virtual_machine = subject.create_virtual_machine(windows_params, options)
|
334
|
+
virtual_machine.must_be_kind_of VirtualMachine
|
335
|
+
virtual_machine.wont_be_nil
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'throws error when location is not given' do
|
339
|
+
params.delete(:location)
|
340
|
+
ex=assert_raises(RuntimeError){subject.create_virtual_machine(params)}
|
341
|
+
error_msg = "You did not provide a valid 'location' value"
|
342
|
+
assert_match(/#{error_msg}*/,ex.message)
|
343
|
+
end
|
344
|
+
|
345
|
+
it 'throws error when wrong location is given' do
|
346
|
+
params.merge!(location: 'wrong location')
|
347
|
+
ex = assert_raises(RuntimeError) {subject.create_virtual_machine(params)}
|
348
|
+
error_msg = "Value 'wrong location' specified for parameter 'location' is invalid"
|
349
|
+
assert_match(/#{error_msg}*/,ex.message)
|
350
|
+
end
|
351
|
+
|
352
|
+
it 'throws error when empty location is given' do
|
353
|
+
params.merge!(location: nil)
|
354
|
+
ex = assert_raises(RuntimeError) {subject.create_virtual_machine(params)}
|
355
|
+
error_msg = "You did not provide a valid 'location' value"
|
356
|
+
assert_match(/#{error_msg}*/,ex.message)
|
357
|
+
end
|
358
|
+
|
359
|
+
it 'location should be case insensitive' do
|
360
|
+
params.merge!(location: 'west us')
|
361
|
+
subject.create_virtual_machine(params)
|
362
|
+
end
|
363
|
+
|
364
|
+
it 'throw error when available_services has not persistentvmrole for given location' do
|
365
|
+
params.merge!(location: 'West Europe')
|
366
|
+
ex = assert_raises(RuntimeError) {subject.create_virtual_machine(params)}
|
367
|
+
error_msg = 'Persistentvmrole not enabled for "West Europe"'
|
368
|
+
assert_match(/#{error_msg}*/,ex.message)
|
369
|
+
end
|
370
|
+
|
371
|
+
it 'warns if vm_size is not in the correct case' do
|
372
|
+
options = {
|
373
|
+
vm_size: 'extralarge'
|
374
|
+
}
|
375
|
+
|
376
|
+
out, err = capture_io do
|
377
|
+
msg = subject.create_virtual_machine(params, options)
|
378
|
+
end
|
379
|
+
error_msg = "'extralarge' specified for parameter 'vm_size' is not in the list of valid VM role sizes."
|
380
|
+
assert_match(/#{error_msg}*/, out)
|
381
|
+
end
|
382
|
+
|
383
|
+
it 'warns when wrong role size is given' do
|
384
|
+
options = {
|
385
|
+
vm_size: 'wrong size'
|
386
|
+
}
|
387
|
+
out, err = capture_io do
|
388
|
+
virtual_machine = subject.create_virtual_machine(params, options)
|
389
|
+
end
|
390
|
+
error_msg = "'wrong size' specified for parameter 'vm_size' is not in the list of valid VM role sizes."
|
391
|
+
assert_match(/#{error_msg}*/, out)
|
392
|
+
end
|
393
|
+
|
394
|
+
it 'should warn if role size is empty' do
|
395
|
+
options = {
|
396
|
+
vm_size: ''
|
397
|
+
}
|
398
|
+
out, err = capture_io do
|
399
|
+
subject.create_virtual_machine(params, options)
|
400
|
+
end
|
401
|
+
error_msg = "'' specified for parameter 'vm_size' is not in the list of valid VM role sizes."
|
402
|
+
assert_match(/#{error_msg}*/, out)
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
describe '#get_image' do
|
407
|
+
|
408
|
+
before do
|
409
|
+
Azure::Loggerx.stubs(:info).returns(nil)
|
410
|
+
Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
|
411
|
+
subject.class.send(:public, *subject.class.private_instance_methods)
|
412
|
+
end
|
413
|
+
|
414
|
+
it 'returns os type of given virtual machine image' do
|
415
|
+
result = subject.get_image 'RightImage-CentOS-6.2-x64-v5.8.8.1'
|
416
|
+
result.os_type.must_equal 'Linux'
|
417
|
+
end
|
418
|
+
|
419
|
+
it 'errors if the virtual machine image does not exist' do
|
420
|
+
exception = assert_raises(RuntimeError) do
|
421
|
+
subject.get_image 'invalid-image-name'
|
422
|
+
end
|
423
|
+
error_msg = 'The virtual machine image source is not valid'
|
424
|
+
assert_match(/#{error_msg}/i, exception.message)
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
describe '#add_role' do
|
429
|
+
|
430
|
+
let(:verb) { :get }
|
431
|
+
|
432
|
+
before do
|
433
|
+
Azure::Loggerx.stubs(:info).returns(nil)
|
434
|
+
Azure::Loggerx.expects(:puts).returns(nil).at_least(0)
|
435
|
+
windows_params[:cloud_service_name] = 'cloud-service-1'
|
436
|
+
mock_request = mock
|
437
|
+
Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(
|
438
|
+
verb,
|
439
|
+
location_request_path,
|
440
|
+
nil
|
441
|
+
).returns(mock_request)
|
442
|
+
mock_request.expects(:call).returns(location_response_body).at_least(0)
|
443
|
+
end
|
444
|
+
|
445
|
+
it 'should throws error when cloud service name is empty' do
|
446
|
+
windows_params.delete(:cloud_service_name)
|
447
|
+
exception = assert_raises(RuntimeError) do
|
448
|
+
subject.add_role(params)
|
449
|
+
end
|
450
|
+
error_msg = 'You did not provide a valid \'cloud_service_name\' value'
|
451
|
+
assert_match(/#{error_msg}/i, exception.message)
|
452
|
+
end
|
453
|
+
|
454
|
+
it 'throws error when vm_user is not given' do
|
455
|
+
windows_params.delete(:vm_user)
|
456
|
+
exception = assert_raises(RuntimeError) do
|
457
|
+
subject.add_role(windows_params)
|
458
|
+
end
|
459
|
+
error_msg = 'You did not provide a valid \'vm_user\' value'
|
460
|
+
assert_match(/#{error_msg}/i, exception.message)
|
461
|
+
end
|
462
|
+
|
463
|
+
it 'throws error when certificate path is not invalid.' do
|
464
|
+
options = {
|
465
|
+
winrm_transport: %w(https http),
|
466
|
+
private_key_file: 'f:/invalid_path/private_key',
|
467
|
+
certificate_file: 'f:/invalid_path/certificate.pem'
|
468
|
+
}
|
469
|
+
exception = assert_raises(RuntimeError) do
|
470
|
+
subject.add_role(windows_params, options)
|
471
|
+
end
|
472
|
+
error_msg = 'No such file or directory'
|
473
|
+
assert_match(/#{error_msg}/i, exception.message)
|
474
|
+
end
|
475
|
+
|
476
|
+
end
|
477
|
+
|
478
|
+
end
|