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

Enable more ipaddr2 test steps #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions lib/sles4sap/ipaddr2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
15 changes: 15 additions & 0 deletions t/22_ipaddr2.t
Original file line number Diff line number Diff line change
Expand Up @@ -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'; });
Expand All @@ -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;
35 changes: 18 additions & 17 deletions tests/sles4sap/ipaddr2/test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,35 @@ 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"

#ssh_node1 'sudo crm configure show' | grep -E "cli-prefer-.*${MYNAME}-vm-02" || test_die "Cluster should now have one cli-prefer- with ${MYNAME}-vm-02"
#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"
Expand All @@ -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 {
Expand Down
Loading