1
0
mirror of https://github.com/TheLocehiliosan/yadm synced 2026-03-02 03:49:29 +00:00

Support DISTRO in alternates (#72)

This commit is contained in:
Tim Byrne
2019-10-06 11:04:21 -05:00
parent 4f6b0f09cd
commit 6a3199ceea
4 changed files with 60 additions and 13 deletions

View File

@@ -49,13 +49,14 @@ def test_alt_source(
@pytest.mark.parametrize('suffix', [
'##default',
'##o.$tst_sys', '##os.$tst_sys',
'##d.$tst_distro', '##distro.$tst_distro',
'##c.$tst_class', '##class.$tst_class',
'##h.$tst_host', '##hostname.$tst_host',
'##u.$tst_user', '##user.$tst_user',
])
def test_alt_conditions(
runner, yadm_y, paths,
tst_sys, tst_host, tst_user, suffix):
tst_sys, tst_distro, tst_host, tst_user, suffix):
"""Test conditions supported by yadm alt"""
# set the class
@@ -64,6 +65,7 @@ def test_alt_conditions(
suffix = string.Template(suffix).substitute(
tst_sys=tst_sys,
tst_distro=tst_distro,
tst_class=tst_class,
tst_host=tst_host,
tst_user=tst_user,

View File

@@ -10,17 +10,21 @@ CONDITION = {
'labels': ['o', 'os'],
'modifier': 1,
},
'distro': {
'labels': ['d', 'distro'],
'modifier': 2,
},
'class': {
'labels': ['c', 'class'],
'modifier': 2,
'modifier': 4,
},
'hostname': {
'labels': ['h', 'hostname'],
'modifier': 4,
'modifier': 8,
},
'user': {
'labels': ['u', 'user'],
'modifier': 8,
'modifier': 16,
},
}
TEMPLATE_LABELS = ['t', 'template', 'yadm']
@@ -44,24 +48,35 @@ def calculate_score(filename):
if value == 'testsystem':
score += 1000 + CONDITION['system']['modifier']
else:
return 0
score = 0
break
elif label in CONDITION['distro']['labels']:
if value == 'testdistro':
score += 1000 + CONDITION['distro']['modifier']
else:
score = 0
break
elif label in CONDITION['class']['labels']:
if value == 'testclass':
score += 1000 + CONDITION['class']['modifier']
else:
return 0
score = 0
break
elif label in CONDITION['hostname']['labels']:
if value == 'testhost':
score += 1000 + CONDITION['hostname']['modifier']
else:
return 0
score = 0
break
elif label in CONDITION['user']['labels']:
if value == 'testuser':
score += 1000 + CONDITION['user']['modifier']
else:
return 0
score = 0
break
elif label in TEMPLATE_LABELS:
return 0
score = 0
break
return score
@@ -69,6 +84,8 @@ def calculate_score(filename):
'default', ['default', None], ids=['default', 'no-default'])
@pytest.mark.parametrize(
'system', ['system', None], ids=['system', 'no-system'])
@pytest.mark.parametrize(
'distro', ['distro', None], ids=['distro', 'no-distro'])
@pytest.mark.parametrize(
'cla', ['class', None], ids=['class', 'no-class'])
@pytest.mark.parametrize(
@@ -76,11 +93,12 @@ def calculate_score(filename):
@pytest.mark.parametrize(
'user', ['user', None], ids=['user', 'no-user'])
def test_score_values(
runner, yadm, default, system, cla, host, user):
runner, yadm, default, system, distro, cla, host, user):
"""Test score results"""
# pylint: disable=too-many-branches
local_class = 'testclass'
local_system = 'testsystem'
local_distro = 'testdistro'
local_host = 'testhost'
local_user = 'testuser'
filenames = {'filename##': 0}
@@ -105,6 +123,18 @@ def test_score_values(
local_system if match else 'badsys'
])
filenames[newfile] = calculate_score(newfile)
if distro:
for filename in list(filenames):
for match in [True, False]:
for label in CONDITION[distro]['labels']:
newfile = filename
if not newfile.endswith('##'):
newfile += ','
newfile += '.'.join([
label,
local_distro if match else 'baddistro'
])
filenames[newfile] = calculate_score(newfile)
if cla:
for filename in list(filenames):
for match in [True, False]:
@@ -147,6 +177,7 @@ def test_score_values(
score=0
local_class={local_class}
local_system={local_system}
local_distro={local_distro}
local_host={local_host}
local_user={local_user}
"""
@@ -169,6 +200,7 @@ def test_score_values_templates(runner, yadm):
"""Test score results"""
local_class = 'testclass'
local_system = 'testsystem'
local_distro = 'testdistro'
local_host = 'testhost'
local_user = 'testuser'
filenames = {'filename##': 0}
@@ -186,6 +218,7 @@ def test_score_values_templates(runner, yadm):
score=0
local_class={local_class}
local_system={local_system}
local_distro={local_distro}
local_host={local_host}
local_user={local_user}
"""