Commit dda8b3fa authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[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.
parent 35bdd068
......@@ -165,7 +165,7 @@ class BaseComponent:
"""
if self.__state == STATE_DEAD:
raise ValueError("Can't resurrect already dead component")
if self.running():
if self.is_running():
raise ValueError("Can't start already running component")
logger.info(BIND10_COMPONENT_START, self.name())
self.__state = STATE_RUNNING
......@@ -190,7 +190,7 @@ class BaseComponent:
"""
# This is not tested. It talks with the outher world, which is out
# of scope of unittests.
if not self.running():
if not self.is_running():
raise ValueError("Can't stop a component which is not running")
logger.info(BIND10_COMPONENT_STOP, self.name())
self.__state = STATE_STOPPED
......@@ -236,7 +236,7 @@ class BaseComponent:
logger.error(BIND10_COMPONENT_FAILED, self.name(), self.pid(),
exit_str)
if not self.running():
if not self.is_running():
raise ValueError("Can't fail component that isn't running")
self.__state = STATE_FAILED
self._failed_internal()
......@@ -286,7 +286,7 @@ class BaseComponent:
else:
return False
def running(self):
def is_running(self):
"""
Informs if the component is currently running. It assumes the failed
is called whenever the component really fails and there might be some
......@@ -301,7 +301,7 @@ class BaseComponent:
def is_failed(self):
"""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.
"""
......@@ -609,7 +609,7 @@ class Configurator:
for cname in old.keys():
if cname not in new:
component = self._components[cname][1]
if component.running() or component.is_failed():
if component.is_running() or component.is_failed():
plan.append({
'command': STOP_CMD,
'component': component,
......@@ -692,7 +692,7 @@ class Configurator:
self._components[task['name']] = (task['config'],
component)
elif command == STOP_CMD:
if component.running():
if component.is_running():
component.stop()
del self._components[task['name']]
else:
......
......@@ -191,7 +191,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
self.assertFalse(self.__start_called)
self.assertFalse(self.__stop_called)
self.assertFalse(self.__failed_called)
self.assertFalse(component.running())
self.assertFalse(component.is_running())
self.assertFalse(component.is_failed())
# We can't stop or fail the component yet
self.assertRaises(ValueError, component.stop)
......@@ -205,7 +205,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
self.assertTrue(self.__start_called)
self.assertFalse(self.__stop_called)
self.assertFalse(self.__failed_called)
self.assertTrue(component.running())
self.assertTrue(component.is_running())
self.assertFalse(component.is_failed())
def __check_dead(self, component):
......@@ -217,7 +217,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
self.assertFalse(self.__stop_called)
self.assertTrue(self.__failed_called)
self.assertEqual(1, self._exitcode)
self.assertFalse(component.running())
self.assertFalse(component.is_running())
self.assertFalse(component.is_failed())
# Surely it can't be stopped when already dead
self.assertRaises(ValueError, component.stop)
......@@ -237,7 +237,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
self.assertTrue(self.__start_called)
self.assertFalse(self.__stop_called)
self.assertTrue(self.__failed_called)
self.assertTrue(component.running())
self.assertTrue(component.is_running())
self.assertFalse(component.is_failed())
# Check it can't be started again
self.assertRaises(ValueError, component.start)
......@@ -250,7 +250,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
self.assertTrue(self.__start_called)
self.assertFalse(self.__stop_called)
self.assertTrue(self.__failed_called)
self.assertFalse(component.running())
self.assertFalse(component.is_running())
self.assertTrue(component.is_failed())
def __do_start_stop(self, kind):
......@@ -275,7 +275,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
self.assertTrue(self.__start_called)
self.assertTrue(self.__stop_called)
self.assertFalse(self.__failed_called)
self.assertFalse(component.running())
self.assertFalse(component.is_running())
self.assertFalse(component.is_failed())
# Check it can't be stopped twice
self.assertRaises(ValueError, component.stop)
......@@ -559,10 +559,10 @@ class ComponentTests(BossUtils, unittest.TestCase):
self.assertIsNone(component.pid())
self.assertEqual(['hello'], component._params)
self.assertEqual('Address', component._address)
self.assertFalse(component.running())
self.assertFalse(component.is_running())
self.assertEqual({}, self.__registered_processes)
component.start()
self.assertTrue(component.running())
self.assertTrue(component.is_running())
# Some versions of unittest miss assertIsInstance
self.assertTrue(isinstance(component._procinfo, TestProcInfo))
self.assertEqual(42, component.pid())
......@@ -586,11 +586,11 @@ class ComponentTests(BossUtils, unittest.TestCase):
"""
component = Component('component', self, 'needed', 'Address')
component.start()
self.assertTrue(component.running())
self.assertTrue(component.is_running())
self.assertEqual('component', self.__start_simple_params)
component.pid = lambda: 42
component.stop()
self.assertFalse(component.running())
self.assertFalse(component.is_running())
self.assertEqual(('component', 'Address', 42),
self.__stop_process_params)
......@@ -615,7 +615,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
component = Component('component', self, 'needed', 'Address',
[], ProcInfo)
component.start()
self.assertTrue(component.running())
self.assertTrue(component.is_running())
component.kill()
self.assertTrue(process.terminated)
self.assertFalse(process.killed)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment