foreman_virt_who_configure 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2f81954f513244fa71dc19f9629494140c96c6f71c915c796efde096a52a1b7
4
- data.tar.gz: 625fc61c55a5947a1180231b1ac249f0971941c66c3808c45a778e1a7fdeac42
3
+ metadata.gz: 5bc24bfcd7c5fe0ea8c6e69c647b7c971496907697ee0035bfd58db208d1b00c
4
+ data.tar.gz: 715876ebff38e880adcc909f5952e124e772680b619ee49c9a1c7d0181ad9e74
5
5
  SHA512:
6
- metadata.gz: 9ad29fe8c09273a39f0252467ea47d556a585c186d3f9d50a4c3f2b47abafbaf769d72bd84aca2261d2e3e95621e7a2a3a4145a6e2a8bf4d6731e51ed287b3c6
7
- data.tar.gz: 9f15813bd839f16eea992dd9b8c9800e435665f8ed51e420e701a8d67c213d8783b83f865f70530bd49d09a4e83efb51e20f465ad5036c10321ecb8affbfeae6
6
+ metadata.gz: 726b628af273e54a87f7066b38a37445f411f2642e3704ff1113465ae5b9034f88d6a82a060ab50aa8a3ae1204820852a0f0feb2c2afa49c7de5842a87da369b
7
+ data.tar.gz: ea0123e3015c62a314a5c6bb6f06c87bc4ea3bdba2fa8c2f292cfc0c153c623d8fd898ac5aaff4b6a19f8ac864d8f9535ffcc6a4f8068f9f7563c9c0245668b2
@@ -3,7 +3,7 @@ module ForemanVirtWhoConfigure
3
3
  PERMITTED_PARAMS = [
4
4
  :interval, :organization_id, :compute_resource_id, :whitelist, :blacklist, :hypervisor_id,
5
5
  :hypervisor_type, :hypervisor_server, :hypervisor_username, :hypervisor_password, :debug,
6
- :satellite_url, :proxy, :no_proxy, :name,
6
+ :satellite_url, :http_proxy_id, :no_proxy, :name,
7
7
  # API parameter filtering_mode gets translated to listing_mode in the controller
8
8
  # We keep both params permitted for compatibility with 1.11
9
9
  :listing_mode, :filtering_mode, :filter_host_parents, :exclude_host_parents, :kubeconfig_path
@@ -73,6 +73,7 @@ module ForemanVirtWhoConfigure
73
73
 
74
74
  belongs_to :compute_resource
75
75
  belongs_to :organization
76
+ belongs_to :http_proxy
76
77
 
77
78
  # service user used by virt-who to report back
78
79
  belongs_to :service_user
@@ -253,7 +253,7 @@ encrypted_password=$cr_password"
253
253
  end
254
254
 
255
255
  def proxy
256
- config.proxy
256
+ config.http_proxy
257
257
  end
258
258
 
259
259
  def no_proxy
@@ -264,9 +264,13 @@ encrypted_password=$cr_password"
264
264
  sanitize(string)
265
265
  end
266
266
 
267
+ def proxy_type
268
+ "#{URI(proxy.url).scheme}_proxy"
269
+ end
270
+
267
271
  def proxy_strings
268
272
  output = ''
269
- output << "\nhttp_proxy=#{sanitize_proxy(proxy)}" if proxy.present?
273
+ output << "\n#{proxy_type}=#{sanitize_proxy(proxy.full_url)}" if proxy.present?
270
274
  output << "\nNO_PROXY=#{sanitize_proxy(no_proxy)}" if no_proxy.present?
271
275
  output << "\nNO_PROXY=*" if !proxy.present? && !no_proxy.present?
272
276
  output
@@ -48,7 +48,7 @@
48
48
  <%= config_attribute :exclude_host_parents, @config.exclude_host_parents if @config.exclude_host_parents.present? %>
49
49
  <% end %>
50
50
  <%= config_attribute :debug, checked_icon(@config.debug), _('Enable debugging output?') %>
51
- <%= config_attribute :proxy, @config.proxy, _('HTTP Proxy') if @config.proxy.present? %>
51
+ <%= config_attribute :http_proxy_id, @config.http_proxy.full_url, _('HTTP Proxy') if @config.http_proxy.present? %>
52
52
  <%= config_attribute :no_proxy, @config.no_proxy, _('Ignore Proxy') if @config.no_proxy.present? %>
53
53
  <%= config_attribute :kubeconfig_path, @config.kubeconfig_path if @config.hypervisor_type == 'kubevirt' %>
54
54
  </div>
@@ -18,7 +18,8 @@
18
18
  <%= textarea_f f, :exclude_host_parents, inline_help_popover(_('Hosts which parent (usually ComputeResource) name is specified in comma-separated list in this option will <b>NOT</b> be reported. Wildcards and regular expressions are supported, multiple records must be separated by comma. Put the value into the double-quotes if it contains special characters like comma. All new line characters will be removed in resulting configuration file, white spaces are removed from beginning and end.')).merge(:label => _('Exclude host parents')) %>
19
19
 
20
20
  <%= checkbox_f f, :debug, { :label => _('Enable debugging output') }.merge(inline_help_popover(_("Different debug value can't be set per hypervisor, therefore it will affect all other deployed configurations on the host on which this configuration will be deployed."))) %>
21
- <%= text_f f, :proxy, inline_help_popover(_('HTTP proxy that should be used for communication between the server on which virt-who is running and the hypervisors and virtualization managers. Leave this blank if no proxy is used.')).merge(:label => _('HTTP proxy')) %>
21
+ <%= select_f f, :http_proxy_id, HttpProxy.all, :id, :full_url, {:include_blank => true}, { :label => _('HTTP Proxy') }.merge(
22
+ inline_help_popover(_('HTTP proxy that should be used for communication between the server on which virt-who is running and the hypervisors and virtualization managers. Leave this blank if no proxy is used.').html_safe)) %>
22
23
  <%= text_f f, :no_proxy, inline_help_popover(_('A comma-separated list of hostnames or domains or ip addresses to ignore proxy settings for. Optionally this may be set to <code>*</code> to bypass proxy settings for all hostnames domains or ip addresses.')).merge(:label => _('Ignore proxy')) %>
23
24
  <%= text_f f, :kubeconfig_path, inline_help_popover(_('Configuration file containing details about how to connect to the cluster and authentication details')).merge(:label => _('Path to kubeconfig file')) %>
24
25
  </div>
@@ -0,0 +1,74 @@
1
+ class ReferConfigProxyToHttpProxy < ActiveRecord::Migration[6.0]
2
+ def up
3
+ add_column :foreman_virt_who_configure_configs, :http_proxy_id, :integer
4
+
5
+ if User.where(login: User::ANONYMOUS_ADMIN).exists?
6
+ User.as_anonymous_admin do
7
+ http_proxies = HttpProxy.all
8
+ ::ForemanVirtWhoConfigure::Config.find_each do |config|
9
+ if config.proxy.present?
10
+ migrate_config(http_proxies, config)
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ remove_column :foreman_virt_who_configure_configs, :proxy
17
+ end
18
+
19
+ def down
20
+ add_column :foreman_virt_who_configure_configs, :proxy, :string
21
+
22
+ if User.where(login: User::ANONYMOUS_ADMIN).exists?
23
+ User.as_anonymous_admin do
24
+ ::ForemanVirtWhoConfigure::Config.find_each do |config|
25
+ if config.http_proxy_id.present?
26
+ config.proxy = config.http_proxy.full_url
27
+ config.save!
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ remove_column :foreman_virt_who_configure_configs, :http_proxy_id
34
+ end
35
+
36
+ private
37
+
38
+ def migrate_config(http_proxies, config)
39
+ http_proxy = http_proxies.find { |proxy| proxy.full_url == proxy_uri(config.proxy).to_s }
40
+
41
+ if http_proxy.present?
42
+ config.http_proxy = http_proxy
43
+ else
44
+ http_proxy = build_http_proxy(config.proxy)
45
+ if http_proxy.save
46
+ config.http_proxy_id = http_proxy.id
47
+ end
48
+ end
49
+
50
+ config.save!
51
+ rescue URI::InvalidURIError
52
+ Rails.logger.debug "Config with id #{config.id} has not valid proxy #{config.proxy}"
53
+ end
54
+
55
+ def proxy_uri(config_proxy)
56
+ uri = URI(config_proxy)
57
+ unless ['http', 'https'].include? uri.scheme
58
+ config_proxy = "http://#{config_proxy}"
59
+ uri = URI(config_proxy)
60
+ end
61
+ uri
62
+ end
63
+
64
+ def build_http_proxy(proxy_url)
65
+ uri = proxy_uri(proxy_url)
66
+ url = if uri.port
67
+ "#{uri.scheme}://#{uri.host}:#{uri.port.to_s}"
68
+ else
69
+ "#{uri.scheme}://#{uri.host}"
70
+ end
71
+
72
+ HttpProxy.new(name: "virt_who_#{uri.host}", url: url, username: uri.user, password: uri.password)
73
+ end
74
+ end
@@ -1,3 +1,3 @@
1
1
  module ForemanVirtWhoConfigure
2
- VERSION = '0.5.2'.freeze
2
+ VERSION = '0.5.3'.freeze
3
3
  end
@@ -2,6 +2,7 @@ require 'test_plugin_helper'
2
2
 
3
3
  class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController::TestCase
4
4
  setup do
5
+ @http_proxy = FactoryBot.create(:http_proxy, name: "test", url: "http://test.com")
5
6
  @new_config = FactoryBot.create(:virt_who_config,
6
7
  :name => 'my vmware',
7
8
  :interval => 120,
@@ -13,7 +14,7 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
13
14
  :hypervisor_username => "root",
14
15
  :debug => false,
15
16
  :satellite_url => "foreman.example.com",
16
- :proxy => 'proxy.example.com',
17
+ :http_proxy_id => @http_proxy.id,
17
18
  :no_proxy => nil
18
19
  )
19
20
 
@@ -41,7 +42,6 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
41
42
  refute result_config['debug']
42
43
  assert_not_nil result_config['debug']
43
44
  assert_equal 'foreman.example.com', result_config['satellite_url']
44
- assert_equal 'proxy.example.com', result_config['proxy']
45
45
  assert_nil result_config['no_proxy']
46
46
  assert_equal 'unknown', result_config['status']
47
47
  assert_nil result_config['last_report_at']
@@ -74,11 +74,11 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
74
74
  refute response['debug']
75
75
  assert_not_nil response['debug']
76
76
  assert_equal 'foreman.example.com', response['satellite_url']
77
- assert_equal 'proxy.example.com', response['proxy']
78
77
  assert_nil response['no_proxy']
79
78
  assert_equal 'unknown', response['status']
80
79
  assert_nil response['last_report_at']
81
80
  assert_nil response['out_of_date_at']
81
+ assert_equal @http_proxy.id, ForemanVirtWhoConfigure::Config.find(response['id']).http_proxy_id
82
82
 
83
83
  assert_response :success
84
84
  end
@@ -0,0 +1,158 @@
1
+ require 'test_plugin_helper'
2
+ require ForemanVirtWhoConfigure::Engine.root.join('db', 'migrate', '20200728054557_refer_config_proxy_to_http_proxy.rb')
3
+
4
+ module ForemanVirtWhoConfigure
5
+ class MigrateConfigProxyToHttpProxy < ActiveSupport::TestCase
6
+ let(:migration) { klass.new }
7
+
8
+ def migration_has_been_run?(version)
9
+ ActiveRecord::SchemaMigration.where(version: version).exists?
10
+ end
11
+
12
+ describe "up" do
13
+ let(:config) { FactoryBot.build(:virt_who_config) }
14
+
15
+ before do
16
+ if migration_has_been_run?('20200728054557')
17
+ migration.down
18
+ end
19
+
20
+ HttpProxy.delete_all
21
+ end
22
+
23
+ it "should create Http Proxy if already not exist" do
24
+ config.proxy = "test.example.com"
25
+ config.save!
26
+
27
+ assert_difference('HttpProxy.count', 1) do
28
+ migration.up
29
+ end
30
+
31
+ assert_equal "http://test.example.com", created_http_proxy.full_url
32
+ end
33
+
34
+ it "should create Http Proxy with user and password if already not exist" do
35
+ config.proxy = "http://user:password@test.example.com"
36
+ config.save!
37
+
38
+ assert_difference('HttpProxy.count', 1) do
39
+ migration.up
40
+ end
41
+
42
+ assert_equal "http://user:password@test.example.com", created_http_proxy.full_url
43
+ assert_equal "user", created_http_proxy.username
44
+ assert_equal "password", created_http_proxy.password
45
+ end
46
+
47
+ it "should not create Http Proxy for invalid config proxy if already not exist" do
48
+ config.proxy = "test.example.com:5000"
49
+ config.save!
50
+
51
+ assert_difference('HttpProxy.count', 1) do
52
+ migration.up
53
+ end
54
+
55
+ assert_equal "http://test.example.com:5000", created_http_proxy.full_url
56
+ end
57
+
58
+ it "should create Http Proxy with port for config proxy if already not exist" do
59
+ config.proxy = "https://test.example.com:5000"
60
+ config.save!
61
+
62
+ assert_difference('HttpProxy.count', 1) do
63
+ migration.up
64
+ end
65
+
66
+ assert_equal "https://test.example.com:5000", created_http_proxy.full_url
67
+ end
68
+
69
+ it "should refer to existed Http Proxy" do
70
+ http_proxy = FactoryBot.create(:http_proxy, name: "test", url: "http://test.com")
71
+ config.proxy = "http://test.com"
72
+ config.save!
73
+
74
+ assert_difference('HttpProxy.count', 0) do
75
+ migration.up
76
+ end
77
+
78
+ assert_equal updated_config.http_proxy_id, http_proxy.id
79
+ end
80
+
81
+ it "should refer to existed IP address http proxy" do
82
+ http_proxy = FactoryBot.create(:http_proxy, name: "test", url: "http://212.212.10.23")
83
+ config.proxy = "212.212.10.23"
84
+ config.save!
85
+
86
+ assert_difference('HttpProxy.count', 0) do
87
+ migration.up
88
+ end
89
+
90
+ assert_equal updated_config.http_proxy_id, http_proxy.id
91
+ end
92
+
93
+ it "should create new http proxy if user and password is present" do
94
+ http_proxy = FactoryBot.create(:http_proxy, name: "test", url: "http://proxy.example.com", username: "admin", password: "pass")
95
+ config.proxy = "http://proxy.example.com"
96
+ config.save!
97
+
98
+ assert_difference('HttpProxy.count', 1) do
99
+ migration.up
100
+ end
101
+
102
+ assert_not_equal updated_config.http_proxy_id, http_proxy.id
103
+ assert_equal updated_config.http_proxy_id, created_http_proxy.id
104
+ assert_equal "http://proxy.example.com", created_http_proxy.full_url
105
+ end
106
+
107
+ it "refer to http proxy if user and password is present" do
108
+ http_proxy = FactoryBot.create(:http_proxy, name: "test", url: "http://proxy.example.com", username: "admin", password: "pass")
109
+ config.proxy = "http://admin:pass@proxy.example.com"
110
+ config.save!
111
+
112
+ assert_difference('HttpProxy.count', 0) do
113
+ migration.up
114
+ end
115
+
116
+ assert_equal updated_config.http_proxy_id, http_proxy.id
117
+ end
118
+
119
+ it "should create new http proxy if port is there" do
120
+ http_proxy = FactoryBot.create(:http_proxy, name: "test", url: "http://proxy.example.com:5000")
121
+ config.proxy = "http://proxy.example.com"
122
+ config.save!
123
+
124
+ assert_difference('HttpProxy.count', 1) do
125
+ migration.up
126
+ end
127
+
128
+ assert_not_equal updated_config.http_proxy_id, http_proxy.id
129
+ assert_equal updated_config.http_proxy_id, created_http_proxy.id
130
+ assert_equal "http://proxy.example.com", created_http_proxy.full_url
131
+ end
132
+
133
+ it "should refer to existed http proxy if port is there and config proxy has also same port" do
134
+ http_proxy = FactoryBot.create(:http_proxy, name: "test", url: "http://proxy.example.com:5000")
135
+ config.proxy = "http://proxy.example.com:5000"
136
+ config.save!
137
+
138
+ assert_difference('HttpProxy.count', 0) do
139
+ migration.up
140
+ end
141
+
142
+ assert_equal updated_config.http_proxy_id, http_proxy.id
143
+ end
144
+ end
145
+
146
+ def klass
147
+ ReferConfigProxyToHttpProxy
148
+ end
149
+
150
+ def updated_config
151
+ ::ForemanVirtWhoConfigure::Config.last
152
+ end
153
+
154
+ def created_http_proxy
155
+ HttpProxy.order(:id).last
156
+ end
157
+ end
158
+ end
@@ -57,15 +57,16 @@ module ForemanVirtWhoConfigure
57
57
 
58
58
  describe 'proxy attributes' do
59
59
  test 'it does not set any proxy attributes by default and set no_proxy to * to bypass sub-man proxy' do
60
- assert_nil config.proxy
60
+ assert_nil config.http_proxy
61
61
  assert_nil config.no_proxy
62
62
  assert_not_includes output, 'http_proxy'
63
63
  assert_includes output, 'NO_PROXY=*'
64
64
  end
65
65
 
66
66
  test 'it configures proxy when set' do
67
- config.proxy = 'http://proxy.com'
68
- assert_includes output, 'http_proxy=http://proxy.com'
67
+ http_proxy = HttpProxy.create!(name: "test", url: "http://test.com")
68
+ config.http_proxy = http_proxy
69
+ assert_includes output, 'http_proxy=http://test.com'
69
70
  end
70
71
 
71
72
  test 'it configures no_proxy when set' do
@@ -74,25 +75,30 @@ module ForemanVirtWhoConfigure
74
75
  end
75
76
 
76
77
  test 'proxy_strings prints both proxy and no proxy if present' do
77
- config.proxy = 'a'
78
+ http_proxy = HttpProxy.create!(name: "test", url: "http://test.com")
79
+ config.http_proxy = http_proxy
78
80
  config.no_proxy = 'b'
79
- assert_includes generator.proxy_strings, "\nhttp_proxy=a"
81
+ assert_includes generator.proxy_strings, "\nhttp_proxy=http://test.com"
80
82
  assert_includes generator.proxy_strings, "\NO_PROXY=b"
81
83
  end
82
84
 
83
85
  test 'proxy_strings ignores empty string values' do
84
- config.proxy = ''
86
+ config.http_proxy = nil
85
87
  config.no_proxy = ''
86
88
  assert_not_includes generator.proxy_strings, 'http_proxy'
87
89
  assert_includes generator.proxy_strings, 'NO_PROXY=*'
88
90
  end
89
91
 
90
92
  test 'proxy_strings removes any new line chars' do
91
- config.proxy = "\na\nb\nc\n"
92
93
  config.no_proxy = "\nx\ny\nz"
93
- assert_includes generator.proxy_strings, "\nhttp_proxy=abc"
94
94
  assert_includes generator.proxy_strings, "\NO_PROXY=xyz"
95
95
  end
96
+
97
+ test 'it configures https proxy when https proxy is set' do
98
+ http_proxy = HttpProxy.create!(name: "test", url: "https://test.com")
99
+ config.http_proxy = http_proxy
100
+ assert_includes output, 'https_proxy=https://test.com'
101
+ end
96
102
  end
97
103
 
98
104
  describe 'error codes' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_virt_who_configure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman virt-who-configure team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-02 00:00:00.000000000 Z
11
+ date: 2020-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello
@@ -107,6 +107,7 @@ files:
107
107
  - db/migrate/20170407152851_add_name_to_config.rb
108
108
  - db/migrate/20181005065724_filter_and_exclude_host_parents.foreman_virt_who_configure.rb
109
109
  - db/migrate/20190104125749_add_kubeconfig_to_config.rb
110
+ - db/migrate/20200728054557_refer_config_proxy_to_http_proxy.rb
110
111
  - lib/foreman_virt_who_configure.rb
111
112
  - lib/foreman_virt_who_configure/engine.rb
112
113
  - lib/foreman_virt_who_configure/version.rb
@@ -121,6 +122,7 @@ files:
121
122
  - test/functional/api/v2/configs_controller_test.rb
122
123
  - test/test_plugin_helper.rb
123
124
  - test/unit/config_test.rb
125
+ - test/unit/migrate_config_proxy_to_http_proxy.rb
124
126
  - test/unit/output_generator_test.rb
125
127
  homepage: https://github.com/theforeman/foreman_virt_who_configure
126
128
  licenses:
@@ -141,13 +143,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
143
  - !ruby/object:Gem::Version
142
144
  version: '0'
143
145
  requirements: []
144
- rubygems_version: 3.0.3
146
+ rubygems_version: 3.1.2
145
147
  signing_key:
146
148
  specification_version: 4
147
149
  summary: A plugin to make virt-who configuration easy
148
150
  test_files:
149
151
  - test/factories/foreman_virt_who_configure_factories.rb
150
- - test/test_plugin_helper.rb
152
+ - test/functional/api/v2/configs_controller_test.rb
153
+ - test/unit/migrate_config_proxy_to_http_proxy.rb
151
154
  - test/unit/config_test.rb
152
155
  - test/unit/output_generator_test.rb
153
- - test/functional/api/v2/configs_controller_test.rb
156
+ - test/test_plugin_helper.rb