commit
c8827b1d6d
|
@ -14,7 +14,6 @@
|
|||
# under the License.
|
||||
|
||||
|
||||
import logging
|
||||
import os
|
||||
import string
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import json
|
||||
|
@ -30,6 +30,7 @@ from instack import runner
|
|||
|
||||
LOG = logging.getLogger()
|
||||
|
||||
|
||||
def load_args(argv):
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Execute diskimage-builder elements on the current "
|
||||
|
@ -75,8 +76,8 @@ def load_args(argv):
|
|||
args = parser.parse_args(argv)
|
||||
|
||||
if args.json_file and (args.element or args.hook or args.exclude_element):
|
||||
print "--json-file not compatible with --element, --hook,"
|
||||
print "--exclude-element, or --blacklist"
|
||||
print("--json-file not compatible with --element, --hook,")
|
||||
print("--exclude-element, or --blacklist")
|
||||
sys.exit(1)
|
||||
|
||||
return args
|
||||
|
@ -89,8 +90,8 @@ def set_environment(tmp_dir):
|
|||
os.symlink('/', os.environ['TMP_MOUNT_PATH'])
|
||||
os.environ['DIB_OFFLINE'] = ''
|
||||
os.environ['DIB_INIT_SYSTEM'] = 'systemd'
|
||||
os.environ['DIB_IMAGE_CACHE'] = \
|
||||
'%s/.cache/image-create' % os.environ['HOME']
|
||||
os.environ['DIB_IMAGE_CACHE'] = (
|
||||
'%s/.cache/image-create' % os.environ['HOME'])
|
||||
os.environ['IMAGE_NAME'] = 'instack'
|
||||
os.environ['PATH'] = "%s:/usr/local/bin" % os.environ['PATH']
|
||||
os.environ.setdefault('DIB_DEFAULT_INSTALLTYPE', 'package')
|
||||
|
@ -108,15 +109,17 @@ def set_environment(tmp_dir):
|
|||
else:
|
||||
os.environ['ARCH'] = 'i386'
|
||||
|
||||
os.environ['DIB_ENV'] = \
|
||||
os.environ['DIB_ENV'] = (
|
||||
subprocess.check_output(['export', '|', 'grep', '\' DIB_.*=\''],
|
||||
shell=True)
|
||||
shell=True))
|
||||
|
||||
os.environ['DIB_ARGS'] = str(sys.argv)
|
||||
|
||||
|
||||
def cleanup(tmp_dir):
|
||||
shutil.rmtree(tmp_dir)
|
||||
|
||||
|
||||
def main(argv=sys.argv):
|
||||
args = load_args(argv[1:])
|
||||
|
||||
|
@ -144,19 +147,19 @@ def main(argv=sys.argv):
|
|||
if "name" in run:
|
||||
LOG.info("Running %s" % run["name"])
|
||||
em = runner.ElementRunner(
|
||||
run['element'], run['hook'], args.element_path,
|
||||
run.get('blacklist', []), run.get('exclude-element', []),
|
||||
args.dry_run, args.interactive, args.no_cleanup)
|
||||
run['element'], run['hook'], args.element_path,
|
||||
run.get('blacklist', []), run.get('exclude-element', []),
|
||||
args.dry_run, args.interactive, args.no_cleanup)
|
||||
em.run()
|
||||
else:
|
||||
em = runner.ElementRunner(
|
||||
args.element, args.hook, args.element_path,
|
||||
args.blacklist, args.exclude_element,
|
||||
args.dry_run, args.interactive,
|
||||
args.no_cleanup)
|
||||
args.element, args.hook, args.element_path,
|
||||
args.blacklist, args.exclude_element,
|
||||
args.dry_run, args.interactive,
|
||||
args.no_cleanup)
|
||||
em.run()
|
||||
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
LOG.error(e.message)
|
||||
LOG.error(traceback.print_tb(sys.exc_info()[2]))
|
||||
sys.exit(1)
|
||||
|
|
|
@ -29,6 +29,7 @@ from instack import element
|
|||
|
||||
LOG = logging.getLogger()
|
||||
|
||||
|
||||
class ElementRunner(object):
|
||||
|
||||
def __init__(self, elements, hooks, element_paths=None, blacklist=None,
|
||||
|
@ -65,7 +66,7 @@ class ElementRunner(object):
|
|||
raise Exception("No element paths specified")
|
||||
|
||||
LOG.info('Initialized with elements path: %s' %
|
||||
' '.join(list(self.element_paths)))
|
||||
' '.join(list(self.element_paths)))
|
||||
|
||||
self.load_elements()
|
||||
self.load_dependencies()
|
||||
|
@ -134,8 +135,8 @@ class ElementRunner(object):
|
|||
self.elements, ':'.join(self.element_paths))
|
||||
self.elements = all_elements
|
||||
os.environ['IMAGE_ELEMENT'] = ' '.join([x for x in self.elements])
|
||||
LOG.info("List of all elements and dependencies: %s" %
|
||||
' '.join(list(self.elements)))
|
||||
LOG.info("List of all elements and dependencies: %s" %
|
||||
' '.join(list(self.elements)))
|
||||
|
||||
def process_exclude_elements(self):
|
||||
"""Remove any elements that have been specified as excluded."""
|
||||
|
@ -155,7 +156,7 @@ class ElementRunner(object):
|
|||
hook_dir = os.path.join(self.tmp_hook_dir, '%s.d' % hook)
|
||||
if not os.path.exists(hook_dir):
|
||||
LOG.info(" Skipping hook %s, the hook directory doesn't "
|
||||
"exist at %s" % (hook, hook_dir))
|
||||
"exist at %s" % (hook, hook_dir))
|
||||
return
|
||||
|
||||
for blacklisted_script in self.blacklist:
|
||||
|
|
|
@ -14,9 +14,10 @@
|
|||
# under the License.
|
||||
|
||||
|
||||
import mock
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from instack import runner
|
||||
|
@ -93,7 +94,7 @@ class TestRunner(testtools.TestCase):
|
|||
self.assertTrue('repo' in self.runner.loaded_elements)
|
||||
|
||||
self.assertRaises(Exception, self.runner.process_path,
|
||||
'/tmp/non/existant/path')
|
||||
'/tmp/non/existant/path') # noqa
|
||||
|
||||
@mock.patch('instack.runner.call',
|
||||
return_value=0)
|
||||
|
@ -106,7 +107,7 @@ class TestRunner(testtools.TestCase):
|
|||
|
||||
self.assertEqual(mock_call.call_count, 1)
|
||||
self.assertEqual(
|
||||
['dib-run-parts',
|
||||
['dib-run-parts',
|
||||
os.path.join(self.runner.tmp_hook_dir, 'install.d')],
|
||||
mock_call.call_args_list[0][0][0])
|
||||
|
||||
|
|
2
setup.py
2
setup.py
|
@ -19,4 +19,4 @@ import setuptools
|
|||
|
||||
setuptools.setup(
|
||||
setup_requires=['pbr>=0.5.21,<1.0'],
|
||||
pbr=True)
|
||||
pbr=True)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
hacking>=0.5.6,<0.8
|
||||
hacking>=0.9.2,<0.10
|
||||
|
||||
coverage>=3.6
|
||||
discover
|
||||
|
@ -8,4 +8,4 @@ sphinx>=1.1.2
|
|||
oslo.sphinx
|
||||
testrepository>=0.0.17
|
||||
testscenarios>=0.4,<0.5
|
||||
testtools>=0.9.32
|
||||
testtools>=0.9.32
|
||||
|
|
Loading…
Reference in New Issue