Add work-dir command-line option

The working directory was previously generated as a temporary one,
but there may be cases when we want to specify a directory, for
example if we want to generate the Dockerfiles and then do some
parsing on them.

Change-Id: Ic332328913924bcb3d0dfa4d473e796050fc14b3
This commit is contained in:
Javier Pena 2017-02-17 17:48:47 +01:00
parent 2c801637e6
commit 8b38c4d5c9
4 changed files with 25 additions and 5 deletions

View File

@ -217,6 +217,8 @@ _CLI_OPTS = [
cfg.StrOpt('logs-dir', help='Path to logs directory'),
cfg.BoolOpt('pull', default=True,
help='Attempt to pull a newer version of the base image.'),
cfg.StrOpt('work-dir', help='Path to be used as working directory.'
'By default, a temporary dir is created.'),
]
_BASE_OPTS = [

View File

@ -633,10 +633,14 @@ class KollaWorker(object):
def setup_working_dir(self):
"""Creates a working directory for use while building"""
ts = time.time()
ts = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H-%M-%S_')
self.temp_dir = tempfile.mkdtemp(prefix='kolla-' + ts)
self.working_dir = os.path.join(self.temp_dir, 'docker')
if self.conf.work_dir:
self.working_dir = os.path.join(self.conf.work_dir, 'docker')
else:
ts = time.time()
ts = datetime.datetime.fromtimestamp(ts).strftime(
'%Y-%m-%d_%H-%M-%S_')
self.temp_dir = tempfile.mkdtemp(prefix='kolla-' + ts)
self.working_dir = os.path.join(self.temp_dir, 'docker')
shutil.copytree(self.images_dir, self.working_dir)
self.copy_apt_files()
LOG.debug('Created working dir: %s', self.working_dir)
@ -754,7 +758,8 @@ class KollaWorker(object):
def cleanup(self):
"""Remove temp files"""
shutil.rmtree(self.temp_dir)
if not self.conf.work_dir:
shutil.rmtree(self.temp_dir)
def filter_images(self):
"""Filter which images to build"""

View File

@ -349,6 +349,13 @@ class KollaWorkerTest(base.TestCase):
results = kolla.summary()
self.assertEqual(None, results['failed'][0]['status'])
@mock.patch('shutil.copytree')
def test_work_dir(self, copytree_mock):
self.conf.set_override('work_dir', '/tmp/foo')
kolla = build.KollaWorker(self.conf)
kolla.setup_working_dir()
self.assertEqual('/tmp/foo/docker', kolla.working_dir)
class MainTest(base.TestCase):

View File

@ -0,0 +1,6 @@
---
features:
- A new work-dir command-line option has been added to
the client, to allow the user to specify a directory
to be used as working dir, instead of the default
temp directory.