Skip to content

Commit

Permalink
Swap qesap_az_get_vnet with az_network_vnet_get
Browse files Browse the repository at this point in the history
Remove qesap_az_get_vnet and replace it with equivalent
az_network_vnet_get.
  • Loading branch information
mpagot committed Jan 20, 2025
1 parent be0a61d commit 707c916
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 61 deletions.
34 changes: 5 additions & 29 deletions lib/qesapdeployment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ our @EXPORT = qw(
qesap_import_instances
qesap_file_find_string
qesap_is_job_finished
qesap_az_get_vnet
qesap_az_get_resource_group
qesap_az_calculate_address_range
qesap_az_vnet_peering
Expand Down Expand Up @@ -1899,29 +1898,6 @@ sub qesap_is_job_finished {
return ($job_state ne 'running');
}

=head3 qesap_az_get_vnet
Return the output of az network vnet list
=over
=item B<RESOURCE_GROUP> - resource group name to query
=back
=cut

sub qesap_az_get_vnet {
my ($resource_group) = @_;
croak 'Missing mandatory resource_group argument' unless $resource_group;

my $cmd = join(' ', 'az network',
'vnet list',
'-g', $resource_group,
'--query "[0].name"',
'-o tsv');
return script_output($cmd, 180);
}

=head3 qesap_az_get_resource_group
Query and return the resource group used
Expand Down Expand Up @@ -1996,8 +1972,8 @@ sub qesap_az_calculate_address_range {
sub qesap_az_vnet_peering {
my (%args) = @_;
foreach (qw(source_group target_group)) { croak "Missing mandatory $_ argument" unless $args{$_}; }
my $source_vnet = qesap_az_get_vnet($args{source_group});
my $target_vnet = qesap_az_get_vnet($args{target_group});
my $source_vnet = az_network_vnet_get(resource_group => $args{source_group}, query => "[0].name");
my $target_vnet = az_network_vnet_get(resource_group => $args{target_group}, query => "[0].name");
$args{timeout} //= bmwqemu::scale_timeout(300);

my $vnet_show_cmd = 'az network vnet show --query id --output tsv';
Expand Down Expand Up @@ -2100,7 +2076,7 @@ sub qesap_az_vnet_peering_delete {
croak 'Missing mandatory target_group argument' unless $args{target_group};
$args{timeout} //= bmwqemu::scale_timeout(300);

my $target_vnet = qesap_az_get_vnet($args{target_group});
my $target_vnet = az_network_vnet_get(resource_group => $args{target_group}, query => "[0].name");

my $peering_name = qesap_az_get_peering_name(resource_group => $args{target_group});
if (!$peering_name) {
Expand All @@ -2113,7 +2089,7 @@ sub qesap_az_vnet_peering_delete {
my $source_ret = 0;
record_info('Destroying job_resources->IBSM peering');
if ($args{source_group}) {
my $source_vnet = qesap_az_get_vnet($args{source_group});
my $source_vnet = az_network_vnet_get(resource_group => $args{source_group}, query => "[0].name");
$source_ret = qesap_az_simple_peering_delete(
rg => $args{source_group},
vnet_name => $source_vnet,
Expand Down Expand Up @@ -2185,7 +2161,7 @@ sub qesap_az_get_peering_name {
croak 'Missing mandatory target_group argument' unless $args{resource_group};

my $job_id = get_current_job_id();
my $cmd = qesap_az_peering_list_cmd(resource_group => $args{resource_group}, vnet => qesap_az_get_vnet($args{resource_group}));
my $cmd = qesap_az_peering_list_cmd(resource_group => $args{resource_group}, vnet => az_network_vnet_get(resource_group => $args{resource_group}, query => "[0].name"));
$cmd .= ' | grep ' . $job_id;
return script_output($cmd, proceed_on_failure => 1);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/trento.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use Carp;
use utils qw(script_retry random_string);
use testapi;
use qesapdeployment;
use sles4sap::azure_cli;

use Exporter 'import';

Expand Down Expand Up @@ -930,9 +931,9 @@ sub cluster_trento_net_peering {
my $cmd = join(' ',
$basedir . '/00.050-trento_net_peering_tserver-sap_group.sh',
'-s', $trento_rg,
'-n', qesap_az_get_vnet($trento_rg),
'-n', az_network_vnet_get(resource_group => $trento_rg, query => "[0].name"),
'-t', $cluster_rg,
'-a', qesap_az_get_vnet($cluster_rg));
'-a', az_network_vnet_get(resource_group => $cluster_rg, query => "[0].name"));
record_info('NET PEERING');
assert_script_run($cmd, 360);
}
Expand Down
9 changes: 5 additions & 4 deletions t/08_trento.t
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ subtest '[cluster_trento_net_peering] cluster_trento_net_peering has to compose
my $expected_net_name = 'PIZZANET';
$trento->redefine(get_resource_group => sub { return 'VALLUTATA'; });
$trento->redefine(qesap_az_get_resource_group => sub { return 'ZUPPA'; });
$trento->redefine(qesap_az_get_vnet => sub {
push @calls, $_[0];
return "PIATTO_DI_VALLUTATA" if ($_[0] =~ /VALLUTATA/);
return "PIATTO_DI_ZUPPA" if ($_[0] =~ /ZUPPA/);
$trento->redefine(az_network_vnet_get => sub {
my (%args) = @_;
push @calls, $args{resource_group};
return "PIATTO_DI_VALLUTATA" if ($args{resource_group} =~ /VALLUTATA/);
return "PIATTO_DI_ZUPPA" if ($args{resource_group} =~ /ZUPPA/);
});

$trento->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
Expand Down
33 changes: 10 additions & 23 deletions t/15_qesap_azure.t
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@ subtest '[qesap_az_calculate_address_range]' => sub {
dies_ok { qesap_az_calculate_address_range(slot => 8193); } "Expected die for slot > 8192";
};

subtest '[qesap_az_get_vnet]' => sub {
my $qesap = Test::MockModule->new('qesapdeployment', no_auto => 1);
my @calls;
$qesap->redefine(script_output => sub { push @calls, $_[0]; return 'DIVER'; });

my $result = qesap_az_get_vnet('AUSTRALIA');

note("\n C--> " . join("\n C--> ", @calls));
ok((any { /az network vnet list.*/ } @calls), 'az command properly composed');
ok($result eq 'DIVER', 'function return is equal to the script_output return');
};

subtest '[qesap_az_get_vnet] no resource_group' => sub {
dies_ok { qesap_az_get_vnet() } "Expected die for missing resource_group";
};

subtest '[qesap_az_vnet_peering] missing group arguments' => sub {
dies_ok { qesap_az_vnet_peering() } "Expected die for missing arguments";
dies_ok { qesap_az_vnet_peering(source_group => 'JELLYFISH') } "Expected die for missing target_group";
Expand All @@ -71,9 +55,10 @@ subtest '[qesap_az_vnet_peering] missing group arguments' => sub {
subtest '[qesap_az_vnet_peering]' => sub {
my $qesap = Test::MockModule->new('qesapdeployment', no_auto => 1);
my @calls;
$qesap->redefine(qesap_az_get_vnet => sub {
return 'VNET_JELLYFISH' if ($_[0] =~ /JELLYFISH/);
return 'VNET_SQUID' if ($_[0] =~ /SQUID/);
$qesap->redefine(az_network_vnet_get => sub {
my (%args) = @_;
return 'VNET_JELLYFISH' if ($args{resource_group} =~ /JELLYFISH/);
return 'VNET_SQUID' if ($args{resource_group} =~ /SQUID/);
return 'VNET_UNKNOWN';
});
$qesap->redefine(script_output => sub { push @calls, $_[0];
Expand Down Expand Up @@ -109,8 +94,9 @@ subtest '[qesap_az_vnet_peering_delete]' => sub {
$qesap->redefine(script_run => sub { push @calls, $_[0]; return 0; });
$qesap->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
$qesap->redefine(record_soft_failure => sub { note(join(' ', 'RECORD_SOFT_FAILURE -->', @_)); });
$qesap->redefine(qesap_az_get_vnet => sub {
return 'VNET_WHALE' if ($_[0] =~ /WHALE/);
$qesap->redefine(az_network_vnet_get => sub {
my (%args) = @_;
return 'VNET_WHALE' if ($args{resource_group} =~ /WHALE/);
return;
});

Expand All @@ -133,8 +119,9 @@ subtest '[qesap_az_vnet_peering_delete] delete failure' => sub {
$qesap->redefine(record_soft_failure => sub {
push @soft_failure, $_[0];
note(join(' ', 'RECORD_SOFT_FAILURE -->', @_)); });
$qesap->redefine(qesap_az_get_vnet => sub {
return 'VNET_WHALE' if ($_[0] =~ /WHALE/);
$qesap->redefine(az_network_vnet_get => sub {
my (%args) = @_;
return 'VNET_WHALE' if ($args{resource_group} =~ /WHALE/);
return;
});

Expand Down
4 changes: 1 addition & 3 deletions tests/sles4sap/publiccloud/clean_leftover_peerings.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ sub run {
record_info('NO IBSM', 'No IBSM_RG variable found. Exiting');
return 0;
}
my $group = get_var('IBSM_RG');
my $vnet_name = qesap_az_get_vnet($group);
qesap_az_clean_old_peerings(rg => $group, vnet => $vnet_name);
qesap_az_clean_old_peerings(rg => $group, vnet => az_network_vnet_get(resource_group => get_var('IBS_RG'), query => "[0].name"));
}
}

Expand Down

0 comments on commit 707c916

Please sign in to comment.