Skip to content

Commit

Permalink
[dns] Do not apply dynamic DNS configuration when MGMT interface has …
Browse files Browse the repository at this point in the history
…static IP address. (sonic-net#17769)

### Why I did it
Fix the issue detected by[ TestStaticMgmtPortIP::test_dynamic_dns_not_working_when_static_ip_configured ](https://github.com/sonic-net/sonic-mgmt/blob/master/tests/dns/static_dns/test_static_dns.py#L105C9-L105C63) test.

### How I did it
Query MGMT interface configuration. Do not apply dynamic DNS configuration when MGMT interface has static IP address.

#### How to verify it
Run `tests/dns/static_dns/test_static_dns.py` sonic-mgmt tests.
  • Loading branch information
oleksandrivantsiv authored and mssonicbld committed Jan 31, 2024
1 parent e2ae581 commit 7e45cda
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions files/image_config/resolv-config/resolv-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@ start()
{
update_symlink

redis-dump -d 4 -k "DNS_NAMESERVER*" -y > /tmp/dns.json
if [[ $? -eq 0 && "$(cat /tmp/dns.json)" != "{}" ]]; then
has_static_mgmt_ip=false
mgmt_ip_cfg=$(redis-dump -d 4 -k "MGMT_INTERFACE|eth0|*" -y)
if [[ $? -eq 0 && ${mgmt_ip_cfg} != "{}" ]]; then
has_static_mgmt_ip=true
fi

has_static_dns=false
dns_cfg=$(redis-dump -d 4 -k "DNS_NAMESERVER*" -y)
if [[ $? -eq 0 && ${dns_cfg} != "{}" ]]; then
has_static_dns=true
fi

if [[ ${has_static_mgmt_ip} == true || ${has_static_dns} == true ]]; then
# Apply static DNS configuration and disable updates
/sbin/resolvconf --disable-updates
pushd ${CONFIG_DIR}
# Backup dynamic configuration to restore it when the static configuration is removed
mv ${DYNAMIC_CONFIG_FILE_TEMPLATE} ${WD} || true
mv ${DYNAMIC_CONFIG_FILE_TEMPLATE} ${WD} 2>/dev/null || true

sonic-cfggen -d -t /usr/share/sonic/templates/resolv.conf.j2,${STATIC_CONFIG_FILE}

Expand All @@ -34,7 +45,7 @@ start()
pushd ${CONFIG_DIR}
rm -f ${STATIC_CONFIG_FILE}
# Restore dynamic configuration if it exists
mv ${WD}/${DYNAMIC_CONFIG_FILE_TEMPLATE} ${CONFIG_DIR} || true
mv ${WD}/${DYNAMIC_CONFIG_FILE_TEMPLATE} ${CONFIG_DIR} 2>/dev/null || true

/sbin/resolvconf --enable-updates
/sbin/resolvconf -u
Expand Down

0 comments on commit 7e45cda

Please sign in to comment.