diff --git a/lib/fog/azurerm/models/compute/server.rb b/lib/fog/azurerm/models/compute/server.rb index 7823ee8c4..5a4dc33fa 100644 --- a/lib/fog/azurerm/models/compute/server.rb +++ b/lib/fog/azurerm/models/compute/server.rb @@ -38,7 +38,12 @@ def self.parse(vm) hash['sku'] = vm['properties']['storageProfile']['imageReference']['sku'] hash['version'] = vm['properties']['storageProfile']['imageReference']['version'] hash['username'] = vm['properties']['osProfile']['adminUsername'] - hash['disable_password_authentication'] = vm['properties']['osProfile']['linuxConfiguration']['disablePasswordAuthentication'] + hash['disable_password_authentication'] = + if vm['properties']['osProfile']['linuxConfiguration'].nil? + false + else + vm['properties']['osProfile']['linuxConfiguration']['disablePasswordAuthentication'] + end hash['network_interface_card_id'] = vm['properties']['networkProfile']['networkInterfaces'][0]['id'] hash['availability_set_id'] = vm['properties']['availabilitySet']['id'] unless vm['properties']['availabilitySet'].nil? hash diff --git a/lib/fog/azurerm/models/compute/servers.rb b/lib/fog/azurerm/models/compute/servers.rb index 007b1b168..e0db89ef1 100644 --- a/lib/fog/azurerm/models/compute/servers.rb +++ b/lib/fog/azurerm/models/compute/servers.rb @@ -19,8 +19,8 @@ def all load(virtual_machines) end - def get(resource_group, identity) - all.find { |s| s.name == identity && s.resource_group == resource_group } + def get(identity) + all.find { |s| s.name == identity } end def get_from_remote(resource_group, name) diff --git a/test/api_stub/models/compute/server.rb b/test/api_stub/models/compute/server.rb index 6f711915f..699ed98b4 100644 --- a/test/api_stub/models/compute/server.rb +++ b/test/api_stub/models/compute/server.rb @@ -3,7 +3,7 @@ module Models module Compute # Mock class for Server Model class Server - def self.create_virtual_machine_response + def self.create_linux_virtual_machine_response { 'id' => '/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.Compute/virtualMachines/fog-test-server', 'name' => 'fog-test-server', @@ -44,6 +44,61 @@ def self.create_virtual_machine_response } end + def self.create_windows_virtual_machine_response + { + 'id' => '/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.Compute/virtualMachines/fog-test-server', + 'name' => 'fog-test-server', + 'location' => 'West US', + 'properties' => { + 'hardwareProfile' => { + 'vmSize' => 'Basic_A0' + }, + 'storageProfile' => { + 'imageReference' => { + 'publisher' => 'Canonical', + 'offer' => 'UbuntuServer', + 'sku' => '14.04.2-LTS', + 'version' => 'latest' + }, + 'osDisk' => { + 'name' => 'fog-test-server_os_disk', + 'vhd' => { + 'uri' => 'http://storageAccount.blob.core.windows.net/vhds/fog-test-server_os_disk.vhd' + } + } + }, + 'osProfile' => { + 'computerName' => 'fog-test-server', + 'adminUsername' => 'shaffan', + 'windowsConfiguration' => { + 'provisionVMAgent' => true, + 'winRM' => { + 'listeners' => [{ + 'protocol' => 'https', + 'certificateUrl' => 'certificateUrl' + }] + }, + 'additionalUnattendContent' => { + 'pass' => 'oobesystem', + 'component' => 'Microsoft-Windows-Shell-Setup', + 'settingName' => 'FirstLogonCommands|AutoLogon', + 'content' => '' + }, + 'enableAutomaticUpdates' => true + }, + 'secrets' => [] + }, + 'networkProfile' => { + 'networkInterfaces' => [ + { + 'id' => '/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.Network/networkInterfaces/fogtestnetworkinterface' + } + ] + } + } + } + end + def self.list_available_sizes_for_virtual_machine_response body = '{ "value": [ diff --git a/test/models/compute/test_server.rb b/test/models/compute/test_server.rb index 8f54bbb5e..f19c413be 100644 --- a/test/models/compute/test_server.rb +++ b/test/models/compute/test_server.rb @@ -51,13 +51,21 @@ def test_model_attributes end end - def test_save_method_response - response = ApiStub::Models::Compute::Server.create_virtual_machine_response + def test_save_method_response_for_linux_vm + response = ApiStub::Models::Compute::Server.create_linux_virtual_machine_response @service.stub :create_virtual_machine, response do assert_instance_of Fog::Compute::AzureRM::Server, @server.save end end + def test_save_method_response_for_windows_vm + response = ApiStub::Models::Compute::Server.create_windows_virtual_machine_response + @service.stub :create_virtual_machine, response do + assert_instance_of Fog::Compute::AzureRM::Server, @server.save + refute @server.save.disable_password_authentication + end + end + def test_destroy_method_response @service.stub :delete_virtual_machine, true do assert @server.destroy diff --git a/test/models/compute/test_servers.rb b/test/models/compute/test_servers.rb index 427f00c4e..a2d4e5099 100644 --- a/test/models/compute/test_servers.rb +++ b/test/models/compute/test_servers.rb @@ -5,7 +5,7 @@ class TestServers < Minitest::Test def setup @service = Fog::Compute::AzureRM.new(credentials) @servers = Fog::Compute::AzureRM::Servers.new(resource_group: 'fog-test-rg', service: @service) - @response = [ApiStub::Models::Compute::Server.create_virtual_machine_response] + @response = [ApiStub::Models::Compute::Server.create_windows_virtual_machine_response] end def test_collection_methods @@ -35,13 +35,13 @@ def test_all_method_response def test_get_method_response @service.stub :list_virtual_machines, @response do - assert_instance_of Fog::Compute::AzureRM::Server, @servers.get('fog-test-rg', 'fog-test-server') - assert @servers.get('fog-test-rg', 'wrong-name').nil?, true + assert_instance_of Fog::Compute::AzureRM::Server, @servers.get('fog-test-server') + assert @servers.get('wrong-name').nil?, true end end def test_get_from_remote_method_response - response = ApiStub::Models::Compute::Server.create_virtual_machine_response + response = ApiStub::Models::Compute::Server.create_windows_virtual_machine_response @service.stub :get_virtual_machine, response do assert_instance_of Fog::Compute::AzureRM::Server, @servers.get_from_remote('fog-test-rg', 'fog-test-server') end