Skip to content

Commit

Permalink
Merge pull request #67 from opscode/adamed-oc-9430
Browse files Browse the repository at this point in the history
OC-9430: Knife cloud should support endpoint config and cli option
  • Loading branch information
Adam Edwards committed Sep 18, 2013
2 parents 394fefd + 5b3e3e0 commit fd4793f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/chef/knife/cloud/openstack_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def initialize(options = {})
}
}}))
end

# add alternate user defined api_endpoint value.
def add_api_endpoint
@auth_params.merge!({:openstack_auth_url => Chef::Config[:knife][:api_endpoint]}) unless Chef::Config[:knife][:api_endpoint].nil?
end
end
end
end
Expand Down
47 changes: 47 additions & 0 deletions spec/unit/openstack_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# Copyright:: Copyright (c) 2011-2013 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'spec_helper'
require 'chef/knife/cloud/openstack_service'

describe Chef::Knife::Cloud::OpenstackService do
describe "#add_api_endpoint" do
before(:each) do
@api_endpoint = "https://test_openstack_api_endpoint"
Chef::Config[:knife][:api_endpoint] = @api_endpoint
@instance = Chef::Knife::Cloud::OpenstackService.new
end

after(:each) do
Chef::Config[:knife].delete(:api_endpoint)
end

it "sets the api_endpoint in auth params" do
@instance.instance_variable_get(:@auth_params)[:openstack_auth_url].should == nil
@instance.add_api_endpoint
@instance.instance_variable_get(:@auth_params)[:openstack_auth_url].should == @api_endpoint
end

it "does not set the endpoint when --api-endpoint option is missing" do
Chef::Config[:knife][:api_endpoint] = nil
@instance.instance_variable_get(:@auth_params)[:openstack_auth_url].should == nil
@instance.add_api_endpoint
@instance.instance_variable_get(:@auth_params)[:openstack_auth_url].should_not == @api_endpoint
@instance.instance_variable_get(:@auth_params)[:openstack_auth_url].should == nil
end
end
end

0 comments on commit fd4793f

Please sign in to comment.