Skip to content

Commit

Permalink
handle review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Blyshchak <stepanb@nvidia.com>
  • Loading branch information
stepanblyschak committed Nov 17, 2021
1 parent eb57015 commit bf05d42
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions config/config_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import os
import re
import shutil
import syslog
import tempfile
import yang as ly
from json import load
from sys import flags
Expand Down Expand Up @@ -220,7 +222,7 @@ def writeConfigDB(self, jDiff):

return

def add_module(self, yang_module_str, replace_if_exists=False):
def add_module(self, yang_module_str):
"""
Validate and add new YANG module to the system.
Expand All @@ -233,7 +235,7 @@ def add_module(self, yang_module_str, replace_if_exists=False):

module_name = self.get_module_name(yang_module_str)
module_path = os.path.join(YANG_DIR, '{}.yang'.format(module_name))
if os.path.exists(module_path) and not replace_if_exists:
if os.path.exists(module_path):
raise Exception('{} already exists'.format(module_name))
with open(module_path, 'w') as module_file:
module_file.write(yang_module_str)
Expand All @@ -245,7 +247,7 @@ def add_module(self, yang_module_str, replace_if_exists=False):

def remove_module(self, module_name):
"""
Remove YANG module on the system and validate.
Remove YANG module from the system and validate.
Parameters:
module_name (str): YANG module name.
Expand All @@ -257,13 +259,12 @@ def remove_module(self, module_name):
module_path = os.path.join(YANG_DIR, '{}.yang'.format(module_name))
if not os.path.exists(module_path):
return
with open(module_path, 'r') as module_file:
yang_module_str = module_file.read()
temp_module_path = tempfile.mktemp()
try:
os.remove(module_path)
shutil.move(module_path, temp_module_path)
self.__init_sonic_yang()
except Exception:
self.add_module(yang_module_str)
shutil.move(temp_module_path, module_path)
raise

@staticmethod
Expand Down

0 comments on commit bf05d42

Please sign in to comment.