foreman_virt_who_configure 0.5.0 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2659de29d0b5edec86a19012025b4330f155235dc95dd52e817761a221909d5d
4
- data.tar.gz: 575a79644dcb7a7b8521750a6b0b987c83891d56290b8abfb3aba6b3e1c31d3a
3
+ metadata.gz: fd228676712de08fec7ea70df6af7170b14fc802ee35d1bd0d74559e8beea160
4
+ data.tar.gz: cd3bd04a86a3315359c302a80bd55c436c6ded0a3e569402f2455fd183b5969c
5
5
  SHA512:
6
- metadata.gz: fa0ab2122fd333de032b1f151fcbda5f03acc0285d38cd35cb3775fe3008965a7dc1ec0f36df186324985f6923d060d313f3c1e176f1e0ce8848f1daad07cc80
7
- data.tar.gz: 4d0c8bb70e05f307b1ab5aefe6c8689b4371d6932f0af2c77ffcb7e25fc0dcef0eee0424c22f0fb133ef1e45cd1c680018232277541119913f1d3a32e15ca2bd
6
+ metadata.gz: 6fb574f47761da65869cdb11b26e26b341e674e8f4f920912bb9ed6a8b87fd2090e3ae933cc1bb8769a953109226b3727cfd740c390394f4076c42c93d47fe5b
7
+ data.tar.gz: a508d300b4417d3546fa27e1dee505d0197ff095578def373f38751d6368afe1989eae238068977060854b7f53887f0358fa8fcbb2f2ef9bdf4d6eb153ebef16
@@ -52,7 +52,7 @@ module ForemanVirtWhoConfigure
52
52
  param :hypervisor_password, String, :desc => N_("Hypervisor password, required for all hypervisor types except for libvirt"), :required => false
53
53
  param :satellite_url, String, :desc => N_("Satellite server FQDN"), :required => true
54
54
  param :debug, :bool, :desc => N_("Enable debugging output")
55
- param :proxy, String, :desc => N_('HTTP proxy that should be used for communication between the server on which virt-who is running and the hypervisors and virtualization managers.'), :required => false
55
+ param :http_proxy_id, Integer, :desc => N_('HTTP proxy that should be used for communication between the server on which virt-who is running and the hypervisors and virtualization managers.')
56
56
  param :no_proxy, String, :desc => N_("Ignore proxy. A comma-separated list of hostnames or domains or ip addresses to ignore proxy settings for. Optionally this may be set to * to bypass proxy settings for all hostnames domains or ip addresses.")
57
57
  param :organization_id, Integer, :required => true, :desc => N_("Organization of the virt-who configuration") if ::SETTINGS[:organizations_enabled]
58
58
  end
@@ -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
@@ -83,8 +83,25 @@ verify_minimal_version() {
83
83
  }
84
84
 
85
85
  result_code=#{error_code(:success)}
86
+
87
+ compose_install_command() {
88
+ $1 packages unlock
89
+ $1 advanced procedure run packages-install --packages virt-who --assumeyes || result_code=$(($result_code|#{error_code(:virt_who_installation)}))
90
+ $1 packages lock
91
+ }
92
+
93
+ install_virt_who() {
94
+ if `rpm -q satellite-maintain > /dev/null`; then
95
+ compose_install_command satellite-maintain
96
+ elif `rpm -q rubygem-foreman_maintain > /dev/null`; then
97
+ compose_install_command foreman-maintain
98
+ else
99
+ yum install -y virt-who || result_code=$(($result_code|#{error_code(:virt_who_installation)}))
100
+ fi
101
+ }
102
+
86
103
  step 1 "Installing virt-who"
87
- yum install -y virt-who || result_code=$(($result_code|#{error_code(:virt_who_installation)}))
104
+ install_virt_who
88
105
 
89
106
  if verify_minimal_version; then
90
107
  step 2 "Encrypting password"
@@ -99,7 +116,7 @@ if verify_minimal_version; then
99
116
  type=#{type}
100
117
  hypervisor_id=#{hypervisor_id}
101
118
  owner=#{owner}
102
- env=Library#{connection_details}
119
+ env=Library#{connection_details}#{filtering}
103
120
  rhsm_hostname=#{satellite_url}
104
121
  rhsm_username=#{service_user_username}
105
122
  rhsm_encrypted_password=$user_password
@@ -142,7 +159,7 @@ EOS
142
159
  else
143
160
  "\nserver=#{cr_server}
144
161
  username=#{cr_username}
145
- encrypted_password=$cr_password#{filtering}"
162
+ encrypted_password=$cr_password"
146
163
  end
147
164
  end
148
165
 
@@ -236,7 +253,7 @@ encrypted_password=$cr_password#{filtering}"
236
253
  end
237
254
 
238
255
  def proxy
239
- config.proxy
256
+ config.http_proxy
240
257
  end
241
258
 
242
259
  def no_proxy
@@ -247,9 +264,13 @@ encrypted_password=$cr_password#{filtering}"
247
264
  sanitize(string)
248
265
  end
249
266
 
267
+ def proxy_type
268
+ "#{URI(proxy.url).scheme}_proxy"
269
+ end
270
+
250
271
  def proxy_strings
251
272
  output = ''
252
- output << "\nhttp_proxy=#{sanitize_proxy(proxy)}" if proxy.present?
273
+ output << "\n#{proxy_type}=#{sanitize_proxy(proxy.full_url)}" if proxy.present?
253
274
  output << "\nNO_PROXY=#{sanitize_proxy(no_proxy)}" if no_proxy.present?
254
275
  output << "\nNO_PROXY=*" if !proxy.present? && !no_proxy.present?
255
276
  output
@@ -2,8 +2,17 @@ object @config
2
2
 
3
3
  extends "foreman_virt_who_configure/api/v2/configs/base"
4
4
 
5
+ glue :http_proxy do
6
+ attributes :url => :proxy
7
+ end
8
+
5
9
  attributes :name, :interval, :organization_id, :whitelist, :blacklist, :hypervisor_id,
6
10
  :hypervisor_type, :hypervisor_server, :hypervisor_username, :debug,
7
11
  :satellite_url, :proxy, :no_proxy, :status, :last_report_at, :out_of_date_at,
8
12
  :filter_host_parents, :exclude_host_parents
13
+
14
+ child :http_proxy do
15
+ attributes :id, :name, :url
16
+ end
17
+
9
18
  attributes :listing_mode => :filtering_mode
@@ -2,12 +2,13 @@
2
2
 
3
3
  <%= breadcrumbs(:resource_url => foreman_virt_who_configure_api_configs_path,
4
4
  :items => [
5
- {:caption => _('Configurations'),
6
- :url => url_for(foreman_virt_who_configure_configs_path)
7
- },
8
- {:caption => _('Edit') + ' ' + @config.name,
9
- :url => (edit_foreman_virt_who_configure_config_path(@config) if authorized_for(hash_for_edit_foreman_virt_who_configure_config_path(@config)))
10
- }
5
+ {
6
+ :caption => _('Virt-who Configurations'),
7
+ :url => foreman_virt_who_configure_configs_path
8
+ },
9
+ {
10
+ :caption => _('Edit') + ' ' + @config.name
11
+ }
11
12
  ]
12
13
  ) %>
13
14
 
@@ -8,12 +8,13 @@
8
8
 
9
9
  <%= breadcrumbs(:resource_url => foreman_virt_who_configure_api_configs_path,
10
10
  :items => [
11
- {:caption => _('Configurations'),
12
- :url => url_for(foreman_virt_who_configure_configs_path)
13
- },
14
- {:caption => @config.name,
15
- :url => (edit_foreman_virt_who_configure_config_path(@config) if authorized_for(hash_for_edit_foreman_virt_who_configure_config_path(@config)))
16
- }
11
+ {
12
+ :caption => _('Virt-who Configurations'),
13
+ :url => foreman_virt_who_configure_configs_path
14
+ },
15
+ {
16
+ :caption => @config.name
17
+ }
17
18
  ]
18
19
  ) %>
19
20
 
@@ -48,7 +49,7 @@
48
49
  <%= config_attribute :exclude_host_parents, @config.exclude_host_parents if @config.exclude_host_parents.present? %>
49
50
  <% end %>
50
51
  <%= config_attribute :debug, checked_icon(@config.debug), _('Enable debugging output?') %>
51
- <%= config_attribute :proxy, @config.proxy, _('HTTP Proxy') if @config.proxy.present? %>
52
+ <%= config_attribute :http_proxy_id, @config.http_proxy.full_url, _('HTTP Proxy') if @config.http_proxy.present? %>
52
53
  <%= config_attribute :no_proxy, @config.no_proxy, _('Ignore Proxy') if @config.no_proxy.present? %>
53
54
  <%= config_attribute :kubeconfig_path, @config.kubeconfig_path if @config.hypervisor_type == 'kubevirt' %>
54
55
  </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>
@@ -1,5 +1,6 @@
1
1
  <div class="blank-slate-pf">
2
2
  <div class="blank-slate-pf-icon">
3
+ <% title _("Virt-who Configurations") %>
3
4
  <%= icon_text("globe", "", :kind => "fa") %>
4
5
  </div>
5
6
  <h1><%= _('Configs') %></h1>
@@ -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
@@ -0,0 +1,5 @@
1
+ class AddForeignKeyProxyId < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_foreign_key :foreman_virt_who_configure_configs, :http_proxies, :column => :http_proxy_id
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module ForemanVirtWhoConfigure
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.5.5'.freeze
3
3
  end
@@ -2,23 +2,23 @@ FactoryBot.define do
2
2
  factory :virt_who_config, :class => ::ForemanVirtWhoConfigure::Config do
3
3
  sequence(:name) { |n| "config #{n}" }
4
4
  organization
5
- interval 120
6
- hypervisor_id 'hostname'
7
- hypervisor_type 'esx'
8
- hypervisor_server 'vmware.example.com'
9
- hypervisor_username 'root'
10
- hypervisor_password 'changeme'
11
- satellite_url 'foreman.example.com'
12
- listing_mode ForemanVirtWhoConfigure::Config::UNLIMITED
5
+ interval { 120 }
6
+ hypervisor_id { 'hostname' }
7
+ hypervisor_type { 'esx' }
8
+ hypervisor_server { 'vmware.example.com' }
9
+ hypervisor_username { 'root' }
10
+ hypervisor_password { 'changeme' }
11
+ satellite_url { 'foreman.example.com' }
12
+ listing_mode { ForemanVirtWhoConfigure::Config::UNLIMITED }
13
13
  end
14
14
 
15
15
  trait :out_of_date do
16
- last_report_at (1.minute.ago - 120.minutes).utc
17
- out_of_date_at (1.minute.ago).utc
16
+ last_report_at { (1.minute.ago - 120.minutes).utc }
17
+ out_of_date_at { (1.minute.ago).utc }
18
18
  end
19
19
 
20
20
  trait :ok do
21
- last_report_at (1.minute.ago).utc
22
- out_of_date_at (1.minute.ago + 120.minutes).utc
21
+ last_report_at { (1.minute.ago).utc }
22
+ out_of_date_at { (1.minute.ago + 120.minutes).utc }
23
23
  end
24
24
  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,12 @@ 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, response['http_proxy']['id']
82
+ assert_equal @http_proxy.url, response['proxy']
82
83
 
83
84
  assert_response :success
84
85
  end
@@ -140,6 +141,7 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
140
141
  :hypervisor_password => "password",
141
142
  :debug => true,
142
143
  :satellite_url => "foreman.example.com",
144
+ :http_proxy_id => @http_proxy.id,
143
145
  :organization_id => org.id }
144
146
  }, :session => set_session_user
145
147
 
@@ -158,6 +160,7 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
158
160
  assert_equal 'password', new_config.hypervisor_password
159
161
  assert_equal true, new_config.debug
160
162
  assert_equal 'foreman.example.com', new_config.satellite_url
163
+ assert_equal @http_proxy.id, response['http_proxy']['id']
161
164
  end
162
165
 
163
166
  test "should update the config" do
@@ -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.0
4
+ version: 0.5.5
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: 2019-11-19 00:00:00.000000000 Z
11
+ date: 2020-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello
@@ -107,6 +107,8 @@ 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
111
+ - db/migrate/20201211160234_add_foreign_key_proxy_id.rb
110
112
  - lib/foreman_virt_who_configure.rb
111
113
  - lib/foreman_virt_who_configure/engine.rb
112
114
  - lib/foreman_virt_who_configure/version.rb
@@ -121,6 +123,7 @@ files:
121
123
  - test/functional/api/v2/configs_controller_test.rb
122
124
  - test/test_plugin_helper.rb
123
125
  - test/unit/config_test.rb
126
+ - test/unit/migrate_config_proxy_to_http_proxy.rb
124
127
  - test/unit/output_generator_test.rb
125
128
  homepage: https://github.com/theforeman/foreman_virt_who_configure
126
129
  licenses:
@@ -141,13 +144,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
144
  - !ruby/object:Gem::Version
142
145
  version: '0'
143
146
  requirements: []
144
- rubygems_version: 3.0.3
147
+ rubygems_version: 3.1.4
145
148
  signing_key:
146
149
  specification_version: 4
147
150
  summary: A plugin to make virt-who configuration easy
148
151
  test_files:
149
152
  - test/factories/foreman_virt_who_configure_factories.rb
150
- - test/test_plugin_helper.rb
153
+ - test/functional/api/v2/configs_controller_test.rb
154
+ - test/unit/migrate_config_proxy_to_http_proxy.rb
151
155
  - test/unit/config_test.rb
152
156
  - test/unit/output_generator_test.rb
153
- - test/functional/api/v2/configs_controller_test.rb
157
+ - test/test_plugin_helper.rb