Merge "Add work-dir command-line option"
This commit is contained in:
commit
d571f83939
@ -217,6 +217,8 @@ _CLI_OPTS = [
|
|||||||
cfg.StrOpt('logs-dir', help='Path to logs directory'),
|
cfg.StrOpt('logs-dir', help='Path to logs directory'),
|
||||||
cfg.BoolOpt('pull', default=True,
|
cfg.BoolOpt('pull', default=True,
|
||||||
help='Attempt to pull a newer version of the base image.'),
|
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 = [
|
_BASE_OPTS = [
|
||||||
|
@ -633,10 +633,14 @@ class KollaWorker(object):
|
|||||||
|
|
||||||
def setup_working_dir(self):
|
def setup_working_dir(self):
|
||||||
"""Creates a working directory for use while building"""
|
"""Creates a working directory for use while building"""
|
||||||
ts = time.time()
|
if self.conf.work_dir:
|
||||||
ts = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H-%M-%S_')
|
self.working_dir = os.path.join(self.conf.work_dir, 'docker')
|
||||||
self.temp_dir = tempfile.mkdtemp(prefix='kolla-' + ts)
|
else:
|
||||||
self.working_dir = os.path.join(self.temp_dir, 'docker')
|
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)
|
shutil.copytree(self.images_dir, self.working_dir)
|
||||||
self.copy_apt_files()
|
self.copy_apt_files()
|
||||||
LOG.debug('Created working dir: %s', self.working_dir)
|
LOG.debug('Created working dir: %s', self.working_dir)
|
||||||
@ -754,7 +758,8 @@ class KollaWorker(object):
|
|||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
"""Remove temp files"""
|
"""Remove temp files"""
|
||||||
shutil.rmtree(self.temp_dir)
|
if not self.conf.work_dir:
|
||||||
|
shutil.rmtree(self.temp_dir)
|
||||||
|
|
||||||
def filter_images(self):
|
def filter_images(self):
|
||||||
"""Filter which images to build"""
|
"""Filter which images to build"""
|
||||||
|
@ -349,6 +349,13 @@ class KollaWorkerTest(base.TestCase):
|
|||||||
results = kolla.summary()
|
results = kolla.summary()
|
||||||
self.assertEqual(None, results['failed'][0]['status'])
|
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):
|
class MainTest(base.TestCase):
|
||||||
|
|
||||||
|
@ -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.
|
Loading…
Reference in New Issue
Block a user