Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/on 324 #54

Merged
merged 3 commits into from
Jun 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/fog/azurerm/models/compute/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/azurerm/models/compute/servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
57 changes: 56 additions & 1 deletion test/api_stub/models/compute/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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' => '<XML unattend 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": [
Expand Down
12 changes: 10 additions & 2 deletions test/models/compute/test_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/models/compute/test_servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down