Skip to content

Commit

Permalink
Add yang models for GNMI #13716
Browse files Browse the repository at this point in the history
Why I did it
Add missing yang models.

How I did it
Add sonic-gnmi.yang and unit test.

How to verify it
Run unit test for sonic-yang-models.
  • Loading branch information
ganglyu authored Feb 16, 2023
1 parent 373f091 commit e673c1d
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/sonic-yang-models/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def run(self):
'./yang-models/sonic-system-tacacs.yang',
'./yang-models/sonic-system-radius.yang',
'./yang-models/sonic-telemetry.yang',
'./yang-models/sonic-gnmi.yang',
'./yang-models/sonic-tunnel.yang',
'./yang-models/sonic-types.yang',
'./yang-models/sonic-versions.yang',
Expand Down Expand Up @@ -226,6 +227,7 @@ def run(self):
'./cvlyang-models/sonic-system-aaa.yang',
'./cvlyang-models/sonic-system-tacacs.yang',
'./cvlyang-models/sonic-telemetry.yang',
'./cvlyang-models/sonic-gnmi.yang',
'./cvlyang-models/sonic-types.yang',
'./cvlyang-models/sonic-versions.yang',
'./cvlyang-models/sonic-vlan.yang',
Expand Down
12 changes: 12 additions & 0 deletions src/sonic-yang-models/tests/files/sample_config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,18 @@
"port": "50051"
}
},
"GNMI": {
"certs": {
"ca_crt": "/etc/sonic/credentials/dsmsroot.cer",
"server_crt": "/etc/sonic/credentials/server.cer",
"server_key": "/etc/sonic/credentials/server.key"
},
"gnmi": {
"client_auth": "true",
"log_level": "2",
"port": "50052"
}
},
"TUNNEL": {
"MuxTunnel0": {
"dscp_mode": "uniform",
Expand Down
17 changes: 17 additions & 0 deletions src/sonic-yang-models/tests/yang_model_tests/tests/gnmi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"GNMI_TABLE_WITH_INCORRECT_CERT": {
"desc": "TABLE_WITH_INCORRECT_CERT failure.",
"eStrKey": "Pattern"
},
"GNMI_TABLE_WITH_INCORRECT_CLIENT_AUTH": {
"desc": "TABLE_WITH_INCORRECT_CLIENT_AUTH failure",
"eStrKey": "InvalidValue"
},
"GNMI_TABLE_WITH_INCORRECT_PORT": {
"desc": "TABLE_WITH_INCORRECT_PORT failure.",
"eStrKey": "InvalidValue"
},
"GNMI_TABLE_WITH_VALID_CONFIG": {
"desc": "TABLE WITH VALID CONFIG."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"GNMI_TABLE_WITH_INCORRECT_CERT": {
"sonic-gnmi:sonic-gnmi": {
"sonic-gnmi:GNMI": {
"certs": {
"ca_crt": "abcd.config",
"server_crt": "a/b/c",
"server_key": "123"
},
"gnmi": {
"client_auth": "true",
"log_level": "2",
"port": "50052"
}
}
}
},
"GNMI_TABLE_WITH_INCORRECT_CLIENT_AUTH": {
"sonic-gnmi:sonic-gnmi": {
"sonic-gnmi:GNMI": {
"certs": {
"ca_crt": "/etc/sonic/credentials/dsmsroot.cer",
"server_crt": "/etc/sonic/credentials/server.cer",
"server_key": "/etc/sonic/credentials/server.key"
},
"gnmi": {
"client_auth": "up",
"log_level": "2",
"port": "50052"
}
}
}
},
"GNMI_TABLE_WITH_INCORRECT_PORT": {
"sonic-gnmi:sonic-gnmi": {
"sonic-gnmi:GNMI": {
"certs": {
"ca_crt": "/etc/sonic/credentials/dsmsroot.cer",
"server_crt": "/etc/sonic/credentials/server.cer",
"server_key": "/etc/sonic/credentials/server.key"
},
"gnmi": {
"client_auth": "true",
"log_level": "2",
"port": "abc"
}
}
}
},
"GNMI_TABLE_WITH_VALID_CONFIG": {
"sonic-gnmi:sonic-gnmi": {
"sonic-gnmi:GNMI": {
"certs": {
"ca_crt": "/etc/sonic/credentials/dsmsroot.cer",
"server_crt": "/etc/sonic/credentials/server.cer",
"server_key": "/etc/sonic/credentials/server.key"
},
"gnmi": {
"client_auth": "true",
"log_level": "2",
"port": "50052"
}
}
}
}
}
78 changes: 78 additions & 0 deletions src/sonic-yang-models/yang-models/sonic-gnmi.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
module sonic-gnmi {

yang-version 1.1;

namespace "http://github.com/sonic-net/sonic-gnmi";
prefix gnmi;

import ietf-inet-types {
prefix inet;
}

organization
"SONiC";

contact
"SONiC";

description "GNMI YANG Module for SONiC OS";

revision 2023-02-10 {
description "First Revision";
}

container sonic-gnmi {

container GNMI {

description "GNMI TABLE part of config_db.json";

container certs {

leaf ca_crt {
type string {
pattern '(/[a-zA-Z0-9_-]+)*/([a-zA-Z0-9_-]+).cer';
}
description "Local path for ca_crt.";
}

leaf server_crt {
type string {
pattern '(/[a-zA-Z0-9_-]+)*/([a-zA-Z0-9_-]+).cer';
}
description "Local path for server_crt.";
}

leaf server_key {
type string {
pattern '(/[a-zA-Z0-9_-]+)*/([a-zA-Z0-9_-]+).key';
}
description "Local path for server_key.";
}

}

container gnmi {

leaf client_auth {
type boolean;
description "Flag for requiring client auth.";
}

leaf log_level {
type uint8 {
range 0..100;
}
description "Log level for gnmi.";
}

leaf port {
type inet:port-number;
description "Port gnmi runs on.";
}

}

}
}
}

0 comments on commit e673c1d

Please sign in to comment.