Skip to content
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
4 changes: 2 additions & 2 deletions lib/facter/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def userdata()
end
end

if (Facter::Util::EC2.has_euca_mac? || Facter::Util::EC2.has_ec2_arp?) &&
Facter::Util::EC2.can_connect?
if (Facter::Util::EC2.has_euca_mac? || Facter::Util::EC2.has_openstack_mac? ||
Facter::Util::EC2.has_ec2_arp?) && Facter::Util::EC2.can_connect?

metadata
userdata
Expand Down
6 changes: 6 additions & 0 deletions lib/facter/util/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def has_euca_mac?
!!(Facter.value(:macaddress) =~ %r{^[dD]0:0[dD]:})
end

# Test if this host has a mac address used by OpenStack, which
# normally starts with 02:16:3E
def has_openstack_mac?
!!(Facter.value(:macaddress) =~ %r{^02:16:3[eE]})
end

# Test if the host has an arp entry in its cache that matches the EC2 arp,
# which is normally +fe:ff:ff:ff:ff:ff+.
def has_ec2_arp?
Expand Down
30 changes: 30 additions & 0 deletions spec/unit/ec2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
before :each do
# This is an ec2 instance, not a eucalyptus instance
Facter::Util::EC2.expects(:has_euca_mac?).at_least_once.returns(false)
Facter::Util::EC2.expects(:has_openstack_mac?).at_least_once.returns(false)
Facter::Util::EC2.expects(:has_ec2_arp?).at_least_once.returns(true)

# Assume we can connect
Expand Down Expand Up @@ -95,6 +96,35 @@
before :each do
# Return false for ec2, true for eucalyptus
Facter::Util::EC2.expects(:has_euca_mac?).at_least_once.returns(true)
Facter::Util::EC2.expects(:has_openstack_mac?).at_least_once.returns(false)
Facter::Util::EC2.expects(:has_ec2_arp?).never

# Assume we can connect
Facter::Util::EC2.expects(:can_connect?).at_least_once.returns(true)
end

it "should create ec2_user_data fact" do
# No meta-data
Object.any_instance.expects(:open).\
with("#{api_prefix}/2008-02-01/meta-data/").\
at_least_once.returns(StringIO.new(""))

Object.any_instance.expects(:open).\
with("#{api_prefix}/2008-02-01/user-data/").\
at_least_once.returns(StringIO.new("test"))

# Force a fact load
Facter.collection.loader.load(:ec2)

Facter.fact(:ec2_userdata).value.should == ["test"]
end
end

describe "when running on openstack" do
before :each do
# Return false for ec2, true for eucalyptus
Facter::Util::EC2.expects(:has_openstack_mac?).at_least_once.returns(true)
Facter::Util::EC2.expects(:has_euca_mac?).at_least_once.returns(false)
Facter::Util::EC2.expects(:has_ec2_arp?).never

# Assume we can connect
Expand Down
16 changes: 16 additions & 0 deletions spec/unit/util/ec2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@
end
end

describe "is_openstack_mac? method" do
it "should return true when the mac is an openstack one" do
Facter.expects(:value).with(:macaddress).\
at_least_once.returns("02:16:3e:54:89:fd")

Facter::Util::EC2.has_openstack_mac?.should == true
end

it "should return false when the mac is not a openstack one" do
Facter.expects(:value).with(:macaddress).\
at_least_once.returns("0c:1d:a0:bc:aa:02")

Facter::Util::EC2.has_openstack_mac?.should == false
end
end

describe "can_connect? method" do
it "returns true if api responds" do
# Return something upon connecting to the root
Expand Down