From 6d91f4232d5f80c7597d3156ba2e4dcd778dfdb4 Mon Sep 17 00:00:00 2001 From: ngcp-config Date: Tue, 22 Nov 2022 13:16:23 +0100 Subject: [PATCH] MT#56017 ngcp-network: don't remove all the list of interfaces on --remove-interface * pre-commit: don't mess with tests files Change-Id: I7ef729ccfbbc31bf46e7a046531bb8afbed54b87 --- .pre-commit-config.yaml | 3 ++- sbin/ngcp-network | 4 ++-- testsuite/network-config/lo.yml | 20 ++++++++++++++++++++ testsuite/ngcp-network | 5 +++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 testsuite/network-config/lo.yml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 830f0ff1..f3a1ec37 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,12 +18,13 @@ repos: - id: yamlfmt args: [--mapping, '2', --sequence, '4', --offset, '2', --width, '150'] exclude: | - (?x)^(.yamllint)$ + (?x)^(.yamllint|testsuite/.*)$ - repo: https://github.com/adrienverge/yamllint.git rev: v1.26.3 hooks: - id: yamllint args: [--format, parsable, --strict] + exclude: ^testsuite/.* - repo: https://github.com/asottile/reorder_python_imports rev: v2.6.0 hooks: diff --git a/sbin/ngcp-network b/sbin/ngcp-network index 754efeb0..91f714a0 100755 --- a/sbin/ngcp-network +++ b/sbin/ngcp-network @@ -415,8 +415,8 @@ sub remove_interface { my $ifaces = $yaml->{hosts}->{$host}->{interfaces}; if ( defined $ifaces ) { - logger("removing interface @$ifaces as requested"); - undef @{$ifaces}; + logger("removing interface $rem_iface from @$ifaces as requested"); + @{$yaml->{hosts}->{$host}->{interfaces}} = grep {$_ ne $rem_iface} @$ifaces; } return; } diff --git a/testsuite/network-config/lo.yml b/testsuite/network-config/lo.yml new file mode 100644 index 00000000..020e9ba2 --- /dev/null +++ b/testsuite/network-config/lo.yml @@ -0,0 +1,20 @@ +--- +hosts: + sp1: + interfaces: + - lo + lo: + ip: 127.0.0.1 + netmask: 255.255.255.0 + type: + - sip_int + - ha_int + - web_ext + - sip_ext + - rtp_ext + - ssh_ext + - mon_ext + role: + - proxy + - lb + - mgmt diff --git a/testsuite/ngcp-network b/testsuite/ngcp-network index 8b492b6b..c224763a 100644 --- a/testsuite/ngcp-network +++ b/testsuite/ngcp-network @@ -148,6 +148,11 @@ ${CMD} --host=$PEER --set-interface=lo --type=sip_int --type=web_ext --type=sip_ assertEqualFiles testfiles/deployment.yml network-config/deployment.yml +# make sure host/interfaces doesn't get cleaned on remove one interface +${CMD} --input-file=network-config/eth42.yml --output-file=testfiles/lo.yml \ + --host=sp1 --remove-interface=eth42 +assertEqualFiles testfiles/lo.yml network-config/lo.yml + # TAP output printf "1..%s\n" "${count}" cat "$OUTPUT"