Skip to content

Commit 98888f4

Browse files
author
Ubuntu
committed
keep one ConfigDBConnector instance
1 parent e9f0baf commit 98888f4

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

config/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ def portchannel(db, ctx, namespace):
18941894
def add_portchannel(ctx, portchannel_name, min_links, fallback):
18951895
"""Add port channel"""
18961896

1897-
db = ValidatedConfigDBConnector(ctx.obj['db'])
1897+
db = validate(ctx.obj['db'])
18981898

18991899
if is_portchannel_present_in_db(db, portchannel_name):
19001900
ctx.fail("{} already exists!".format(portchannel_name))
@@ -1914,7 +1914,7 @@ def add_portchannel(ctx, portchannel_name, min_links, fallback):
19141914
def remove_portchannel(ctx, portchannel_name):
19151915
"""Remove port channel"""
19161916

1917-
db = ValidatedConfigDBConnector(ctx.obj['db'])
1917+
db = validate(ctx.obj['db'])
19181918

19191919
if len([(k, v) for k, v in db.get_table('PORTCHANNEL_MEMBER') if k == portchannel_name]) != 0:
19201920
click.echo("Error: Portchannel {} contains members. Remove members before deleting Portchannel!".format(portchannel_name))

config/validated_config_db_connector.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
from swsscommon.swsscommon import ConfigDBConnector
44
from generic_config_updater.generic_updater import GenericUpdater, ConfigFormat
55

6-
class ValidatedConfigDBConnector(ConfigDBConnector):
6+
def validate(config_db_connector):
77

8-
def __init__(self, db):
9-
super().__init__()
10-
11-
def set_entry(self, table, key, value):
8+
def validated_set_entry(table, key, value):
129
if value:
1310
op = "add"
1411
else:
@@ -25,3 +22,6 @@ def set_entry(self, table, key, value):
2522
format = ConfigFormat.CONFIGDB.name
2623
config_format = ConfigFormat[format.upper()]
2724
GenericUpdater().apply_patch(patch=gcu_patch, config_format=config_format, verbose=False, dry_run=False, ignore_non_yang_tables=False, ignore_paths=None)
25+
26+
config_db_connector.set_entry = validated_set_entry
27+
return config_db_connector

0 commit comments

Comments
 (0)