Prevent silent failure of element-info:
bin/element-info accesses it's library via a symlink: bin/diskimage_builder -> diskimage_builder This causes the relative path in elements.py to be incorrect. element-info silently fails in this situation, because it allows missing 'element-deps' files, so that these files may be optional. This change causes element-info to fail explicitly if $ELEMENTS_DIR is not set, as it now is when called by diskimage-create, and adds tests reflecting this behavior. Change-Id: Iec50f934feb13dfed64d69297a3af6ac9f842677
This commit is contained in:
parent
9978720051
commit
6cfea30246
@ -20,9 +20,8 @@ import sys
|
|||||||
|
|
||||||
|
|
||||||
def get_elements_dir():
|
def get_elements_dir():
|
||||||
if 'ELEMENTS_DIR' not in os.environ:
|
if not os.environ.get('ELEMENTS_DIR'):
|
||||||
return os.path.abspath(
|
raise Exception("$ELEMENTS_DIR must be set.")
|
||||||
os.path.join(os.path.dirname(__file__), '..', 'elements'))
|
|
||||||
return os.environ['ELEMENTS_DIR']
|
return os.environ['ELEMENTS_DIR']
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,9 +16,10 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from testtools import TestCase
|
from testtools import TestCase
|
||||||
from fixtures import Fixture, TempDir
|
from fixtures import Fixture, EnvironmentVariable, TempDir
|
||||||
|
|
||||||
from diskimage_builder.elements import expand_dependencies
|
from diskimage_builder.elements import expand_dependencies
|
||||||
|
from diskimage_builder.elements import get_elements_dir
|
||||||
|
|
||||||
data_dir = os.path.abspath(
|
data_dir = os.path.abspath(
|
||||||
os.path.join(os.path.dirname(__file__), 'test-elements'))
|
os.path.join(os.path.dirname(__file__), 'test-elements'))
|
||||||
@ -72,3 +73,13 @@ class TestElementDeps(TestCase):
|
|||||||
result = expand_dependencies(['circular1'],
|
result = expand_dependencies(['circular1'],
|
||||||
elements_dir=self.element_dir)
|
elements_dir=self.element_dir)
|
||||||
self.assertEquals(set(['circular1', 'circular2']), result)
|
self.assertEquals(set(['circular1', 'circular2']), result)
|
||||||
|
|
||||||
|
|
||||||
|
class TestElements(TestCase):
|
||||||
|
def test_depends_on_env(self):
|
||||||
|
self.useFixture(EnvironmentVariable('ELEMENTS_DIR', '/foo/bar'))
|
||||||
|
self.assertEquals('/foo/bar', get_elements_dir())
|
||||||
|
|
||||||
|
def test_env_not_set(self):
|
||||||
|
self.useFixture(EnvironmentVariable('ELEMENTS_DIR', ''))
|
||||||
|
self.assertRaises(Exception, get_elements_dir, ())
|
||||||
|
@ -22,6 +22,7 @@ class StubPackage:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# load all tests from /elements/*/tests/ dirs.
|
||||||
# conceptually load_tests should be in __init__, but see
|
# conceptually load_tests should be in __init__, but see
|
||||||
# http://bugs.python.org/issue16662 instead. So, its here in test_elements.py
|
# http://bugs.python.org/issue16662 instead. So, its here in test_elements.py
|
||||||
def load_tests(loader, tests, pattern):
|
def load_tests(loader, tests, pattern):
|
||||||
|
Loading…
Reference in New Issue
Block a user