Merge "Adds MonitorMetricTypeField enum field"

This commit is contained in:
Jenkins 2015-06-30 22:35:47 +00:00 committed by Gerrit Code Review
commit af84e3dea3
2 changed files with 63 additions and 0 deletions

View File

@ -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

View File

@ -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()