Merge "Add support for multiple images"
This commit is contained in:
commit
320e05e8c2
3
dox.yml
3
dox.yml
|
@ -1,4 +1,5 @@
|
|||
image: infra/trusty
|
||||
images:
|
||||
- infra/trusty
|
||||
add:
|
||||
- requirements.txt
|
||||
- test-requirements.txt
|
||||
|
|
16
dox/cmd.py
16
dox/cmd.py
|
@ -14,6 +14,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
import argparse
|
||||
import functools
|
||||
import logging
|
||||
import sys
|
||||
|
||||
|
@ -47,8 +48,8 @@ def parse_args():
|
|||
parser.add_argument(dest='extra_args', nargs='*',
|
||||
help='args to append to command, or command to run'
|
||||
' if -c is given')
|
||||
parser.add_argument('-i', '--image', dest='image',
|
||||
help='Base image to use')
|
||||
parser.add_argument('-i', '--images', dest='images',
|
||||
help='Base images to use')
|
||||
parser.add_argument('-c', '--command', dest='command', default=False,
|
||||
action='store_true',
|
||||
help='Treat arguments as the entire command to run')
|
||||
|
@ -80,9 +81,10 @@ def run_dox(args):
|
|||
sys.exit(1)
|
||||
|
||||
# Get Image
|
||||
image = args.image
|
||||
if args.image is None:
|
||||
image = dox.images.get_image()
|
||||
if args.images is None:
|
||||
images = dox.images.get_images()
|
||||
else:
|
||||
images = args.images.split(',')
|
||||
|
||||
# Get Command
|
||||
if args.command:
|
||||
|
@ -92,7 +94,9 @@ def run_dox(args):
|
|||
|
||||
# Run
|
||||
try:
|
||||
return dox.runner.Runner(args).run(image, command)
|
||||
run = functools.partial(dox.runner.Runner(args).run,
|
||||
command=command)
|
||||
map(run, images)
|
||||
except Exception:
|
||||
logger.error(
|
||||
"Operation failed, aborting dox.", exc_info=args.debug)
|
||||
|
|
|
@ -43,8 +43,8 @@ class DoxYaml(object):
|
|||
def exists(self):
|
||||
return os.path.exists('dox.yml')
|
||||
|
||||
def get_image(self, image):
|
||||
return self._open_dox_yaml().get('image', image)
|
||||
def get_images(self):
|
||||
return self._open_dox_yaml().get('images', [])
|
||||
|
||||
def get_commands(self, extra_args):
|
||||
return " ".join([self._open_dox_yaml().get('commands')] + extra_args)
|
||||
|
|
|
@ -43,11 +43,10 @@ class ToxIni(object):
|
|||
def exists(self):
|
||||
return os.path.exists('tox.ini')
|
||||
|
||||
def get_image(self, image):
|
||||
def get_images(self):
|
||||
ini = self._open_tox_ini()
|
||||
if ini.has_option('docker', 'image'):
|
||||
image = ini.get('docker', 'image')
|
||||
return image
|
||||
if ini.has_option('docker', 'images'):
|
||||
return ini.get('docker', 'images', '').split(',')
|
||||
|
||||
def get_commands(self, extra_args):
|
||||
ini = self._open_tox_ini()
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
__all__ = [
|
||||
'get_image',
|
||||
'get_images',
|
||||
]
|
||||
|
||||
import dox.config.dockerfile
|
||||
|
@ -22,21 +22,24 @@ import dox.config.dox_yaml
|
|||
import dox.config.tox_ini
|
||||
|
||||
|
||||
def get_image():
|
||||
def get_images():
|
||||
'''Examine the local environment and figure out where we should run.'''
|
||||
|
||||
dockerfile = dox.config.dockerfile.get_dockerfile()
|
||||
dox_yaml = dox.config.dox_yaml.get_dox_yaml()
|
||||
tox_ini = dox.config.tox_ini.get_tox_ini()
|
||||
|
||||
# Set default image value
|
||||
if dockerfile.exists():
|
||||
image = None
|
||||
default_images = []
|
||||
else:
|
||||
image = 'ubuntu'
|
||||
# NOTE(flaper87): We should probably raise
|
||||
# `RuntimeError` if no image was specified
|
||||
default_images = ['ubuntu']
|
||||
|
||||
images = []
|
||||
if dox_yaml.exists():
|
||||
image = dox_yaml.get_image(image)
|
||||
images = dox_yaml.get_images()
|
||||
elif tox_ini.exists():
|
||||
image = tox_ini.get_image(image)
|
||||
return image
|
||||
images = tox_ini.get_images()
|
||||
|
||||
return images or default_images
|
||||
|
|
|
@ -29,12 +29,12 @@ from dox.tests import base
|
|||
|
||||
|
||||
def get_fake_image(value):
|
||||
if value:
|
||||
def fake_value(self, image):
|
||||
if value is not None:
|
||||
def fake_value(self):
|
||||
return value
|
||||
else:
|
||||
def fake_value(self, image):
|
||||
return image
|
||||
def fake_value(self):
|
||||
return ['ubuntu']
|
||||
return fake_value
|
||||
|
||||
|
||||
|
@ -43,37 +43,38 @@ class TestImages(base.TestCase):
|
|||
scenarios = [
|
||||
('have_dockerfile', dict(
|
||||
dockerfile=True, tox_ini=False, dox_yaml=False,
|
||||
tox_value=None, dox_value=None, image=None)),
|
||||
tox_value=[], dox_value=[], images=[])),
|
||||
('no_dockerfile', dict(
|
||||
dockerfile=False, tox_ini=False, dox_yaml=False,
|
||||
tox_value=None, dox_value=None, image='ubuntu')),
|
||||
tox_value=[], dox_value=[], images=['ubuntu'])),
|
||||
('tox_no_docker', dict(
|
||||
dockerfile=False, tox_ini=True, dox_yaml=False,
|
||||
tox_value=None, dox_value=None, image='ubuntu')),
|
||||
tox_value=[], dox_value=[], images=['ubuntu'])),
|
||||
('tox_docker', dict(
|
||||
dockerfile=False, tox_ini=True, dox_yaml=False,
|
||||
tox_value='tox_docker', dox_value=None, image='tox_docker')),
|
||||
tox_value=['tox_docker'], dox_value=[], images=['tox_docker'])),
|
||||
('dox_image', dict(
|
||||
dockerfile=False, tox_ini=False, dox_yaml=True,
|
||||
tox_value=None, dox_value=None, image='ubuntu')),
|
||||
tox_value=[], dox_value=[], images=['ubuntu'])),
|
||||
('dox_no_image', dict(
|
||||
dockerfile=False, tox_ini=False, dox_yaml=True,
|
||||
tox_value=None, dox_value='dox_value', image='dox_value')),
|
||||
tox_value=[], dox_value=['dox_value'], images=['dox_value'])),
|
||||
('both_dox_wins', dict(
|
||||
dockerfile=False, tox_ini=True, dox_yaml=True,
|
||||
tox_value='tox_wins', dox_value='dox_wins', image='dox_wins')),
|
||||
tox_value=['tox_wins'], dox_value=['dox_wins'],
|
||||
images=['dox_wins'])),
|
||||
('both_no_dox', dict(
|
||||
dockerfile=False, tox_ini=True, dox_yaml=True,
|
||||
tox_value='tox_wins', dox_value=None, image='ubuntu')),
|
||||
tox_value=['tox_wins'], dox_value=[], images=['ubuntu'])),
|
||||
('both_dockerfile_passthru', dict(
|
||||
dockerfile=True, tox_ini=True, dox_yaml=True,
|
||||
tox_value=None, dox_value=None, image=None)),
|
||||
tox_value=[], dox_value=[], images=[])),
|
||||
('all_dockerfile_dox_override', dict(
|
||||
dockerfile=True, tox_ini=True, dox_yaml=True,
|
||||
tox_value=None, dox_value='dox_wins', image='dox_wins')),
|
||||
tox_value=[], dox_value=['dox_wins'], images=['dox_wins'])),
|
||||
('all_dockerfile_tox_loses', dict(
|
||||
dockerfile=True, tox_ini=True, dox_yaml=True,
|
||||
tox_value='tox_wins', dox_value=None, image=None)),
|
||||
tox_value=['tox_wins'], dox_value=[], images=[])),
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
@ -88,15 +89,15 @@ class TestImages(base.TestCase):
|
|||
'dox.config.tox_ini.ToxIni.exists',
|
||||
base.bool_to_fake(self.tox_ini)))
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'dox.config.dox_yaml.DoxYaml.get_image',
|
||||
'dox.config.dox_yaml.DoxYaml.get_images',
|
||||
get_fake_image(self.dox_value)))
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'dox.config.tox_ini.ToxIni.get_image',
|
||||
'dox.config.tox_ini.ToxIni.get_images',
|
||||
get_fake_image(self.tox_value)))
|
||||
|
||||
def test_images(self):
|
||||
image = images.get_image()
|
||||
self.assertEqual(image, self.image)
|
||||
image = images.get_images()
|
||||
self.assertEqual(image, self.images)
|
||||
|
||||
|
||||
def load_tests(loader, in_tests, pattern):
|
||||
|
|
Loading…
Reference in New Issue