foreman_discovery 10.0.0 → 11.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/controllers/api/v2/discovered_hosts_controller.rb +1 -1
  4. data/app/controllers/api/v2/discovery_rules_controller.rb +2 -1
  5. data/app/controllers/concerns/foreman/controller/parameters/discovered_host.rb +9 -2
  6. data/app/controllers/discovered_hosts_controller.rb +16 -15
  7. data/app/controllers/discovery_rules_controller.rb +1 -1
  8. data/app/models/host/discovered.rb +10 -4
  9. data/app/models/host/managed_extensions.rb +4 -1
  10. data/app/views/foreman_discovery/debian_kexec.erb +1 -1
  11. data/db/migrate/20141107091416_create_discovery_rules.rb +1 -1
  12. data/db/migrate/20141107091417_add_discovery_rule_to_host.rb +1 -1
  13. data/db/migrate/20141126165451_add_discovery_id_to_subnet.rb +1 -1
  14. data/db/migrate/20141223101707_create_discovery_attribute_sets.rb +1 -1
  15. data/db/migrate/20141223142759_fill_discovery_attribute_sets_for_existing_hosts.rb +1 -1
  16. data/db/migrate/20150302112545_remove_duplicate_tokens_from_hosts.rb +1 -1
  17. data/db/migrate/20150310153859_remove_discovery_attribute_sets_from_managed_hosts.rb +1 -1
  18. data/db/migrate/20150331132115_remove_old_permissions.rb +1 -1
  19. data/db/migrate/20150505111345_remove_leftover_tokens.rb +1 -1
  20. data/db/migrate/20150512150432_remove_old_discovery_reader_permissions.rb +1 -1
  21. data/db/migrate/20150714144500_review_discovery_permissions.rb +1 -1
  22. data/db/migrate/20151023144501_regenerate_red_hat_kexec.rb +1 -1
  23. data/db/migrate/20160719124942_add_missing_view_permissions.rb +1 -1
  24. data/db/migrate/20160805104605_rename_lock_template_setting.rb +1 -1
  25. data/db/migrate/20160818091421_add_permissions_from_default_roles.rb +1 -1
  26. data/db/migrate/20160925213030_change_discovery_widget_names.rb +1 -1
  27. data/db/migrate/20160927164411_define_explicit_length_for_discovery_rule_attributes.rb +1 -1
  28. data/db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb +4 -1
  29. data/lib/foreman_discovery/engine.rb +2 -1
  30. data/lib/foreman_discovery/version.rb +1 -1
  31. data/locale/ca/LC_MESSAGES/foreman_discovery.mo +0 -0
  32. data/locale/ca/foreman_discovery.edit.po +47 -38
  33. data/locale/ca/foreman_discovery.po +18 -11
  34. data/locale/de/LC_MESSAGES/foreman_discovery.mo +0 -0
  35. data/locale/de/foreman_discovery.edit.po +50 -42
  36. data/locale/de/foreman_discovery.po +21 -15
  37. data/locale/en/LC_MESSAGES/foreman_discovery.mo +0 -0
  38. data/locale/en/foreman_discovery.edit.po +51 -43
  39. data/locale/en/foreman_discovery.po +7 -1
  40. data/locale/en_GB/LC_MESSAGES/foreman_discovery.mo +0 -0
  41. data/locale/en_GB/foreman_discovery.edit.po +43 -35
  42. data/locale/en_GB/foreman_discovery.po +14 -8
  43. data/locale/es/LC_MESSAGES/foreman_discovery.mo +0 -0
  44. data/locale/es/foreman_discovery.edit.po +208 -200
  45. data/locale/es/foreman_discovery.po +179 -173
  46. data/locale/foreman_discovery.pot +52 -44
  47. data/locale/fr/LC_MESSAGES/foreman_discovery.mo +0 -0
  48. data/locale/fr/foreman_discovery.edit.po +54 -46
  49. data/locale/fr/foreman_discovery.po +25 -19
  50. data/locale/gl/LC_MESSAGES/foreman_discovery.mo +0 -0
  51. data/locale/gl/foreman_discovery.edit.po +37 -29
  52. data/locale/gl/foreman_discovery.po +8 -2
  53. data/locale/it/LC_MESSAGES/foreman_discovery.mo +0 -0
  54. data/locale/it/foreman_discovery.edit.po +51 -43
  55. data/locale/it/foreman_discovery.po +22 -16
  56. data/locale/ja/LC_MESSAGES/foreman_discovery.mo +0 -0
  57. data/locale/ja/foreman_discovery.edit.po +184 -176
  58. data/locale/ja/foreman_discovery.po +155 -151
  59. data/locale/ko/LC_MESSAGES/foreman_discovery.mo +0 -0
  60. data/locale/ko/foreman_discovery.edit.po +57 -49
  61. data/locale/ko/foreman_discovery.po +28 -22
  62. data/locale/pt_BR/LC_MESSAGES/foreman_discovery.mo +0 -0
  63. data/locale/pt_BR/foreman_discovery.edit.po +206 -198
  64. data/locale/pt_BR/foreman_discovery.po +177 -171
  65. data/locale/ru/LC_MESSAGES/foreman_discovery.mo +0 -0
  66. data/locale/ru/foreman_discovery.edit.po +57 -49
  67. data/locale/ru/foreman_discovery.po +28 -22
  68. data/locale/sv_SE/LC_MESSAGES/foreman_discovery.mo +0 -0
  69. data/locale/sv_SE/foreman_discovery.edit.po +37 -29
  70. data/locale/sv_SE/foreman_discovery.po +8 -2
  71. data/locale/zh_CN/LC_MESSAGES/foreman_discovery.mo +0 -0
  72. data/locale/zh_CN/foreman_discovery.edit.po +204 -196
  73. data/locale/zh_CN/foreman_discovery.po +177 -169
  74. data/locale/zh_TW/LC_MESSAGES/foreman_discovery.mo +0 -0
  75. data/locale/zh_TW/foreman_discovery.edit.po +47 -39
  76. data/locale/zh_TW/foreman_discovery.po +18 -12
  77. data/test/factories/discovery_host_related.rb +2 -2
  78. data/test/factories/discovery_rule_related.rb +1 -1
  79. data/test/functional/api/v2/discovered_hosts_controller_test.rb +28 -27
  80. data/test/functional/api/v2/discovery_rules_controller_test.rb +14 -14
  81. data/test/functional/api/v2/fact_value_extensions_test.rb +5 -2
  82. data/test/functional/discovered_hosts_controller_test.rb +47 -40
  83. data/test/functional/discovery_rules_controller_test.rb +14 -14
  84. data/test/functional/foreman_discovery/concerns/hosts_controller_extensions_test.rb +2 -2
  85. data/test/integration/discovered_hosts_test.rb +151 -0
  86. data/test/test_helper_discovery.rb +53 -23
  87. data/test/test_plugin_helper.rb +3 -7
  88. data/test/unit/discovered_extensions_test.rb +40 -38
  89. data/test/unit/discovered_mailer_test.rb +1 -1
  90. data/test/unit/discovery_attribute_set_test.rb +4 -2
  91. data/test/unit/discovery_rule_test.rb +2 -2
  92. data/test/unit/discovery_taxonomy_extensions_test.rb +1 -1
  93. data/test/unit/fact_parser_test.rb +1 -1
  94. data/test/unit/host_discovered_test.rb +26 -23
  95. data/test/unit/managed_extensions_test.rb +1 -1
  96. data/test/unit/ui_notifications/destroy_host_test.rb +21 -17
  97. data/test/unit/ui_notifications/new_host_test.rb +11 -11
  98. metadata +8 -3
  99. data/config/as_deprecation_whitelist.yaml +0 -0
@@ -7,14 +7,14 @@ module ForemanDiscovery
7
7
 
8
8
  context 'hosts controller requests from discovered_hosts url' do
9
9
  test 'get "host" params from "discovered_hosts" params' do
10
- os = FactoryGirl.create(:operatingsystem, :with_associations)
10
+ os = FactoryBot.create(:operatingsystem, :with_associations)
11
11
  arch_id = os.architectures.first.id
12
12
  discovered_host_params = {
13
13
  'discovered_host' => { 'architecture_id' => arch_id }
14
14
  }
15
15
 
16
16
  @request.stubs(:path).returns(architecture_selected_discovered_hosts_path)
17
- post :architecture_selected, discovered_host_params, set_session_user
17
+ post :architecture_selected, params: discovered_host_params, session: set_session_user
18
18
  assert_match(/"#{os.id}"/, response.body)
19
19
  end
20
20
  end
@@ -0,0 +1,151 @@
1
+ require 'test_plugin_helper'
2
+ require 'integration_test_helper'
3
+
4
+ class DiscoveredHostsTest < IntegrationTestWithJavascript
5
+ let(:discovered_host) { FactoryBot.create(:discovered_host, :with_facts) }
6
+ let(:discovered_hosts) { Host::Discovered.all }
7
+
8
+ extend Minitest::OptionalRetry
9
+
10
+ setup do
11
+ assert discovered_notification_blueprint
12
+ discovered_host.save!
13
+ visit discovered_hosts_path
14
+ end
15
+
16
+ teardown do
17
+ Host::Discovered.destroy_all
18
+ end
19
+
20
+ describe 'Reboot all' do
21
+ test 'triggers reboot on all discovered_hosts' do
22
+ Host::Discovered.any_instance
23
+ .expects(:reboot)
24
+ .at_least(discovered_hosts.count)
25
+ select_all_hosts
26
+ page.find_link('Reboot All').click
27
+ end
28
+ end
29
+
30
+ describe 'Autoprovision all' do
31
+ test 'converts all discovered to managed hosts' do
32
+ select_all_hosts
33
+ page.find_link('Auto Provision All').click
34
+ wait_for_ajax
35
+ assert page.has_text?('Discovered hosts are provisioning now')
36
+ end
37
+ end
38
+
39
+ describe 'Delete hosts' do
40
+ test 'it removes all hosts' do
41
+ select_all_hosts
42
+ page.find_link('Select Action').click
43
+ page.find_link('Delete hosts').click
44
+ wait_for_ajax
45
+ assert page.has_text?('The following hosts are about to be changed')
46
+ page.find_button('Submit').click
47
+ wait_for_ajax
48
+ assert page.has_text?('Destroyed selected hosts')
49
+ end
50
+ end
51
+
52
+ describe 'using Create Host link' do
53
+ setup do
54
+ page.find("#host_ids_#{discovered_host.id}")
55
+ .query_scope
56
+ .find_link('Provision').click
57
+ end
58
+
59
+ test 'and forwards to editing it' do
60
+ create_host
61
+ assert_equal edit_discovered_host_path(id: discovered_host),
62
+ current_path
63
+ end
64
+
65
+ context 'with a Hostgroup selected' do
66
+ let(:discovery_hostgroup) { Hostgroup.first }
67
+
68
+ test 'it passes it on' do
69
+ select_from('host_hostgroup_id', discovery_hostgroup.id)
70
+ create_host
71
+ assert_param discovery_hostgroup.id.to_s,
72
+ 'host.hostgroup_id'
73
+ end
74
+ end
75
+
76
+ context 'with a Location selected' do
77
+ let(:discovery_location) { Location.first }
78
+
79
+ test 'it passes it on' do
80
+ select_from('host_location_id', discovery_location.id)
81
+ create_host
82
+ assert_param discovery_location.id.to_s,
83
+ 'host.location_id'
84
+ end
85
+ end
86
+
87
+ context 'with a Organization selected' do
88
+ let(:discovery_organization) { Organization.first }
89
+
90
+ test 'it passes it on' do
91
+ select_from('host_organization_id', discovery_organization.id)
92
+ create_host
93
+ assert_param discovery_organization.id.to_s,
94
+ 'host.organization_id'
95
+ end
96
+ end
97
+ end
98
+
99
+ describe 'edit form' do
100
+ test 'it is a host form' do
101
+ visit edit_discovered_host_path(discovered_host)
102
+ assert page.find("form#edit_host_#{discovered_host.id}")
103
+ end
104
+
105
+ context 'with a hostgroup passed' do
106
+ let(:hostgroup_environment) { FactoryBot.create(:environment) }
107
+ let(:hostgroup_domain) { FactoryBot.create(:domain) }
108
+ let(:hostgroup) do
109
+ FactoryBot.create(:hostgroup, :with_os,
110
+ environment: hostgroup_environment,
111
+ domain: hostgroup_domain)
112
+ end
113
+
114
+ setup do
115
+ visit edit_discovered_host_path(discovered_host,
116
+ 'host[hostgroup_id]' => hostgroup.id)
117
+ page.find("a[href='#os']").click
118
+ assert_selected '#host_hostgroup_id', hostgroup.id
119
+ end
120
+
121
+ it 'sets inherited attributes' do
122
+ %i[environment architecture operatingsystem].each do |attribute|
123
+ assert_selected "#host_#{attribute}_id", hostgroup.send(attribute).id
124
+ end
125
+
126
+ page.find('a[href="#network"]').click
127
+ page.find_button('Edit').click
128
+ assert_selected '#host_interfaces_attributes_0_domain_id',
129
+ hostgroup.domain.id
130
+ end
131
+ end
132
+ end
133
+
134
+ private
135
+
136
+ def select_all_hosts
137
+ page.find('#check_all').click
138
+ end
139
+
140
+ def select_from(element_id, id)
141
+ page.find_by_id(element_id, visible: false)
142
+ .find("option[value='#{id}']", visible: false)
143
+ .select_option
144
+ end
145
+
146
+ def create_host
147
+ page.find("#fixedPropertiesSelector-#{discovered_host.id}")
148
+ .find_button('Create Host').click
149
+ wait_for_ajax
150
+ end
151
+ end
@@ -9,11 +9,11 @@ def user_with_perms(perms)
9
9
  p.resource_type = 'DiscoveryRule' if p.name =~ /discovery_rules$/
10
10
  p.save!
11
11
  end
12
- role = FactoryGirl.create :role
12
+ role = FactoryBot.create :role
13
13
  perms.each do |perm|
14
- FactoryGirl.create(:filter, :role => role, :permissions => [perm])
14
+ FactoryBot.create(:filter, :role => role, :permissions => [perm])
15
15
  end
16
- user = FactoryGirl.create :user, :with_mail, :admin => false
16
+ user = FactoryBot.create :user, :with_mail, :admin => false
17
17
  user.roles << role
18
18
  user.save
19
19
  user
@@ -52,29 +52,29 @@ def extract_form_errors(response)
52
52
  end
53
53
 
54
54
  def set_default_settings
55
- FactoryGirl.create(:setting, :name => 'discovery_fact', :value => 'discovery_bootif', :category => 'Setting::Discovered')
56
- FactoryGirl.create(:setting, :name => 'discovery_hostname', :value => 'discovery_bootif', :category => 'Setting::Discovered')
57
- FactoryGirl.create(:setting, :name => 'discovery_auto', :value => true, :category => 'Setting::Discovered')
58
- FactoryGirl.create(:setting, :name => 'discovery_reboot', :value => true, :category => 'Setting::Discovered')
59
- FactoryGirl.create(:setting, :name => 'discovery_organization', :value => "Organization 1", :category => 'Setting::Discovered')
60
- FactoryGirl.create(:setting, :name => 'discovery_location', :value => "Location 1", :category => 'Setting::Discovered')
61
- FactoryGirl.create(:setting, :name => 'discovery_prefix', :value => 'mac', :category => 'Setting::Discovered')
62
- FactoryGirl.create(:setting, :name => 'discovery_clean_facts', :value => false, :category => 'Setting::Discovered')
63
- FactoryGirl.create(:setting, :name => 'discovery_lock', :value => 'false', :category => 'Setting::Discovered')
64
- FactoryGirl.create(:setting, :name => 'discovery_lock_template', :value => 'pxelinux_discovery', :category => 'Setting::Discovered')
65
- FactoryGirl.create(:setting, :name => 'discovery_pxelinux_lock_template', :value => 'pxelinux_discovery', :category => 'Setting::Discovered')
66
- FactoryGirl.create(:setting, :name => 'discovery_pxegrub_lock_template', :value => 'pxegrub_discovery', :category => 'Setting::Discovered')
67
- FactoryGirl.create(:setting, :name => 'discovery_pxegrub2_lock_template', :value => 'pxegrub2_discovery', :category => 'Setting::Discovered')
68
- FactoryGirl.create(:setting, :name => 'discovery_always_rebuild_dns', :value => true, :category => 'Setting::Discovered')
55
+ FactoryBot.create(:setting, :name => 'discovery_fact', :value => 'discovery_bootif', :category => 'Setting::Discovered')
56
+ FactoryBot.create(:setting, :name => 'discovery_hostname', :value => 'discovery_bootif', :category => 'Setting::Discovered')
57
+ FactoryBot.create(:setting, :name => 'discovery_auto', :value => true, :category => 'Setting::Discovered')
58
+ FactoryBot.create(:setting, :name => 'discovery_reboot', :value => true, :category => 'Setting::Discovered')
59
+ FactoryBot.create(:setting, :name => 'discovery_organization', :value => "Organization 1", :category => 'Setting::Discovered')
60
+ FactoryBot.create(:setting, :name => 'discovery_location', :value => "Location 1", :category => 'Setting::Discovered')
61
+ FactoryBot.create(:setting, :name => 'discovery_prefix', :value => 'mac', :category => 'Setting::Discovered')
62
+ FactoryBot.create(:setting, :name => 'discovery_clean_facts', :value => false, :category => 'Setting::Discovered')
63
+ FactoryBot.create(:setting, :name => 'discovery_lock', :value => 'false', :category => 'Setting::Discovered')
64
+ FactoryBot.create(:setting, :name => 'discovery_lock_template', :value => 'pxelinux_discovery', :category => 'Setting::Discovered')
65
+ FactoryBot.create(:setting, :name => 'discovery_pxelinux_lock_template', :value => 'pxelinux_discovery', :category => 'Setting::Discovered')
66
+ FactoryBot.create(:setting, :name => 'discovery_pxegrub_lock_template', :value => 'pxegrub_discovery', :category => 'Setting::Discovered')
67
+ FactoryBot.create(:setting, :name => 'discovery_pxegrub2_lock_template', :value => 'pxegrub2_discovery', :category => 'Setting::Discovered')
68
+ FactoryBot.create(:setting, :name => 'discovery_always_rebuild_dns', :value => true, :category => 'Setting::Discovered')
69
69
  end
70
70
 
71
71
  def setup_hostgroup(host)
72
- domain = FactoryGirl.create(:domain)
73
- subnet = FactoryGirl.create(:subnet_ipv4, :network => "192.168.100.0")
74
- environment = FactoryGirl.create(:environment, :organizations => [host.organization], :locations => [host.location])
75
- medium = FactoryGirl.create(:medium, :organizations => [host.organization], :locations => [host.location])
76
- os = FactoryGirl.create(:operatingsystem, :with_ptables, :with_archs, :media => [medium])
77
- hostgroup = FactoryGirl.create(
72
+ domain = FactoryBot.create(:domain)
73
+ subnet = FactoryBot.create(:subnet_ipv4, :network => "192.168.100.0")
74
+ environment = FactoryBot.create(:environment, :organizations => [host.organization], :locations => [host.location])
75
+ medium = FactoryBot.create(:medium, :organizations => [host.organization], :locations => [host.location])
76
+ os = FactoryBot.create(:operatingsystem, :with_ptables, :with_archs, :media => [medium])
77
+ hostgroup = FactoryBot.create(
78
78
  :hostgroup, :with_rootpass, :with_puppet_orchestration,
79
79
  :operatingsystem => os,
80
80
  :architecture => os.architectures.first,
@@ -110,6 +110,15 @@ def location_one
110
110
  Location.find_by_name('Location 1')
111
111
  end
112
112
 
113
+ def current_path_info
114
+ current_url.sub(%r{.*?://}, '')[%r{[/\?\#].*}] || '/'
115
+ end
116
+
117
+ def current_params
118
+ query = current_path_info.split('?')[1]
119
+ Rack::Utils.parse_nested_query query
120
+ end
121
+
113
122
  def facts_simple_network100_42
114
123
  {
115
124
  "interfaces" => "lo,eth0,eth1",
@@ -127,3 +136,24 @@ def discover_host_from_facts(facts)
127
136
  Host::Discovered.import_host(facts)
128
137
  end
129
138
  end
139
+
140
+ def assert_param(expected, param)
141
+ keys = param.split('.')
142
+ result = current_params
143
+ keys.each do |key|
144
+ result = result[key]
145
+ end
146
+ assert_equal expected, result
147
+ end
148
+
149
+ def assert_selected(select_selector, value)
150
+ select = page.all(select_selector, visible: false).last
151
+ selected = select.find("option[selected='selected']", visible: false) rescue nil
152
+ assert_not_nil selected, "Nothing selected in #{select_selector}"
153
+ assert_equal value.to_s, selected.value
154
+ end
155
+
156
+ def discovered_notification_blueprint
157
+ @blueprint ||= FactoryBot.create(:notification_blueprint,
158
+ name: 'new_discovered_host')
159
+ end
@@ -3,10 +3,6 @@ require 'test_helper'
3
3
 
4
4
  require 'test_helper_discovery'
5
5
 
6
- # Add plugin to FactoryGirl's paths
7
- FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
8
- FactoryGirl.reload
9
- # load notification seeds.
10
- require File.join(
11
- File.dirname(__FILE__), '..', 'db', 'seeds.d', '80_discovery_ui_notification'
12
- )
6
+ # Add plugin to FactoryBot's paths
7
+ FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
8
+ FactoryBot.reload
@@ -2,6 +2,8 @@ require 'test_plugin_helper'
2
2
 
3
3
  class DiscoveredExtensionsTest < ActiveSupport::TestCase
4
4
  include Foreman::Controller::DiscoveredExtensions
5
+ include FactImporterIsolation
6
+ allow_transactions_for_any_importer
5
7
 
6
8
  setup do
7
9
  @facts = facts_simple_network100_42
@@ -15,28 +17,28 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
15
17
 
16
18
  test "no rule is found out of one for a discovered host with no facts" do
17
19
  host = discover_host_from_facts(@facts)
18
- FactoryGirl.create(:discovery_rule, :search => "facts.foo = bar")
20
+ FactoryBot.create(:discovery_rule, :search => "facts.foo = bar")
19
21
  refute find_discovery_rule(host)
20
22
  end
21
23
 
22
24
  test "no rule is found out of one for a discovered host with some facts" do
23
25
  host = discover_host_from_facts(@facts)
24
- FactoryGirl.create(:discovery_rule, :search => "facts.foo = doesnotexist")
26
+ FactoryBot.create(:discovery_rule, :search => "facts.foo = doesnotexist")
25
27
  refute find_discovery_rule(host)
26
28
  end
27
29
 
28
30
  test "no rule is found out of two for a discovered host" do
29
31
  facts = @facts.merge({"somefact" => "abc"})
30
32
  host = discover_host_from_facts(facts)
31
- FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = xxx")
32
- FactoryGirl.create(:discovery_rule, :priority => 2, :search => "facts.somefact = zzz")
33
+ FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = xxx")
34
+ FactoryBot.create(:discovery_rule, :priority => 2, :search => "facts.somefact = zzz")
33
35
  refute find_discovery_rule(host)
34
36
  end
35
37
 
36
38
  test "rule out of one is found for a discovered host" do
37
39
  facts = @facts.merge({"somefact" => "abc"})
38
40
  host = discover_host_from_facts(facts)
39
- r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
41
+ r1 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
40
42
  :organizations => [host.organization], :locations => [host.location])
41
43
  assert_equal find_discovery_rule(host), r1
42
44
  end
@@ -44,9 +46,9 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
44
46
  test "first rule out of two is found for a discovered host" do
45
47
  facts = @facts.merge({"somefact" => "abc"})
46
48
  host = discover_host_from_facts(facts)
47
- r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
49
+ r1 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
48
50
  :organizations => [host.organization], :locations => [host.location])
49
- FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = x",
51
+ FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = x",
50
52
  :organizations => [host.organization], :locations => [host.location])
51
53
  assert_equal find_discovery_rule(host), r1
52
54
  end
@@ -54,9 +56,9 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
54
56
  test "second rule out of two is found for a discovered host" do
55
57
  facts = @facts.merge({"somefact" => "abc"})
56
58
  host = discover_host_from_facts(facts)
57
- FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = x",
59
+ FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = x",
58
60
  :organizations => [host.organization], :locations => [host.location])
59
- r2 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
61
+ r2 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
60
62
  :organizations => [host.organization], :locations => [host.location])
61
63
  assert_equal find_discovery_rule(host), r2
62
64
  end
@@ -64,9 +66,9 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
64
66
  test "first rule out of two with different priorities is found for a discovered host" do
65
67
  facts = @facts.merge({"somefact" => "abc"})
66
68
  host = discover_host_from_facts(facts)
67
- r1 = FactoryGirl.create(:discovery_rule, :name => "A", :priority => 1, :search => "facts.somefact = abc",
69
+ r1 = FactoryBot.create(:discovery_rule, :name => "A", :priority => 1, :search => "facts.somefact = abc",
68
70
  :organizations => [host.organization], :locations => [host.location])
69
- r2 = FactoryGirl.create(:discovery_rule, :name => "B", :priority => 2, :search => "facts.somefact = abc",
71
+ r2 = FactoryBot.create(:discovery_rule, :name => "B", :priority => 2, :search => "facts.somefact = abc",
70
72
  :organizations => [host.organization], :locations => [host.location])
71
73
  assert_equal find_discovery_rule(host), r1
72
74
  end
@@ -74,9 +76,9 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
74
76
  test "second rule out of two with different priorities is found for a discovered host" do
75
77
  facts = @facts.merge({"somefact" => "abc"})
76
78
  host = discover_host_from_facts(facts)
77
- r1 = FactoryGirl.create(:discovery_rule, :name => "A", :priority => 2, :search => "facts.somefact = abc",
79
+ r1 = FactoryBot.create(:discovery_rule, :name => "A", :priority => 2, :search => "facts.somefact = abc",
78
80
  :organizations => [host.organization], :locations => [host.location])
79
- r2 = FactoryGirl.create(:discovery_rule, :name => "B", :priority => 1, :search => "facts.somefact = abc",
81
+ r2 = FactoryBot.create(:discovery_rule, :name => "B", :priority => 1, :search => "facts.somefact = abc",
80
82
  :organizations => [host.organization], :locations => [host.location])
81
83
  assert_equal find_discovery_rule(host), r2
82
84
  end
@@ -84,9 +86,9 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
84
86
  test "older rule out of two is found for a discovered host" do
85
87
  facts = @facts.merge({"somefact" => "abc"})
86
88
  host = discover_host_from_facts(facts)
87
- r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
89
+ r1 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
88
90
  :organizations => [host.organization], :locations => [host.location])
89
- r2 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
91
+ r2 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
90
92
  :organizations => [host.organization], :locations => [host.location],
91
93
  :created_at => Time.now + 1.day)
92
94
  assert_equal find_discovery_rule(host), r1
@@ -95,18 +97,18 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
95
97
  test "drained rule does not match for a discovered host" do
96
98
  facts = @facts.merge({"somefact" => "abc"})
97
99
  host = discover_host_from_facts(facts)
98
- r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc", :max_count => 1,
100
+ r1 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc", :max_count => 1,
99
101
  :organizations => [host.organization], :locations => [host.location])
100
- r2 = FactoryGirl.create(:discovery_rule, :priority => 2, :search => "facts.somefact = abc",
102
+ r2 = FactoryBot.create(:discovery_rule, :priority => 2, :search => "facts.somefact = abc",
101
103
  :organizations => [host.organization], :locations => [host.location])
102
- FactoryGirl.create(:host, :discovery_rule => r1)
104
+ FactoryBot.create(:host, :discovery_rule => r1)
103
105
  assert_equal find_discovery_rule(host), r2
104
106
  end
105
107
 
106
108
  test "discovery rule is associated after auto provisioning" do
107
109
  facts = @facts.merge({"somefact" => "abc"})
108
110
  host = discover_host_from_facts(facts)
109
- r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
111
+ r1 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
110
112
  :organizations => [host.organization], :locations => [host.location])
111
113
  perform_auto_provision host, r1
112
114
  assert_equal host.primary_interface.managed, true
@@ -118,7 +120,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
118
120
  test "auto provisioning fails for rule without a hostgroup" do
119
121
  facts = @facts.merge({"somefact" => "abc"})
120
122
  host = discover_host_from_facts(facts)
121
- r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
123
+ r1 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
122
124
  :organizations => [host.organization], :locations => [host.location])
123
125
  r1.hostgroup = nil
124
126
  exception = assert_raises(::Foreman::Exception) do
@@ -130,7 +132,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
130
132
  test "existing rule revent from hostgroup deletion" do
131
133
  facts = @facts.merge({"somefact" => "abc"})
132
134
  host = discover_host_from_facts(facts)
133
- r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
135
+ r1 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
134
136
  :organizations => [host.organization], :locations => [host.location])
135
137
  assert_raises(ActiveRecord::RecordNotDestroyed) do
136
138
  r1.hostgroup.destroy!
@@ -140,9 +142,9 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
140
142
  test "rules with incorrect syntax are skipped" do
141
143
  facts = @facts.merge({"somefact" => "abc"})
142
144
  host = discover_host_from_facts(facts)
143
- FactoryGirl.create(:discovery_rule, :priority => 1, :search => '=!^$#@?x',
145
+ FactoryBot.create(:discovery_rule, :priority => 1, :search => '=!^$#@?x',
144
146
  :organizations => [host.organization], :locations => [host.location])
145
- r2 = FactoryGirl.create(:discovery_rule, :priority => 2, :search => "facts.somefact = abc",
147
+ r2 = FactoryBot.create(:discovery_rule, :priority => 2, :search => "facts.somefact = abc",
146
148
  :organizations => [host.organization], :locations => [host.location])
147
149
  assert_equal find_discovery_rule(host), r2
148
150
  end
@@ -150,7 +152,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
150
152
  test "hostname is copied after auto provisioning" do
151
153
  facts = @facts.merge({"somefact" => "abc"})
152
154
  host = discover_host_from_facts(facts)
153
- r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
155
+ r1 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
154
156
  :organizations => [host.organization], :locations => [host.location])
155
157
  perform_auto_provision host, r1
156
158
  assert_equal host.name, "macaabbccddeeff"
@@ -158,12 +160,12 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
158
160
 
159
161
  test "attributes from hostgroup are copied after auto provisioning for host with subnet detected" do
160
162
  facts = @facts.merge({"somefact" => "abc"})
161
- domain = FactoryGirl.create(:domain)
162
- subnet = FactoryGirl.create(:subnet_ipv4, :tftp, :dhcp, :name => 'subnet_100', :network => '192.168.100.0', :organizations => [Organization.find_by_name("Organization 1")], :locations => [Location.find_by_name("Location 1")])
163
+ domain = FactoryBot.create(:domain)
164
+ subnet = FactoryBot.create(:subnet_ipv4, :tftp, :dhcp, :name => 'subnet_100', :network => '192.168.100.0', :organizations => [Organization.find_by_name("Organization 1")], :locations => [Location.find_by_name("Location 1")])
163
165
  host = discover_host_from_facts(facts)
164
166
  assert_equal subnet, host.subnet
165
- hostgroup = FactoryGirl.create(:hostgroup, :with_environment, :with_rootpass, :with_puppet_orchestration, :with_os, :pxe_loader => "PXELinux BIOS", :subnet => subnet, :domain => domain)
166
- r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc", :organizations => [host.organization], :locations => [host.location], :hostgroup => hostgroup)
167
+ hostgroup = FactoryBot.create(:hostgroup, :with_environment, :with_rootpass, :with_puppet_orchestration, :with_os, :pxe_loader => "PXELinux BIOS", :subnet => subnet, :domain => domain)
168
+ r1 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc", :organizations => [host.organization], :locations => [host.location], :hostgroup => hostgroup)
167
169
  host.primary_interface.expects(:queue_tftp).at_least(1)
168
170
  host.primary_interface.expects(:queue_dhcp).at_least(1)
169
171
  assert managed_host = perform_auto_provision(host, r1)
@@ -190,10 +192,10 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
190
192
  facts = @facts.merge({"somefact" => "abc"})
191
193
  host = discover_host_from_facts(facts)
192
194
  refute host.subnet
193
- domain = FactoryGirl.create(:domain)
194
- subnet = FactoryGirl.create(:subnet_ipv4, :tftp, :dhcp, :name => 'subnet_100', :network => '192.168.100.0', :organizations => [Organization.find_by_name("Organization 1")], :locations => [Location.find_by_name("Location 1")])
195
- hostgroup = FactoryGirl.create(:hostgroup, :with_environment, :with_rootpass, :with_puppet_orchestration, :with_os, :pxe_loader => "PXELinux BIOS", :subnet => subnet, :domain => domain)
196
- r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc", :organizations => [host.organization], :locations => [host.location], :hostgroup => hostgroup)
195
+ domain = FactoryBot.create(:domain)
196
+ subnet = FactoryBot.create(:subnet_ipv4, :tftp, :dhcp, :name => 'subnet_100', :network => '192.168.100.0', :organizations => [Organization.find_by_name("Organization 1")], :locations => [Location.find_by_name("Location 1")])
197
+ hostgroup = FactoryBot.create(:hostgroup, :with_environment, :with_rootpass, :with_puppet_orchestration, :with_os, :pxe_loader => "PXELinux BIOS", :subnet => subnet, :domain => domain)
198
+ r1 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc", :organizations => [host.organization], :locations => [host.location], :hostgroup => hostgroup)
197
199
  host.primary_interface.expects(:queue_tftp).at_least(1)
198
200
  host.primary_interface.expects(:queue_dhcp).at_least(1)
199
201
  assert managed_host = perform_auto_provision(host, r1)
@@ -238,7 +240,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
238
240
 
239
241
  test "hostname falls back to original name on empty response via #{renderer_name}" do
240
242
  host = discover_host_from_facts(@facts)
241
- r1 = FactoryGirl.create(:discovery_rule,
243
+ r1 = FactoryBot.create(:discovery_rule,
242
244
  :search => "facts.somefact = abc",
243
245
  :hostname => '<%= "" %>',
244
246
  :organizations => [host.organization],
@@ -249,7 +251,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
249
251
 
250
252
  test "hostname is rendered after auto provisioning using #{renderer_name}" do
251
253
  host = discover_host_from_facts(@facts)
252
- r1 = FactoryGirl.create(:discovery_rule,
254
+ r1 = FactoryBot.create(:discovery_rule,
253
255
  :search => "facts.somefact = abc",
254
256
  :hostname => 'x<%= 1+1 %>',
255
257
  :organizations => [host.organization],
@@ -260,7 +262,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
260
262
 
261
263
  test "function rand is renderer properly using #{renderer_name}" do
262
264
  host = discover_host_from_facts(@facts)
263
- r1 = FactoryGirl.create(:discovery_rule,
265
+ r1 = FactoryBot.create(:discovery_rule,
264
266
  :search => "facts.somefact = abc",
265
267
  :hostname => 'x<%= rand(4) %>',
266
268
  :organizations => [host.organization],
@@ -271,7 +273,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
271
273
 
272
274
  test "hostname attribute name is renderer properly using #{renderer_name}" do
273
275
  host = discover_host_from_facts(@facts)
274
- r1 = FactoryGirl.create(:discovery_rule,
276
+ r1 = FactoryBot.create(:discovery_rule,
275
277
  :search => "facts.somefact = abc",
276
278
  :hostname => 'x<%= @host.name %>',
277
279
  :organizations => [host.organization],
@@ -282,7 +284,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
282
284
 
283
285
  test "hostname attribute ip is renderer properly using #{renderer_name}" do
284
286
  host = discover_host_from_facts(@facts)
285
- r1 = FactoryGirl.create(:discovery_rule,
287
+ r1 = FactoryBot.create(:discovery_rule,
286
288
  :search => "facts.somefact = abc",
287
289
  :hostname => 'x<%= @host.ip.gsub(".","-") %>',
288
290
  :organizations => [host.organization],
@@ -294,7 +296,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
294
296
  test "hostname attribute facts_hash is renderer properly using #{renderer_name}" do
295
297
  facts = @facts.merge({"somefact" => "abc"})
296
298
  host = discover_host_from_facts(facts)
297
- r1 = FactoryGirl.create(:discovery_rule,
299
+ r1 = FactoryBot.create(:discovery_rule,
298
300
  :search => "facts.somefact = abc",
299
301
  :hostname => 'x<%= @host.facts["somefact"] %>',
300
302
  :organizations => [host.organization],