Skip to content
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

[SAI-PTF] Enhance the function for getting counters in sai_adapter.py #1626

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 42 additions & 12 deletions meta/templates/sai_adapter.py.tt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ def [% function.thrift_name %](client
[%- FOREACH attr IN apis.$api.objects.${function.object}.attrs.${function.operation} -%]
,[% br %][% attr.simple_name %]=None
[%- END -%]
[%- IF function.operation == 'stats' OR function.operation == 'clear' -%]
[%- FOREACH arg IN function.adapter_preprocessed_args -%]
[%- IF arg.is_list and arg.name == 'counter_ids' -%]
,[% br %][% arg.name %]=[% function.name %]_[% arg.name %]
[%- ELSIF arg.is_attr %]
[% arg.name %] = None
[%- END -%]
[%- END -%]
[%- END -%]
):
[% END -%]

Expand All @@ -103,14 +112,33 @@ def [% function.thrift_name %](client
[%- # but are required by thritft functions -%]
[%- FOREACH arg IN function.adapter_preprocessed_args -%]

[%- IF arg.is_list %]
[%- IF arg.is_list AND arg.name!= 'counter_ids' %]
[% arg.name %] = []
[%- ELSIF arg.is_attr %]
[% arg.name %] = None
[%- END -%]
[%- END -%]
[%- END -%]

[%- BLOCK declare_stats_variables -%]
[%- IF function.operation == 'stats' OR function.operation == 'clear' %]
[%- FOREACH arg IN function.adapter_preprocessed_args -%]

[%- IF arg.is_list %]
[% function.name %]_[% arg.name %] = []
[% function.name %]_[% arg.name %]_dict = dict()
[%- ELSIF arg.is_attr %]
[% arg.name %] = None
[%- END -%]
[%- END -%]
[%- FOREACH stat IN apis.$api.objects.${function.object}.stats.all %]
[% function.name %]_[% arg.name %].append([% stat.name %])
[% function.name %]_[% arg.name %]_dict[[% stat.name %]] = "[% stat.name %]"
[%- END -%]

[%- END -%]
[%- END -%]

[%- ######################################################################## -%]

[%- ######################################################################## -%]
Expand Down Expand Up @@ -240,6 +268,7 @@ client.[% function.thrift_name %](
[%- BLOCK preprocess_attributes %]
[%- # For 'set attr' function we just do call the funtion for first argument -%]
[%- IF function.operation == 'set' -%]

global status
status = SAI_STATUS_SUCCESS

Expand Down Expand Up @@ -279,8 +308,10 @@ client.[% function.thrift_name %](

[%- BLOCK preprocess_stats -%]

[%- FOREACH stat IN apis.$api.objects.${function.object}.stats.all %]
[% arg.name %].append([% stat.name %])
[%- IF arg.name != "counter_ids" -%]
[%- FOREACH stat IN apis.$api.objects.${function.object}.stats.all %]
[% function.name %]_[% arg.name %].append([% stat.name %])
[%- END -%]
[%- END -%]

[%- END -%]
Expand All @@ -292,11 +323,9 @@ client.[% function.thrift_name %](
[%- BLOCK postprocess_stats %]
stats = dict()

[%- i = 0 %]
[%- FOREACH stat IN apis.$api.objects.${function.object}.stats.all %]
stats["[% stat.name %]"] = [% function.rpc_return.name %][[% i %]]
[%- i = i + 1 -%]
[%- END %]
for index, item in enumerate(counter_ids):
stats[[% function.name %]_[% arg.name %]_dict[item]] = counters[index]


[%- END -%]

Expand All @@ -308,13 +337,11 @@ client.[% function.thrift_name %](
[%- # Basically we do it for each list variable, we assume we have one -%]
[%- FOREACH arg IN function.adapter_preprocessed_args -%]
[%- IF function.operation == 'stats' OR function.operation == 'clear' %]
[%- # For 'get stats' function create stats list -%]
[%- # For 'get stats' function NOT create stats list in function body -%]
[%- PROCESS preprocess_stats %]

[%- ELSIF function.operation != 'remove' %]
[%- # For 'create' and 'get' functions create list of arguments -%]
[%- PROCESS preprocess_attributes %]

[%- END -%]
[%- END -%]

Expand Down Expand Up @@ -400,18 +427,21 @@ client.[% function.thrift_name %](
[%- ######################################################################## -%]

[%- BLOCK function_body -%]
[%- PROCESS declare_stats_variables -%]


[%- PROCESS decorate_method IF dev_utils -%]
[%- PROCESS decorate_skip_test_on_error IF skip_error -%]
[%- PROCESS function_header %]
[%- PROCESS function_docstring %]

[%- IF has_body -%]
[%- PROCESS declare_variables %]

[%- PROCESS preprocess_args -%]

[%- # Now, call the thrift function -%]
[%- IF function.operation != 'set' -%]

global status
status = SAI_STATUS_SUCCESS

Expand Down