Skip to content

Commit

Permalink
Fix warnings about uninitialized value $device
Browse files Browse the repository at this point in the history
Remove warnings on autoinst-logs about the uninitialized value of the `$device`.
When `$device` is initialized is gets the non-whitespace flag to pass to the grep
  • Loading branch information
b10n1k committed Feb 21, 2024
1 parent 678060a commit 153496f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/mm_network.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ sub get_host_resolv_conf {

sub is_networkmanager {
my $is_nm = (script_run('readlink /etc/systemd/system/network.service | grep NetworkManager') == 0);
record_info('NetworkManager', (($is_nm) ? 'NetworkManager has been detected.' : 'NetworkManager has not been detected.'));
my $msg = $is_nm ? 'NetworkManager has been detected.' : 'NetworkManager has not been detected.';
record_info('NetworkManager', "$msg");
return $is_nm;
}

Expand All @@ -58,11 +59,11 @@ sub configure_static_ip {
my $ip = $args{ip};
my $mtu = $args{mtu} // get_var('MM_MTU', 1380);
my $is_nm = $args{is_nm} // is_networkmanager();
my $device = $args{device};
my $device = $args{device} // '\S';

if ($is_nm) {
my $nm_id;
my $nm_list = script_output("nmcli -t -f DEVICE,NAME c | grep -v ^lo: | grep '$device' | head -n1");
my $nm_list = script_output("nmcli -t -f DEVICE,NAME c | grep -v '^lo:' | grep -e '$device' | head -n1");
($device, $nm_id) = split(':', $nm_list);

record_info('set_ip', "Device: $device\n NM ID: $nm_id\nIP: $ip\nMTU: $mtu");
Expand Down Expand Up @@ -105,11 +106,11 @@ sub configure_dhcp {
sub configure_default_gateway {
my (%args) = @_;
my $is_nm = $args{is_nm} // is_networkmanager();
my $device = $args{device};
my $device = $args{device} // '\S';
if ($is_nm) {
my $nm_id;
# When $device is not specified grep just does nothing and first connection is selected
my $nm_list = script_output("nmcli -t -f DEVICE,NAME c | grep -v ^lo: | grep '$device' | head -n1");
my $nm_list = script_output("nmcli -t -f DEVICE,NAME c | grep -v '^lo:' | grep -e '$device' | head -n1");
($device, $nm_id) = split(':', $nm_list);

assert_script_run "nmcli connection modify '$nm_id' ipv4.gateway 10.0.2.2";
Expand Down

0 comments on commit 153496f

Please sign in to comment.