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/add snapshot functionalities #362

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add 'all' method to fog collection snapshots
KevinLoiseau committed Dec 20, 2017
commit 305ac129c447d910de1680e8c4de638f0149b7a0
12 changes: 12 additions & 0 deletions lib/fog/azurerm/models/compute/snapshots.rb
Original file line number Diff line number Diff line change
@@ -6,6 +6,18 @@ class AzureRM
class Snapshots < Fog::Collection
model Fog::Compute::AzureRM::Snapshot
attribute :resource_group

def all
snapshots = if resource_group.nil?
service.list_snapshots_in_subscription
else
requires :resource_group
service.list_snapshots_by_rg(resource_group)
end
snapshots = snapshots.map { |snapshot| Fog::Compute::AzureRM::Snapshot.parse snapshot }

load(snapshots)
end
end
end
end
41 changes: 41 additions & 0 deletions test/api_stub/models/compute/snapshot.rb
Original file line number Diff line number Diff line change
@@ -3,6 +3,47 @@ module Models
module Compute
# Mock class for Snapshot Model
class Snapshot
def self.create_snapshot_response(sdk_compute_client)
snap = {
'accountType' => 'Standard_LRS',
'properties' => {
'osType' => 'Windows',
'creationData' => {
'createOption' => 'Copy',
'sourceResourceId' => 'subscriptions/subscriptionId/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot'
},
'diskSizeGB' => 200,
'encryptionSettings' => {
'enabled' => true,
'diskEncryptionKey' => {
'sourceVault' => {
'id' => '/subscriptions/subscriptionId/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/myVMVault'
},
'secretUrl' => 'https://myvmvault.vault-int.azure-int.net/secrets/secret'
},
'keyEncryptionKey' => {
'sourceVault' => {
'id' => '/subscriptions/subscriptionId/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/myVMVault'
},
'keyUrl' => 'https://myvmvault.vault-int.azure-int.net/keys/key'
}
},
'timeCreated' => '2016-12-28T04:41:35.9278721+00:00',
'provisioningState' => 'Succeeded',
'diskState' => 'Unattached'
},
'type' => 'Microsoft.Compute/snapshots',
'location' => 'westus',
'tags' => {
'department' => 'Development',
'project' => 'Snapshots'
},
'id' => '/subscriptions/subscriptionId/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot',
'name' => 'mySnapshot'
}
result_mapper = Azure::ARM::Compute::Models::Snapshot.mapper
sdk_compute_client.deserialize(result_mapper, snap, 'result.body')
end
end
end
end
20 changes: 19 additions & 1 deletion test/models/compute/test_snapshots.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
require File.expand_path '../../test_helper', __dir__

# Test class for Managed Disk Collection
# Test class for Snapshots Collection
class TestSnapshots < Minitest::Test
def setup
@service = Fog::Compute::AzureRM.new(credentials)
@snapshots = Fog::Compute::AzureRM::Snapshots.new(resource_group: 'fog-test-rg', service: @service)
@client = @service.instance_variable_get(:@compute_mgmt_client)
@snapshot_list = [ApiStub::Models::Compute::Snapshot.create_snapshot_response(@client)]
end

def test_collection_methods
methods = %i(all)
methods.each do |method|
assert_respond_to @snapshots, method
end
end

def test_collection_attributes
assert_respond_to @snapshots, :resource_group
end

def test_all_method_response
@service.stub :list_snapshots_by_rg, @snapshot_list do
assert_instance_of Fog::Compute::AzureRM::Snapshots, @snapshots.all
assert @snapshots.all.size >= 1
@snapshots.all.each do |disk|
assert_instance_of Fog::Compute::AzureRM::Snapshot, disk
end
end
end
end