Skip to content

Commit a82e45a

Browse files
[DNS] yang model for static DNS (#13834)
- Why I did it Add SONiC YANG model for DNS to provide the possibility to configure static DNS entries in Config DB. - How I did it Added sonic-dns.yang file that contains the YANG model for the static DNS configuration. - How to verify it This PR extends YANG model tests to cover DNS configuration. To run the test sonic_yang_models-1.0-py3-none-any.whl should be compiled.
1 parent a81ffeb commit a82e45a

File tree

6 files changed

+126
-2
lines changed

6 files changed

+126
-2
lines changed

src/sonic-yang-models/doc/Configuration.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ Table of Contents
6666
* [LOGGER](#logger)
6767
* [WRED_PROFILE](#wred_profile)
6868
* [PASSWORD_HARDENING](#password_hardening)
69-
* [SYSTEM_DEFAULTS table](#systemdefaults-table)
70-
* [RADIUS](#radius)
69+
* [SYSTEM_DEFAULTS table](#systemdefaults-table)
70+
* [RADIUS](#radius)
71+
* [Static DNS](#static-dns)
7172
* [For Developers](#for-developers)
7273
* [Generating Application Config by Jinja2 Template](#generating-application-config-by-jinja2-template)
7374
* [Incremental Configuration by Subscribing to ConfigDB](#incremental-configuration-by-subscribing-to-configdb)
@@ -2096,6 +2097,19 @@ The RADIUS and RADIUS_SERVER tables define RADIUS configuration parameters. RADI
20962097
}
20972098
```
20982099

2100+
### Static DNS
2101+
2102+
The DNS_NAMESERVER table introduces static DNS nameservers configuration.
2103+
2104+
```json
2105+
{
2106+
"DNS_NAMESERVER": {
2107+
"1.1.1.1": {},
2108+
"fe80:1000:2000:3000::1": {}
2109+
},
2110+
}
2111+
```
2112+
20992113
#### 5.2.3 Update value directly in db memory
21002114

21012115
For Developers

src/sonic-yang-models/setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def run(self):
107107
'./yang-models/sonic-device_neighbor_metadata.yang',
108108
'./yang-models/sonic-dhcp-server.yang',
109109
'./yang-models/sonic-dhcpv6-relay.yang',
110+
'./yang-models/sonic-dns.yang',
110111
'./yang-models/sonic-events-bgp.yang',
111112
'./yang-models/sonic-events-common.yang',
112113
'./yang-models/sonic-events-dhcp-relay.yang',

src/sonic-yang-models/tests/files/sample_config_db.json

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"192.0.0.8": {},
99
"192.0.0.8": {}
1010
},
11+
"DNS_NAMESERVER": {
12+
"1.1.1.1": {},
13+
"fe80:1000:2000:3000::1": {}
14+
},
1115
"BUFFER_POOL": {
1216
"ingress_lossy_pool": {
1317
"mode": "static",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"DNS_NAMESERVER_TEST" : {
3+
"desc": "DNS nameserver configuration in DNS_NAMESERVER table."
4+
},
5+
"DNS_NAMESERVER_TEST_INVALID_IP" : {
6+
"desc": "DNS nameserver configuration with invalid IP value in DNS_NAMESERVER table.",
7+
"eStr": "Invalid value"
8+
},
9+
"DNS_NAMESERVER_TEST_MAX_IP_NUMBER" : {
10+
"desc": "DNS nameserver configuration exceeds the maximum IPs in DNS_NAMESERVER table.",
11+
"eStr": "Too many elements."
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"DNS_NAMESERVER_TEST": {
3+
"sonic-dns:sonic-dns": {
4+
"sonic-dns:DNS_NAMESERVER": {
5+
"DNS_NAMESERVER_LIST": [
6+
{
7+
"ip": "192.168.1.1"
8+
},
9+
{
10+
"ip": "fe80:1000:2000:3000::1"
11+
}
12+
]
13+
}
14+
}
15+
},
16+
"DNS_NAMESERVER_TEST_INVALID_IP": {
17+
"sonic-dns:sonic-dns": {
18+
"sonic-dns:DNS_NAMESERVER": {
19+
"DNS_NAMESERVER_LIST": [
20+
{
21+
"ip": "1.x.2.x"
22+
}
23+
]
24+
}
25+
}
26+
},
27+
"DNS_NAMESERVER_TEST_MAX_IP_NUMBER": {
28+
"sonic-dns:sonic-dns": {
29+
"sonic-dns:DNS_NAMESERVER": {
30+
"DNS_NAMESERVER_LIST": [
31+
{
32+
"ip": "192.168.1.1"
33+
},
34+
{
35+
"ip": "fe80:1000:2000:3000::2"
36+
},
37+
{
38+
"ip": "192.168.1.3"
39+
},
40+
{
41+
"ip": "fe80:1000:2000:3000::4"
42+
}
43+
]
44+
}
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module sonic-dns {
2+
3+
namespace "http://github.com/sonic-net/sonic-dns";
4+
yang-version 1.1;
5+
prefix dns;
6+
7+
import ietf-inet-types {
8+
prefix inet;
9+
}
10+
11+
organization
12+
"SONiC";
13+
14+
contact
15+
"SONiC";
16+
17+
description "DNS YANG module for SONiC OS";
18+
19+
revision 2023-02-14 {
20+
description "Initial version";
21+
}
22+
23+
container sonic-dns {
24+
25+
container DNS_NAMESERVER {
26+
27+
description "DNS_NAMESERVER part of config_db.json";
28+
29+
list DNS_NAMESERVER_LIST {
30+
max-elements 3;
31+
description "List of nameservers IPs";
32+
33+
key "ip";
34+
35+
leaf ip {
36+
description "IP as DHCP_SERVER";
37+
type inet:ip-address;
38+
}
39+
} /* end of list DNS_NAMESERVER_LIST */
40+
41+
} /* end of container DNS_NAMESERVER */
42+
43+
} /* end of container sonic-dns */
44+
45+
} /* end of module sonic-dns */

0 commit comments

Comments
 (0)