azure-fix 0.7.0.pre3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.env_sample +13 -0
- data/.gitignore +30 -0
- data/.travis.yml +13 -0
- data/ChangeLog.txt +56 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +202 -0
- data/README.md +702 -0
- data/Rakefile +121 -0
- data/azure.gemspec +51 -0
- data/bin/pfxer +35 -0
- data/lib/azure.rb +147 -0
- data/lib/azure/base_management/affinity_group.rb +32 -0
- data/lib/azure/base_management/base_management_service.rb +220 -0
- data/lib/azure/base_management/location.rb +27 -0
- data/lib/azure/base_management/management_http_request.rb +172 -0
- data/lib/azure/base_management/serialization.rb +135 -0
- data/lib/azure/base_management/sql_management_http_request.rb +35 -0
- data/lib/azure/blob/auth/shared_access_signature.rb +147 -0
- data/lib/azure/blob/blob.rb +32 -0
- data/lib/azure/blob/blob_service.rb +1452 -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/client.rb +31 -0
- data/lib/azure/client_services.rb +98 -0
- data/lib/azure/cloud_service_management/cloud_service.rb +38 -0
- data/lib/azure/cloud_service_management/cloud_service_management_service.rb +135 -0
- data/lib/azure/cloud_service_management/serialization.rb +118 -0
- data/lib/azure/configurable.rb +290 -0
- data/lib/azure/core/auth/authorizer.rb +36 -0
- data/lib/azure/core/auth/shared_key.rb +118 -0
- data/lib/azure/core/auth/shared_key_lite.rb +48 -0
- data/lib/azure/core/auth/signer.rb +51 -0
- data/lib/azure/core/error.rb +21 -0
- data/lib/azure/core/filtered_service.rb +45 -0
- data/lib/azure/core/http/debug_filter.rb +36 -0
- data/lib/azure/core/http/http_error.rb +86 -0
- data/lib/azure/core/http/http_filter.rb +53 -0
- data/lib/azure/core/http/http_request.rb +173 -0
- data/lib/azure/core/http/http_response.rb +96 -0
- data/lib/azure/core/http/retry_policy.rb +74 -0
- data/lib/azure/core/http/signer_filter.rb +33 -0
- data/lib/azure/core/service.rb +46 -0
- data/lib/azure/core/signed_service.rb +45 -0
- data/lib/azure/core/utility.rb +244 -0
- data/lib/azure/default.rb +126 -0
- data/lib/azure/http_client.rb +85 -0
- data/lib/azure/queue/message.rb +30 -0
- data/lib/azure/queue/queue.rb +28 -0
- data/lib/azure/queue/queue_service.rb +570 -0
- data/lib/azure/queue/serialization.rb +105 -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 +86 -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/shared_access_signer.rb +44 -0
- data/lib/azure/service_bus/auth/wrap_service.rb +90 -0
- data/lib/azure/service_bus/auth/wrap_signer.rb +77 -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 +899 -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/errors.rb +11 -0
- data/lib/azure/sql_database_management/firewall_rule.rb +30 -0
- data/lib/azure/sql_database_management/serialization.rb +99 -0
- data/lib/azure/sql_database_management/sql_database_management_service.rb +211 -0
- data/lib/azure/sql_database_management/sql_server.rb +32 -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 +207 -0
- data/lib/azure/table/auth/shared_key.rb +59 -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 +563 -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 +83 -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 +552 -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 +108 -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 +24 -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/management_certificate.pfx +0 -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 +87 -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 +55 -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 +81 -0
- data/test/integration/database/create_sql_server_test.rb +53 -0
- data/test/integration/database/delete_sql_server_firewall_test.rb +64 -0
- data/test/integration/database/delete_sql_server_test.rb +45 -0
- data/test/integration/database/list_sql_server_firewall_test.rb +44 -0
- data/test/integration/database/list_sql_servers_test.rb +44 -0
- data/test/integration/database/reset_password_sql_server_test.rb +53 -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 +43 -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 +196 -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 +40 -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 +47 -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/base_management_service_test.rb +19 -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 +1970 -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/config/azure_test.rb +112 -0
- data/test/unit/config/client_test.rb +37 -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 +61 -0
- data/test/unit/core/http/http_request_test.rb +138 -0
- data/test/unit/core/http/http_response_test.rb +20 -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 +94 -0
- data/test/unit/database/sql_database_server_service_test.rb +341 -0
- data/test/unit/http_client_test.rb +74 -0
- data/test/unit/service/serialization_test.rb +533 -0
- data/test/unit/service/storage_service_test.rb +297 -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 +480 -0
- data/test/unit/vnet/serialization_test.rb +187 -0
- data/test/unit/vnet/virtual_network_management_service_test.rb +131 -0
- metadata +579 -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,480 @@
|
|
|
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
|