-
Notifications
You must be signed in to change notification settings - Fork 664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[crm]: Fix failures in CLI show commands #221
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,8 @@ def show_summary(self): | |
|
||
crm_info = configdb.get_entry('CRM', 'Config') | ||
|
||
print '\nPolling Interval: ' + crm_info['polling_interval'] + ' second(s)\n' | ||
if crm_info: | ||
print '\nPolling Interval: ' + crm_info['polling_interval'] + ' second(s)\n' | ||
|
||
def show_thresholds(self, resource): | ||
""" | ||
|
@@ -44,13 +45,14 @@ def show_thresholds(self, resource): | |
header = ("Resource Name", "Threshold Type", "Low Threshold", "High Threshold") | ||
data = [] | ||
|
||
if resource == 'all': | ||
for res in ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", "ipv6_neighbor", | ||
"nexthop_group_member", "nexthop_group", "acl_table", "acl_group", "acl_entry", | ||
"acl_counter", "fdb_entry"]: | ||
data.append([res, crm_info[res + "_threshold_type"], crm_info[res + "_low_threshold"], crm_info[res + "_high_threshold"]]) | ||
else: | ||
data.append([resource, crm_info[resource + "_threshold_type"], crm_info[resource + "_low_threshold"], crm_info[resource + "_high_threshold"]]) | ||
if crm_info: | ||
if resource == 'all': | ||
for res in ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", "ipv6_neighbor", | ||
"nexthop_group_member", "nexthop_group", "acl_table", "acl_group", "acl_entry", | ||
"acl_counter", "fdb_entry"]: | ||
data.append([res, crm_info[res + "_threshold_type"], crm_info[res + "_low_threshold"], crm_info[res + "_high_threshold"]]) | ||
else: | ||
data.append([resource, crm_info[resource + "_threshold_type"], crm_info[resource + "_low_threshold"], crm_info[resource + "_high_threshold"]]) | ||
|
||
print '\n' | ||
print tabulate(data, headers=header, tablefmt="simple", missingval="") | ||
|
@@ -68,12 +70,13 @@ def show_resources(self, resource): | |
header = ("Resource Name", "Used Count", "Available Count") | ||
data = [] | ||
|
||
if resource == 'all': | ||
for res in ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", "ipv6_neighbor", | ||
"nexthop_group_member", "nexthop_group", "fdb_entry"]: | ||
data.append([res, crm_stats['crm_stats_' + res + "_used"], crm_stats['crm_stats_' + res + "_available"]]) | ||
else: | ||
data.append([resource, crm_stats['crm_stats_' + resource + "_used"], crm_stats['crm_stats_' + resource + "_available"]]) | ||
if crm_stats: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The else part has to display some message stating crm_stats is not_ready since it would be populated only after the polling interval |
||
if resource == 'all': | ||
for res in ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", "ipv6_neighbor", | ||
"nexthop_group_member", "nexthop_group", "fdb_entry"]: | ||
data.append([res, crm_stats['crm_stats_' + res + "_used"], crm_stats['crm_stats_' + res + "_available"]]) | ||
else: | ||
data.append([resource, crm_stats['crm_stats_' + resource + "_used"], crm_stats['crm_stats_' + resource + "_available"]]) | ||
|
||
print '\n' | ||
print tabulate(data, headers=header, tablefmt="simple", missingval="") | ||
|
@@ -118,15 +121,17 @@ def show_acl_table_resources(self): | |
proc = Popen("docker exec -i database redis-cli --raw -n 2 KEYS *CRM:ACL_TABLE_STATS*", stdout=PIPE, stderr=PIPE, shell=True) | ||
out, err = proc.communicate() | ||
|
||
for key in out.splitlines(): | ||
for key in out.splitlines() or [None]: | ||
data = [] | ||
id = key.replace('CRM:ACL_TABLE_STATS:', '') | ||
|
||
crm_stats = countersdb.get_all(countersdb.COUNTERS_DB, key) | ||
if key: | ||
id = key.replace('CRM:ACL_TABLE_STATS:', '') | ||
|
||
for res in ['acl_entry', 'acl_counter']: | ||
if ('crm_stats_' + res + '_used' in crm_stats) and ('crm_stats_' + res + '_available' in crm_stats): | ||
data.append([id, res, crm_stats['crm_stats_' + res + '_used'], crm_stats['crm_stats_' + res + '_available']]) | ||
crm_stats = countersdb.get_all(countersdb.COUNTERS_DB, key) | ||
|
||
for res in ['acl_entry', 'acl_counter']: | ||
if ('crm_stats_' + res + '_used' in crm_stats) and ('crm_stats_' + res + '_available' in crm_stats): | ||
data.append([id, res, crm_stats['crm_stats_' + res + '_used'], crm_stats['crm_stats_' + res + '_available']]) | ||
|
||
print '\n' | ||
print tabulate(data, headers=header, tablefmt="simple", missingval="") | ||
|
@@ -459,14 +464,14 @@ def table(ctx): | |
elif ctx.obj["crm"].cli_mode == 'resources': | ||
ctx.obj["crm"].show_acl_table_resources() | ||
|
||
@acl.group() | ||
@acl.command() | ||
@click.pass_context | ||
def group(ctx): | ||
"""Show CRM information for acl group resource""" | ||
if ctx.obj["crm"].cli_mode == 'thresholds': | ||
ctx.obj["crm"].show_thresholds('acl_group') | ||
elif ctx.obj["crm"].cli_mode == 'resources': | ||
ctx.obj["crm"].show_resources('acl_group') | ||
ctx.obj["crm"].show_acl_resources() | ||
|
||
@resources.command() | ||
@click.pass_context | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would need to print some failure message if crm_info is null for some reason!