File tree 2 files changed +48
-0
lines changed
2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -1923,6 +1923,21 @@ def synchronous_mode(sync_mode):
1923
1923
else :
1924
1924
raise click .BadParameter ("Error: Invalid argument %s, expect either enable or disable" % sync_mode )
1925
1925
1926
+ #
1927
+ # 'yang_config_validation' command ('config yang_config_validation ...')
1928
+ #
1929
+ @config .command ('yang_config_validation' )
1930
+ @click .argument ('yang_config_validation' , metavar = '<enable|disable>' , required = True )
1931
+ def yang_config_validation (yang_config_validation ):
1932
+ # Enable or disable YANG validation on updates to ConfigDB
1933
+ if yang_config_validation == 'enable' or yang_config_validation == 'disable' :
1934
+ config_db = ConfigDBConnector ()
1935
+ config_db .connect ()
1936
+ config_db .mod_entry ('DEVICE_METADATA' , 'localhost' , {"yang_config_validation" : yang_config_validation })
1937
+ click .echo ("""Wrote %s yang config validation into CONFIG_DB""" % yang_config_validation )
1938
+ else :
1939
+ raise click .BadParameter ("Error: Invalid argument %s, expect either enable or disable" % yang_config_validation )
1940
+
1926
1941
#
1927
1942
# 'portchannel' group ('config portchannel ...')
1928
1943
#
Original file line number Diff line number Diff line change
1
+ from click .testing import CliRunner
2
+ import config .main as config
3
+
4
+ class TestYangConfigValidation (object ):
5
+ @classmethod
6
+ def setup_class (cls ):
7
+ print ("SETUP" )
8
+
9
+ def __check_result (self , result_msg , mode ):
10
+ if mode == "enable" or mode == "disable" :
11
+ expected_msg = """Wrote %s yang config validation into CONFIG_DB""" % mode
12
+ else :
13
+ expected_msg = "Error: Invalid argument %s, expect either enable or disable" % mode
14
+
15
+ return expected_msg in result_msg
16
+
17
+ def test_yang_config_validation (self ):
18
+ runner = CliRunner ()
19
+
20
+ result = runner .invoke (config .config .commands ["yang_config_validation" ], ["enable" ])
21
+ print (result .output )
22
+ assert result .exit_code == 0
23
+ assert self .__check_result (result .output , "enable" )
24
+
25
+ result = runner .invoke (config .config .commands ["yang_config_validation" ], ["disable" ])
26
+ print (result .output )
27
+ assert result .exit_code == 0
28
+ assert self .__check_result (result .output , "disable" )
29
+
30
+ result = runner .invoke (config .config .commands ["yang_config_validation" ], ["invalid-input" ])
31
+ print (result .output )
32
+ assert result .exit_code != 0
33
+ assert self .__check_result (result .output , "invalid-input" )
You can’t perform that action at this time.
0 commit comments