package-installs: allow when filter to be a list
Allow the "when:" statements to be a list of values, which are effectively anded together to filter the package install. Change-Id: Ia6f10741fa6be24b11d6991c8a6b6e07951ff68d
This commit is contained in:
parent
9080d04923
commit
138d3f9b81
@ -93,6 +93,9 @@ packages), you can use something like::
|
|||||||
other_package:
|
other_package:
|
||||||
when: DIB_FEATURE_FLAG!=0
|
when: DIB_FEATURE_FLAG!=0
|
||||||
|
|
||||||
|
You can also use a list of items in the ``when`` statement, which will
|
||||||
|
be effectively combined with *and*.
|
||||||
|
|
||||||
DEPRECATED: Adding a file under your elements pre-install.d, install.d, or
|
DEPRECATED: Adding a file under your elements pre-install.d, install.d, or
|
||||||
post-install.d directories called package-installs-<element-name> will cause
|
post-install.d directories called package-installs-<element-name> will cause
|
||||||
the list of packages in that file to be installed at the beginning of the
|
the list of packages in that file to be installed at the beginning of the
|
||||||
|
@ -61,7 +61,7 @@ def _valid_for_arch(pkg_name, arch, not_arch):
|
|||||||
return not _is_arch_in_list(not_arch)
|
return not _is_arch_in_list(not_arch)
|
||||||
|
|
||||||
|
|
||||||
def _when(statement):
|
def _when(statements):
|
||||||
'''evaulate a when: statement
|
'''evaulate a when: statement
|
||||||
|
|
||||||
Evaluate statements of the form
|
Evaluate statements of the form
|
||||||
@ -74,15 +74,21 @@ def _when(statement):
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
# No statement means install
|
# No statement means install
|
||||||
if statement is None:
|
if statements is None:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
if not isinstance(statements, list):
|
||||||
|
statements = [statements]
|
||||||
|
|
||||||
|
result = []
|
||||||
|
|
||||||
|
for s in statements:
|
||||||
# FOO = BAR
|
# FOO = BAR
|
||||||
# var op val
|
# var op val
|
||||||
match = re.match(
|
match = re.match(
|
||||||
r"(?P<var>[\w]+)(\s*)(?P<op>=|!=)(\s*)(?P<val>.*)", statement)
|
r"(?P<var>[\w]+)(\s*)(?P<op>=|!=)(\s*)(?P<val>.*)", s)
|
||||||
if not match:
|
if not match:
|
||||||
print("Malformed when line: <%s>" % statement)
|
print("Malformed when line: <%s>" % s)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
match = match.groupdict()
|
match = match.groupdict()
|
||||||
var = match['var']
|
var = match['var']
|
||||||
@ -97,15 +103,19 @@ def _when(statement):
|
|||||||
|
|
||||||
if op == '=':
|
if op == '=':
|
||||||
if val == os.environ[var]:
|
if val == os.environ[var]:
|
||||||
return True
|
result.append(True)
|
||||||
|
continue
|
||||||
elif op == '!=':
|
elif op == '!=':
|
||||||
if val != os.environ[var]:
|
if val != os.environ[var]:
|
||||||
return True
|
result.append(True)
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
print("Malformed when op: %s" % op)
|
print("Malformed when op: %s" % op)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
return False
|
result.append(False)
|
||||||
|
|
||||||
|
return all(result)
|
||||||
|
|
||||||
|
|
||||||
def collect_data(data, objs, element_name):
|
def collect_data(data, objs, element_name):
|
||||||
|
@ -138,3 +138,39 @@ class TestPackageInstall(base.BaseTestCase):
|
|||||||
|
|
||||||
self.assertRaises(RuntimeError, installs_squash.collect_data,
|
self.assertRaises(RuntimeError, installs_squash.collect_data,
|
||||||
self.final_dict, objs, 'test_element')
|
self.final_dict, objs, 'test_element')
|
||||||
|
|
||||||
|
@mock.patch.object(os, 'environ',
|
||||||
|
dict(
|
||||||
|
DIB_A_FEATURE='1',
|
||||||
|
DIB_B_FEATURE='1',
|
||||||
|
DIB_C_FEATURE='1',
|
||||||
|
**os.environ))
|
||||||
|
def test_skip_when_list(self):
|
||||||
|
'''Exercise the when flag with lists'''
|
||||||
|
objs = {
|
||||||
|
'not_skipped_package': {
|
||||||
|
'when': [
|
||||||
|
'DIB_A_FEATURE=1',
|
||||||
|
'DIB_B_FEATURE=1',
|
||||||
|
'DIB_C_FEATURE=1'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'skipped_package': {
|
||||||
|
'when': [
|
||||||
|
'DIB_A_FEATURE=1',
|
||||||
|
'DIB_B_FEATURE=0',
|
||||||
|
'DIB_C_FEATURE=1',
|
||||||
|
]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result = installs_squash.collect_data(
|
||||||
|
self.final_dict, objs, 'test_element')
|
||||||
|
|
||||||
|
expected = {
|
||||||
|
'install.d': {
|
||||||
|
'install': [('not_skipped_package', 'test_element')]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.assertThat(result, IsMatchingInstallList(expected))
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
The ``package-installs`` element can now take a list value for the
|
||||||
|
``when`` environment filter.
|
Loading…
Reference in New Issue
Block a user