Added performance management config frequency override handling in the CLI.
Addressed a TODO for performance management configuration in the global
handler.
Fixed missing imports for PmConfigs in device_pb2 protobuf definitions
in the global handler.
Change-Id: Ie99e49ee443be352ffa12e8663733b0f9c6a9b69
diff --git a/cli/device.py b/cli/device.py
index 05f97c9..d503c48 100644
--- a/cli/device.py
+++ b/cli/device.py
@@ -112,7 +112,7 @@
immediately. The reset command will undo any changes sinc the start of the
device session.
-If grouped is tre then the -d, -e and -o commands refer to groups and not
+If grouped is true then the -d, -e and -o commands refer to groups and not
individual metrics.
'''
)
@@ -124,11 +124,11 @@
default=None),
make_option('-d', '--disable', action='append', dest='disable',
default=None),
- make_option('-o', '--overried', action='store', dest='override',
+ make_option('-o', '--overried', action='append', dest='override',
nargs=2, default=None, type='string'),
])
def do_perf_config(self, line, opts):
- print(line)
+ #print(line)
"""Show and set the performance monitoring configuration of the device"""
device = self.get_device(depth=-1)
@@ -157,6 +157,7 @@
self.pm_config_last.default_freq = opts.default_freq
self.pm_config_dirty = True
+ # Field or group visibility
if self.pm_config_last.grouped:
for g in self.pm_config_last.groups:
if opts.enable:
@@ -179,9 +180,63 @@
if m.name in opts.disable:
m.enabled = False
self.pm_config_dirty = True
- #TODO: Add frequency overrides.
- if opts.override:
- pass
+
+ #Frequency overrides.
+ if opts.override:
+ if self.pm_config_last.freq_override:
+ oo = dict()
+ for o in opts.override:
+ oo[o[0]] = o[1]
+ if self.pm_config_last.grouped:
+ for g in self.pm_config_last.groups:
+ if g.group_name in oo:
+ try:
+ g.group_freq = int(oo[g.group_name])
+ except ValueError:
+ self.poutput(self.colorize('Warning: ',
+ 'yellow') + \
+ self.colorize(oo[m.name],
+ 'blue') +\
+ " is not an integer... ignored")
+ del oo[g.group_name]
+ self.pm_config_dirty = True
+ else:
+ for m in self.pm_config_last.metrics:
+ if m.name in oo:
+ try:
+ m.sample_freq = int(oo[m.name])
+ except ValueError:
+ self.poutput(self.colorize('Warning: ',
+ 'yellow') + \
+ self.colorize(oo[m.name],
+ 'blue') +\
+ " is not an integer... ignored")
+ del oo[m.name]
+ self.pm_config_dirty = True
+
+ # If there's anything left the input was typoed
+ if self.pm_config_last.grouped:
+ field = 'group'
+ else:
+ field = 'metric'
+ for o in oo:
+ self.poutput(self.colorize('Warning: ', 'yellow') + \
+ 'the parameter' + ' ' + \
+ self.colorize(o, 'blue') + ' is not ' + \
+ 'a ' + field + ' name... ignored')
+ if oo:
+ return
+
+ else: # Frequency overrides not enabled
+ self.poutput(self.colorize('Error: ', 'red') + \
+ 'Individual overrides are only ' + \
+ 'supported if ' + \
+ self.colorize('freq_override', 'blue') + \
+ ' is set to ' + self.colorize('True', 'blue'))
+ return
+ self.poutput("Success")
+ return
+
elif line.strip() == "commit" and self.pm_config_dirty:
stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
stub.UpdateDevicePmConfigs(self.pm_config_last)
@@ -191,6 +246,7 @@
self.pm_config_last = self.get_device(depth=-1).pm_configs
self.pm_config_dirty = False
+
omit_fields = {'groups', 'metrics', 'id'}
print_pb_as_table('PM Config:', self.pm_config_last, omit_fields,
self.poutput)
diff --git a/voltha/core/global_handler.py b/voltha/core/global_handler.py
index 88ac4bd..b42a554 100644
--- a/voltha/core/global_handler.py
+++ b/voltha/core/global_handler.py
@@ -19,6 +19,7 @@
from common.utils.grpc_utils import twisted_async
from voltha.core.config.config_root import ConfigRoot
+from voltha.protos.device_pb2 import PmConfigs
from voltha.protos.voltha_pb2 import \
add_VolthaGlobalServiceServicer_to_server, VolthaLocalServiceStub, \
VolthaGlobalServiceServicer, Voltha, VolthaInstances, VolthaInstance, \
@@ -390,10 +391,26 @@
request,
context)
- #TODO: create the global PM config update function.
@twisted_async
def UpdateDevicePmConfigs(self, request, context):
- raise NotImplementedError('Method not implemented!')
+ log.info('grpc-request', request=request)
+
+ try:
+ instance_id = self.dispatcher.instance_id_by_device_id(
+ request.id
+ )
+ except KeyError:
+ context.set_details(
+ 'Device \'{}\' not found'.format(request.id))
+ context.set_code(StatusCode.NOT_FOUND)
+ return Empty()
+
+ return self.dispatcher.dispatch(
+ instance_id,
+ VolthaLocalServiceStub,
+ 'UpdateDevicePmConfigs',
+ request,
+ context)
@twisted_async
def ListDeviceFlows(self, request, context):