From 84d31ce8a5291ca3678fb0ab66514a392b022a62 Mon Sep 17 00:00:00 2001 From: Trey Dockendorf Date: Tue, 15 Apr 2014 17:10:46 -0500 Subject: [PATCH 1/3] Fix Rake error ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc 2.4.2+) instead. --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index ed263cc..ce2aa35 100644 --- a/Rakefile +++ b/Rakefile @@ -38,7 +38,7 @@ end task :default => :spec -require 'rake/rdoctask' +require 'rdoc/task' Rake::RDocTask.new do |rdoc| version = File.exist?('VERSION') ? File.read('VERSION') : "" From e70ba4b1fdc220e57f5d7c2f4de2d11c0df41e08 Mon Sep 17 00:00:00 2001 From: Trey Dockendorf Date: Tue, 15 Apr 2014 17:10:56 -0500 Subject: [PATCH 2/3] Allow configurable use of Pulp v2 API path --- lib/pulp.rb | 1 + lib/pulp/connection/base.rb | 6 +-- lib/pulp/connection/handler.rb | 12 +++--- spec/pulp/connection/handler_spec.rb | 59 +++++++++++++++++++++++++++- 4 files changed, 69 insertions(+), 9 deletions(-) diff --git a/lib/pulp.rb b/lib/pulp.rb index 99c4535..86b4970 100644 --- a/lib/pulp.rb +++ b/lib/pulp.rb @@ -23,4 +23,5 @@ Pulp::Connection::Handler.username = global_options['username'] Pulp::Connection::Handler.password = global_options['password'] Pulp::Connection::Handler.debug_enabled = global_options['debug']||false + Pulp::Connection::Handler.enable_v2 = global_options['enable_v2']||false end \ No newline at end of file diff --git a/lib/pulp/connection/base.rb b/lib/pulp/connection/base.rb index 2f0f465..e0cf06a 100644 --- a/lib/pulp/connection/base.rb +++ b/lib/pulp/connection/base.rb @@ -14,7 +14,7 @@ def set_fields(field_data) end class << self - attr_accessor :hostname, :username, :password, :https + attr_accessor :hostname, :username, :password, :https, :enable_v2 def reset Pulp::Connection::Handler.reset_instance(self.identifier) @@ -71,11 +71,11 @@ def base_put(cmd,item=nil,params=nil) end def base - Pulp::Connection::Handler.instance_for(self.identifier, hostname, username, password, (https.nil? ? true : https)) + Pulp::Connection::Handler.instance_for(self.identifier, hostname, username, password, (https.nil? ? true : https), enable_v2) end def plain_base - Pulp::Connection::Handler.instance_for('', hostname, username, password, (https.nil? ? true : https)) + Pulp::Connection::Handler.instance_for('', hostname, username, password, (https.nil? ? true : https), enable_v2) end def parse_item_cmd(item,cmd) diff --git a/lib/pulp/connection/handler.rb b/lib/pulp/connection/handler.rb index c071d33..9c78264 100644 --- a/lib/pulp/connection/handler.rb +++ b/lib/pulp/connection/handler.rb @@ -5,14 +5,15 @@ class Handler include Pulp::Common::Debug class << self - attr_accessor :hostname,:username, :password + attr_accessor :hostname,:username, :password, :enable_v2 - def instance_for(identifier,h=nil,u=nil,p=nil,https=true) + def instance_for(identifier,h=nil,u=nil,p=nil,https=true,v2=nil) instances[identifier] ||= Handler.new(identifier, h||hostname||'localhost', u||username||'admin', p||password||'admin', - https + https, + v2||enable_v2||false ) end @@ -30,12 +31,13 @@ def instances end end - def initialize(identifier,hostname,username=nil,password=nil,https=true) + def initialize(identifier,hostname,username=nil,password=nil,https=true,enable_v2=nil) @identifier = identifier @hostname = hostname @username = username @password = password @https = https + @enable_v2 = enable_v2 end def parsed @@ -47,7 +49,7 @@ def connection end def api_path - "/pulp/api" + @enable_v2 ? "/pulp/api/v2" : "/pulp/api" end def url diff --git a/spec/pulp/connection/handler_spec.rb b/spec/pulp/connection/handler_spec.rb index f78e255..daeef69 100644 --- a/spec/pulp/connection/handler_spec.rb +++ b/spec/pulp/connection/handler_spec.rb @@ -48,9 +48,18 @@ it "defaults https to true" do Pulp::Connection::Handler.instance_for(:default_https,'bla','user','secret2').instance_variable_get('@https').should eql(true) end + it "takes passed https setting" do Pulp::Connection::Handler.instance_for(:default_https2,'bla','user2','secret2',false).instance_variable_get('@https').should eql(false) end + + it "defaults enable_v2 to false" do + Pulp::Connection::Handler.instance_for(:default_enable_v2,'bla','user','secret2').instance_variable_get('@enable_v2').should eql(false) + end + + it "takes passed enable_v2 setting" do + Pulp::Connection::Handler.instance_for(:default_enable_v2_2,'bla','user2','secret2',false, true).instance_variable_get('@enable_v2').should eql(true) + end end describe ".reset" do @@ -104,7 +113,7 @@ end describe "#api_path" do - it "is a fixed apth" do + it "default v1 path" do instance.api_path.should eql("/pulp/api") end end @@ -119,4 +128,52 @@ end end end + + describe "a v2 instance" do + let(:instance) do + Pulp::Connection::Handler.hostname = 'localhost' + Pulp::Connection::Handler.username = 'admin' + Pulp::Connection::Handler.password = 'admin' + Pulp::Connection::Handler.enable_v2 = true + Pulp::Connection::Handler.instance_for(:instance) + end + before(:each) { Pulp::Connection::Handler.reset_all } + describe "#parsed" do + it "gets the connection passed" do + instance.parsed{|conn| conn.should eql(instance.connection); DummyResult } + end + + it "parses the result" do + instance.parsed{|conn| DummyResult }['a'].should eql(1) + end + end + + describe "#connection" do + it "'s url should match our url" do + instance.connection.url.should eql(instance.url) + end + it "'s user should match our username" do + instance.connection.user.should eql(Pulp::Connection::Handler.username) + end + it "'s passowrd should match our password" do + instance.connection.password.should eql(Pulp::Connection::Handler.password) + end + end + + describe "#api_path" do + it "should be v2 path" do + instance.api_path.should eql("/pulp/api/v2") + end + end + + describe "#url" do + it "should be a full url depending on the identifier" do + instance.url.should eql("https://localhost/pulp/api/v2/instances") + end + it "should depend on the https flag" do + i = Pulp::Connection::Handler.instance_for(:second_instance,'localhost','user','password',false) + i.url.should eql("http://localhost/pulp/api/v2/second_instances") + end + end + end end \ No newline at end of file From bbb64223dface6af1b4d3ab291f5b3bb223119ee Mon Sep 17 00:00:00 2001 From: Trey Dockendorf Date: Tue, 15 Apr 2014 17:12:21 -0500 Subject: [PATCH 3/3] Add new option to README and example yaml configuration file --- README.rdoc | 1 + examples/test_pulp.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/README.rdoc b/README.rdoc index 2465135..d9fa018 100644 --- a/README.rdoc +++ b/README.rdoc @@ -67,6 +67,7 @@ However, you can also later configure the access credentils with: Pulp::Connection::Handler.hostname = 'localhost' Pulp::Connection::Handler.username = 'admin' Pulp::Connection::Handler.password = 'admin' + Pulp::Connection::Handler.enable_v2 = false == Examples diff --git a/examples/test_pulp.yml b/examples/test_pulp.yml index 4db3480..bbddfe9 100644 --- a/examples/test_pulp.yml +++ b/examples/test_pulp.yml @@ -1,4 +1,5 @@ hostname: localhost username: admin password: admin +enable_v2: false debug: false