ec2-metadata 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -14
- data/README.rdoc +45 -1
- data/Rakefile +5 -0
- data/VERSION +1 -1
- data/bin/ec2-metadata +44 -0
- data/ec2-metadata.gemspec +85 -0
- data/lib/ec2_metadata.rb +27 -5
- data/lib/ec2_metadata/base.rb +36 -3
- data/lib/ec2_metadata/command.rb +68 -0
- data/lib/ec2_metadata/dummy.rb +38 -0
- data/lib/ec2_metadata/dummy.yml +34 -0
- data/lib/ec2_metadata/http_client.rb +29 -0
- data/lib/hash_key_orderable.rb +23 -0
- data/spec/ec2_metadata/base_spec.rb +16 -15
- data/spec/ec2_metadata/command_spec.rb +101 -0
- data/spec/ec2_metadata/dummy_spec.rb +92 -0
- data/spec/ec2_metadata/http_client_spec.rb +34 -0
- data/spec/ec2_metadata/revision_spec.rb +2 -2
- data/spec/ec2_metadata/root_spec.rb +7 -7
- data/spec/ec2_metadata_spec.rb +8 -8
- data/spec/hash_key_orderable_spec.rb +50 -0
- data/spec/introduction_spec.rb +27 -27
- data/spec/rcov.opts +1 -0
- data/spec/to_hash_spec.rb +121 -0
- metadata +24 -7
- data/lib/ec2_metadata/named_base.rb +0 -17
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
meta-data:
|
3
|
+
ami-id: ami-6966372c
|
4
|
+
ami-launch-index: "0"
|
5
|
+
ami-manifest-path: akm2000-us-west-1/dev-20100406-01.manifest.xml
|
6
|
+
ancestor-ami-ids: ami-c32e7f86
|
7
|
+
instance-id: i-3de0f678
|
8
|
+
instance-type: m1.small
|
9
|
+
instance-action: none
|
10
|
+
security-groups: |-
|
11
|
+
ruby-dev
|
12
|
+
default
|
13
|
+
hostname: ip-10-160-115-246.us-west-1.compute.internal
|
14
|
+
public-hostname: ec2-204-236-178-101.us-west-1.compute.amazonaws.com
|
15
|
+
public-ipv4: 204.236.178.101
|
16
|
+
local-hostname: ip-10-160-115-246.us-west-1.compute.internal
|
17
|
+
local-ipv4: 10.160.115.246
|
18
|
+
kernel-id: aki-773c6d32
|
19
|
+
ramdisk-id: ari-c12e7f84
|
20
|
+
reservation-id: r-b76769f2
|
21
|
+
block-device-mapping:
|
22
|
+
root: /dev/sda1
|
23
|
+
ami: sda1
|
24
|
+
swap: sda3
|
25
|
+
ephemeral0: sda2
|
26
|
+
public-keys:
|
27
|
+
"0":
|
28
|
+
west-dev01:
|
29
|
+
openssh-key: |
|
30
|
+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3on58pV0jEdOukPJMi3zaI90Vg5n+vTaWVNBC2pDfaFX5yVIwcT/LQn9CqvcFsayvRaLfrVT8+wz7BnvQwldUAoIC5wCb5MXhhdr+3dk3ey/t8t3rS0lO6pxYc1jchkH23C/RQz+gOzFDuuzxX4zngRRkajYt1hKEVOPLVv9tqBawalCF0d3iALu/XBguj6fUogaqHgNgZZpZXTXDyfmLtWnXErB0/hqmuV6iIXjclB+K94lZCcJaOQSm/+9C6R0jCKwJNteJInvD553IzyTzBgc5Os3ukNuYv+Ub6aP717ikmI5fa5P0pBL+684kkPKvpGoADJveACoL1+uKpk0j west-dev01
|
31
|
+
|
32
|
+
placement:
|
33
|
+
availability-zone: us-west-1b
|
34
|
+
user-data:
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'ec2_metadata'
|
2
|
+
|
3
|
+
module Ec2Metadata
|
4
|
+
module HttpClient
|
5
|
+
def self.extended(obj)
|
6
|
+
obj.open_timeout_sec ||= DEFAULT_OPEN_TIMEOUT
|
7
|
+
obj.read_timeout_sec ||= DEFAULT_READ_TIMEOUT
|
8
|
+
end
|
9
|
+
|
10
|
+
DEFAULT_OPEN_TIMEOUT = 5
|
11
|
+
DEFAULT_READ_TIMEOUT = 10
|
12
|
+
|
13
|
+
attr_accessor :open_timeout_sec
|
14
|
+
attr_accessor :read_timeout_sec
|
15
|
+
|
16
|
+
def get(path)
|
17
|
+
logging("Ec2Metadata.get(#{path.inspect})") do
|
18
|
+
http = Net::HTTP.new(DEFAULT_HOST)
|
19
|
+
http.open_timeout = self.open_timeout_sec
|
20
|
+
http.read_timeout = self.read_timeout_sec
|
21
|
+
http.start do |http|
|
22
|
+
res = http.get(path)
|
23
|
+
res.is_a?(Net::HTTPSuccess) ? res.body : nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module HashKeyOrderable
|
2
|
+
attr_accessor :key_order
|
3
|
+
|
4
|
+
def each_with_key_order(&block)
|
5
|
+
if @key_order.nil? || @key_order.empty?
|
6
|
+
each_without_key_order(&block)
|
7
|
+
return self
|
8
|
+
end
|
9
|
+
unexist_keys = @key_order - self.keys
|
10
|
+
actual_order = (@key_order - unexist_keys) | self.keys
|
11
|
+
actual_order.each do |key|
|
12
|
+
yield(key, self[key])
|
13
|
+
end
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.extended(obj)
|
18
|
+
obj.instance_eval do
|
19
|
+
alias :each_without_key_order :each
|
20
|
+
alias :each :each_with_key_order
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -8,13 +8,13 @@ describe Ec2Metadata::Base do
|
|
8
8
|
describe revision do
|
9
9
|
before do
|
10
10
|
@meta_data = Ec2Metadata::Base.new("/#{revision}/meta-data/")
|
11
|
-
|
11
|
+
Ec2Metadata.should_receive(:get).with("/#{revision}/meta-data/").once.
|
12
12
|
and_return(ALL_ATTR_KEYS.join("\n"))
|
13
13
|
end
|
14
14
|
|
15
15
|
SIMPLE_ATTR_KEYS.each do |attr_key|
|
16
16
|
it "(#{attr_key.gsub(/-/, '_').inspect}) should return #{attr_key}" do
|
17
|
-
|
17
|
+
Ec2Metadata.should_receive(:get).with("/#{revision}/meta-data/#{attr_key}").once.
|
18
18
|
and_return("#{revision}_#{attr_key}")
|
19
19
|
@meta_data[attr_key].should == "#{revision}_#{attr_key}"
|
20
20
|
@meta_data[attr_key.to_sym].should == "#{revision}_#{attr_key}"
|
@@ -22,38 +22,39 @@ describe Ec2Metadata::Base do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "('placement') should return object like Hash" do
|
25
|
-
|
25
|
+
Ec2Metadata.should_receive(:get).with("/#{revision}/meta-data/placement/").and_return("availability-zone")
|
26
26
|
obj = @meta_data[:placement]
|
27
27
|
obj.child_keys.should == ["availability-zone"]
|
28
|
-
|
28
|
+
Ec2Metadata.should_receive(:get).with("/#{revision}/meta-data/placement/availability-zone").and_return("us-east-1a")
|
29
29
|
obj[:availability_zone].should == "us-east-1a"
|
30
30
|
end
|
31
31
|
|
32
32
|
it "('block_device_mapping') should return object like Hash" do
|
33
|
-
|
33
|
+
Ec2Metadata.should_receive(:get).with("/#{revision}/meta-data/block-device-mapping/").and_return(["ami", "ephemeral0", "root", "swap"].join("\n"))
|
34
34
|
obj = @meta_data[:block_device_mapping]
|
35
35
|
obj.child_keys.should == ["ami", "ephemeral0", "root", "swap"]
|
36
|
-
|
36
|
+
Ec2Metadata.should_receive(:get).with("/#{revision}/meta-data/block-device-mapping/ami").and_return("sda1")
|
37
37
|
obj[:ami].should == "sda1"
|
38
|
-
|
38
|
+
Ec2Metadata.should_receive(:get).with("/#{revision}/meta-data/block-device-mapping/ephemeral0").and_return("sda2")
|
39
39
|
obj[:ephemeral0].should == "sda2"
|
40
|
-
|
40
|
+
Ec2Metadata.should_receive(:get).with("/#{revision}/meta-data/block-device-mapping/root").and_return("/dev/sda1")
|
41
41
|
obj[:root].should == "/dev/sda1"
|
42
|
-
|
42
|
+
Ec2Metadata.should_receive(:get).with("/#{revision}/meta-data/block-device-mapping/swap").and_return("sda3")
|
43
43
|
obj[:swap].should == "sda3"
|
44
44
|
end
|
45
45
|
|
46
46
|
it "('public_keys') should return object like Hash" do
|
47
|
-
|
47
|
+
Ec2Metadata.should_receive(:get).with("/#{revision}/meta-data/public-keys/").and_return("0=keypair0")
|
48
48
|
obj = @meta_data[:public_keys]
|
49
49
|
obj.child_keys.should == ["0"]
|
50
50
|
obj.class.should == Ec2Metadata::Base
|
51
51
|
key0 = obj["0"]
|
52
|
-
key0.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
key0.child_keys.should == ["keypair0"]
|
53
|
+
key0name = key0["keypair0"]
|
54
|
+
Ec2Metadata.should_receive(:get).with("/#{revision}/meta-data/public-keys/0/").and_return("openssh-key")
|
55
|
+
key0name.child_keys.should == ["openssh-key"]
|
56
|
+
Ec2Metadata.should_receive(:get).with("/#{revision}/meta-data/public-keys/0/openssh-key").and_return("ssh-rsa 1234567890")
|
57
|
+
key0name[:openssh_key].should == "ssh-rsa 1234567890"
|
57
58
|
end
|
58
59
|
|
59
60
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
|
2
|
+
|
3
|
+
describe Ec2Metadata::Root do
|
4
|
+
|
5
|
+
before do
|
6
|
+
Ec2Metadata.clear_instance
|
7
|
+
end
|
8
|
+
|
9
|
+
describe :show do
|
10
|
+
describe "valid" do
|
11
|
+
it "should puts sorted data" do
|
12
|
+
revisions = %w(1.0 2009-04-04 latest)
|
13
|
+
data_types = %w(user-data meta-data)
|
14
|
+
attrs = %w(ami-id hostname instance-id local-hostname local-ipv4 public-hostname public-ipv4)
|
15
|
+
Ec2Metadata.should_receive(:get).with("/").once.and_return(revisions.join("\n"))
|
16
|
+
Ec2Metadata.should_receive(:get).with("/latest/").once.and_return(data_types.join("\n"))
|
17
|
+
Ec2Metadata.should_receive(:get).with("/latest/user-data").once.and_return((1..3).map{|n| "user-data-line#{n}"}.join("\n"))
|
18
|
+
Ec2Metadata.should_receive(:get).with("/latest/meta-data/").once.and_return(attrs.join("\n"))
|
19
|
+
Ec2Metadata.should_receive(:get).with("/latest/meta-data/ami-id").once.and_return('ami-abcdef01')
|
20
|
+
Ec2Metadata.should_receive(:get).with("/latest/meta-data/instance-id").once.and_return('i-12345678')
|
21
|
+
Ec2Metadata.should_receive(:get).with("/latest/meta-data/public-hostname").once.and_return('ec2-75-101-241-136.compute-1.amazonaws.com')
|
22
|
+
Ec2Metadata.should_receive(:get).with("/latest/meta-data/local-hostname").once.and_return('ip-10-123-123-123')
|
23
|
+
Ec2Metadata.should_receive(:get).with("/latest/meta-data/hostname").once.and_return('ip-10-123-123-123')
|
24
|
+
Ec2Metadata.should_receive(:get).with("/latest/meta-data/local-ipv4").once.and_return('10.123.123.123')
|
25
|
+
Ec2Metadata.should_receive(:get).with("/latest/meta-data/public-ipv4").once.and_return('75.101.241.136')
|
26
|
+
result = <<EOS
|
27
|
+
---
|
28
|
+
meta-data:
|
29
|
+
ami-id: ami-abcdef01
|
30
|
+
instance-id: i-12345678
|
31
|
+
hostname: ip-10-123-123-123
|
32
|
+
public-hostname: ec2-75-101-241-136.compute-1.amazonaws.com
|
33
|
+
public-ipv4: 75.101.241.136
|
34
|
+
local-hostname: ip-10-123-123-123
|
35
|
+
local-ipv4: 10.123.123.123
|
36
|
+
user-data: |-
|
37
|
+
user-data-line1
|
38
|
+
user-data-line2
|
39
|
+
user-data-line3
|
40
|
+
EOS
|
41
|
+
Ec2Metadata::Command.should_receive(:puts).with(result)
|
42
|
+
Ec2Metadata::Command.show
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should display message which means 'dummy data is used'" do
|
46
|
+
Ec2Metadata.from_hash({
|
47
|
+
'user-data' => "user-data-line1\nuser-data-line2\nuser-data-line3",
|
48
|
+
'meta-data' => {
|
49
|
+
'ami-id' => 'ami-abcdef01',
|
50
|
+
'instance-id' => 'i-12345678',
|
51
|
+
'public-hostname' => "ec2-75-101-241-136.compute-1.amazonaws.com",
|
52
|
+
'local-hostname' => "ip-10-123-123-123",
|
53
|
+
'hostname' => "ip-10-123-123-123",
|
54
|
+
'local-ipv4' => "10.123.123.123",
|
55
|
+
'public-ipv4' => "75.101.241.136",
|
56
|
+
# 'public_keys' => [{'openssh-key' => "ssh-rsa 1234567890"}]
|
57
|
+
}
|
58
|
+
})
|
59
|
+
Ec2Metadata::Dummy.instance_variable_set(:@loaded_yaml_path, '/path/to/ec2_metadata.yml')
|
60
|
+
result = <<EOS
|
61
|
+
---
|
62
|
+
meta-data:
|
63
|
+
ami-id: ami-abcdef01
|
64
|
+
instance-id: i-12345678
|
65
|
+
hostname: ip-10-123-123-123
|
66
|
+
public-hostname: ec2-75-101-241-136.compute-1.amazonaws.com
|
67
|
+
public-ipv4: 75.101.241.136
|
68
|
+
local-hostname: ip-10-123-123-123
|
69
|
+
local-ipv4: 10.123.123.123
|
70
|
+
user-data: |-
|
71
|
+
user-data-line1
|
72
|
+
user-data-line2
|
73
|
+
user-data-line3
|
74
|
+
EOS
|
75
|
+
Ec2Metadata::Command.should_receive(:puts).with(result).once
|
76
|
+
Ec2Metadata::Command.should_receive(:puts).with("Actually these data is based on a DUMMY yaml file: /path/to/ec2_metadata.yml").once
|
77
|
+
Ec2Metadata::Command.show
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should raise ArgumentError for invalid api version" do
|
82
|
+
revisions = %w(1.0 2009-04-04 latest)
|
83
|
+
Ec2Metadata.should_receive(:get).with("/").once.and_return(revisions.join("\n"))
|
84
|
+
lambda{
|
85
|
+
Ec2Metadata::Command.show("invalid api version")
|
86
|
+
}.should raise_error(ArgumentError)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
describe :show_api_versions do
|
92
|
+
it "default" do
|
93
|
+
revisions = %w(1.0 2009-04-04 latest)
|
94
|
+
Ec2Metadata.should_receive(:get).with("/").once.and_return(revisions.join("\n"))
|
95
|
+
Ec2Metadata::Command.should_receive(:puts).with(revisions)
|
96
|
+
Ec2Metadata::Command.show_api_versions
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
|
2
|
+
|
3
|
+
describe Ec2Metadata::Dummy do
|
4
|
+
after(:all) do
|
5
|
+
Ec2Metadata::Dummy.instance_variable_set(:@loaded_yaml_path, nil)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe :yaml_paths do
|
9
|
+
it "default" do
|
10
|
+
ENV.should_receive(:[]).with("EC2_METADATA_DUMMY_YAML").once.and_return(nil)
|
11
|
+
original_constants = Module.constants
|
12
|
+
Module.should_receive(:constants).once.and_return(original_constants - %w(RAILS_ROOT))
|
13
|
+
Ec2Metadata::Dummy.yaml_paths.should == [
|
14
|
+
'./config/ec2_metadata.yml',
|
15
|
+
'./ec2_metadata.yml',
|
16
|
+
'~/ec2_metadata.yml',
|
17
|
+
'/etc/ec2_metadata.yml'
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "with rails" do
|
22
|
+
ENV.should_receive(:[]).with("EC2_METADATA_DUMMY_YAML").once.and_return(nil)
|
23
|
+
original_constants = Module.constants
|
24
|
+
Module.should_receive(:constants).once.and_return(original_constants + %w(RAILS_ROOT))
|
25
|
+
Module.should_receive(:const_get).with("RAILS_ROOT").once.and_return("/path/to/rails/project")
|
26
|
+
Ec2Metadata::Dummy.yaml_paths.should == [
|
27
|
+
'/path/to/rails/project/config/ec2_metadata.yml',
|
28
|
+
'./config/ec2_metadata.yml',
|
29
|
+
'./ec2_metadata.yml',
|
30
|
+
'~/ec2_metadata.yml',
|
31
|
+
'/etc/ec2_metadata.yml'
|
32
|
+
]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "with specified_path" do
|
36
|
+
ENV.should_receive(:[]).with("EC2_METADATA_DUMMY_YAML").once.and_return("/path/to/dummy/yaml")
|
37
|
+
original_constants = Module.constants
|
38
|
+
Module.should_receive(:constants).once.and_return(original_constants - %w(RAILS_ROOT))
|
39
|
+
Ec2Metadata::Dummy.yaml_paths.should == [
|
40
|
+
'/path/to/dummy/yaml',
|
41
|
+
'./config/ec2_metadata.yml',
|
42
|
+
'./ec2_metadata.yml',
|
43
|
+
'~/ec2_metadata.yml',
|
44
|
+
'/etc/ec2_metadata.yml'
|
45
|
+
]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe :search_and_load_yaml do
|
50
|
+
it "should load_yaml if yaml exists" do
|
51
|
+
yaml_path = "/path/to/ec2_metadata.yml"
|
52
|
+
Ec2Metadata::Dummy.should_receive(:yaml_paths).once.and_return([yaml_path])
|
53
|
+
Dir.should_receive(:glob).with([yaml_path]).and_return([yaml_path])
|
54
|
+
Ec2Metadata::Dummy.should_receive(:load_yaml).with(yaml_path).once
|
55
|
+
Ec2Metadata::Dummy.search_and_load_yaml
|
56
|
+
end
|
57
|
+
|
58
|
+
it "shouldn't load_yaml unless yaml exists" do
|
59
|
+
yaml_path = "/path/to/ec2_metadata.yml"
|
60
|
+
Ec2Metadata::Dummy.should_receive(:yaml_paths).once.and_return([yaml_path])
|
61
|
+
Dir.should_receive(:glob).with([yaml_path]).and_return([])
|
62
|
+
Ec2Metadata::Dummy.should_not_receive(:load_yaml)
|
63
|
+
Ec2Metadata::Dummy.search_and_load_yaml
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe :load_yaml do
|
68
|
+
require 'yaml'
|
69
|
+
require 'erb'
|
70
|
+
|
71
|
+
it "should load by from_hash" do
|
72
|
+
yaml = {
|
73
|
+
'user-data' => "user-data-line1\nuser-data-line2\nuser-data-line3",
|
74
|
+
'meta-data' => {
|
75
|
+
'ami-id' => 'ami-abcdef01',
|
76
|
+
'instance-id' => 'i-12345678',
|
77
|
+
'public-hostname' => "ec2-75-101-241-136.compute-1.amazonaws.com",
|
78
|
+
'local-hostname' => "ip-10-123-123-123",
|
79
|
+
'hostname' => "ip-10-123-123-123",
|
80
|
+
'local-ipv4' => "10.123.123.123",
|
81
|
+
'public-ipv4' => "75.101.241.136"
|
82
|
+
}
|
83
|
+
}
|
84
|
+
yaml_path = "/path/to/ec2_metadata.yml"
|
85
|
+
IO.should_receive(:read).with(yaml_path).and_return(YAML.dump(yaml))
|
86
|
+
Ec2Metadata.should_receive(:from_hash).with(yaml)
|
87
|
+
Ec2Metadata::Dummy.load_yaml(yaml_path)
|
88
|
+
Ec2Metadata::Dummy.loaded_yaml_path.should == yaml_path
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
|
2
|
+
|
3
|
+
describe Ec2Metadata::HttpClient do
|
4
|
+
|
5
|
+
describe :get do
|
6
|
+
it "should return body for Net::HTTPSuccess" do
|
7
|
+
mock_http = mock(:http)
|
8
|
+
mock_res = mock(:http_res)
|
9
|
+
Net::HTTP.should_receive(:new).with("169.254.169.254").and_return(mock_http)
|
10
|
+
mock_http.should_receive(:open_timeout=).with(5)
|
11
|
+
mock_http.should_receive(:read_timeout=).with(10)
|
12
|
+
mock_http.should_receive(:start).and_yield(mock_http)
|
13
|
+
mock_http.should_receive(:get).with("/path1").and_return(mock_res)
|
14
|
+
mock_res.should_receive(:is_a?).with(Net::HTTPSuccess).and_return(true)
|
15
|
+
mock_res.should_receive(:body).and_return("HTTP Success Response Body1")
|
16
|
+
Ec2Metadata.get("/path1").should == "HTTP Success Response Body1"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return nil not for Net::HTTPSuccess" do
|
20
|
+
mock_http = mock(:http)
|
21
|
+
mock_res = mock(:http_res)
|
22
|
+
Net::HTTP.should_receive(:new).with("169.254.169.254").and_return(mock_http)
|
23
|
+
mock_http.should_receive(:open_timeout=).with(5)
|
24
|
+
mock_http.should_receive(:read_timeout=).with(10)
|
25
|
+
mock_http.should_receive(:start).and_yield(mock_http)
|
26
|
+
mock_http.should_receive(:get).with("/path1").and_return(mock_res)
|
27
|
+
mock_res.should_receive(:is_a?).with(Net::HTTPSuccess).and_return(false)
|
28
|
+
mock_res.should_not_receive(:body) # .and_return("404 not found")
|
29
|
+
Ec2Metadata.get("/path1").should == nil
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -8,7 +8,7 @@ describe Ec2Metadata::Root do
|
|
8
8
|
describe revision do
|
9
9
|
before do
|
10
10
|
@rev_obj = Ec2Metadata::Revision.new("/#{revision}/")
|
11
|
-
|
11
|
+
Ec2Metadata.should_receive(:get).with("/#{revision}/").once.
|
12
12
|
and_return(DATA_TYPES.join("\n"))
|
13
13
|
end
|
14
14
|
|
@@ -18,7 +18,7 @@ describe Ec2Metadata::Root do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should return Ec2Metadata::Base for user_data" do
|
21
|
-
|
21
|
+
Ec2Metadata.should_receive(:get).with("/#{revision}/user-data").once.
|
22
22
|
and_return("#{revision}-user_data")
|
23
23
|
user_data = @rev_obj[:user_data]
|
24
24
|
user_data.should == "#{revision}-user_data"
|
@@ -9,7 +9,7 @@ describe Ec2Metadata::Root do
|
|
9
9
|
|
10
10
|
REVISIONS.each do |rev|
|
11
11
|
it "should return Revision for #{rev}" do
|
12
|
-
|
12
|
+
Ec2Metadata.should_receive(:get).with("/").once.
|
13
13
|
and_return(REVISIONS.join("\n"))
|
14
14
|
revision = @root[rev]
|
15
15
|
revision.class.should == Ec2Metadata::Revision
|
@@ -17,22 +17,22 @@ describe Ec2Metadata::Root do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should return latest DataType for user-data" do
|
20
|
-
|
20
|
+
Ec2Metadata.should_receive(:get).with("/").once.
|
21
21
|
and_return(REVISIONS.join("\n"))
|
22
|
-
|
22
|
+
Ec2Metadata.should_receive(:get).with("/latest/").once.
|
23
23
|
and_return(DATA_TYPES.join("\n"))
|
24
|
-
|
24
|
+
Ec2Metadata.should_receive(:get).with("/latest/user-data").once.
|
25
25
|
and_return("test-user-data1")
|
26
26
|
obj = @root['user-data']
|
27
27
|
obj.should == "test-user-data1"
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should return latest DataType for meta-data" do
|
31
|
-
|
31
|
+
Ec2Metadata.should_receive(:get).with("/").once.
|
32
32
|
and_return(REVISIONS.join("\n"))
|
33
|
-
|
33
|
+
Ec2Metadata.should_receive(:get).with("/latest/").once.
|
34
34
|
and_return(DATA_TYPES.join("\n"))
|
35
|
-
|
35
|
+
Ec2Metadata.should_not_receive(:get).with("/latest/meta-data/")
|
36
36
|
obj = @root['meta-data']
|
37
37
|
obj.class.should == Ec2Metadata::Base
|
38
38
|
end
|