Moved #endpoint_uri to #endpoint
This commit is contained in:
@@ -20,24 +20,16 @@
|
||||
require "uri"
|
||||
|
||||
module ::Openstack
|
||||
# Instead of specifying the verbose node["openstack"]["endpoints"][name],
|
||||
# this shortcut allows the simpler and shorter endpoint(name)
|
||||
def endpoint name
|
||||
@node['openstack']['endpoints'][name]
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
|
||||
# Shortcut to get the full URI for an endpoint. If the "uri" key isn't
|
||||
# set in the endpoint hash, we use the ::Openstack.get_uri_from_mash
|
||||
# library routine from the openstack-utils cookbook to grab a URI object
|
||||
# and construct the URI object from the endpoint parts.
|
||||
def endpoint_uri name
|
||||
ep = endpoint(name)
|
||||
def endpoint name
|
||||
ep = endpoint_for name
|
||||
if ep && ep.has_key?("uri")
|
||||
::URI.parse ep["uri"]
|
||||
elsif ep
|
||||
uri_from_hash(ep)
|
||||
uri_from_hash ep
|
||||
end
|
||||
end
|
||||
|
||||
@@ -153,4 +145,13 @@ module ::Openstack
|
||||
end
|
||||
info
|
||||
end
|
||||
|
||||
private
|
||||
# Instead of specifying the verbose node["openstack"]["endpoints"][name],
|
||||
# this shortcut allows the simpler and shorter endpoint(name)
|
||||
def endpoint_for name
|
||||
@node['openstack']['endpoints'][name]
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,6 +4,6 @@ maintainer_email "jaypipes@gmail.com"
|
||||
license "Apache 2.0"
|
||||
description "Common OpenStack attributes, libraries and recipes."
|
||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||
version "0.0.1"
|
||||
version "0.1.0"
|
||||
depends "database"
|
||||
depends "openstack-utils"
|
||||
|
||||
@@ -20,22 +20,6 @@ describe ::Openstack do
|
||||
@subject.instance_variable_set :@node, @chef_run.node
|
||||
@subject.endpoint("nonexisting").should be_nil
|
||||
end
|
||||
it "returns endpoint hash when found" do
|
||||
@subject.instance_variable_set :@node, @chef_run.node
|
||||
@subject.endpoint("compute-api")['host'].should == "127.0.0.1"
|
||||
@subject.endpoint("compute-api").has_key?("uri").should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#endpoint_uri" do
|
||||
it "returns nil when no openstack.endpoints not in node attrs" do
|
||||
@subject.instance_variable_set :@node, {}
|
||||
@subject.endpoint_uri("nonexisting").should be_nil
|
||||
end
|
||||
it "returns nil when no such endpoint was found" do
|
||||
@subject.instance_variable_set :@node, @chef_run.node
|
||||
@subject.endpoint_uri("nonexisting").should be_nil
|
||||
end
|
||||
it "returns endpoint URI object when uri key in endpoint hash" do
|
||||
uri_hash = {
|
||||
"openstack" => {
|
||||
@@ -47,7 +31,7 @@ describe ::Openstack do
|
||||
}
|
||||
}
|
||||
@subject.instance_variable_set :@node, uri_hash
|
||||
result = @subject.endpoint_uri("compute-api")
|
||||
result = @subject.endpoint "compute-api"
|
||||
result.port.should == 8080
|
||||
end
|
||||
it "returns endpoint URI string when uri key in endpoint hash and host also in hash" do
|
||||
@@ -62,7 +46,7 @@ describe ::Openstack do
|
||||
}
|
||||
}
|
||||
@subject.instance_variable_set :@node, uri_hash
|
||||
@subject.endpoint_uri("compute-api").to_s.should eq "http://localhost"
|
||||
@subject.endpoint("compute-api").to_s.should eq "http://localhost"
|
||||
end
|
||||
it "returns endpoint URI object when uri key not in endpoint hash but host is in hash" do
|
||||
uri_hash = {
|
||||
@@ -76,7 +60,7 @@ describe ::Openstack do
|
||||
}
|
||||
}
|
||||
@subject.instance_variable_set :@node, uri_hash
|
||||
result = @subject.endpoint_uri("compute-api")
|
||||
result = @subject.endpoint "compute-api"
|
||||
result.port.should == 8080
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user