From 282e0c1dfdce7f48ae25a8afb7c9c2e1a107e30f Mon Sep 17 00:00:00 2001 From: dzenichev Date: Thu, 11 Aug 2022 15:30:41 +0200 Subject: [PATCH] TT#168102 instances-validator: add additional checks * check that host on which instance runs exists * check that instance names are not dupplicated * check that instance names in connections are not duplicated Additionally fix an uniqueness of array members in 'dupe_conn'. Change-Id: I65fc31107d7e784614974ab9992836885ff50d75 (cherry picked from commit adda56e1229f662c946f8036f7d23622c09e7233) --- sbin/ngcp-instances-validator | 2 +- .../host_to_run_on_is_absent.yml | 243 ++++++++++++++++++ .../repeated_instance_name.yml | 243 ++++++++++++++++++ .../repeated_instance_name_in_connections.yml | 243 ++++++++++++++++++ t/test_ngcp_instances_validator.py | 42 +++ 5 files changed, 772 insertions(+), 1 deletion(-) create mode 100644 t/fixtures/instances-validator/host_to_run_on_is_absent.yml create mode 100644 t/fixtures/instances-validator/repeated_instance_name.yml create mode 100644 t/fixtures/instances-validator/repeated_instance_name_in_connections.yml diff --git a/sbin/ngcp-instances-validator b/sbin/ngcp-instances-validator index 49d7db1e..465677f5 100755 --- a/sbin/ngcp-instances-validator +++ b/sbin/ngcp-instances-validator @@ -61,7 +61,7 @@ if (exists $yaml->{instances}) { # Iterate through the list of connections. foreach my $conn (@{$instance->{connections}}) { # Catch connections names duplicates of each given instance. - my $conn_id = $instance->{name} . ': ' . $conn->{name}; + my $conn_id = '#' . $i . ' : ' . $instance->{name} . ': ' . $conn->{name}; push @{$dupe_conn{$conn_id}}, "con #$j: $conn->{name} ;"; # Iterate through the list of connection links. diff --git a/t/fixtures/instances-validator/host_to_run_on_is_absent.yml b/t/fixtures/instances-validator/host_to_run_on_is_absent.yml new file mode 100644 index 00000000..b831b956 --- /dev/null +++ b/t/fixtures/instances-validator/host_to_run_on_is_absent.yml @@ -0,0 +1,243 @@ +--- +hosts: + sp1: + dbnode: '1' + interfaces: + - lo + - neth0 + - neth1 + - neth2 + lo: + advertised_ip: [] + hwaddr: 00:00:00:00:00:00 + ip: 127.0.0.1 + netmask: 255.0.0.0 + shared_ip: [] + shared_v6ip: [] + type: + - web_ext + - web_int + - aux_ext + - ssh_ext + - api_int + - stor_int + v6ip: ::1 + v6netmask: 128 + neth0: + dhcp: yes + dns_nameservers: + - 10.15.20.30 + gateway: 192.168.211.1 + hwaddr: 08:00:27:9c:a3:22 + ip: 10.0.2.15 + netmask: 255.255.255.0 + shared_ip: + shared_v6ip: + type: + - ssh_ext + - web_ext + - web_int + neth1: + cluster_sets: + - default + hwaddr: da:52:ca:90:8f:63 + ip: 192.168.255.251 + netmask: 255.255.255.248 + shared_ip: + - 192.168.255.250 + shared_v6ip: + type: + - ssh_ext + - ha_int + - boot_int + - sip_int + - rtp_int + neth2: + hwaddr: 0a:00:27:45:bb:ce + ip: 192.168.2.173 + netmask: 255.255.255.0 + shared_ip: + - 192.168.2.151 + shared_v6ip: + type: + - ssh_ext + - web_ext + - web_int + - sip_ext + - rtp_ext + - mon_ext + peer: sp2 + role: + - proxy + - lb + - mgmt + - rtp + - db + - storage + status: online + swraiddevices: [] + sysdescr: '' + syslocation: '' + sysname: '' + sp2: + dbnode: '2' + interfaces: + - lo + - neth0 + - neth1 + - neth2 + lo: + cluster_sets: + - default + hwaddr: 00:00:00:00:00:00 + ip: 127.0.0.1 + netmask: 255.0.0.0 + shared_ip: [] + shared_v6ip: [] + type: + - api_int + - stor_int + - web_int + - web_ext + - aux_ext + v6ip: ::1 + neth0: + dhcp: yes + dns_nameservers: + - 10.15.20.30 + gateway: 192.168.211.1 + hwaddr: 08:00:27:75:e6:93 + ip: 10.0.3.15 + netmask: 255.255.255.0 + shared_ip: + shared_v6ip: + type: + - ssh_ext + - web_int + - web_ext + neth1: + cluster_sets: + - default + hwaddr: 00:00:00:00:00:00 + ip: 192.168.255.252 + netmask: 255.255.255.248 + shared_ip: + - 192.168.255.250 + shared_v6ip: + type: + - ssh_ext + - ha_int + - boot_int + - sip_int + - rtp_int + neth2: + hwaddr: 0a:00:27:45:bb:66 + ip: 192.168.2.177 + netmask: 255.255.255.0 + shared_ip: + - 192.168.2.151 + shared_v6ip: + type: + - ssh_ext + - web_ext + - web_int + - sip_ext + - rtp_ext + - mon_ext + peer: sp1 + role: + - storage + - proxy + - lb + - mgmt + - rtp + - db + status: online + swraiddevices: [] + sysdescr: '' + syslocation: '' + sysname: '' +instances: + - name: A + service: kamailio-lb + host: sp3 + status: online + label: lb + interfaces: + - name: neth2 + ip: 192.168.2.250 + type: + - sip_ext + - name: neth1 + ip: 192.168.255.253 + type: + - sip_int + connections: + - name: proxy + algorithm: serial + links: + - type: instance + name: C + interfaces: + - name: neth1 + type: sip_int + - name: B + service: kamailio-lb + host: sp1 + label: lb + status: online + interfaces: + - name: neth2 + ip: 192.168.2.251 + type: + - sip_ext + - name: neth1 + ip: 192.168.255.254 + type: + - sip_int + connections: + - name: proxy + algorithm: serial + links: + - type: host + name: sp2 + interfaces: + - name: neth1 + type: sip_int + - name: C + service: kamailio-proxy + host: sp1 + status: online + label: proxy + interfaces: + - name: neth1 + ip: 192.168.255.249 + type: + - sip_int + - name: D + service: sems-b2b + host: sp1 + label: b2b + status: online + interfaces: + - name: neth1 + ip: 192.168.255.205 + type: + - sip_int + connections: + - name: proxy + links: + - type: instance + name: PROXD + interfaces: + - name: neth1 + type: sip_int + - name: lb + links: + - type: instance + name: LBB + interfaces: + - name: neth1 + type: sip_int + - name: neth2 + type: sip_ext diff --git a/t/fixtures/instances-validator/repeated_instance_name.yml b/t/fixtures/instances-validator/repeated_instance_name.yml new file mode 100644 index 00000000..cc7d1e76 --- /dev/null +++ b/t/fixtures/instances-validator/repeated_instance_name.yml @@ -0,0 +1,243 @@ +--- + hosts: + sp1: + dbnode: '1' + interfaces: + - lo + - neth0 + - neth1 + - neth2 + lo: + advertised_ip: [] + hwaddr: 00:00:00:00:00:00 + ip: 127.0.0.1 + netmask: 255.0.0.0 + shared_ip: [] + shared_v6ip: [] + type: + - web_ext + - web_int + - aux_ext + - ssh_ext + - api_int + - stor_int + v6ip: ::1 + v6netmask: 128 + neth0: + dhcp: yes + dns_nameservers: + - 10.15.20.30 + gateway: 192.168.211.1 + hwaddr: 08:00:27:9c:a3:22 + ip: 10.0.2.15 + netmask: 255.255.255.0 + shared_ip: + shared_v6ip: + type: + - ssh_ext + - web_ext + - web_int + neth1: + cluster_sets: + - default + hwaddr: da:52:ca:90:8f:63 + ip: 192.168.255.251 + netmask: 255.255.255.248 + shared_ip: + - 192.168.255.250 + shared_v6ip: + type: + - ssh_ext + - ha_int + - boot_int + - sip_int + - rtp_int + neth2: + hwaddr: 0a:00:27:45:bb:ce + ip: 192.168.2.173 + netmask: 255.255.255.0 + shared_ip: + - 192.168.2.151 + shared_v6ip: + type: + - ssh_ext + - web_ext + - web_int + - sip_ext + - rtp_ext + - mon_ext + peer: sp2 + role: + - proxy + - lb + - mgmt + - rtp + - db + - storage + status: online + swraiddevices: [] + sysdescr: '' + syslocation: '' + sysname: '' + sp2: + dbnode: '2' + interfaces: + - lo + - neth0 + - neth1 + - neth2 + lo: + cluster_sets: + - default + hwaddr: 00:00:00:00:00:00 + ip: 127.0.0.1 + netmask: 255.0.0.0 + shared_ip: [] + shared_v6ip: [] + type: + - api_int + - stor_int + - web_int + - web_ext + - aux_ext + v6ip: ::1 + neth0: + dhcp: yes + dns_nameservers: + - 10.15.20.30 + gateway: 192.168.211.1 + hwaddr: 08:00:27:75:e6:93 + ip: 10.0.3.15 + netmask: 255.255.255.0 + shared_ip: + shared_v6ip: + type: + - ssh_ext + - web_int + - web_ext + neth1: + cluster_sets: + - default + hwaddr: 00:00:00:00:00:00 + ip: 192.168.255.252 + netmask: 255.255.255.248 + shared_ip: + - 192.168.255.250 + shared_v6ip: + type: + - ssh_ext + - ha_int + - boot_int + - sip_int + - rtp_int + neth2: + hwaddr: 0a:00:27:45:bb:66 + ip: 192.168.2.177 + netmask: 255.255.255.0 + shared_ip: + - 192.168.2.151 + shared_v6ip: + type: + - ssh_ext + - web_ext + - web_int + - sip_ext + - rtp_ext + - mon_ext + peer: sp1 + role: + - storage + - proxy + - lb + - mgmt + - rtp + - db + status: online + swraiddevices: [] + sysdescr: '' + syslocation: '' + sysname: '' + instances: + - name: A + service: kamailio-lb + host: sp2 + status: online + label: lb + interfaces: + - name: neth2 + ip: 192.168.2.250 + type: + - sip_ext + - name: neth1 + ip: 192.168.255.253 + type: + - sip_int + connections: + - name: proxy + algorithm: serial + links: + - type: instance + name: C + interfaces: + - name: neth1 + type: sip_int + - name: A + service: kamailio-lb + host: sp1 + label: lb + status: online + interfaces: + - name: neth2 + ip: 192.168.2.251 + type: + - sip_ext + - name: neth1 + ip: 192.168.255.254 + type: + - sip_int + connections: + - name: proxy + algorithm: serial + links: + - type: host + name: sp2 + interfaces: + - name: neth1 + type: sip_int + - name: C + service: kamailio-proxy + host: sp1 + status: online + label: proxy + interfaces: + - name: neth1 + ip: 192.168.255.249 + type: + - sip_int + - name: D + service: sems-b2b + host: sp1 + label: b2b + status: online + interfaces: + - name: neth1 + ip: 192.168.255.205 + type: + - sip_int + connections: + - name: proxy + links: + - type: instance + name: C + interfaces: + - name: neth1 + type: sip_int + - name: lb + links: + - type: instance + name: A + interfaces: + - name: neth1 + type: sip_int + - name: neth2 + type: sip_ext \ No newline at end of file diff --git a/t/fixtures/instances-validator/repeated_instance_name_in_connections.yml b/t/fixtures/instances-validator/repeated_instance_name_in_connections.yml new file mode 100644 index 00000000..95d84b1e --- /dev/null +++ b/t/fixtures/instances-validator/repeated_instance_name_in_connections.yml @@ -0,0 +1,243 @@ +--- +hosts: + sp1: + dbnode: '1' + interfaces: + - lo + - neth0 + - neth1 + - neth2 + lo: + advertised_ip: [] + hwaddr: 00:00:00:00:00:00 + ip: 127.0.0.1 + netmask: 255.0.0.0 + shared_ip: [] + shared_v6ip: [] + type: + - web_ext + - web_int + - aux_ext + - ssh_ext + - api_int + - stor_int + v6ip: ::1 + v6netmask: 128 + neth0: + dhcp: yes + dns_nameservers: + - 10.15.20.30 + gateway: 192.168.211.1 + hwaddr: 08:00:27:9c:a3:22 + ip: 10.0.2.15 + netmask: 255.255.255.0 + shared_ip: + shared_v6ip: + type: + - ssh_ext + - web_ext + - web_int + neth1: + cluster_sets: + - default + hwaddr: da:52:ca:90:8f:63 + ip: 192.168.255.251 + netmask: 255.255.255.248 + shared_ip: + - 192.168.255.250 + shared_v6ip: + type: + - ssh_ext + - ha_int + - boot_int + - sip_int + - rtp_int + neth2: + hwaddr: 0a:00:27:45:bb:ce + ip: 192.168.2.173 + netmask: 255.255.255.0 + shared_ip: + - 192.168.2.151 + shared_v6ip: + type: + - ssh_ext + - web_ext + - web_int + - sip_ext + - rtp_ext + - mon_ext + peer: sp2 + role: + - proxy + - lb + - mgmt + - rtp + - db + - storage + status: online + swraiddevices: [] + sysdescr: '' + syslocation: '' + sysname: '' + sp2: + dbnode: '2' + interfaces: + - lo + - neth0 + - neth1 + - neth2 + lo: + cluster_sets: + - default + hwaddr: 00:00:00:00:00:00 + ip: 127.0.0.1 + netmask: 255.0.0.0 + shared_ip: [] + shared_v6ip: [] + type: + - api_int + - stor_int + - web_int + - web_ext + - aux_ext + v6ip: ::1 + neth0: + dhcp: yes + dns_nameservers: + - 10.15.20.30 + gateway: 192.168.211.1 + hwaddr: 08:00:27:75:e6:93 + ip: 10.0.3.15 + netmask: 255.255.255.0 + shared_ip: + shared_v6ip: + type: + - ssh_ext + - web_int + - web_ext + neth1: + cluster_sets: + - default + hwaddr: 00:00:00:00:00:00 + ip: 192.168.255.252 + netmask: 255.255.255.248 + shared_ip: + - 192.168.255.250 + shared_v6ip: + type: + - ssh_ext + - ha_int + - boot_int + - sip_int + - rtp_int + neth2: + hwaddr: 0a:00:27:45:bb:66 + ip: 192.168.2.177 + netmask: 255.255.255.0 + shared_ip: + - 192.168.2.151 + shared_v6ip: + type: + - ssh_ext + - web_ext + - web_int + - sip_ext + - rtp_ext + - mon_ext + peer: sp1 + role: + - storage + - proxy + - lb + - mgmt + - rtp + - db + status: online + swraiddevices: [] + sysdescr: '' + syslocation: '' + sysname: '' +instances: + - name: A + service: kamailio-lb + host: sp2 + status: online + label: lb + interfaces: + - name: neth2 + ip: 192.168.2.250 + type: + - sip_ext + - name: neth1 + ip: 192.168.255.253 + type: + - sip_int + connections: + - name: proxy + algorithm: serial + links: + - type: instance + name: C + interfaces: + - name: neth1 + type: sip_int + - name: B + service: kamailio-lb + host: sp1 + label: lb + status: online + interfaces: + - name: neth2 + ip: 192.168.2.251 + type: + - sip_ext + - name: neth1 + ip: 192.168.255.254 + type: + - sip_int + connections: + - name: proxy + algorithm: serial + links: + - type: host + name: sp2 + interfaces: + - name: neth1 + type: sip_int + - name: C + service: kamailio-proxy + host: sp1 + status: online + label: proxy + interfaces: + - name: neth1 + ip: 192.168.255.249 + type: + - sip_int + - name: D + service: sems-b2b + host: sp1 + label: b2b + status: online + interfaces: + - name: neth1 + ip: 192.168.255.205 + type: + - sip_int + connections: + - name: proxy + links: + - type: instance + name: C + interfaces: + - name: neth1 + type: sip_int + - name: proxy + links: + - type: instance + name: A + interfaces: + - name: neth1 + type: sip_int + - name: neth2 + type: sip_ext diff --git a/t/test_ngcp_instances_validator.py b/t/test_ngcp_instances_validator.py index 1a42f821..e7540fdd 100644 --- a/t/test_ngcp_instances_validator.py +++ b/t/test_ngcp_instances_validator.py @@ -67,3 +67,45 @@ def test_wrong_link_interfaces(cli): rf"\[instances/B/proxy/sp2/neth1\] {msg}", out.stderr, ) + +def test_repeated_instance_name(cli): + file = "repeated_instance_name" + cmd = [ + CMD, + f"--network-file=./fixtures/instances-validator/{file}.yml", + ] + out = cli(*cmd) + assert out.exitcode != 0 + msg = "Duplicate instance name with an existing instance A" + assert re.search( + rf"\[/instances/\] {msg}", + out.stderr, + ) + +def test_repeated_instance_name_in_connections(cli): + file = "repeated_instance_name_in_connections" + cmd = [ + CMD, + f"--network-file=./fixtures/instances-validator/{file}.yml", + ] + out = cli(*cmd) + assert out.exitcode != 0 + msg = "Duplicate connetion name #3 : D: proxy" + assert re.search( + rf"\[/instances/\] {msg}", + out.stderr, + ) + +def test_host_to_run_on_is_absent(cli): + file = "host_to_run_on_is_absent" + cmd = [ + CMD, + f"--network-file=./fixtures/instances-validator/{file}.yml", + ] + out = cli(*cmd) + assert out.exitcode != 0 + msg = "Missing required host sp3" + assert re.search( + rf"\[instances/A\] {msg}", + out.stderr, + )