Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #18717 - Allows use of proxies on multiple interfaces #4346

Closed
wants to merge 1 commit into from

Conversation

sean797
Copy link
Member

@sean797 sean797 commented Feb 28, 2017

This moves Smart Proxies URL to its own model and during provision you select a URL instead of a proxy. All communication between foreman -> proxy is still done via the "Primary URL".

@mention-bot
Copy link

@sean797, thanks for your PR! By analyzing the history of the files in this pull request, we identified @isratrade, @dLobatog and @ohadlevy to be potential reviewers.


validates :url, :length => {:maximum => 255}, :presence => true, :url_schema => ['http', 'https']
validates_uniqueness_of :smart_proxy_id, :scope => :url
validates_uniqueness_of :smart_proxy_id, :scope => :primary, if: :primary?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer the new style validations validates :column, uniqueness: value over validates_uniqueness_of.

has_many :puppet_ca_hostgroups, :class_name => 'Hostgroup', :foreign_key => 'puppet_ca_proxy_url_id'

validates :url, :length => {:maximum => 255}, :presence => true, :url_schema => ['http', 'https']
validates_uniqueness_of :smart_proxy_id, :scope => :url

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer the new style validations validates :column, uniqueness: value over validates_uniqueness_of.

@@ -0,0 +1,37 @@
class SmartProxyUrl < ActiveRecord::Base

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at class body beginning.

has_many_hosts :through => 'urls'
has_many :hostgroups, :through => 'urls'
has_many :puppet_ca_hosts, :class_name => 'Host::Managed', :through => 'urls'
has_many :puppet_ca_hostgroups, :class_name => 'Hostgroup', :through => 'urls'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@sean797 sean797 force-pushed the proxy_int branch 3 times, most recently from 76f044d to e784d0c Compare March 1, 2017 14:48
@sean797 sean797 changed the title Fixes #18717 - Allows use of proxies on multiple interfaces [WIP] Fixes #18717 - Allows use of proxies on multiple interfaces Mar 2, 2017
@sean797
Copy link
Member Author

sean797 commented Mar 2, 2017

Setting WIP, this needs a fair bit more work - only raised this really so I could run the whole test suite.

@@ -320,6 +347,7 @@ def blank_or_inherit_f(f, attr)
return true unless f.object.respond_to?(:parent_id) && f.object.parent_id
inherited_value = f.object.send(attr).try(:name_method)
inherited_value ||= _("no value")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@@ -32,15 +32,17 @@ def test_edit

def test_update_invalid
SmartProxy.any_instance.stubs(:valid?).returns(false)
put :update, {:id => SmartProxy.first.to_param, :smart_proxy => {:url => nil}}, set_session_user
put :update, {:id => SmartProxy.first.to_param, :smart_proxy => {:urls_attributes => {"0"=>{:url => nil,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@sean797 sean797 force-pushed the proxy_int branch 8 times, most recently from dd36c95 to 29a1490 Compare March 7, 2017 17:38
SmartProxy.with_features(proxy_feature).map {|p| [p.name, p.id]},
:url_id,
options_for_select([[_("Select desired %s proxy URL") % _(proxy_feature), "disabled"],
[_("*Clear %s proxy URL*") % _(proxy_feature), "" ]]) +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.

end
end

def self.with_features_unscoped(*feature_names)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@sean797 sean797 force-pushed the proxy_int branch 6 times, most recently from 059060f to d517cbc Compare March 11, 2017 13:48
@sean797
Copy link
Member Author

sean797 commented Mar 20, 2017

Thanks for taking a look @stbenjam

  • I'm a little concerned we're removing some API's instead of deprecating them.

Fair point, I've update it so if a proxy is given we use the primary URL. I've also on deprecated the API v2 params. I guess we should leave API v1 alone & stable ?

  • Do we need to explicit support for multiple URL's, or wouldn't just alternate host names be enough? The proxy is still going to be using the same protocol and port isn't it? Maybe there is a use case for different ports?

Host names are enough for our purposes. Though I'm not sure if a URL would be useful to any plugins?

  • What about letting the user specify a name as well as a URL? If a proxy exists in a lot of networks, it'd be easier to pick something like "Atlanta - Dev Network" than try to select a URL.

I'm not adverse to that, though I'm not sure its really that helpful. In my experience people tend to name things in foreman by another attribute, e.g Networks by CIDR, Proxies by hostname which a lot of the time creates unnecessary duplication.

sean797 added a commit to sean797/katello that referenced this pull request Mar 20, 2017
jlsherrill pushed a commit to Katello/katello that referenced this pull request Mar 20, 2017
@sean797
Copy link
Member Author

sean797 commented Mar 22, 2017

Just a couple of screenshots in its current state

screenshot from 2017-03-22 16-07-16
screenshot from 2017-03-22 16-02-04
screenshot from 2017-03-22 16-41-26

@dmitri-d
Copy link
Member

Tangential to this PR, but to support https on multiple interfaces, smart-proxy will need a wildcard certificate. ATM there's no way to associate a certificate with a specific interface.

@sean797
Copy link
Member Author

sean797 commented Mar 24, 2017

Thanks @witlessbird, theforeman/puppet-puppet#490 fixes that using dns_alt_names 👍

end

test "can search smart proxy by feature" do
proxy = smart_proxies(:one)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@@ -92,9 +92,35 @@ class SmartProxyTest < ActiveSupport::TestCase
end

test "should not be saved if features are not array" do
proxy = SmartProxy.new(:name => 'Proxy', :url => 'https://some.where.net:8443')
proxy = SmartProxy.new(:name => 'Proxy', :url => 'https://some.where.net:8443')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@@ -83,7 +83,7 @@ class SmartProxyTest < ActiveSupport::TestCase
end

test "should not be saved if features do not exist" do
proxy = SmartProxy.new(:name => 'Proxy', :url => 'https://some.where.net:8443')
proxy = SmartProxy.new(:name => 'Proxy', :url => 'https://some.where.net:8443')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@@ -69,7 +69,7 @@ class SmartProxyTest < ActiveSupport::TestCase

test "can count connected hosts" do
proxy = FactoryGirl.create(:puppet_smart_proxy)
FactoryGirl.create(:host, :with_environment, :puppet_proxy => proxy)
FactoryGirl.create(:host, :with_environment, :puppet_proxy_hostname => proxy.hostnames.first)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@@ -49,7 +49,7 @@ class SmartProxyTest < ActiveSupport::TestCase

# test taxonomix methods
test "should get used location ids for host" do
FactoryGirl.create(:host, :with_environment, :puppet_proxy => smart_proxies(:puppetmaster),
FactoryGirl.create(:host, :with_environment, :puppet_proxy_hostname => hostnames(:puppetmaster),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@@ -21,7 +21,7 @@ def test_create_valid
ProxyAPI::Features.any_instance.stubs(:features => Feature.name_map.keys)
SmartProxy.any_instance.stubs(:valid?).returns(true)
SmartProxy.any_instance.stubs(:to_s).returns("puppet")
post :create, {:smart_proxy => {:name => "MySmartProxy", :url => "http://nowhere.net:8000"}}, set_session_user
post :create, {:smart_proxy => {:name => "MySmartProxy", :url => "http://nowhere.net:8000"}}, set_session_user

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@@ -2,7 +2,7 @@
require 'controllers/shared/smart_proxies_controller_shared_test'

class Api::V2::SmartProxiesControllerTest < ActionController::TestCase
valid_attrs = { :name => 'master02', :url => 'http://server:8443' }
valid_attrs = { :name => 'master02', :url => 'http://server:8443' }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

end

test "can search smart proxy by feature" do
proxy = smart_proxies(:one)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@@ -92,9 +92,35 @@ class SmartProxyTest < ActiveSupport::TestCase
end

test "should not be saved if features are not array" do
proxy = SmartProxy.new(:name => 'Proxy', :url => 'https://some.where.net:8443')
proxy = SmartProxy.new(:name => 'Proxy', :url => 'https://some.where.net:8443')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@@ -83,7 +83,7 @@ class SmartProxyTest < ActiveSupport::TestCase
end

test "should not be saved if features do not exist" do
proxy = SmartProxy.new(:name => 'Proxy', :url => 'https://some.where.net:8443')
proxy = SmartProxy.new(:name => 'Proxy', :url => 'https://some.where.net:8443')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@@ -69,7 +69,7 @@ class SmartProxyTest < ActiveSupport::TestCase

test "can count connected hosts" do
proxy = FactoryGirl.create(:puppet_smart_proxy)
FactoryGirl.create(:host, :with_environment, :puppet_proxy => proxy)
FactoryGirl.create(:host, :with_environment, :puppet_proxy_hostname => proxy.hostnames.first)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@@ -49,7 +49,7 @@ class SmartProxyTest < ActiveSupport::TestCase

# test taxonomix methods
test "should get used location ids for host" do
FactoryGirl.create(:host, :with_environment, :puppet_proxy => smart_proxies(:puppetmaster),
FactoryGirl.create(:host, :with_environment, :puppet_proxy_hostname => hostnames(:puppetmaster),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@@ -21,7 +21,7 @@ def test_create_valid
ProxyAPI::Features.any_instance.stubs(:features => Feature.name_map.keys)
SmartProxy.any_instance.stubs(:valid?).returns(true)
SmartProxy.any_instance.stubs(:to_s).returns("puppet")
post :create, {:smart_proxy => {:name => "MySmartProxy", :url => "http://nowhere.net:8000"}}, set_session_user
post :create, {:smart_proxy => {:name => "MySmartProxy", :url => "http://nowhere.net:8000"}}, set_session_user

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@@ -2,7 +2,7 @@
require 'controllers/shared/smart_proxies_controller_shared_test'

class Api::V2::SmartProxiesControllerTest < ActionController::TestCase
valid_attrs = { :name => 'master02', :url => 'http://server:8443' }
valid_attrs = { :name => 'master02', :url => 'http://server:8443' }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@sean797 sean797 force-pushed the proxy_int branch 10 times, most recently from 1b15bee to 33c7a64 Compare May 30, 2017 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants