Revision 3ce9a5e7
b/lib/opcodes.py | ||
---|---|---|
129 | 129 |
_TestNicDef = ht.TDictOf(ht.TElemOf(constants.INIC_PARAMS), |
130 | 130 |
ht.TOr(ht.TNone, ht.TNonEmptyString)) |
131 | 131 |
|
132 |
_SUMMARY_PREFIX = { |
|
133 |
"CLUSTER_": "C_", |
|
134 |
"GROUP_": "G_", |
|
135 |
"NODE_": "N_", |
|
136 |
"INSTANCE_": "I_", |
|
137 |
} |
|
138 |
|
|
132 | 139 |
|
133 | 140 |
def _NameToId(name): |
134 | 141 |
"""Convert an opcode class name to an OP_ID. |
... | ... | |
463 | 470 |
txt = "%s(%s)" % (txt, field_value) |
464 | 471 |
return txt |
465 | 472 |
|
473 |
def TinySummary(self): |
|
474 |
"""Generates a compact summary description of the opcode. |
|
475 |
|
|
476 |
""" |
|
477 |
assert self.OP_ID.startswith("OP_") |
|
478 |
|
|
479 |
text = self.OP_ID[3:] |
|
480 |
|
|
481 |
for (prefix, supplement) in _SUMMARY_PREFIX.items(): |
|
482 |
if text.startswith(prefix): |
|
483 |
return supplement + text[len(prefix):] |
|
484 |
|
|
485 |
return text |
|
486 |
|
|
466 | 487 |
|
467 | 488 |
# cluster opcodes |
468 | 489 |
|
b/test/ganeti.opcodes_unittest.py | ||
---|---|---|
47 | 47 |
self.assert_(len(cls.OP_ID) > 3) |
48 | 48 |
self.assertEqual(cls.OP_ID, cls.OP_ID.upper()) |
49 | 49 |
self.assertEqual(cls.OP_ID, opcodes._NameToId(cls.__name__)) |
50 |
self.assertFalse(compat.any(cls.OP_ID.startswith(prefix) |
|
51 |
for prefix in opcodes._SUMMARY_PREFIX.keys())) |
|
50 | 52 |
|
51 | 53 |
self.assertRaises(TypeError, cls, unsupported_parameter="some value") |
52 | 54 |
|
... | ... | |
102 | 104 |
self.assertEqual(OpTest(data="node1.example.com").Summary(), |
103 | 105 |
"TEST(node1.example.com)") |
104 | 106 |
|
107 |
def testTinySummary(self): |
|
108 |
self.assertFalse(utils.FindDuplicates(opcodes._SUMMARY_PREFIX.values())) |
|
109 |
self.assertTrue(compat.all(prefix.endswith("_") and supplement.endswith("_") |
|
110 |
for (prefix, supplement) in |
|
111 |
opcodes._SUMMARY_PREFIX.items())) |
|
112 |
|
|
113 |
self.assertEqual(opcodes.OpClusterPostInit().TinySummary(), "C_POST_INIT") |
|
114 |
self.assertEqual(opcodes.OpNodeRemove().TinySummary(), "N_REMOVE") |
|
115 |
self.assertEqual(opcodes.OpInstanceMigrate().TinySummary(), "I_MIGRATE") |
|
116 |
self.assertEqual(opcodes.OpGroupQuery().TinySummary(), "G_QUERY") |
|
117 |
self.assertEqual(opcodes.OpTestJqueue().TinySummary(), "TEST_JQUEUE") |
|
118 |
|
|
105 | 119 |
def testListSummary(self): |
106 | 120 |
class OpTest(opcodes.OpCode): |
107 | 121 |
OP_DSC_FIELD = "data" |
Also available in: Unified diff