mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 11:21:25 -07:00
simplify status
This commit is contained in:
parent
c59fd9b796
commit
2faaa70d14
2 changed files with 12 additions and 13 deletions
|
@ -56,17 +56,16 @@ STATE_COMMAND_MAP = {
|
||||||
|
|
||||||
MIN_VERSION = (5, 21)
|
MIN_VERSION = (5, 21)
|
||||||
|
|
||||||
ALL_STATUS = [
|
|
||||||
'missing', 'ok', 'not_monitored', 'initializing', 'does_not_exist'
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class StatusValue(namedtuple("Status", "value, is_pending")):
|
class StatusValue(namedtuple("Status", "value, is_pending")):
|
||||||
MISSING = 0
|
MISSING = 'missing'
|
||||||
OK = 1
|
OK = 'ok'
|
||||||
NOT_MONITORED = 2
|
NOT_MONITORED = 'not_monitored'
|
||||||
INITIALIZING = 3
|
INITIALIZING = 'initializing'
|
||||||
DOES_NOT_EXIST = 4
|
DOES_NOT_EXIST = 'does_not_exist'
|
||||||
|
ALL_STATUS = [
|
||||||
|
MISSING, OK, NOT_MONITORED, INITIALIZING, DOES_NOT_EXIST
|
||||||
|
]
|
||||||
|
|
||||||
def __new__(cls, value, is_pending=False):
|
def __new__(cls, value, is_pending=False):
|
||||||
return super(StatusValue, cls).__new__(cls, value, is_pending)
|
return super(StatusValue, cls).__new__(cls, value, is_pending)
|
||||||
|
@ -75,7 +74,7 @@ class StatusValue(namedtuple("Status", "value, is_pending")):
|
||||||
return StatusValue(self.value, True)
|
return StatusValue(self.value, True)
|
||||||
|
|
||||||
def __getattr__(self, item):
|
def __getattr__(self, item):
|
||||||
if item in ('is_%s' % status for status in ALL_STATUS):
|
if item in ('is_%s' % status for status in self.ALL_STATUS):
|
||||||
return self.value == getattr(self, item[3:].upper())
|
return self.value == getattr(self, item[3:].upper())
|
||||||
raise AttributeError(item)
|
raise AttributeError(item)
|
||||||
|
|
||||||
|
|
|
@ -89,17 +89,17 @@ class MonitTest(unittest.TestCase):
|
||||||
self.monit.wait_for_monit_to_stop_pending('stopped')
|
self.monit.wait_for_monit_to_stop_pending('stopped')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('status_name', [name for name in monit.ALL_STATUS])
|
@pytest.mark.parametrize('status_name', [name for name in monit.StatusValue.ALL_STATUS])
|
||||||
def test_status_value(status_name):
|
def test_status_value(status_name):
|
||||||
value = getattr(monit.StatusValue, status_name.upper())
|
value = getattr(monit.StatusValue, status_name.upper())
|
||||||
status = monit.StatusValue(value)
|
status = monit.StatusValue(value)
|
||||||
assert getattr(status, 'is_%s' % status_name)
|
assert getattr(status, 'is_%s' % status_name)
|
||||||
assert not all(getattr(status, 'is_%s' % name) for name in monit.ALL_STATUS if name != status_name)
|
assert not all(getattr(status, 'is_%s' % name) for name in monit.StatusValue.ALL_STATUS if name != status_name)
|
||||||
|
|
||||||
|
|
||||||
BASIC_OUTPUT_CASES = [
|
BASIC_OUTPUT_CASES = [
|
||||||
(TEST_OUTPUT % ('processX', name), getattr(monit.Status, name.upper()))
|
(TEST_OUTPUT % ('processX', name), getattr(monit.Status, name.upper()))
|
||||||
for name in monit.ALL_STATUS
|
for name in monit.StatusValue.ALL_STATUS
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue