Skip to content

Commit

Permalink
[config] Ensure idempotence of config load_mgmt_conf call (sonic-net#126
Browse files Browse the repository at this point in the history
)

Avoid error in config load_mgmt_conf when mgmt is already configured
  • Loading branch information
taoyl-ms authored Oct 6, 2017
1 parent abd5e8a commit aa3254b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Helper functions
#

def run_command(command, display_cmd=False):
def run_command(command, display_cmd=False, ignore_error=False):
"""Run bash command and print output to stdout
"""
if display_cmd == True:
Expand All @@ -29,7 +29,7 @@ def run_command(command, display_cmd=False):
if len(out) > 0:
click.echo(out)

if proc.returncode != 0:
if proc.returncode != 0 and not ignore_error:
sys.exit(proc.returncode)

def _is_neighbor_ipaddress(ipaddress):
Expand Down Expand Up @@ -149,11 +149,11 @@ def load_mgmt_config(filename):
command = "ifconfig eth0 {} netmask {}".format(str(mgmt_conf.ip), str(mgmt_conf.netmask))
run_command(command, display_cmd=True)
command = "ip route add default via {} dev eth0 table default".format(gw_addr)
run_command(command, display_cmd=True)
run_command(command, display_cmd=True, ignore_error=True)
command = "ip rule add from {} table default".format(str(mgmt_conf.ip))
run_command(command, display_cmd=True)
run_command(command, display_cmd=True, ignore_error=True)
command = "[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid"
run_command(command, display_cmd=True)
run_command(command, display_cmd=True, ignore_error=True)
print "Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`."

@cli.command()
Expand Down

0 comments on commit aa3254b

Please sign in to comment.