Skip to content

Commit

Permalink
add key error checking to set_tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
grybak-arista committed Nov 6, 2015
1 parent b80a4cc commit f2f2667
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pyeapi/api/vrrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,11 +987,27 @@ def set_tracks(self, name, vrid, tracks, run=True):
unset = '_none_'
tracks_set = []
for track in tracks:
keys = track.keys()

# Validate no extraneous keys in track definition
err_keys = set(keys).difference(('name', 'action', 'amount'))
if err_keys:
err_keys = ', '.join(err_keys)
raise ValueError("Error found in vrrp property 'track': "
"unknown key(s) '%s' found. Valid keys are "
"name, action, and amount" % err_keys)

# Validate required keys in track definition
if not set(keys).issuperset(('name', 'action')):
raise ValueError("Error found in vrrp property 'track': "
"track definition must contain 'name' and "
"'action' keys")

tr_obj = track['name']
action = track['action']
amount = track['amount'] if 'amount' in track else unset

# Validate track definition
# Validate values in track definition
error = False
if action not in ('shutdown', 'decrement'):
error = True
Expand Down

0 comments on commit f2f2667

Please sign in to comment.