@@ -697,17 +697,25 @@ def storm_control_set_entry(port_name, kbps, storm_type, namespace):
697
697
return False
698
698
699
699
#Validate kbps value
700
- config_db = ConfigDBConnector ()
700
+ config_db = ValidatedConfigDBConnector ( ConfigDBConnector () )
701
701
config_db .connect ()
702
702
key = port_name + '|' + storm_type
703
703
entry = config_db .get_entry ('PORT_STORM_CONTROL' , key )
704
704
705
705
if len (entry ) == 0 :
706
- config_db .set_entry ('PORT_STORM_CONTROL' , key , {'kbps' :kbps })
706
+ try :
707
+ config_db .set_entry ('PORT_STORM_CONTROL' , key , {'kbps' :kbps })
708
+ except ValueError as e :
709
+ ctx = click .get_current_context ()
710
+ ctx .fail ("Invalid ConfigDB. Error: {}" .format (e ))
707
711
else :
708
712
kbps_value = int (entry .get ('kbps' ,0 ))
709
713
if kbps_value != kbps :
710
- config_db .mod_entry ('PORT_STORM_CONTROL' , key , {'kbps' :kbps })
714
+ try :
715
+ config_db .mod_entry ('PORT_STORM_CONTROL' , key , {'kbps' :kbps })
716
+ except ValueError as e :
717
+ ctx = click .get_current_context ()
718
+ ctx .fail ("Invalid ConfigDB. Error: {}" .format (e ))
711
719
712
720
return True
713
721
@@ -717,7 +725,7 @@ def storm_control_delete_entry(port_name, storm_type):
717
725
if storm_control_interface_validate (port_name ) is False :
718
726
return False
719
727
720
- config_db = ConfigDBConnector ()
728
+ config_db = ValidatedConfigDBConnector ( ConfigDBConnector () )
721
729
config_db .connect ()
722
730
key = port_name + '|' + storm_type
723
731
entry = config_db .get_entry ('PORT_STORM_CONTROL' , key )
@@ -726,7 +734,11 @@ def storm_control_delete_entry(port_name, storm_type):
726
734
click .echo ("%s storm-control not enabled on interface %s" % (storm_type , port_name ))
727
735
return False
728
736
else :
729
- config_db .set_entry ('PORT_STORM_CONTROL' , key , None )
737
+ try :
738
+ config_db .set_entry ('PORT_STORM_CONTROL' , key , None )
739
+ except JsonPatchConflict as e :
740
+ ctx = click .get_current_context ()
741
+ ctx .fail ("Invalid ConfigDB. Error: {}" .format (e ))
730
742
731
743
return True
732
744
@@ -4470,7 +4482,7 @@ def _parse_object_id(idsmap):
4470
4482
4471
4483
4472
4484
def update_buffer_object (db , interface_name , object_map , override_profile , is_pg , add = True ):
4473
- config_db = db .cfgdb
4485
+ config_db = ValidatedConfigDBConnector ( db .cfgdb )
4474
4486
ctx = click .get_current_context ()
4475
4487
4476
4488
# Check whether port is legal
@@ -4500,16 +4512,22 @@ def update_buffer_object(db, interface_name, object_map, override_profile, is_pg
4500
4512
if is_pg :
4501
4513
if not 'xoff' in profile_dict .keys () and 'size' in profile_dict .keys ():
4502
4514
ctx .fail ("Profile {} doesn't exist or isn't a lossless profile" .format (override_profile ))
4503
- config_db .set_entry (buffer_table , (interface_name , object_map ), {"profile" : override_profile })
4515
+ try :
4516
+ config_db .set_entry (buffer_table , (interface_name , object_map ), {"profile" : override_profile })
4517
+ except ValueError as e :
4518
+ ctx .fail ("Invalid ConfigDB. Error: {}" .format (e ))
4504
4519
else :
4505
- config_db .set_entry (buffer_table , (interface_name , object_map ), {"profile" : "NULL" })
4520
+ try :
4521
+ config_db .set_entry (buffer_table , (interface_name , object_map ), {"profile" : "NULL" })
4522
+ except ValueError as e :
4523
+ ctx .fail ("Invalid ConfigDB. Error: {}" .format (e ))
4506
4524
4507
4525
if is_pg :
4508
4526
adjust_pfc_enable (ctx , db , interface_name , object_map , True )
4509
4527
4510
4528
4511
4529
def remove_buffer_object_on_port (db , interface_name , buffer_object_map , is_pg = True ):
4512
- config_db = db .cfgdb
4530
+ config_db = ValidatedConfigDBConnector ( db .cfgdb )
4513
4531
ctx = click .get_current_context ()
4514
4532
4515
4533
# Check whether port is legal
@@ -4530,7 +4548,10 @@ def remove_buffer_object_on_port(db, interface_name, buffer_object_map, is_pg=Tr
4530
4548
ctx .fail ("Lossy PG {} can't be removed" .format (buffer_object_map ))
4531
4549
else :
4532
4550
continue
4533
- config_db .set_entry (buffer_table , (interface_name , existing_buffer_object ), None )
4551
+ try :
4552
+ config_db .set_entry (buffer_table , (interface_name , existing_buffer_object ), None )
4553
+ except JsonPatchConflict as e :
4554
+ ctx .fail ("Invalid ConfigDB. Error: {}" .format (e ))
4534
4555
if is_pg :
4535
4556
adjust_pfc_enable (ctx , db , interface_name , buffer_object_map , False )
4536
4557
removed = True
@@ -4543,7 +4564,7 @@ def remove_buffer_object_on_port(db, interface_name, buffer_object_map, is_pg=Tr
4543
4564
4544
4565
4545
4566
def adjust_pfc_enable (ctx , db , interface_name , pg_map , add ):
4546
- config_db = db .cfgdb
4567
+ config_db = ValidatedConfigDBConnector ( db .cfgdb )
4547
4568
4548
4569
# Fetch the original pfc_enable
4549
4570
qosmap = config_db .get_entry ("PORT_QOS_MAP" , interface_name )
@@ -4576,7 +4597,10 @@ def adjust_pfc_enable(ctx, db, interface_name, pg_map, add):
4576
4597
ctx .fail ("Try to add empty priorities" )
4577
4598
4578
4599
qosmap ["pfc_enable" ] = pfc_enable [:- 1 ]
4579
- config_db .set_entry ("PORT_QOS_MAP" , interface_name , qosmap )
4600
+ try :
4601
+ config_db .set_entry ("PORT_QOS_MAP" , interface_name , qosmap )
4602
+ except ValueError as e :
4603
+ ctx .fail ("Invalid ConfigDB. Error: {}" .format (e ))
4580
4604
4581
4605
4582
4606
#
@@ -5811,6 +5835,7 @@ def _is_shared_headroom_pool_enabled(ctx, config_db):
5811
5835
5812
5836
5813
5837
def update_profile (ctx , config_db , profile_name , xon , xoff , size , dynamic_th , pool , profile_entry = None ):
5838
+ config_db = ValidatedConfigDBConnector (config_db )
5814
5839
params = {}
5815
5840
if profile_entry :
5816
5841
params = profile_entry
@@ -5882,14 +5907,17 @@ def update_profile(ctx, config_db, profile_name, xon, xoff, size, dynamic_th, po
5882
5907
else :
5883
5908
ctx .fail ("No dynamic_th defined in DEFAULT_LOSSLESS_BUFFER_PARAMETER" )
5884
5909
5885
- config_db .set_entry ("BUFFER_PROFILE" , (profile_name ), params )
5910
+ try :
5911
+ config_db .set_entry ("BUFFER_PROFILE" , (profile_name ), params )
5912
+ except ValueError as e :
5913
+ ctx .fail ("Invalid ConfigDB. Error: {}" .format (e ))
5886
5914
5887
5915
@profile .command ('remove' )
5888
5916
@click .argument ('profile' , metavar = '<profile>' , required = True )
5889
5917
@clicommon .pass_db
5890
5918
def remove_profile (db , profile ):
5891
5919
"""Delete a buffer profile"""
5892
- config_db = db .cfgdb
5920
+ config_db = ValidatedConfigDBConnector ( db .cfgdb )
5893
5921
ctx = click .get_current_context ()
5894
5922
5895
5923
existing_pgs = config_db .get_table ("BUFFER_PG" )
@@ -5901,7 +5929,10 @@ def remove_profile(db, profile):
5901
5929
5902
5930
entry = config_db .get_entry ("BUFFER_PROFILE" , profile )
5903
5931
if entry :
5904
- config_db .set_entry ("BUFFER_PROFILE" , profile , None )
5932
+ try :
5933
+ config_db .set_entry ("BUFFER_PROFILE" , profile , None )
5934
+ except JsonPatchConflict as e :
5935
+ ctx .fail ("Invalid ConfigDB. Error: {}" .format (e ))
5905
5936
else :
5906
5937
ctx .fail ("Profile {} doesn't exist" .format (profile ))
5907
5938
@@ -5917,7 +5948,7 @@ def shared_headroom_pool(ctx):
5917
5948
@clicommon .pass_db
5918
5949
def over_subscribe_ratio (db , ratio ):
5919
5950
"""Configure over subscribe ratio"""
5920
- config_db = db .cfgdb
5951
+ config_db = ValidatedConfigDBConnector ( db .cfgdb )
5921
5952
ctx = click .get_current_context ()
5922
5953
5923
5954
port_number = len (config_db .get_table ('PORT' ))
@@ -5937,15 +5968,18 @@ def over_subscribe_ratio(db, ratio):
5937
5968
else :
5938
5969
v ["over_subscribe_ratio" ] = ratio
5939
5970
5940
- config_db .set_entry ("DEFAULT_LOSSLESS_BUFFER_PARAMETER" , k , v )
5971
+ try :
5972
+ config_db .set_entry ("DEFAULT_LOSSLESS_BUFFER_PARAMETER" , k , v )
5973
+ except ValueError as e :
5974
+ ctx .fail ("Invalid ConfigDB. Error: {}" .format (e ))
5941
5975
5942
5976
5943
5977
@shared_headroom_pool .command ()
5944
5978
@click .argument ('size' , metavar = '<size>' , type = int , required = True )
5945
5979
@clicommon .pass_db
5946
5980
def size (db , size ):
5947
5981
"""Configure shared headroom pool size"""
5948
- config_db = db .cfgdb
5982
+ config_db = ValidatedConfigDBConnector ( db .cfgdb )
5949
5983
state_db = db .db
5950
5984
ctx = click .get_current_context ()
5951
5985
@@ -5964,7 +5998,10 @@ def size(db, size):
5964
5998
else :
5965
5999
ingress_lossless_pool ["xoff" ] = size
5966
6000
5967
- config_db .set_entry ("BUFFER_POOL" , "ingress_lossless_pool" , ingress_lossless_pool )
6001
+ try :
6002
+ config_db .set_entry ("BUFFER_POOL" , "ingress_lossless_pool" , ingress_lossless_pool )
6003
+ except ValueError as e :
6004
+ ctx .fail ("Invalid ConfigDB. Error: {}" .format (e ))
5968
6005
5969
6006
5970
6007
#
0 commit comments