foreman_virt_who_configure 0.5.1 → 0.5.6

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: ee0215d08a85e32061608ec7f2452a0d6df0cc73a322491582aa3704b43f81a0
4
- data.tar.gz: 93df5caf56ec4158b525485a7f04656ef03a6a61b1b592c54c7c3397e09a488f
3
+ metadata.gz: 38a1caca71ecc26f921be69f4efe48943a0ac7b79a0b5a7cb2d99fe41bfc202f
4
+ data.tar.gz: 000115561c5ad123da017fb662913cb3dbbe2e1113adf23cc73315735c906022
5
5
  SHA512:
6
- metadata.gz: 49be70fdb7fa4fda78219dbc332754ef38628749eda69499fdfdb238bc1aa6b2c5be9fe2c791d9e11b86ba7b34ac4196c51db467d99b522357467098eba12ed0
7
- data.tar.gz: e05cf7553259f2303652c9d4fe72c0ebb05ac975dd2b41b31dfebff88b640a31d26186293e160b6e5b9dd25a2bc1baacceb3393ec6d12eb5e10bc29f327817ff
6
+ metadata.gz: e84d2ec1aa61e5f37e1354ece1ef2e04493623cd791d0b839f996270fa32bb652aaa96af7c365015f53638658a5064d6d13c14be61704f8a765208d190389e58
7
+ data.tar.gz: 5c3d700fc5babc9d73a53c77aab32b5e92f896818fa9903efdcc5f1350c94c0c776cc27ba564bd2b0826298eef0952a7da90ccc2ab2ff24ba5f9444e50ab83f3
@@ -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
@@ -4,9 +4,7 @@ module ForemanVirtWhoConfigure
4
4
  @hypervisor_server_help_data ||= {
5
5
  'esx' => _('VMware vCenter server’s fully qualified host name or IP address.'),
6
6
  'rhevm' => _('Red Hat Virtualization Manager’s fully qualified host name or IP address. For example, <code>https://hostname:443/ovirt-engine/</code> for v4, <code>https://hostname_or_IP:443</code> for v3'),
7
- # 'vdsm' => 'Red Hat Enterprise Linux Hypervisor (vdsm)',
8
7
  'hyperv' => _('Microsoft Hyper-V fully qualified host name or IP address.'),
9
- 'xen' => _('XenServer server’s fully qualified host name or IP address.'),
10
8
  'libvirt' => _('Libvirt server’s fully qualified host name or IP address. You can also specify preferred schema, for example: <code>qemu+ssh://libvirt.example.com/system</code>. If you use SSH, make sure you setup root\'s SSH key on target host for a user specified at hypervisor username field'),
11
9
  'kubevirt' => _('Container-native virtualization’s fully qualified host name or IP address. In order to connect to the cluster it is required to provide path to kubeconfig which contains connection details and authentication token.')
12
10
  }
@@ -16,9 +14,7 @@ module ForemanVirtWhoConfigure
16
14
  @hypervisor_username_help_data ||= {
17
15
  'esx' => _('Account name by which virt-who is to connect to the hypervisor, in the format <code>domain_name\account_name</code>. Note that only a single backslash separates the values for domain_name and account_name. If you are using a domain account, and the global configuration file <code>/etc/sysconfig/virt-who</code>, then <b>two</b> backslashes are required. For further details, see <a href="https://access.redhat.com/solutions/1270223">Red Hat Knowledgebase solution How to use a windows domain account with virt-who</a> for more information.'),
18
16
  'rhevm' => _('Account name by which virt-who is to connect to the Red Hat Enterprise Virtualization Manager instance. The username option requires input in the format username@domain.'),
19
- # 'vdsm' => '',
20
17
  'hyperv' => _('Account name by which virt-who is to connect to the hypervisor. By default this is <code>Administrator</code>. To use an alternate account, create a user account and assign that account to the following groups (Windows 2012 Server): Hyper-V Administrators and Remote Management Users.'),
21
- 'xen' => _('Account name by which virt-who is to connect to the hypervisor.'),
22
18
  'libvirt' => _('Account name by which virt-who is to connect to the hypervisor. Virt-who does not support password based authentication, you must manually setup SSH key, see <a href="https://access.redhat.com/solutions/1515983">Red Hat Knowledgebase solution How to configure virt-who for a KVM host</a> for more information.'),
23
19
  'kubevirt' => ''
24
20
  }
@@ -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
@@ -32,9 +32,7 @@ module ForemanVirtWhoConfigure
32
32
  HYPERVISOR_TYPES = {
33
33
  'esx' => 'VMware vSphere / vCenter (esx)',
34
34
  'rhevm' => 'Red Hat Virtualization Hypervisor (rhevm)',
35
- # 'vdsm' => 'Red Hat Enterprise Linux Hypervisor (vdsm)',
36
35
  'hyperv' => 'Microsoft Hyper-V (hyperv)',
37
- 'xen' => 'XenServer (xen)',
38
36
  'libvirt' => 'libvirt',
39
37
  'kubevirt' => 'Container-native virtualization'
40
38
  }
@@ -73,6 +71,7 @@ module ForemanVirtWhoConfigure
73
71
 
74
72
  belongs_to :compute_resource
75
73
  belongs_to :organization
74
+ belongs_to :http_proxy
76
75
 
77
76
  # service user used by virt-who to report back
78
77
  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"
@@ -236,7 +253,7 @@ encrypted_password=$cr_password"
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"
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
- :filter_host_parents, :exclude_host_parents
12
+ :filter_host_parents, :exclude_host_parents, :kubeconfig_path
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>
@@ -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
@@ -0,0 +1,5 @@
1
+ class DeleteXenProfiles < ActiveRecord::Migration[6.0]
2
+ def change
3
+ ForemanVirtWhoConfigure::Config.where(:hypervisor_type => 'xen').destroy_all
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module ForemanVirtWhoConfigure
2
- VERSION = '0.5.1'.freeze
2
+ VERSION = '0.5.6'.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,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.1
4
+ version: 0.5.6
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-02-25 00:00:00.000000000 Z
11
+ date: 2021-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello
@@ -107,6 +107,9 @@ 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
112
+ - db/migrate/20210413165147_delete_xen_profiles.rb
110
113
  - lib/foreman_virt_who_configure.rb
111
114
  - lib/foreman_virt_who_configure/engine.rb
112
115
  - lib/foreman_virt_who_configure/version.rb
@@ -121,6 +124,7 @@ files:
121
124
  - test/functional/api/v2/configs_controller_test.rb
122
125
  - test/test_plugin_helper.rb
123
126
  - test/unit/config_test.rb
127
+ - test/unit/migrate_config_proxy_to_http_proxy.rb
124
128
  - test/unit/output_generator_test.rb
125
129
  homepage: https://github.com/theforeman/foreman_virt_who_configure
126
130
  licenses:
@@ -141,13 +145,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
145
  - !ruby/object:Gem::Version
142
146
  version: '0'
143
147
  requirements: []
144
- rubygems_version: 3.0.3
148
+ rubygems_version: 3.1.4
145
149
  signing_key:
146
150
  specification_version: 4
147
151
  summary: A plugin to make virt-who configuration easy
148
152
  test_files:
149
153
  - test/factories/foreman_virt_who_configure_factories.rb
150
- - test/test_plugin_helper.rb
154
+ - test/functional/api/v2/configs_controller_test.rb
155
+ - test/unit/migrate_config_proxy_to_http_proxy.rb
151
156
  - test/unit/config_test.rb
152
157
  - test/unit/output_generator_test.rb
153
- - test/functional/api/v2/configs_controller_test.rb
158
+ - test/test_plugin_helper.rb