Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #22933 - fix functional test case for reboot all hosts #413

Merged
merged 1 commit into from Mar 26, 2018

Conversation

rabajaj0509
Copy link
Member

No description provided.

@theforeman-bot
Copy link
Member

Issues: #22933

@lzap
Copy link
Member

lzap commented Mar 20, 2018

I still see 8 failures here.

FYI you need to remove this line because of this change in core: theforeman/foreman#5318

diff --git a/test/integration/discovered_hosts_test.rb b/test/integration/discovered_hosts_test.rb
index edcf4f7..0e47e50 100644
--- a/test/integration/discovered_hosts_test.rb
+++ b/test/integration/discovered_hosts_test.rb
@@ -5,8 +5,6 @@ class DiscoveredHostsTest < IntegrationTestWithJavascript
   let(:discovered_host) { FactoryBot.create(:discovered_host, :with_facts) }
   let(:discovered_hosts) { Host::Discovered.all }
 
-  extend Minitest::OptionalRetry
-
   setup do
     assert discovered_notification_blueprint
     discovered_host.save!

@lzap
Copy link
Member

lzap commented Mar 20, 2018

Here is what I see locally atm:

# Running:

..[MinitestRetry] retry 'test_reboot_success' count: 1,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"Rebooting host macaabbccddeeff"
+nil

[MinitestRetry] retry 'test_reboot_success' count: 2,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"Rebooting host macaabbccddeeff"
+nil

[MinitestRetry] retry 'test_reboot_success' count: 3,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"Rebooting host macaabbccddeeff"
+nil

F

Failure:
DiscoveredHostsControllerTest#test_reboot_success [/home/lzap/work/foreman_discovery/test/functional/discovered_hosts_controller_test.rb:181]:
--- expected
+++ actual
@@ -1 +1 @@
-"Rebooting host macaabbccddeeff"
+nil



bin/rails test _discovery/test/functional/discovered_hosts_controller_test.rb:174

.[MinitestRetry] retry 'test_auto_provision_no_rule_success' count: 1,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"No rule found for host macaabbccddeeff"
+nil

[MinitestRetry] retry 'test_auto_provision_no_rule_success' count: 2,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"No rule found for host macaabbccddeeff"
+nil

[MinitestRetry] retry 'test_auto_provision_no_rule_success' count: 3,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"No rule found for host macaabbccddeeff"
+nil

F

Failure:
DiscoveredHostsControllerTest#test_auto_provision_no_rule_success [/home/lzap/work/foreman_discovery/test/functional/discovered_hosts_controller_test.rb:223]:
--- expected
+++ actual
@@ -1 +1 @@
-"No rule found for host macaabbccddeeff"
+nil



bin/rails test _discovery/test/functional/discovered_hosts_controller_test.rb:216

......[MinitestRetry] retry 'test_edit_form_quick_submit' count: 1,  msg: Expected /Successfully/ to match nil.
[MinitestRetry] retry 'test_edit_form_quick_submit' count: 2,  msg: Expected /Successfully/ to match nil.
[MinitestRetry] retry 'test_edit_form_quick_submit' count: 3,  msg: Expected /Successfully/ to match nil.
F

Failure:
DiscoveredHostsControllerTest#test_edit_form_quick_submit [/home/lzap/work/foreman_discovery/test/functional/discovered_hosts_controller_test.rb:106]:
Expected /Successfully/ to match nil.


bin/rails test _discovery/test/functional/discovered_hosts_controller_test.rb:86

[MinitestRetry] retry 'test_auto_provision_all_no_rule_success' count: 1,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"Discovered hosts are provisioning now"
+nil

[MinitestRetry] retry 'test_auto_provision_all_no_rule_success' count: 2,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"Discovered hosts are provisioning now"
+nil

[MinitestRetry] retry 'test_auto_provision_all_no_rule_success' count: 3,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"Discovered hosts are provisioning now"
+nil

F

Failure:
DiscoveredHostsControllerTest#test_auto_provision_all_no_rule_success [/home/lzap/work/foreman_discovery/test/functional/discovered_hosts_controller_test.rb:259]:
--- expected
+++ actual
@@ -1 +1 @@
-"Discovered hosts are provisioning now"
+nil



bin/rails test _discovery/test/functional/discovered_hosts_controller_test.rb:244

[MinitestRetry] retry 'test_auto_provision_success' count: 1,  msg: Expected /^Host macaabbccddeeff.* was provisioned/ to match nil.
[MinitestRetry] retry 'test_auto_provision_success' count: 2,  msg: Expected /^Host macaabbccddeeff.* was provisioned/ to match nil.
[MinitestRetry] retry 'test_auto_provision_success' count: 3,  msg: Expected /^Host macaabbccddeeff.* was provisioned/ to match nil.
F

Failure:
DiscoveredHostsControllerTest#test_auto_provision_success [/home/lzap/work/foreman_discovery/test/functional/discovered_hosts_controller_test.rb:211]:
Expected /^Host macaabbccddeeff.* was provisioned/ to match nil.


bin/rails test _discovery/test/functional/discovered_hosts_controller_test.rb:202

..[MinitestRetry] retry 'test_auto_provision_all_success' count: 1,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"Discovered hosts are provisioning now"
+nil

[MinitestRetry] retry 'test_auto_provision_all_success' count: 2,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"Discovered hosts are provisioning now"
+nil

[MinitestRetry] retry 'test_auto_provision_all_success' count: 3,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"Discovered hosts are provisioning now"
+nil

F

Failure:
DiscoveredHostsControllerTest#test_auto_provision_all_success [/home/lzap/work/foreman_discovery/test/functional/discovered_hosts_controller_test.rb:241]:
--- expected
+++ actual
@@ -1 +1 @@
-"Discovered hosts are provisioning now"
+nil



bin/rails test _discovery/test/functional/discovered_hosts_controller_test.rb:226

...[MinitestRetry] retry 'test_reboot_all_success' count: 1,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"Discovered hosts are rebooting now"
+nil

[MinitestRetry] retry 'test_reboot_all_success' count: 2,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"Discovered hosts are rebooting now"
+nil

[MinitestRetry] retry 'test_reboot_all_success' count: 3,  msg: --- expected
+++ actual
@@ -1 +1 @@
-"Discovered hosts are rebooting now"
+nil

F

Failure:
DiscoveredHostsControllerTest#test_reboot_all_success [/home/lzap/work/foreman_discovery/test/functional/discovered_hosts_controller_test.rb:269]:
--- expected
+++ actual
@@ -1 +1 @@
-"Discovered hosts are rebooting now"
+nil



bin/rails test _discovery/test/functional/discovered_hosts_controller_test.rb:262

.............................................[MinitestRetry] retry 'test_0017_should refresh existing discovered' count: 1,  msg: unexpected invocation: Nic::Managed(id: integer, mac: string, ip: string, type: string, name: string, host_id: integer, subnet_id: integer, domain_id: integer, attrs: text, created_at: datetime, updated_at: datetime, provider: string, username: string, password: string, virtual: boolean, link: boolean, identifier: string, tag: string, attached_to: string, managed: boolean, mode: string, attached_devices: string, bond_options: string, primary: boolean, provision: boolean, compute_attributes: text, ip6: string, subnet6_id: integer).where(:id => 1)
satisfied expectations:
- allowed any number of times, invoked once: #<Mock:0x561b050e8708>.host(any_parameters)
- allowed any number of times, invoked once: Nic::Managed(id: integer, mac: string, ip: string, type: string, name: string, host_id: integer, subnet_id: integer, domain_id: integer, attrs: text, created_at: datetime, updated_at: datetime, provider: string, username: string, password: string, virtual: boolean, link: boolean, identifier: string, tag: string, attached_to: string, managed: boolean, mode: string, attached_devices: string, bond_options: string, primary: boolean, provision: boolean, compute_attributes: text, ip6: string, subnet6_id: integer).where(:mac => "e4:1f:13:cc:36:58", :primary => true)

[MinitestRetry] retry 'test_0017_should refresh existing discovered' count: 2,  msg: unexpected invocation: Nic::Managed(id: integer, mac: string, ip: string, type: string, name: string, host_id: integer, subnet_id: integer, domain_id: integer, attrs: text, created_at: datetime, updated_at: datetime, provider: string, username: string, password: string, virtual: boolean, link: boolean, identifier: string, tag: string, attached_to: string, managed: boolean, mode: string, attached_devices: string, bond_options: string, primary: boolean, provision: boolean, compute_attributes: text, ip6: string, subnet6_id: integer).where(:id => 1)
satisfied expectations:
- allowed any number of times, invoked once: #<Mock:0x561b050d2a70>.host(any_parameters)
- allowed any number of times, invoked once: Nic::Managed(id: integer, mac: string, ip: string, type: string, name: string, host_id: integer, subnet_id: integer, domain_id: integer, attrs: text, created_at: datetime, updated_at: datetime, provider: string, username: string, password: string, virtual: boolean, link: boolean, identifier: string, tag: string, attached_to: string, managed: boolean, mode: string, attached_devices: string, bond_options: string, primary: boolean, provision: boolean, compute_attributes: text, ip6: string, subnet6_id: integer).where(:mac => "e4:1f:13:cc:36:58", :primary => true)

[MinitestRetry] retry 'test_0017_should refresh existing discovered' count: 3,  msg: unexpected invocation: Nic::Managed(id: integer, mac: string, ip: string, type: string, name: string, host_id: integer, subnet_id: integer, domain_id: integer, attrs: text, created_at: datetime, updated_at: datetime, provider: string, username: string, password: string, virtual: boolean, link: boolean, identifier: string, tag: string, attached_to: string, managed: boolean, mode: string, attached_devices: string, bond_options: string, primary: boolean, provision: boolean, compute_attributes: text, ip6: string, subnet6_id: integer).where(:id => 1)
satisfied expectations:
- allowed any number of times, invoked once: #<Mock:0x561b03e716d8>.host(any_parameters)
- allowed any number of times, invoked once: Nic::Managed(id: integer, mac: string, ip: string, type: string, name: string, host_id: integer, subnet_id: integer, domain_id: integer, attrs: text, created_at: datetime, updated_at: datetime, provider: string, username: string, password: string, virtual: boolean, link: boolean, identifier: string, tag: string, attached_to: string, managed: boolean, mode: string, attached_devices: string, bond_options: string, primary: boolean, provision: boolean, compute_attributes: text, ip6: string, subnet6_id: integer).where(:mac => "e4:1f:13:cc:36:58", :primary => true)

F

Failure:
HostDiscoveredTest#test_0017_should refresh existing discovered [/home/lzap/work/foreman/app/models/concerns/audit_extensions.rb:139]:
unexpected invocation: Nic::Managed(id: integer, mac: string, ip: string, type: string, name: string, host_id: integer, subnet_id: integer, domain_id: integer, attrs: text, created_at: datetime, updated_at: datetime, provider: string, username: string, password: string, virtual: boolean, link: boolean, identifier: string, tag: string, attached_to: string, managed: boolean, mode: string, attached_devices: string, bond_options: string, primary: boolean, provision: boolean, compute_attributes: text, ip6: string, subnet6_id: integer).where(:id => 1)
satisfied expectations:
- allowed any number of times, invoked once: #<Mock:0x561b07ef4cc8>.host(any_parameters)
- allowed any number of times, invoked once: Nic::Managed(id: integer, mac: string, ip: string, type: string, name: string, host_id: integer, subnet_id: integer, domain_id: integer, attrs: text, created_at: datetime, updated_at: datetime, provider: string, username: string, password: string, virtual: boolean, link: boolean, identifier: string, tag: string, attached_to: string, managed: boolean, mode: string, attached_devices: string, bond_options: string, primary: boolean, provision: boolean, compute_attributes: text, ip6: string, subnet6_id: integer).where(:mac => "e4:1f:13:cc:36:58", :primary => true)



bin/rails test /home/lzap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/minitest-spec-rails-5.4.0/lib/minitest-spec-rails/dsl.rb:27

.......................................................................................................

Finished in 94.474860s, 1.7994 runs/s, 5.9698 assertions/s.
170 runs, 564 assertions, 8 failures, 0 errors, 0 skips

@@ -155,7 +155,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
test "should refresh existing discovered" do
interface = mock()
interface.stubs(:host).returns(Host.create(:name => "xyz", :type => "Host::Discovered"))
::Nic::Managed.stubs(:where).with(:mac => @facts['discovery_bootif'].downcase, :primary => true).returns([interface])
::Nic::Managed.stubs(:where).with(:mac => @facts['discovery_bootif'].downcase, :primary => true).returns([interface]).never
host = discover_host_from_facts(@facts)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lzap not sure if this helps, can you please look into this?

@mmoll
Copy link
Contributor

mmoll commented Mar 25, 2018

@lzap
Copy link
Member

lzap commented Mar 26, 2018

@mmoll thanks is there a trick to trigger them other than manually via Jenkins Web UI ? :-D

@rahulbajaj0509 still failing lemme look

@lzap
Copy link
Member

lzap commented Mar 26, 2018

@rahulbajaj0509 ok so the problem is that the test is clunky, no idea why it regressed but here is better version of doing the same - we want to basically make sure that if there is an existing discovered host, new one is not created. Here is new version much better, also tests NIC and fact:

diff --git a/test/unit/host_discovered_test.rb b/test/unit/host_discovered_test.rb
index 5597fe9..89bad06 100644
--- a/test/unit/host_discovered_test.rb
+++ b/test/unit/host_discovered_test.rb
@@ -152,12 +152,20 @@ class HostDiscoveredTest < ActiveSupport::TestCase
     assert_equal 'e41f13cc3658',host.name
   end
 
-  test "should refresh existing discovered" do
-    interface = mock()
-    interface.stubs(:host).returns(Host.create(:name => "xyz", :type => "Host::Discovered"))
-    ::Nic::Managed.stubs(:where).with(:mac => @facts['discovery_bootif'].downcase, :primary => true).returns([interface]).never
-    host = discover_host_from_facts(@facts)
-    assert_equal 'xyz', host.name
+  test "should refresh facts and NICs of an existing discovered host" do
+    host1 = discover_host_from_facts(@facts)
+    assert_equal 'mace41f13cc3658', host1.name
+    assert_equal 'IBM System x -[7870K4G]-', host1.facts["productname"]
+    assert_equal 1, Host::Discovered.where(:name => 'mace41f13cc3658').count
+    assert_equal '10.35.27.3', host1.ip
+
+    @facts["ipaddress_eth0"] = "1.2.3.4"
+    @facts["productname"] = "Dishwasher DW400"
+    host2 = discover_host_from_facts(@facts)
+    assert_equal 'mace41f13cc3658', host2.name
+    assert_equal 'Dishwasher DW400', host2.facts["productname"]
+    assert_equal '1.2.3.4', host2.ip
+    assert_equal 1, Host::Discovered.where(:name => 'mace41f13cc3658').count
   end
 
   test "should raise when hostname fact cannot be found" do

For easy copypaste here it is:

  test "should refresh facts and NICs of an existing discovered host" do
    host1 = discover_host_from_facts(@facts)
    assert_equal 'mace41f13cc3658', host1.name
    assert_equal 'IBM System x -[7870K4G]-', host1.facts["productname"]
    assert_equal 1, Host::Discovered.where(:name => 'mace41f13cc3658').count
    assert_equal '10.35.27.3', host1.ip

    @facts["ipaddress_eth0"] = "1.2.3.4"
    @facts["productname"] = "Dishwasher DW400"
    host2 = discover_host_from_facts(@facts)
    assert_equal 'mace41f13cc3658', host2.name
    assert_equal 'Dishwasher DW400', host2.facts["productname"]
    assert_equal '1.2.3.4', host2.ip
    assert_equal 1, Host::Discovered.where(:name => 'mace41f13cc3658').count
  end

Ping me after you rebase so I can quickly test and merge! Thanks.

@lzap lzap merged commit 3b3518d into theforeman:develop Mar 26, 2018
@lzap
Copy link
Member

lzap commented Mar 26, 2018

Merged, all green locally!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants