diff --git a/lib/sles4sap/ipaddr2.pm b/lib/sles4sap/ipaddr2.pm index 80e571c2858b..575822628a28 100644 --- a/lib/sles4sap/ipaddr2.pm +++ b/lib/sles4sap/ipaddr2.pm @@ -33,6 +33,7 @@ our @EXPORT = qw( ipaddr2_deployment_sanity ipaddr2_deployment_logs ipaddr2_os_sanity + ipaddr2_os_connectivity_sanity ipaddr2_cluster_sanity ipaddr2_bastion_pubip ipaddr2_internal_key_accept @@ -765,26 +766,43 @@ die in case of failure sub ipaddr2_os_connectivity_sanity { my (%args) = @_; $args{bastion_ip} //= ipaddr2_bastion_pubip(); + my $ping_cmd = 'ping -c 3'; # proceed_on_failure needed as ping or nc # could be missing on the qcow2 running these commands # (for example pc_tools) - script_run("ping -c 3 $args{bastion_ip}", proceed_on_failure => 1); + script_run("$ping_cmd $args{bastion_ip}", proceed_on_failure => 1); script_run("nc -vz -w 1 $args{bastion_ip} 22", proceed_on_failure => 1); - # Check if the bastion is able to ping - # the VM by hostname and private IP + foreach my $i (1 .. 2) { + # Check if the bastion is able to ping + # the VM by hostname and private IP foreach my $addr ( ipaddr2_get_internal_vm_private_ip(id => $i), ipaddr2_get_internal_vm_name(id => $i)) { - foreach my $cmd ('ping -c 3 ', 'tracepath ', 'dig ') { + foreach my $cmd ($ping_cmd, 'tracepath', 'dig') { ipaddr2_ssh_bastion_assert_script_run( cmd => "$cmd $addr", bastion_ip => $args{bastion_ip}); } } + # Check if each internal VM can ping the virtual IP + ipaddr2_ssh_internal( + id => $i, + cmd => join(' ', $ping_cmd, $frontend_ip), + bastion_ip => $args{bastion_ip}); } + + ipaddr2_ssh_internal( + id => 1, + cmd => join(' ', $ping_cmd, ipaddr2_get_internal_vm_private_ip(id => 2)), + bastion_ip => $args{bastion_ip}); + + ipaddr2_ssh_internal( + id => 2, + cmd => 'ping -c 3 ' . ipaddr2_get_internal_vm_private_ip(id => 1), + bastion_ip => $args{bastion_ip}); } =head2 ipaddr2_os_cloud_init_sanity @@ -1346,7 +1364,7 @@ sub ipaddr2_configure_web_server { $args{bastion_ip} //= ipaddr2_bastion_pubip(); ipaddr2_ssh_internal(id => $args{id}, cmd => $_, - timeout => 180, + timeout => 240, bastion_ip => $args{bastion_ip}) for (@nginx_cmds); } diff --git a/t/22_ipaddr2.t b/t/22_ipaddr2.t index 39848698ac2a..43ba9935ec03 100644 --- a/t/22_ipaddr2.t +++ b/t/22_ipaddr2.t @@ -703,6 +703,7 @@ subtest '[ipaddr2_registeration_set]' => sub { ok((any { /registercloudguest.*clean/ } @calls), 'registercloudguest clean'); ok((any { /registercloudguest.*-r.*1234567890/ } @calls), 'registercloudguest register'); }; + subtest '[ipaddr2_os_cloud_init_logs]' => sub { my $ipaddr2 = Test::MockModule->new('sles4sap::ipaddr2', no_auto => 1); $ipaddr2->redefine(ipaddr2_bastion_pubip => sub { return '1.2.3.4'; }); @@ -722,4 +723,18 @@ subtest '[ipaddr2_os_cloud_init_logs]' => sub { ok((scalar @calls > 0), "Some calls to ipaddr2_ssh_internal"); }; +subtest '[ipaddr2_os_connectivity_sanity]' => sub { + my $ipaddr2 = Test::MockModule->new('sles4sap::ipaddr2', no_auto => 1); + $ipaddr2->redefine(ipaddr2_bastion_pubip => sub { return '1.2.3.4'; }); + my @calls; + $ipaddr2->redefine(script_run => sub { push @calls, $_[0]; return; }); + $ipaddr2->redefine(assert_script_run => sub { push @calls, $_[0]; return; }); + + ipaddr2_os_connectivity_sanity(); + + note("\n --> " . join("\n --> ", @calls)); + + ok 1; +}; + done_testing; diff --git a/tests/sles4sap/ipaddr2/test.pm b/tests/sles4sap/ipaddr2/test.pm index 6be63f179523..f871a5db65ff 100644 --- a/tests/sles4sap/ipaddr2/test.pm +++ b/tests/sles4sap/ipaddr2/test.pm @@ -33,10 +33,14 @@ sub run { ipaddr2_crm_move(bastion_ip => $bastion_ip, destination => 2); sleep 30; - # use curl to probe the webserver using the frontend IP + # probe the webserver using the frontend IP # until the reply come from the VM-02 die "Takeover does not happens in time" unless ipaddr2_wait_for_takeover(bastion_ip => $bastion_ip, destination => 2); - #test_connectivity + + ipaddr2_os_connectivity_sanity(); + + # Check the status on the VM that is supposed to be + # the master for the webservice ipaddr2_test_master_vm(bastion_ip => $bastion_ip, id => 2); #test_other_vm "${MYNAME}-vm-01" @@ -44,20 +48,20 @@ sub run { #ssh_node1 'sudo crm configure show' | grep -c cli-prefer- | grep 1 || test_die "Cluster should now have one cli-prefer-" # Slow down, take a break, then check again, nothing should be changed. - #test_step "Check again later" - #sleep 30 - #test_connectivity - #test_web "${MYNAME}-vm-02" + sleep 60; + ipaddr2_os_connectivity_sanity(); + ipaddr2_test_master_vm(bastion_ip => $bastion_ip, id => 2); ################################################################################# # Repeat the same but this time from VM-02 to VM-01 #test_step "Move back the IpAddr2 resource to VM1" - #ssh_node1 'sudo crm resource move '"${MY_MOVE_RES} ${MYNAME}-vm-01" || test_die "Error in resource move" - #sleep 30 + ipaddr2_crm_move(bastion_ip => $bastion_ip, destination => 1); + sleep 30; + + die "Takeover does not happens in time" unless ipaddr2_wait_for_takeover(bastion_ip => $bastion_ip, destination => 1); - #wait_for_takeover "${MYNAME}-vm-01" - #test_connectivity - #test_on_vm "${MYNAME}-vm-01" + ipaddr2_os_connectivity_sanity(); + ipaddr2_test_master_vm(bastion_ip => $bastion_ip, id => 1); #test_other_vm "${MYNAME}-vm-02" #test_step "Clear all location constrain used during the test" @@ -69,12 +73,9 @@ sub run { #ssh_node1 'sudo crm status' # Slow down, take a break, then check again, nothing should be changed. - #test_step "Check again later" - #sleep 30 - #test_connectivity - #test_web "${MYNAME}-vm-01" - - + sleep 60; + ipaddr2_os_connectivity_sanity(); + ipaddr2_test_master_vm(bastion_ip => $bastion_ip, id => 1); } sub test_flags {