Adds MonitorMetricTypeField enum field
Preparation for cleanup of the nova.compute.monitors modules to use a versioned object interface. Here we add a new enum derivative field that contains the current string keys used for metric "names" that the compute monitors return in the get_metrics() calls. This allows us to standardize these metric key names. Change-Id: I47d3ed2d3c0f6a3c33eaa9539d38aaff2f4df573 Partial-bug: 1466929
This commit is contained in:
parent
fe0d7e8e3a
commit
fe0332580e
|
@ -287,6 +287,37 @@ class WatchdogAction(Enum):
|
|||
valid_values=WatchdogAction.ALL)
|
||||
|
||||
|
||||
class MonitorMetricType(Enum):
|
||||
|
||||
CPU_FREQUENCY = "cpu.frequency"
|
||||
CPU_USER_TIME = "cpu.user.time"
|
||||
CPU_KERNEL_TIME = "cpu.kernel.time"
|
||||
CPU_IDLE_TIME = "cpu.idle.time"
|
||||
CPU_IOWAIT_TIME = "cpu.iowait.time"
|
||||
CPU_USER_PERCENT = "cpu.user.percent"
|
||||
CPU_KERNEL_PERCENT = "cpu.kernel.percent"
|
||||
CPU_IDLE_PERCENT = "cpu.idle.percent"
|
||||
CPU_IOWAIT_PERCENT = "cpu.iowait.percent"
|
||||
CPU_PERCENT = "cpu.percent"
|
||||
|
||||
ALL = (
|
||||
CPU_FREQUENCY,
|
||||
CPU_USER_TIME,
|
||||
CPU_KERNEL_TIME,
|
||||
CPU_IDLE_TIME,
|
||||
CPU_IOWAIT_TIME,
|
||||
CPU_USER_PERCENT,
|
||||
CPU_KERNEL_PERCENT,
|
||||
CPU_IDLE_PERCENT,
|
||||
CPU_IOWAIT_PERCENT,
|
||||
CPU_PERCENT,
|
||||
)
|
||||
|
||||
def __init__(self):
|
||||
super(MonitorMetricType, self).__init__(
|
||||
valid_values=MonitorMetricType.ALL)
|
||||
|
||||
|
||||
# NOTE(danms): Remove this on next release of oslo.versionedobjects
|
||||
class FlexibleBoolean(fields.Boolean):
|
||||
@staticmethod
|
||||
|
@ -538,6 +569,10 @@ class WatchdogActionField(BaseEnumField):
|
|||
AUTO_TYPE = WatchdogAction()
|
||||
|
||||
|
||||
class MonitorMetricTypeField(BaseEnumField):
|
||||
AUTO_TYPE = MonitorMetricType()
|
||||
|
||||
|
||||
# FIXME(danms): Remove this after oslo.versionedobjects gets it
|
||||
# This is a flexible interpretation of boolean
|
||||
# values using common user friendly semantics for
|
||||
|
|
|
@ -445,6 +445,34 @@ class TestWatchdogAction(TestField):
|
|||
self.assertRaises(ValueError, self.field.stringify, 'acme')
|
||||
|
||||
|
||||
class TestMonitorMetricType(TestField):
|
||||
def setUp(self):
|
||||
super(TestMonitorMetricType, self).setUp()
|
||||
self.field = fields.MonitorMetricTypeField()
|
||||
self.coerce_good_values = [('cpu.frequency', 'cpu.frequency'),
|
||||
('cpu.user.time', 'cpu.user.time'),
|
||||
('cpu.kernel.time', 'cpu.kernel.time'),
|
||||
('cpu.idle.time', 'cpu.idle.time'),
|
||||
('cpu.iowait.time', 'cpu.iowait.time'),
|
||||
('cpu.user.percent', 'cpu.user.percent'),
|
||||
('cpu.kernel.percent',
|
||||
'cpu.kernel.percent'),
|
||||
('cpu.idle.percent', 'cpu.idle.percent'),
|
||||
('cpu.iowait.percent',
|
||||
'cpu.iowait.percent'),
|
||||
('cpu.percent', 'cpu.percent')]
|
||||
self.coerce_bad_values = ['cpu.typo']
|
||||
self.to_primitive_values = self.coerce_good_values[0:1]
|
||||
self.from_primitive_values = self.coerce_good_values[0:1]
|
||||
|
||||
def test_stringify(self):
|
||||
self.assertEqual("'cpu.frequency'",
|
||||
self.field.stringify('cpu.frequency'))
|
||||
|
||||
def test_stringify_invalid(self):
|
||||
self.assertRaises(ValueError, self.field.stringify, 'cpufrequency')
|
||||
|
||||
|
||||
class TestInteger(TestField):
|
||||
def setUp(self):
|
||||
super(TestInteger, self).setUp()
|
||||
|
|
Loading…
Reference in New Issue