Skip to content

Commit 4adcf0c

Browse files
committed
FEATURE: make the minor version of a distro available as an attribute
1 parent 6747c57 commit 4adcf0c

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

common/src/stack/command/stack/commands/list/attr/plugin_host_intrinsic.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def run(self, scope_mappings):
7070
# First the pallets
7171
pallets = []
7272
os_version = None
73+
minor_version = None
7374
for name, version, rel, pallet_os in self.db.select("""
7475
rolls.name, rolls.version, rolls.rel, rolls.os
7576
FROM rolls
@@ -81,14 +82,19 @@ def run(self, scope_mappings):
8182
# the attr os.version is '{major_version}.x'
8283
# release is now '{OS}{major_version}'
8384
if pallet_os in rel:
84-
os_version = f'{rel.replace(pallet_os, "")}.x'
85+
major_version = rel.replace(pallet_os, "")
86+
os_version = f'{major_version}.x'
87+
# take the version field and carve away the major version, stripping remaining leading dots.
88+
# note, this may stay '' in some cases (Fedora, inital releases of ubuntu, sles15, ...)
89+
minor_version = f'{version.replace(major_version, "")}'.lstrip('.')
8590
# fedora's OS is 'redhat' ...
8691
elif name.lower() in rel:
8792
os_version = f'{rel.replace(name.lower(), "")}.x'
8893

8994
for hostname in box_map[box_id]:
9095
output_rows.append([hostname, 'host', 'const', 'pallets', pallets])
9196
output_rows.append([hostname, 'host', 'const', 'os.version', os_version])
97+
output_rows.append([hostname, 'host', 'const', 'os.minor_version', minor_version])
9298

9399
# Then the carts
94100
carts = flatten(self.db.select("""

test-framework/test-suites/integration/tests/list/test_list_host_attr.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,32 @@ def test_regression_shadow_glob_interaction(self, host, add_host):
306306
'stack list host attr a:backend attr=time.* output-format=json'
307307
)
308308
assert result.rc == 0
309+
310+
def test_const_determined_correctly(self, host):
311+
result = host.run('stack list host attr localhost attr=os* output-format=json')
312+
assert result.rc == 0
313+
attrs = json.loads(result.stdout)
314+
315+
stacki_os_attributes = {}
316+
317+
for this_attr in attrs:
318+
if this_attr['attr'] == 'os':
319+
stacki_os_attributes['os'] = this_attr['value']
320+
elif this_attr['attr'] == 'os.version':
321+
stacki_os_attributes['os.version'] = this_attr['value']
322+
elif this_attr['attr'] == 'os.minor_version':
323+
stacki_os_attributes['os.minor_version'] = this_attr['value']
324+
325+
expected_keys = ('os', 'os.version', 'os.minor_version')
326+
assert set(expected_keys) == set(stacki_os_attributes.keys())
327+
328+
expected_values = itemgetter(*expected_keys)(stacki_os_attributes)
329+
330+
distro, rel = host.system_info.distribution, host.system_info.release
331+
if (distro, rel) == ('sles', '12.3'):
332+
assert ('sles', '12.x', 'sp3') == expected_values
333+
if (distro, rel) == ('sles', '15.1'):
334+
assert ('sles', '15.x', 'sp1') == expected_values
335+
elif (distro, rel) == ('centos', '7'):
336+
assert ('redhat', '7.x', '6') == expected_values
337+
# TODO Ubuntu

0 commit comments

Comments
 (0)