File: snapshot_tests.rb

package info (click to toggle)
ruby-fog-aws 3.33.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,180 kB
  • sloc: ruby: 75,405; javascript: 14; makefile: 9; sh: 4
file content (77 lines) | stat: -rw-r--r-- 2,585 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Shindo.tests('Fog::Compute[:aws] | snapshot requests', ['aws']) do

  @snapshot_format = {
    'description' => Fog::Nullable::String,
    'encrypted'   => Fog::Boolean,
    'ownerId'     => String,
    'progress'    => String,
    'snapshotId'  => String,
    'startTime'   => Time,
    'status'      => String,
    'volumeId'    => String,
    'volumeSize'  => Integer
  }

  @snapshots_format = {
    'requestId'   => String,
    'snapshotSet' => [@snapshot_format.merge('tagSet' => {})]
  }

  @snapshot_copy_result = {
    'requestId'   => String,
    'snapshotId'  => String
  }

  @volume = Fog::Compute[:aws].volumes.create(:availability_zone => 'us-east-1a', :size => 1)

  tests('success') do

    @snapshot_id = nil

    tests("#create_snapshot(#{@volume.identity})").formats(@snapshot_format.merge('progress' => NilClass, 'requestId' => String)) do
      data = Fog::Compute[:aws].create_snapshot(@volume.identity).body
      @snapshot_id = data['snapshotId']
      data
    end

    Fog.wait_for { Fog::Compute[:aws].snapshots.get(@snapshot_id) }
    Fog::Compute[:aws].snapshots.get(@snapshot_id).wait_for { ready? }

    tests("#describe_snapshots").formats(@snapshots_format) do
      Fog::Compute[:aws].describe_snapshots.body
    end

    tests("#describe_snapshots('snapshot-id' => '#{@snapshot_id}')").formats(@snapshots_format) do
      Fog::Compute[:aws].describe_snapshots('snapshot-id' => @snapshot_id).body
    end

    tests("#copy_snapshot (#{@snapshot_id}, 'us-east-1')").formats(@snapshot_copy_result) do
      data = Fog::Compute.new(:provider => :aws, :region => "us-west-1").copy_snapshot(@snapshot_id, "us-east-1").body
      @west_snapshot_id = data['snapshotId']
      data
    end

    tests("#delete_snapshots(#{@snapshot_id})").formats(AWS::Compute::Formats::BASIC) do
      Fog::Compute[:aws].delete_snapshot(@snapshot_id).body
    end

    #NOTE: waiting for the copy to complete can sometimes take up to 5 minutes (but sometimes it's nearly instant)
    #for faster tests: comment out the rest of this block
    Fog.wait_for { Fog::Compute.new(:provider => :aws, :region => "us-west-1").snapshots.get(@west_snapshot_id) }

    tests("#delete_snapshots(#{@west_snapshot_id})").formats(AWS::Compute::Formats::BASIC) do
      Fog::Compute.new(:provider => :aws, :region => "us-west-1").delete_snapshot(@west_snapshot_id).body
    end

  end
  tests('failure') do

    tests("#delete_snapshot('snap-00000000')").raises(Fog::AWS::Compute::NotFound) do
      Fog::Compute[:aws].delete_snapshot('snap-00000000')
    end

  end

  @volume.destroy

end