Add --fake command line option to builder

This allows the builder to be run in an otherwise production-like
setting but with the actual image build stubbed out.

Change-Id: If41428605c13f263da78ebe382ac83b4c1858c42
This commit is contained in:
James E. Blair 2017-01-18 14:15:36 -08:00
parent 8fd7744935
commit 8b44689550
2 changed files with 12 additions and 3 deletions

View File

@ -1034,13 +1034,15 @@ class NodePoolBuilder(object):
'''
log = logging.getLogger("nodepool.builder.NodePoolBuilder")
def __init__(self, config_path, num_builders=1, num_uploaders=4):
def __init__(self, config_path, num_builders=1, num_uploaders=4,
fake=False):
'''
Initialize the NodePoolBuilder object.
:param str config_path: Path to configuration file.
:param int num_builders: Number of build workers to start.
:param int num_uploaders: Number of upload workers to start.
:param bool fake: Whether to fake the image builds.
'''
self._config_path = config_path
self._config = None
@ -1053,7 +1055,11 @@ class NodePoolBuilder(object):
self.cleanup_interval = 60
self.build_interval = 10
self.upload_interval = 10
self.dib_cmd = 'disk-image-create'
if fake:
self.dib_cmd = os.path.join(os.path.dirname(__file__), '..',
'nodepool/tests/fake-image-create')
else:
self.dib_cmd = 'disk-image-create'
self.zk = None
# This lock is needed because the run() method is started in a

View File

@ -52,13 +52,16 @@ class NodePoolBuilderApp(nodepool.cmd.NodepoolApp):
parser.add_argument('--upload-workers', dest='upload_workers',
default=4, help='number of upload workers',
type=int)
parser.add_argument('--fake', action='store_true',
help='Do not actually run diskimage-builder '
'(used for testing)')
self.args = parser.parse_args()
def main(self):
self.setup_logging()
self.nb = builder.NodePoolBuilder(
self.args.config, self.args.build_workers,
self.args.upload_workers)
self.args.upload_workers, self.args.fake)
signal.signal(signal.SIGINT, self.sigint_handler)
signal.signal(signal.SIGUSR2, nodepool.cmd.stack_dump_handler)