2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 05:55:28 +00:00

[2244] rename Componet.running() is_running() for consistency.

this branch introduced is_failed() (and failed() was already defined for
a different a purpose), so for consistency it would be better to name
the running version is_xxx too.
This commit is contained in:
JINMEI Tatuya
2012-10-04 22:19:27 -07:00
parent 35bdd068cf
commit dda8b3fa72
2 changed files with 18 additions and 18 deletions

View File

@@ -165,7 +165,7 @@ class BaseComponent:
""" """
if self.__state == STATE_DEAD: if self.__state == STATE_DEAD:
raise ValueError("Can't resurrect already dead component") raise ValueError("Can't resurrect already dead component")
if self.running(): if self.is_running():
raise ValueError("Can't start already running component") raise ValueError("Can't start already running component")
logger.info(BIND10_COMPONENT_START, self.name()) logger.info(BIND10_COMPONENT_START, self.name())
self.__state = STATE_RUNNING self.__state = STATE_RUNNING
@@ -190,7 +190,7 @@ class BaseComponent:
""" """
# This is not tested. It talks with the outher world, which is out # This is not tested. It talks with the outher world, which is out
# of scope of unittests. # of scope of unittests.
if not self.running(): if not self.is_running():
raise ValueError("Can't stop a component which is not running") raise ValueError("Can't stop a component which is not running")
logger.info(BIND10_COMPONENT_STOP, self.name()) logger.info(BIND10_COMPONENT_STOP, self.name())
self.__state = STATE_STOPPED self.__state = STATE_STOPPED
@@ -236,7 +236,7 @@ class BaseComponent:
logger.error(BIND10_COMPONENT_FAILED, self.name(), self.pid(), logger.error(BIND10_COMPONENT_FAILED, self.name(), self.pid(),
exit_str) exit_str)
if not self.running(): if not self.is_running():
raise ValueError("Can't fail component that isn't running") raise ValueError("Can't fail component that isn't running")
self.__state = STATE_FAILED self.__state = STATE_FAILED
self._failed_internal() self._failed_internal()
@@ -286,7 +286,7 @@ class BaseComponent:
else: else:
return False return False
def running(self): def is_running(self):
""" """
Informs if the component is currently running. It assumes the failed Informs if the component is currently running. It assumes the failed
is called whenever the component really fails and there might be some is called whenever the component really fails and there might be some
@@ -301,7 +301,7 @@ class BaseComponent:
def is_failed(self): def is_failed(self):
"""Informs if the component has failed and is waiting for a restart. """Informs if the component has failed and is waiting for a restart.
Unlike the case of running(), if this returns True it always means Unlike the case of is_running(), if this returns True it always means
the corresponding process has died and not yet restarted. the corresponding process has died and not yet restarted.
""" """
@@ -609,7 +609,7 @@ class Configurator:
for cname in old.keys(): for cname in old.keys():
if cname not in new: if cname not in new:
component = self._components[cname][1] component = self._components[cname][1]
if component.running() or component.is_failed(): if component.is_running() or component.is_failed():
plan.append({ plan.append({
'command': STOP_CMD, 'command': STOP_CMD,
'component': component, 'component': component,
@@ -692,7 +692,7 @@ class Configurator:
self._components[task['name']] = (task['config'], self._components[task['name']] = (task['config'],
component) component)
elif command == STOP_CMD: elif command == STOP_CMD:
if component.running(): if component.is_running():
component.stop() component.stop()
del self._components[task['name']] del self._components[task['name']]
else: else:

View File

@@ -191,7 +191,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
self.assertFalse(self.__start_called) self.assertFalse(self.__start_called)
self.assertFalse(self.__stop_called) self.assertFalse(self.__stop_called)
self.assertFalse(self.__failed_called) self.assertFalse(self.__failed_called)
self.assertFalse(component.running()) self.assertFalse(component.is_running())
self.assertFalse(component.is_failed()) self.assertFalse(component.is_failed())
# We can't stop or fail the component yet # We can't stop or fail the component yet
self.assertRaises(ValueError, component.stop) self.assertRaises(ValueError, component.stop)
@@ -205,7 +205,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
self.assertTrue(self.__start_called) self.assertTrue(self.__start_called)
self.assertFalse(self.__stop_called) self.assertFalse(self.__stop_called)
self.assertFalse(self.__failed_called) self.assertFalse(self.__failed_called)
self.assertTrue(component.running()) self.assertTrue(component.is_running())
self.assertFalse(component.is_failed()) self.assertFalse(component.is_failed())
def __check_dead(self, component): def __check_dead(self, component):
@@ -217,7 +217,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
self.assertFalse(self.__stop_called) self.assertFalse(self.__stop_called)
self.assertTrue(self.__failed_called) self.assertTrue(self.__failed_called)
self.assertEqual(1, self._exitcode) self.assertEqual(1, self._exitcode)
self.assertFalse(component.running()) self.assertFalse(component.is_running())
self.assertFalse(component.is_failed()) self.assertFalse(component.is_failed())
# Surely it can't be stopped when already dead # Surely it can't be stopped when already dead
self.assertRaises(ValueError, component.stop) self.assertRaises(ValueError, component.stop)
@@ -237,7 +237,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
self.assertTrue(self.__start_called) self.assertTrue(self.__start_called)
self.assertFalse(self.__stop_called) self.assertFalse(self.__stop_called)
self.assertTrue(self.__failed_called) self.assertTrue(self.__failed_called)
self.assertTrue(component.running()) self.assertTrue(component.is_running())
self.assertFalse(component.is_failed()) self.assertFalse(component.is_failed())
# Check it can't be started again # Check it can't be started again
self.assertRaises(ValueError, component.start) self.assertRaises(ValueError, component.start)
@@ -250,7 +250,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
self.assertTrue(self.__start_called) self.assertTrue(self.__start_called)
self.assertFalse(self.__stop_called) self.assertFalse(self.__stop_called)
self.assertTrue(self.__failed_called) self.assertTrue(self.__failed_called)
self.assertFalse(component.running()) self.assertFalse(component.is_running())
self.assertTrue(component.is_failed()) self.assertTrue(component.is_failed())
def __do_start_stop(self, kind): def __do_start_stop(self, kind):
@@ -275,7 +275,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
self.assertTrue(self.__start_called) self.assertTrue(self.__start_called)
self.assertTrue(self.__stop_called) self.assertTrue(self.__stop_called)
self.assertFalse(self.__failed_called) self.assertFalse(self.__failed_called)
self.assertFalse(component.running()) self.assertFalse(component.is_running())
self.assertFalse(component.is_failed()) self.assertFalse(component.is_failed())
# Check it can't be stopped twice # Check it can't be stopped twice
self.assertRaises(ValueError, component.stop) self.assertRaises(ValueError, component.stop)
@@ -559,10 +559,10 @@ class ComponentTests(BossUtils, unittest.TestCase):
self.assertIsNone(component.pid()) self.assertIsNone(component.pid())
self.assertEqual(['hello'], component._params) self.assertEqual(['hello'], component._params)
self.assertEqual('Address', component._address) self.assertEqual('Address', component._address)
self.assertFalse(component.running()) self.assertFalse(component.is_running())
self.assertEqual({}, self.__registered_processes) self.assertEqual({}, self.__registered_processes)
component.start() component.start()
self.assertTrue(component.running()) self.assertTrue(component.is_running())
# Some versions of unittest miss assertIsInstance # Some versions of unittest miss assertIsInstance
self.assertTrue(isinstance(component._procinfo, TestProcInfo)) self.assertTrue(isinstance(component._procinfo, TestProcInfo))
self.assertEqual(42, component.pid()) self.assertEqual(42, component.pid())
@@ -586,11 +586,11 @@ class ComponentTests(BossUtils, unittest.TestCase):
""" """
component = Component('component', self, 'needed', 'Address') component = Component('component', self, 'needed', 'Address')
component.start() component.start()
self.assertTrue(component.running()) self.assertTrue(component.is_running())
self.assertEqual('component', self.__start_simple_params) self.assertEqual('component', self.__start_simple_params)
component.pid = lambda: 42 component.pid = lambda: 42
component.stop() component.stop()
self.assertFalse(component.running()) self.assertFalse(component.is_running())
self.assertEqual(('component', 'Address', 42), self.assertEqual(('component', 'Address', 42),
self.__stop_process_params) self.__stop_process_params)
@@ -615,7 +615,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
component = Component('component', self, 'needed', 'Address', component = Component('component', self, 'needed', 'Address',
[], ProcInfo) [], ProcInfo)
component.start() component.start()
self.assertTrue(component.running()) self.assertTrue(component.is_running())
component.kill() component.kill()
self.assertTrue(process.terminated) self.assertTrue(process.terminated)
self.assertFalse(process.killed) self.assertFalse(process.killed)