On 13/10/11 16:57 +0100, mtaylor(a)redhat.com wrote:
From: Martyn Taylor <mtaylor(a)redhat.com>
---
examples/aeolus-cli | 6 +---
lib/aeolus_image/command/base_command.rb | 46 ++++-------------------------
spec/base_command_spec.rb | 23 +++++----------
3 files changed, 16 insertions(+), 59 deletions(-)
ACK to the series going on the public branch, with one minor fix needed for this
patch, inline.
diff --git a/examples/aeolus-cli b/examples/aeolus-cli
index 22c4a17..896eaef 100644
--- a/examples/aeolus-cli
+++ b/examples/aeolus-cli
@@ -1,9 +1,5 @@
-
# Below is the correct format for this file, please update any older version you may
have
-:iwhd:
- :url:
http://localhost:9090
-
:conductor:
- :url:
http://localhost:3000/conductor
+ :url:
http://localhost/conductor/api
:username: admin
:password: password
\ No newline at end of file
diff --git a/lib/aeolus_image/command/base_command.rb
b/lib/aeolus_image/command/base_command.rb
index c758145..5d3f8ed 100644
--- a/lib/aeolus_image/command/base_command.rb
+++ b/lib/aeolus_image/command/base_command.rb
@@ -27,6 +27,7 @@ module Aeolus
@options = opts
@config_location = "~/.aeolus-cli"
@config = load_config
+ configure_active_resource
end
protected
@@ -44,14 +45,6 @@ module Aeolus
return @logger
end
- def iwhd
- create_resource(:iwhd)
- end
-
- def conductor
- create_resource(:conductor)
- end
-
def read_file(path)
begin
full_path = File.expand_path(path)
@@ -91,6 +84,12 @@ module Aeolus
end
private
+ def configure_active_resource
+ Aeolus::CLI::Base.site = @config[:conductor][:url]
+ Aeolus::CLI::Base.user = @config[:conductor][:username]
+ Aeolus::CLI::Base.password = @config[:conductor][:password]
+ end
+
def load_config
begin
file_str = read_file(@config_location)
@@ -117,37 +116,6 @@ module Aeolus
f.write(example)
end
end
-
- def create_resource(resource_name)
- # Check to see if config has a resource with this name
- if !(a)config.has_key?(resource_name)
- raise "Unable to determine resource: " + resource_name.to_s + "
from configuration file. Please check: " + @config_location
- return
- end
-
- #Use command line arguments for username/password
- if @options.has_key?(:username)
- if @options.has_key?(:password)
- RestClient::Resource.new(@config[resource_name][:url], :user =>
@options[:username], :password => @options[:password])
- else
- #TODO: Create a custom exception to wrap CLI Exceptions
- raise "Password not found for user: " + @options[:username]
- end
-
- #Use config for username/password
- elsif @config[resource_name].has_key?(:username)
- if @config[resource_name].has_key?(:password)
- RestClient::Resource.new(@config[resource_name][:url], :user =>
@config[resource_name][:username], :password => @config[resource_name][:password])
- else
- #TODO: Create a custom exception to wrap CLI Exceptions
- raise "Password not found for user: " +
@config[resource_name][:username]
- end
-
- # Do not use authentication
- else
- RestClient::Resource.new(@config[resource_name][:url])
- end
- end
end
end
end
diff --git a/spec/base_command_spec.rb b/spec/base_command_spec.rb
index 3ed5373..9c9042d 100644
--- a/spec/base_command_spec.rb
+++ b/spec/base_command_spec.rb
@@ -17,20 +17,13 @@ require 'spec_helper'
module Aeolus
module Image
describe BaseCommand do
-
- it "should determine the correct credentials for HTTP Authentication" do
- basec = BaseCommand.new
- iwhd = basec.send :iwhd
- iwhd.user.should == nil
-
- conductor = basec.send :conductor
- conductor.user.should == "admin"
- conductor.password.should == "password"
-
- basec = BaseCommand.new({:username => "testusername", :password=>
"testpassword"})
- conductor = basec.send :conductor
- conductor.user.should == "testusername"
- conductor.password.should == "testpassword"
+ describe "configure_active_resource" do
+ it "should setup ActiveResource with endpoint and authentication" do
+ basec = BaseCommand.new
+ Aeolus::CLI::Base.site.to_s.should == "http://localhost/conductor"
This still fails because you set the config file to point to /api, but
this test to compare with /conductor. If base.site is really supposed
to be /api, I suggest checking just for that. The benefit of this vs
an exact string it that is will work for dev setups as well. For
instance, while the production conductor may well be at
http://localhost/conductor/api , for my dev setup, I may just have
rails server running, in which case the url would just be
http://localhost:3000/api . It would be nice, I think, if the tests
work in both cases. This can be accomplished simply by using include
instead of '==' (test this locally):
- Aeolus::CLI::Base.site.to_s.should ==
"http://localhost/conductor"
+ Aeolus::CLI::Base.site.to_s.should include("/api")
Once this test passes, I think you are good to push it out to the
branch.
-j
+ Aeolus::CLI::Base.user.to_s.should == "admin"
+ Aeolus::CLI::Base.password.to_s.should == "password"
+ end
end
describe "#read_file" do
@@ -67,7 +60,7 @@ module Aeolus
b.instance_eval {@config_location = new_file}
b.send(:write_file)
conf = YAML::load(File.open(File.expand_path(new_file)))
- conf.has_key?(:iwhd).should be_true
+ conf.has_key?(:conductor).should be_true
File.delete(new_file)
end
end
--
1.7.6.2
_______________________________________________
aeolus-devel mailing list
aeolus-devel(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/aeolus-devel