From ac3391b4345048d9e2f943680f3bda23f6bfbb2b Mon Sep 17 00:00:00 2001 From: Vivek Reddy Karri Date: Tue, 4 Oct 2022 00:23:11 +0000 Subject: [PATCH 1/4] Updated wait_for_intf.sh to wait for ipv6 global and link local addr Signed-off-by: Vivek Reddy Karri --- dockers/docker-dhcp-relay/wait_for_intf.sh.j2 | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/dockers/docker-dhcp-relay/wait_for_intf.sh.j2 b/dockers/docker-dhcp-relay/wait_for_intf.sh.j2 index b224a697b5b..987e8219c0b 100644 --- a/dockers/docker-dhcp-relay/wait_for_intf.sh.j2 +++ b/dockers/docker-dhcp-relay/wait_for_intf.sh.j2 @@ -21,6 +21,24 @@ function wait_until_iface_ready echo "Interface ${IFACE_NAME} is ready!" } +function check_for_ipv6_link_local +{ + IFACE_NAME=$1 + echo "Waiting until interface ${IFACE_NAME} has a link-local ipv6 address configured...." + + # Status of link local address is not populated in STATE_DB + while true; do + HAS_LL=$(ip -6 addr show ${IFACE_NAME} scope link 2> /dev/null) + RC=$? + if [[ ${RC} == "0" ]] && [[ ! -z ${HAS_LL} ]]; then + break + fi + + sleep 1 + done + + echo "Link-Local address is configured on ${IFACE_NAME}" +} # Wait for all interfaces with IPv4 addresses to be up and ready {% for (name, prefix) in INTERFACE|pfx_filter %} @@ -32,6 +50,14 @@ wait_until_iface_ready {{ name }} {{ prefix }} {% if prefix | ipv4 %} wait_until_iface_ready {{ name }} {{ prefix }} {% endif %} +{% if prefix | ipv6 %} +{% if DHCP_RELAY and name in DHCP_RELAY %} +# dhcp6relay binds to ipv6 addresses configured on these vlan ifaces +# Thus check if they are ready before launching dhcp6relay +wait_until_iface_ready {{ name }} {{ prefix }} +check_for_ipv6_link_local {{ name }} +{% endif %} +{% endif %} {% endfor %} {% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} {% if prefix | ipv4 %} From 76b9c939d14aee87c3b1efd8944207587cda7879 Mon Sep 17 00:00:00 2001 From: Vivek Reddy Karri Date: Tue, 4 Oct 2022 22:06:01 +0000 Subject: [PATCH 2/4] Resolved UT failure and added ipv6 config to UT Signed-off-by: Vivek Reddy Karri --- dockers/docker-dhcp-relay/wait_for_intf.sh.j2 | 4 +-- .../tests/dhcp-relay-sample.json | 5 ++++ .../tests/sample_output/py2/wait_for_intf.sh | 26 +++++++++++++++++-- .../tests/sample_output/py3/wait_for_intf.sh | 22 ++++++++++++++++ src/sonic-config-engine/tests/test_j2files.py | 5 +++- 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 src/sonic-config-engine/tests/dhcp-relay-sample.json diff --git a/dockers/docker-dhcp-relay/wait_for_intf.sh.j2 b/dockers/docker-dhcp-relay/wait_for_intf.sh.j2 index 987e8219c0b..13499a6e6c5 100644 --- a/dockers/docker-dhcp-relay/wait_for_intf.sh.j2 +++ b/dockers/docker-dhcp-relay/wait_for_intf.sh.j2 @@ -41,6 +41,8 @@ function check_for_ipv6_link_local } # Wait for all interfaces with IPv4 addresses to be up and ready +# dhcp6relay binds to ipv6 addresses configured on these vlan ifaces +# Thus check if they are ready before launching dhcp6relay {% for (name, prefix) in INTERFACE|pfx_filter %} {% if prefix | ipv4 %} wait_until_iface_ready {{ name }} {{ prefix }} @@ -52,8 +54,6 @@ wait_until_iface_ready {{ name }} {{ prefix }} {% endif %} {% if prefix | ipv6 %} {% if DHCP_RELAY and name in DHCP_RELAY %} -# dhcp6relay binds to ipv6 addresses configured on these vlan ifaces -# Thus check if they are ready before launching dhcp6relay wait_until_iface_ready {{ name }} {{ prefix }} check_for_ipv6_link_local {{ name }} {% endif %} diff --git a/src/sonic-config-engine/tests/dhcp-relay-sample.json b/src/sonic-config-engine/tests/dhcp-relay-sample.json new file mode 100644 index 00000000000..7350199a47b --- /dev/null +++ b/src/sonic-config-engine/tests/dhcp-relay-sample.json @@ -0,0 +1,5 @@ +{ + "VLAN_INTERFACE": { + "Vlan1000|fc02:2000::2/24": {} + } +} \ No newline at end of file diff --git a/src/sonic-config-engine/tests/sample_output/py2/wait_for_intf.sh b/src/sonic-config-engine/tests/sample_output/py2/wait_for_intf.sh index 8ba15b1c835..5f0f46a5914 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/wait_for_intf.sh +++ b/src/sonic-config-engine/tests/sample_output/py2/wait_for_intf.sh @@ -21,14 +21,36 @@ function wait_until_iface_ready echo "Interface ${IFACE_NAME} is ready!" } +function check_for_ipv6_link_local +{ + IFACE_NAME=$1 + echo "Waiting until interface ${IFACE_NAME} has a link-local ipv6 address configured...." + + # Status of link local address is not populated in STATE_DB + while true; do + HAS_LL=$(ip -6 addr show ${IFACE_NAME} scope link 2> /dev/null) + RC=$? + if [[ ${RC} == "0" ]] && [[ ! -z ${HAS_LL} ]]; then + break + fi + + sleep 1 + done + + echo "Link-Local address is configured on ${IFACE_NAME}" +} # Wait for all interfaces with IPv4 addresses to be up and ready -wait_until_iface_ready Vlan2000 192.168.200.1/27 +# dhcp6relay binds to ipv6 addresses configured on these vlan ifaces +# Thus check if they are ready before launching dhcp6relay +wait_until_iface_ready Vlan1000 fc02:2000::2/24 +check_for_ipv6_link_local Vlan1000 wait_until_iface_ready Vlan1000 192.168.0.1/27 +wait_until_iface_ready Vlan2000 192.168.200.1/27 +wait_until_iface_ready PortChannel01 10.0.0.56/31 wait_until_iface_ready PortChannel02 10.0.0.58/31 wait_until_iface_ready PortChannel03 10.0.0.60/31 wait_until_iface_ready PortChannel04 10.0.0.62/31 -wait_until_iface_ready PortChannel01 10.0.0.56/31 # Wait 10 seconds for the rest of interfaces to get added/populated. # dhcrelay listens on each of the interfaces (in addition to the port diff --git a/src/sonic-config-engine/tests/sample_output/py3/wait_for_intf.sh b/src/sonic-config-engine/tests/sample_output/py3/wait_for_intf.sh index 6e5012d5939..5f0f46a5914 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/wait_for_intf.sh +++ b/src/sonic-config-engine/tests/sample_output/py3/wait_for_intf.sh @@ -21,8 +21,30 @@ function wait_until_iface_ready echo "Interface ${IFACE_NAME} is ready!" } +function check_for_ipv6_link_local +{ + IFACE_NAME=$1 + echo "Waiting until interface ${IFACE_NAME} has a link-local ipv6 address configured...." + + # Status of link local address is not populated in STATE_DB + while true; do + HAS_LL=$(ip -6 addr show ${IFACE_NAME} scope link 2> /dev/null) + RC=$? + if [[ ${RC} == "0" ]] && [[ ! -z ${HAS_LL} ]]; then + break + fi + + sleep 1 + done + + echo "Link-Local address is configured on ${IFACE_NAME}" +} # Wait for all interfaces with IPv4 addresses to be up and ready +# dhcp6relay binds to ipv6 addresses configured on these vlan ifaces +# Thus check if they are ready before launching dhcp6relay +wait_until_iface_ready Vlan1000 fc02:2000::2/24 +check_for_ipv6_link_local Vlan1000 wait_until_iface_ready Vlan1000 192.168.0.1/27 wait_until_iface_ready Vlan2000 192.168.200.1/27 wait_until_iface_ready PortChannel01 10.0.0.56/31 diff --git a/src/sonic-config-engine/tests/test_j2files.py b/src/sonic-config-engine/tests/test_j2files.py index fef27be40b7..dbf6ae55ca9 100644 --- a/src/sonic-config-engine/tests/test_j2files.py +++ b/src/sonic-config-engine/tests/test_j2files.py @@ -142,9 +142,12 @@ def test_ports_json(self): def test_dhcp_relay(self): # Test generation of wait_for_intf.sh + dhc_sample_data = os.path.join(self.test_dir, "dhcp-relay-sample.json") template_path = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-dhcp-relay', 'wait_for_intf.sh.j2') - argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -t ' + template_path + ' > ' + self.output_file + argument = '-m ' + self.t0_minigraph + ' -j ' + dhc_sample_data + ' -p ' + self.t0_port_config + ' -t ' + template_path + ' > ' + self.output_file self.run_script(argument) + with open(self.output_file, 'r') as f: + print(f.read()) self.assertTrue(utils.cmp(os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, 'wait_for_intf.sh'), self.output_file)) # Test generation of docker-dhcp-relay.supervisord.conf From 2260b030ab9c27a7067b2bc630883afc14113d24 Mon Sep 17 00:00:00 2001 From: Vivek Reddy Karri Date: Tue, 4 Oct 2022 22:07:33 +0000 Subject: [PATCH 3/4] Minor updates Signed-off-by: Vivek Reddy Karri --- src/sonic-config-engine/tests/dhcp-relay-sample.json | 2 +- src/sonic-config-engine/tests/test_j2files.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sonic-config-engine/tests/dhcp-relay-sample.json b/src/sonic-config-engine/tests/dhcp-relay-sample.json index 7350199a47b..dfd29ed80f4 100644 --- a/src/sonic-config-engine/tests/dhcp-relay-sample.json +++ b/src/sonic-config-engine/tests/dhcp-relay-sample.json @@ -2,4 +2,4 @@ "VLAN_INTERFACE": { "Vlan1000|fc02:2000::2/24": {} } -} \ No newline at end of file +} diff --git a/src/sonic-config-engine/tests/test_j2files.py b/src/sonic-config-engine/tests/test_j2files.py index dbf6ae55ca9..3ac219468e4 100644 --- a/src/sonic-config-engine/tests/test_j2files.py +++ b/src/sonic-config-engine/tests/test_j2files.py @@ -146,8 +146,6 @@ def test_dhcp_relay(self): template_path = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-dhcp-relay', 'wait_for_intf.sh.j2') argument = '-m ' + self.t0_minigraph + ' -j ' + dhc_sample_data + ' -p ' + self.t0_port_config + ' -t ' + template_path + ' > ' + self.output_file self.run_script(argument) - with open(self.output_file, 'r') as f: - print(f.read()) self.assertTrue(utils.cmp(os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, 'wait_for_intf.sh'), self.output_file)) # Test generation of docker-dhcp-relay.supervisord.conf From ebf826b6143c483cacbf91f1619c18626ea0d7e5 Mon Sep 17 00:00:00 2001 From: Vivek Reddy Karri Date: Tue, 4 Oct 2022 22:38:20 +0000 Subject: [PATCH 4/4] updated py2 output Signed-off-by: Vivek Reddy Karri --- .../tests/sample_output/py2/wait_for_intf.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sonic-config-engine/tests/sample_output/py2/wait_for_intf.sh b/src/sonic-config-engine/tests/sample_output/py2/wait_for_intf.sh index 5f0f46a5914..1d58bc956bd 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/wait_for_intf.sh +++ b/src/sonic-config-engine/tests/sample_output/py2/wait_for_intf.sh @@ -43,14 +43,14 @@ function check_for_ipv6_link_local # Wait for all interfaces with IPv4 addresses to be up and ready # dhcp6relay binds to ipv6 addresses configured on these vlan ifaces # Thus check if they are ready before launching dhcp6relay +wait_until_iface_ready Vlan2000 192.168.200.1/27 +wait_until_iface_ready Vlan1000 192.168.0.1/27 wait_until_iface_ready Vlan1000 fc02:2000::2/24 check_for_ipv6_link_local Vlan1000 -wait_until_iface_ready Vlan1000 192.168.0.1/27 -wait_until_iface_ready Vlan2000 192.168.200.1/27 -wait_until_iface_ready PortChannel01 10.0.0.56/31 wait_until_iface_ready PortChannel02 10.0.0.58/31 wait_until_iface_ready PortChannel03 10.0.0.60/31 wait_until_iface_ready PortChannel04 10.0.0.62/31 +wait_until_iface_ready PortChannel01 10.0.0.56/31 # Wait 10 seconds for the rest of interfaces to get added/populated. # dhcrelay listens on each of the interfaces (in addition to the port