component_test.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. # Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. #
  3. # Permission to use, copy, modify, and distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  8. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  9. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  10. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  12. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  14. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. """
  16. Tests for the bind10.component module
  17. """
  18. import unittest
  19. import isc.log
  20. import time
  21. import copy
  22. from isc.bind10.component import Component, Configurator, specials
  23. class TestError(Exception):
  24. """
  25. Just a private exception not known to anybody we use for our tests.
  26. """
  27. pass
  28. class BossUtils:
  29. """
  30. A class that brings some utilities for pretending we're Boss.
  31. This is expected to be inherited by the testcases themself.
  32. """
  33. def setUp(self):
  34. """
  35. Part of setup. Should be called by descendand's setUp.
  36. """
  37. self._shutdown = False
  38. self._exitcode = None
  39. # Back up the time function, we may want to replace it with something
  40. self.__orig_time = isc.bind10.component.time.time
  41. def tearDown(self):
  42. """
  43. Clean up after tests. If the descendand implements a tearDown, it
  44. should call this method internally.
  45. """
  46. # Return the original time function
  47. isc.bind10.component.time.time = self.__orig_time
  48. def component_shutdown(self, exitcode=0):
  49. """
  50. Mock function to shut down. We just note we were asked to do so.
  51. """
  52. self._shutdown = True
  53. self._exitcode = None
  54. def _timeskip(self):
  55. """
  56. Skip in time to future some 30s. Implemented by replacing the
  57. time.time function in the tested module with function that returns
  58. current time increased by 30.
  59. """
  60. tm = time.time()
  61. isc.bind10.component.time.time = lambda: tm + 30
  62. class ComponentTests(BossUtils, unittest.TestCase):
  63. """
  64. Tests for the bind10.component.Component class
  65. """
  66. def setUp(self):
  67. """
  68. Pretend a newly started system.
  69. """
  70. BossUtils.setUp(self)
  71. self._shutdown = False
  72. self._exitcode = None
  73. self.__start_called = False
  74. self.__stop_called = False
  75. self.__failed_called = False
  76. def __start(self):
  77. """
  78. Mock function, installed into the component into start_internal.
  79. This only notes the component was "started".
  80. """
  81. self.__start_called = True
  82. def __stop(self):
  83. """
  84. Mock function, installed into the component into stop_internal.
  85. This only notes the component was "stopped".
  86. """
  87. self.__stop_called = True
  88. def __fail(self):
  89. """
  90. Mock function, installed into the component into failed_internal.
  91. This only notes the component called the method.
  92. """
  93. self.__failed_called = True
  94. def __fail_to_start(self):
  95. """
  96. Mock function. It can be installed into the component's start_internal
  97. to simulate a component that fails to start by raising an exception.
  98. """
  99. orig_started = self.__start_called
  100. self.__start_called = True
  101. if not orig_started:
  102. # This one is from restart. Avoid infinite recursion for now.
  103. # FIXME: We should use the restart scheduler to avoid it, not this.
  104. raise TestError("Test error")
  105. def __create_component(self, kind):
  106. """
  107. Convenience function that creates a component of given kind
  108. and installs the mock functions into it so we can hook up into
  109. its behaviour.
  110. The process used is some nonsense, as this isn't used in this
  111. kind of tests and we pretend to be the boss.
  112. """
  113. component = Component('No process', self, kind, 'homeless', [])
  114. component.start_internal = self.__start
  115. component.stop_internal = self.__stop
  116. component.failed_internal = self.__fail
  117. return component
  118. def test_name(self):
  119. """
  120. Test the name provides whatever we passed to the constructor as process.
  121. """
  122. component = self.__create_component('core')
  123. self.assertEqual('No process', component.name())
  124. def test_guts(self):
  125. """
  126. Test the correct data are stored inside the component.
  127. """
  128. component = self.__create_component('core')
  129. self.assertEqual(self, component._boss)
  130. self.assertEqual("No process", component._process)
  131. self.assertEqual(None, component._start_func)
  132. self.assertEqual("homeless", component._address)
  133. self.assertEqual([], component._params)
  134. def __check_startup(self, component):
  135. """
  136. Check that nothing was called yet. A newly created component should
  137. not get started right away, so this should pass after the creation.
  138. """
  139. self.assertFalse(self._shutdown)
  140. self.assertFalse(self.__start_called)
  141. self.assertFalse(self.__stop_called)
  142. self.assertFalse(self.__failed_called)
  143. self.assertFalse(component.running())
  144. # We can't stop or fail the component yet
  145. self.assertRaises(ValueError, component.stop)
  146. self.assertRaises(ValueError, component.failed)
  147. def __check_started(self, component):
  148. """
  149. Check the component was started, but not stopped anyhow yet.
  150. """
  151. self.assertFalse(self._shutdown)
  152. self.assertTrue(self.__start_called)
  153. self.assertFalse(self.__stop_called)
  154. self.assertFalse(self.__failed_called)
  155. self.assertTrue(component.running())
  156. def __check_dead(self, component):
  157. """
  158. Check the component is completely dead, and the server too.
  159. """
  160. self.assertTrue(self._shutdown)
  161. self.assertTrue(self.__start_called)
  162. self.assertFalse(self.__stop_called)
  163. self.assertTrue(self.__failed_called)
  164. self.assertNotEqual(0, self._exitcode)
  165. self.assertFalse(component.running())
  166. # Surely it can't be stopped again
  167. self.assertRaises(ValueError, component.stop)
  168. # Nor started
  169. self.assertRaises(ValueError, component.start)
  170. def __check_restarted(self, component):
  171. """
  172. Check the component restarted successfully.
  173. Currently, it is implemented as starting it again right away. This will
  174. change, it will register itself into the restart schedule in boss. But
  175. as the integration with boss is not clear yet, we don't know how
  176. exactly that will happen.
  177. Reset the self.__start_called to False before calling the function when
  178. the component should fail.
  179. """
  180. self.assertFalse(self._shutdown)
  181. self.assertTrue(self.__start_called)
  182. self.assertFalse(self.__stop_called)
  183. self.assertTrue(self.__failed_called)
  184. self.assertTrue(component.running())
  185. # Check it can't be started again
  186. self.assertRaises(ValueError, component.start)
  187. def __do_start_stop(self, kind):
  188. """
  189. This is a body of a test. It creates a componend of given kind,
  190. then starts it and stops it. It checks correct functions are called
  191. and the component's status is correct.
  192. It also checks the component can't be started/stopped twice.
  193. """
  194. # Create it and check it did not do any funny stuff yet
  195. component = self.__create_component(kind)
  196. self.__check_startup(component)
  197. # Start it and check it called the correct starting functions
  198. component.start()
  199. self.__check_started(component)
  200. # Check it can't be started twice
  201. self.assertRaises(ValueError, component.start)
  202. # Stop it again and check
  203. component.stop()
  204. self.assertFalse(self._shutdown)
  205. self.assertTrue(self.__start_called)
  206. self.assertTrue(self.__stop_called)
  207. self.assertFalse(self.__failed_called)
  208. self.assertFalse(component.running())
  209. # Check it can't be stopped twice
  210. self.assertRaises(ValueError, component.stop)
  211. # Or failed
  212. self.assertRaises(ValueError, component.failed)
  213. # But it can be started again if it is stopped
  214. # (no more checking here, just it doesn't crash)
  215. component.start()
  216. def test_start_stop_core(self):
  217. """
  218. A start-stop test for core component. See do_start_stop.
  219. """
  220. self.__do_start_stop('core')
  221. def test_start_stop_needed(self):
  222. """
  223. A start-stop test for needed component. See do_start_stop.
  224. """
  225. self.__do_start_stop('needed')
  226. def test_start_stop_dispensable(self):
  227. """
  228. A start-stop test for dispensable component. See do_start_stop.
  229. """
  230. self.__do_start_stop('dispensable')
  231. def test_start_fail_core(self):
  232. """
  233. Start and then fail a core component. It should stop the whole server.
  234. """
  235. # Just ordinary startup
  236. component = self.__create_component('core')
  237. self.__check_startup(component)
  238. component.start()
  239. self.__check_started(component)
  240. # Pretend the component died
  241. component.failed()
  242. # It should bring down the whole server
  243. self.__check_dead(component)
  244. def test_start_fail_core_later(self):
  245. """
  246. Start and then fail a core component, but let it be running for longer time.
  247. It should still stop the whole server.
  248. """
  249. # Just ordinary startup
  250. component = self.__create_component('core')
  251. self.__check_startup(component)
  252. component.start()
  253. self.__check_started(component)
  254. self._timeskip()
  255. # Pretend the componend died some time later
  256. component.failed()
  257. # Check the component is still dead
  258. self.__check_dead(component)
  259. def test_start_fail_needed(self):
  260. """
  261. Start and then fail a needed component. As this happens really soon after
  262. being started, it is considered failure to start and should bring down the
  263. whole server.
  264. """
  265. # Just ordinary startup
  266. component = self.__create_component('needed')
  267. self.__check_startup(component)
  268. component.start()
  269. self.__check_started(component)
  270. # Make it fail right away.
  271. component.failed()
  272. self.__check_dead(component)
  273. def test_start_fail_needed_later(self):
  274. """
  275. Start and then fail a needed component. But the failure is later on, so
  276. we just restart it and will be happy.
  277. """
  278. # Just ordinary startup
  279. component = self.__create_component('needed')
  280. self.__check_startup(component)
  281. component.start()
  282. self.__check_started(component)
  283. # Make it fail later on
  284. self.__start_called = False
  285. self._timeskip()
  286. component.failed()
  287. self.__check_restarted(component)
  288. def test_start_fail_dispensable(self):
  289. """
  290. Start and then fail a dispensable component. Should just get restarted.
  291. """
  292. # Just ordinary startup
  293. component = self.__create_component('needed')
  294. self.__check_startup(component)
  295. component.start()
  296. self.__check_started(component)
  297. # Make it fail right away
  298. self.__start_called = False
  299. component.failed()
  300. self.__check_restarted(component)
  301. def test_start_fail_dispensable(self):
  302. """
  303. Start and then later on fail a dispensable component. Should just get
  304. restarted.
  305. """
  306. # Just ordinary startup
  307. component = self.__create_component('needed')
  308. self.__check_startup(component)
  309. component.start()
  310. self.__check_started(component)
  311. # Make it fail later on
  312. self.__start_called = False
  313. self._timeskip()
  314. component.failed()
  315. self.__check_restarted(component)
  316. def test_fail_core(self):
  317. """
  318. Failure to start a core component. Should bring the system down
  319. and the exception should get through.
  320. """
  321. component = self.__create_component('core')
  322. self.__check_startup(component)
  323. component.start_internal = self.__fail_to_start
  324. self.assertRaises(TestError, component.start)
  325. self.__check_dead(component)
  326. def test_fail_needed(self):
  327. """
  328. Failure to start a needed component. Should bring the system down
  329. and the exception should get through.
  330. """
  331. component = self.__create_component('needed')
  332. self.__check_startup(component)
  333. component.start_internal = self.__fail_to_start
  334. self.assertRaises(TestError, component.start)
  335. self.__check_dead(component)
  336. def test_fail_dispensable(self):
  337. """
  338. Failure to start a dispensable component. The exception should get
  339. through, but it should be restarted.
  340. """
  341. component = self.__create_component('dispensable')
  342. self.__check_startup(component)
  343. component.start_internal = self.__fail_to_start
  344. self.assertRaises(TestError, component.start)
  345. self.__check_restarted(component)
  346. def test_bad_kind(self):
  347. """
  348. Test the component rejects nonsensual kinds. This includes bad
  349. capitalization.
  350. """
  351. for kind in ['Core', 'CORE', 'nonsense', 'need ed', 'required']:
  352. self.assertRaises(ValueError, Component, 'No process', self, kind)
  353. class TestComponent(Component):
  354. """
  355. A test component. It does not start any processes or so, it just logs
  356. information about what happens.
  357. """
  358. def __init__(self, owner, name, kind, address=None, params=None):
  359. """
  360. Initializes the component. The owner is the test that started the
  361. component. The logging will happen into it.
  362. The process is used as a name for the logging.
  363. """
  364. Component.__init__(self, name, owner, kind, address, params)
  365. self.__owner = owner
  366. self.__name = name
  367. self.log('init')
  368. self.log(kind)
  369. def log(self, event):
  370. """
  371. Log an event into the owner. The owner can then check the correct
  372. order of events that happened.
  373. """
  374. self.__owner.log.append((self.__name, event))
  375. def start_internal(self):
  376. self.log('start')
  377. def stop_internal(self):
  378. self.log('stop')
  379. def failed_internal(self):
  380. self.log('failed')
  381. class FailComponent(Component):
  382. """
  383. A mock component that fails whenever it is started.
  384. """
  385. def start_internal(self):
  386. raise TestError("test error")
  387. class ConfiguratorTest(BossUtils, unittest.TestCase):
  388. """
  389. Tests for the configurator.
  390. """
  391. def setUp(self):
  392. """
  393. Insert the special evaluated test components we use and prepare the
  394. log. Also provide some data for the tests and prepare us to pretend
  395. we're boss.
  396. """
  397. BossUtils.setUp(self)
  398. # We put our functions inside instead of class constructors,
  399. # so we can look into what is happening more easily
  400. self.__orig_specials = copy.copy(specials)
  401. specials['test'] = self.__component_test
  402. self.log = []
  403. # The core "hardcoded" configuration
  404. self.__core = {
  405. 'core1': {
  406. 'priority': 5,
  407. 'process': 'core1',
  408. 'special': 'test',
  409. 'kind': 'core'
  410. },
  411. 'core2': {
  412. 'process': 'core2',
  413. 'special': 'test',
  414. 'kind': 'core'
  415. },
  416. 'core3': {
  417. 'process': 'core3',
  418. 'priority': 3,
  419. 'special': 'test',
  420. 'kind': 'core'
  421. }
  422. }
  423. # How they should be started. They are created in the order they are
  424. # found in the dict, but then they should be started by priority.
  425. # This expects that the same dict returns its keys in the same order
  426. # every time
  427. self.__core_log_create = []
  428. for core in self.__core.keys():
  429. self.__core_log_create.append((core, 'init'))
  430. self.__core_log_create.append((core, 'core'))
  431. self.__core_log_start = [('core1', 'start'), ('core3', 'start'),
  432. ('core2', 'start')]
  433. self.__core_log = self.__core_log_create + self.__core_log_start
  434. def tearDown(self):
  435. """
  436. Clean up the special evaluated test components and other stuff.
  437. """
  438. BossUtils.tearDown(self)
  439. specials = self.__orig_specials
  440. def __component_test(self, process, boss, kind, address=None, params=None):
  441. """
  442. Create a test component. It will log events to us.
  443. """
  444. self.assertEqual(self, boss)
  445. return TestComponent(self, process, kind, address, params)
  446. def test_init(self):
  447. """
  448. Tests the configurator can be created and it does not create
  449. any components yet, nor does it remember anything.
  450. """
  451. configurator = Configurator(self)
  452. self.assertEqual([], self.log)
  453. self.assertEqual({}, configurator._components)
  454. self.assertEqual({}, configurator._old_config)
  455. self.assertFalse(configurator._running)
  456. def test_run_plan(self):
  457. """
  458. Test the internal function of running plans. Just see it can handle
  459. the commands in the given order. We see that by the log.
  460. Also includes one that raises, so we see it just stops there.
  461. """
  462. # Prepare the configurator and the plan
  463. configurator = Configurator(self)
  464. started = self.__component_test('second', self, 'dispensable')
  465. started.start()
  466. stopped = self.__component_test('first', self, 'core')
  467. configurator._components = {'second': started}
  468. plan = [
  469. {
  470. 'component': stopped,
  471. 'command': 'start',
  472. 'name': 'first'
  473. },
  474. {
  475. 'component': started,
  476. 'command': 'stop',
  477. 'name': 'second'
  478. },
  479. {
  480. 'component': FailComponent('third', self, 'needed'),
  481. 'command': 'start',
  482. 'name': 'third'
  483. },
  484. {
  485. 'component': self.__component_test('fourth', self, 'core'),
  486. 'command': 'start',
  487. 'name': 'fourth'
  488. }
  489. ]
  490. # Don't include the preparation into the log
  491. self.log = []
  492. # The error from the third component is propagated
  493. self.assertRaises(TestError, configurator._run_plan, plan)
  494. # The first two were handled, the rest not, due to the exception
  495. self.assertEqual([('first', 'start'), ('second', 'stop')], self.log)
  496. self.assertEqual({'first': stopped}, configurator._components)
  497. def test_build_plan(self):
  498. """
  499. Test building the plan correctly. Not complete yet, this grows as we
  500. add more ways of changing the plan.
  501. """
  502. configurator = Configurator(self)
  503. plan = configurator._build_plan({}, self.__core)
  504. # This should have created the components
  505. self.assertEqual(self.__core_log_create, self.log)
  506. self.assertEqual(3, len(plan))
  507. for (task, name) in zip(plan, ['core1', 'core3', 'core2']):
  508. self.assertTrue('component' in task)
  509. self.assertEqual('start', task['command'])
  510. self.assertEqual(name, task['name'])
  511. component = task['component']
  512. self.assertIsNone(component._address)
  513. self.assertIsNone(component._params)
  514. # A plan to go from older state to newer one containing more components
  515. bigger = copy.copy(self.__core)
  516. bigger['additional'] = {
  517. 'priority': 6,
  518. 'special': 'test',
  519. 'process': 'additional',
  520. 'kind': 'needed'
  521. }
  522. self.log = []
  523. plan = configurator._build_plan(self.__core, bigger)
  524. self.assertEqual([('additional', 'init'), ('additional', 'needed')],
  525. self.log)
  526. self.assertEqual(1, len(plan))
  527. self.assertTrue('component' in plan[0])
  528. component = plan[0]['component']
  529. self.assertEqual('start', plan[0]['command'])
  530. self.assertEqual('additional', plan[0]['name'])
  531. # Now remove the one component again
  532. # We run the plan so the component is wired into internal structures
  533. configurator._run_plan(plan)
  534. self.log = []
  535. plan = configurator._build_plan(bigger, self.__core)
  536. self.assertEqual([], self.log)
  537. self.assertEqual([{
  538. 'command': 'stop',
  539. 'name': 'additional',
  540. 'component': component
  541. }], plan)
  542. # We want to switch a component. So, prepare the configurator so it
  543. # holds one
  544. configurator._run_plan(configurator._build_plan(self.__core, bigger))
  545. # Get a different configuration with a different component
  546. different = copy.copy(self.__core)
  547. different['another'] = {
  548. 'special': 'test',
  549. 'process': 'another',
  550. 'kind': 'dispensable'
  551. }
  552. self.log = []
  553. plan = configurator._build_plan(bigger, different)
  554. self.assertEqual([('another', 'init'), ('another', 'dispensable')],
  555. self.log)
  556. self.assertEqual(2, len(plan))
  557. self.assertEqual('stop', plan[0]['command'])
  558. self.assertEqual('additional', plan[0]['name'])
  559. self.assertTrue('component' in plan[0])
  560. self.assertEqual('start', plan[1]['command'])
  561. self.assertEqual('another', plan[1]['name'])
  562. self.assertTrue('component' in plan[1])
  563. # Some slightly insane plans, like missing process, having parameters,
  564. # no special, etc
  565. plan = configurator._build_plan({}, {
  566. 'component': {
  567. 'kind': 'needed',
  568. 'params': [1, 2],
  569. 'address': 'address'
  570. }
  571. })
  572. self.assertEqual(1, len(plan))
  573. self.assertEqual('start', plan[0]['command'])
  574. self.assertEqual('component', plan[0]['name'])
  575. component = plan[0]['component']
  576. self.assertEqual('component', component.name())
  577. self.assertEqual([1, 2], component._params)
  578. self.assertEqual('address', component._address)
  579. # We don't use isinstance on purpose, it would allow a descendand
  580. self.assertTrue(type(component) is Component)
  581. def __do_switch(self, option, value):
  582. """
  583. Start it with some component and then switch the configuration of the
  584. component. This will probably raise, as it is not yet supported.
  585. """
  586. configurator = Configurator(self)
  587. compconfig = {
  588. 'special': 'test',
  589. 'process': 'process',
  590. 'priority': 13,
  591. 'kind': 'core'
  592. }
  593. modifiedconfig = copy.copy(compconfig)
  594. modifiedconfig[option] = value
  595. return configurator._build_plan({'comp': compconfig},
  596. {'comp': modifiedconfig})
  597. def test_change_config_plan(self):
  598. """
  599. Test changing a configuration of one component. This is not yet
  600. implemented and should therefore throw.
  601. """
  602. self.assertRaises(NotImplementedError, self.__do_switch, 'kind',
  603. 'dispensable')
  604. self.assertRaises(NotImplementedError, self.__do_switch, 'special',
  605. 'not_a_test')
  606. self.assertRaises(NotImplementedError, self.__do_switch, 'process',
  607. 'different')
  608. # This does not change anything on running component, so no need to
  609. # raise
  610. self.assertEqual([], self.__do_switch('priority', 5))
  611. # Check against false positive, if the data are the same, but different
  612. # instance
  613. self.assertEqual([], self.__do_switch('special', 'test'))
  614. def __check_shutdown_log(self):
  615. """
  616. Checks the log for shutting down from the core configuration.
  617. """
  618. # We know everything must be stopped, we know what it is.
  619. # But we don't know the order, so we check everything is exactly
  620. # once in the log
  621. components = set(self.__core.keys())
  622. for (name, command) in self.log:
  623. self.assertEqual('stop', command)
  624. self.assertTrue(name in components)
  625. components.remove(name)
  626. self.assertEqual(set([]), components, "Some component wasn't stopped")
  627. def test_run(self):
  628. """
  629. Passes some configuration to the startup method and sees if
  630. the components are started up. Then it reconfigures it with
  631. empty configuration, the original configuration again and shuts
  632. down.
  633. It also checks the components are kept inside the configurator.
  634. """
  635. configurator = Configurator(self)
  636. # Can't reconfigure nor stop yet
  637. self.assertRaises(ValueError, configurator.reconfigure, self.__core)
  638. self.assertRaises(ValueError, configurator.shutdown)
  639. self.assertFalse(configurator.running())
  640. # Start it
  641. configurator.startup(self.__core)
  642. self.assertEqual(self.__core_log, self.log)
  643. for core in self.__core.keys():
  644. self.assertTrue(core in configurator._components)
  645. self.assertEqual(self.__core, configurator._old_config)
  646. self.assertTrue(configurator._running)
  647. self.assertTrue(configurator.running())
  648. # It can't be started twice
  649. self.assertRaises(ValueError, configurator.startup, self.__core)
  650. self.log = []
  651. # Reconfigure - stop everything
  652. configurator.reconfigure({})
  653. self.assertEqual({}, configurator._components)
  654. self.assertEqual({}, configurator._old_config)
  655. self.assertTrue(configurator._running)
  656. self.__check_shutdown_log()
  657. # Start it again
  658. self.log = []
  659. configurator.reconfigure(self.__core)
  660. self.assertEqual(self.__core_log, self.log)
  661. for core in self.__core.keys():
  662. self.assertTrue(core in configurator._components)
  663. self.assertEqual(self.__core, configurator._old_config)
  664. self.assertTrue(configurator._running)
  665. # Do a shutdown
  666. self.log = []
  667. configurator.shutdown()
  668. self.assertEqual({}, configurator._components)
  669. self.assertEqual({}, configurator._old_config)
  670. self.assertFalse(configurator._running)
  671. self.assertFalse(configurator.running())
  672. self.__check_shutdown_log()
  673. # It can't be stopped twice
  674. self.assertRaises(ValueError, configurator.shutdown)
  675. if __name__ == '__main__':
  676. isc.log.init("bind10") # FIXME Should this be needed?
  677. isc.log.resetUnitTestRootLogger()
  678. unittest.main()