-
Notifications
You must be signed in to change notification settings - Fork 987
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
Conversation
@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. |
app/models/smart_proxy_url.rb
Outdated
|
||
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? |
There was a problem hiding this comment.
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.
app/models/smart_proxy_url.rb
Outdated
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 |
There was a problem hiding this comment.
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.
app/models/smart_proxy_url.rb
Outdated
@@ -0,0 +1,37 @@ | |||
class SmartProxyUrl < ActiveRecord::Base | |||
|
There was a problem hiding this comment.
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.
app/models/smart_proxy.rb
Outdated
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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
76f044d
to
e784d0c
Compare
Setting WIP, this needs a fair bit more work - only raised this really so I could run the whole test suite. |
app/helpers/form_helper.rb
Outdated
@@ -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") | |||
|
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
dd36c95
to
29a1490
Compare
app/helpers/hosts_helper.rb
Outdated
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), "" ]]) + |
There was a problem hiding this comment.
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.
app/models/smart_proxy_url.rb
Outdated
end | ||
end | ||
|
||
def self.with_features_unscoped(*feature_names) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
059060f
to
d517cbc
Compare
Thanks for taking a look @stbenjam
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 ?
Host names are enough for our purposes. Though I'm not sure if a URL would be useful to any plugins?
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. |
This fixes the failing test on theforeman/foreman#4346
This fixes the failing test on theforeman/foreman#4346
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. |
Thanks @witlessbird, theforeman/puppet-puppet#490 fixes that using dns_alt_names 👍 |
5da98af
to
52ffd33
Compare
test/models/smart_proxy_test.rb
Outdated
end | ||
|
||
test "can search smart proxy by feature" do | ||
proxy = smart_proxies(:one) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
test/models/smart_proxy_test.rb
Outdated
@@ -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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
test/models/smart_proxy_test.rb
Outdated
@@ -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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
test/models/smart_proxy_test.rb
Outdated
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
test/models/smart_proxy_test.rb
Outdated
@@ -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), |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
test/models/smart_proxy_test.rb
Outdated
end | ||
|
||
test "can search smart proxy by feature" do | ||
proxy = smart_proxies(:one) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
test/models/smart_proxy_test.rb
Outdated
@@ -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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
test/models/smart_proxy_test.rb
Outdated
@@ -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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
test/models/smart_proxy_test.rb
Outdated
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
test/models/smart_proxy_test.rb
Outdated
@@ -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), |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
1b15bee
to
33c7a64
Compare
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".