diff --git a/nodepool/builder.py b/nodepool/builder.py index 5d1690e4c..c043e39af 100644 --- a/nodepool/builder.py +++ b/nodepool/builder.py @@ -222,17 +222,29 @@ class BuilderScheduler(object): if not self._config.imagesdir: raise RuntimeError('No images-dir specified in config.') - def _start(self): - ''' - Execution block for the main scheduler thread. + def _registerWatches(self): + while self._running: + time.sleep(0.1) - This starts the scheduler thread and all child threads, including the - builders, uploaders, and watch threads. + #======================================================================= + # Public methods + #======================================================================= + + def start(self): + ''' + Start the builder. + + The builder functionality is encapsulated within threads run + by the BuilderScheduler. This starts the needed sub-threads + which will run forever until we tell them to stop. ''' with self._start_lock: if self._running: raise exceptions.BuilderError('Cannot start, already running.') + self._load_config(self._config_path) + self._validate_config() + self._running = True # Create build and upload worker objects @@ -260,12 +272,13 @@ class BuilderScheduler(object): watch_thread.start() self._threads.append(watch_thread) - def _stop(self): + def stop(self): ''' - Stop the BuilderScheduler threads. + Stop the builder. - NOTE: This method will block if called soon after startup and the - startup process has not yet completed. + Signal the sub threads to begin the shutdown process. We don't + want this method to return until the scheduler has successfully + stopped all of its own threads. ''' with self._start_lock: self.log.debug("Stopping. BuilderScheduler shutting down workers") @@ -275,36 +288,6 @@ class BuilderScheduler(object): # Setting _running to False will trigger the watch thread to stop. self._running = False - def _registerWatches(self): - while self._running: - time.sleep(0.1) - - #======================================================================= - # Public methods - #======================================================================= - - def startBuilder(self): - ''' - Start the builder. - - The builder functionality is encapsulated within threads run - by the BuilderScheduler. This starts the needed sub-threads - which will run forever until we tell them to stop. - ''' - self._load_config(self._config_path) - self._validate_config() - self._start() - - def stopBuilder(self): - ''' - Stop the builder. - - Signal the sub threads to begin the shutdown process. We don't - want this method to return until the scheduler has successfully - stopped all of its own threads. - ''' - self._stop() - self.log.debug('Waiting for jobs to complete') # Do not exit until all of our owned threads exit. diff --git a/nodepool/cmd/builder.py b/nodepool/cmd/builder.py index 52f3f7616..42406cc01 100644 --- a/nodepool/cmd/builder.py +++ b/nodepool/cmd/builder.py @@ -30,7 +30,7 @@ pid_file_module = extras.try_imports(['daemon.pidlockfile', 'daemon.pidfile']) class NodePoolBuilderApp(nodepool.cmd.NodepoolApp): def sigint_handler(self, signal, frame): - self.nb.stopBuilder() + self.nb.stop() sys.exit(0) def parse_arguments(self): @@ -61,7 +61,7 @@ class NodePoolBuilderApp(nodepool.cmd.NodepoolApp): self.args.upload_workers) signal.signal(signal.SIGINT, self.sigint_handler) - self.nb.startBuilder() + self.nb.start() while True: signal.pause() diff --git a/nodepool/tests/test_builder.py b/nodepool/tests/test_builder.py index 87287fd5b..7264c17b6 100644 --- a/nodepool/tests/test_builder.py +++ b/nodepool/tests/test_builder.py @@ -87,9 +87,8 @@ class TestBuilderScheduler(tests.DBTestCase): def test_start_stop(self): config = self.setup_config('node_dib.yaml') nb = builder.BuilderScheduler(config) - nb.startBuilder() - - nb.stopBuilder() + nb.start() + nb.stop() def test_image_upload_fail(self): """Test that image upload fails are handled properly."""