Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export alt values in hooks and bootstrap #312

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_bootstrap(
paths.bootstrap.write(
'#!/bin/bash\n'
f'echo {expect}\n'
f'[[ $(id -un) = $YADM_USER ]] && echo "user is set"\n'
f'exit {code}\n'
)
paths.bootstrap.chmod(0o775)
Expand All @@ -30,6 +31,7 @@ def test_bootstrap(
if exists and executable:
assert run.err == ''
assert expect in run.out
assert 'user is set' in run.out
else:
assert expect in run.err
assert run.out == ''
5 changes: 0 additions & 5 deletions test/test_unit_record_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
import pytest

INIT_VARS = """
score=0
local_class=testclass
local_system=testsystem
local_host=testhost
local_user=testuser
alt_scores=()
alt_targets=()
alt_sources=()
Expand Down
48 changes: 24 additions & 24 deletions test/test_unit_score_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'labels': ['a', 'arch', 'architecture'],
'modifier': 1,
},
'system': {
'os': {
'labels': ['o', 'os'],
'modifier': 2,
},
Expand Down Expand Up @@ -54,9 +54,9 @@ def calculate_score(filename):
else:
score = 0
break
elif label in CONDITION['system']['labels']:
if value == 'testsystem':
score += 1000 + CONDITION['system']['modifier']
elif label in CONDITION['os']['labels']:
if value == 'testos':
score += 1000 + CONDITION['os']['modifier']
else:
score = 0
break
Expand Down Expand Up @@ -95,7 +95,7 @@ def calculate_score(filename):
@pytest.mark.parametrize(
'arch', ['arch', None], ids=['arch', 'no-arch'])
@pytest.mark.parametrize(
'system', ['system', None], ids=['system', 'no-system'])
'system', ['os', None], ids=['os', 'no-os'])
@pytest.mark.parametrize(
'distro', ['distro', None], ids=['distro', 'no-distro'])
@pytest.mark.parametrize(
Expand All @@ -110,9 +110,9 @@ def test_score_values(
# pylint: disable=too-many-branches
local_class = 'testclass'
local_arch = 'testarch'
local_system = 'testsystem'
local_os = 'testos'
local_distro = 'testdistro'
local_host = 'testhost'
local_hostname = 'testhost'
local_user = 'testuser'
filenames = {'filename##': 0}

Expand Down Expand Up @@ -145,7 +145,7 @@ def test_score_values(
newfile += ','
newfile += '.'.join([
label,
local_system if match else 'badsys'
local_os if match else 'bados'
])
filenames[newfile] = calculate_score(newfile)
if distro:
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_score_values(
newfile += ','
newfile += '.'.join([
label,
local_host if match else 'badhost'
local_hostname if match else 'badhost'
])
filenames[newfile] = calculate_score(newfile)
if user:
Expand All @@ -200,12 +200,12 @@ def test_score_values(
script = f"""
YADM_TEST=1 source {yadm}
score=0
local_class={local_class}
local_arch={local_arch}
local_system={local_system}
local_distro={local_distro}
local_host={local_host}
local_user={local_user}
YADM_CLASS={local_class}
YADM_ARCH={local_arch}
YADM_OS={local_os}
YADM_DISTRO={local_distro}
YADM_HOSTNAME={local_hostname}
YADM_USER={local_user}
"""
expected = ''
for filename in filenames:
Expand Down Expand Up @@ -233,7 +233,7 @@ def test_extensions(runner, yadm, ext):
script = f"""
YADM_TEST=1 source {yadm}
score=0
local_user={local_user}
YADM_USER={local_user}
score_file "{filename}"
echo "$score"
"""
Expand All @@ -248,9 +248,9 @@ def test_score_values_templates(runner, yadm):
"""Test score results"""
local_class = 'testclass'
local_arch = 'arch'
local_system = 'testsystem'
local_os = 'testos'
local_distro = 'testdistro'
local_host = 'testhost'
local_hostname = 'testhost'
local_user = 'testuser'
filenames = {'filename##': 0}

Expand All @@ -265,12 +265,12 @@ def test_score_values_templates(runner, yadm):
script = f"""
YADM_TEST=1 source {yadm}
score=0
local_class={local_class}
local_arch={local_arch}
local_system={local_system}
local_distro={local_distro}
local_host={local_host}
local_user={local_user}
YADM_CLASS={local_class}
YADM_ARCH={local_arch}
YADM_OS={local_os}
YADM_DISTRO={local_distro}
YADM_HOSTNAME={local_hostname}
YADM_USER={local_user}
"""
expected = ''
for filename in filenames:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Unit tests: set_local_alt_values"""
"""Unit tests: set_alt_values"""
import pytest
import utils

Expand All @@ -20,18 +20,18 @@
]
)
@pytest.mark.usefixtures('ds1_copy')
def test_set_local_alt_values(
def test_set_alt_values(
runner, yadm, paths, tst_sys, tst_host, tst_user, override):
"""Use issue_legacy_path_warning"""
script = f"""
YADM_TEST=1 source {yadm} &&
set_operating_system &&
YADM_DIR={paths.yadm} YADM_DATA={paths.data} configure_paths &&
set_local_alt_values
echo "class='$local_class'"
echo "os='$local_system'"
echo "host='$local_host'"
echo "user='$local_user'"
ALT_VALUES_SET=0 set_alt_values
echo "class='$YADM_CLASS'"
echo "os='$YADM_OS'"
echo "host='$YADM_HOSTNAME'"
echo "user='$YADM_USER'"
"""

if override:
Expand Down Expand Up @@ -69,8 +69,8 @@ def test_distro(runner, yadm):
YADM_TEST=1 source {yadm}
function config() {{ echo "$1"; }}
function query_distro() {{ echo "testdistro"; }}
set_local_alt_values
echo "distro='$local_distro'"
ALT_VALUES_SET=0 set_alt_values
echo "distro='$YADM_DISTRO'"
"""
run = runner(command=['bash'], inp=script)
assert run.success
Expand Down
34 changes: 17 additions & 17 deletions test/test_unit_template_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# these values are also testing the handling of bizarre characters
LOCAL_CLASS = "default_Test+@-!^Class"
LOCAL_ARCH = "default_Test+@-!^Arch"
LOCAL_SYSTEM = "default_Test+@-!^System"
LOCAL_HOST = "default_Test+@-!^Host"
LOCAL_OS = "default_Test+@-!^System"
LOCAL_HOSTNAME = "default_Test+@-!^Host"
LOCAL_USER = "default_Test+@-!^User"
LOCAL_DISTRO = "default_Test+@-!^Distro"
TEMPLATE = f'''
Expand Down Expand Up @@ -47,7 +47,7 @@
{{% if yadm.os == "wrongos1" %}}
wrong os 1
{{% endif %}}
{{% if yadm.os == "{LOCAL_SYSTEM}" %}}
{{% if yadm.os == "{LOCAL_OS}" %}}
Included section for os = {{{{yadm.os}}}} ({{{{yadm.os}}}} repeated)
{{% endif %}}
{{% if yadm.os == "wrongos2" %}}
Expand All @@ -56,7 +56,7 @@
{{% if yadm.hostname == "wronghost1" %}}
wrong host 1
{{% endif %}}
{{% if yadm.hostname == "{LOCAL_HOST}" %}}
{{% if yadm.hostname == "{LOCAL_HOSTNAME}" %}}
Included section for host = {{{{yadm.hostname}}}} ({{{{yadm.hostname}}}} again)
{{% endif %}}
{{% if yadm.hostname == "wronghost2" %}}
Expand Down Expand Up @@ -86,16 +86,16 @@
start of template
default class = >{LOCAL_CLASS}<
default arch = >{LOCAL_ARCH}<
default os = >{LOCAL_SYSTEM}<
default host = >{LOCAL_HOST}<
default os = >{LOCAL_OS}<
default host = >{LOCAL_HOSTNAME}<
default user = >{LOCAL_USER}<
default distro = >{LOCAL_DISTRO}<
Included section from else
Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated)
Multiple lines
Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated)
Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated)
Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again)
Included section for os = {LOCAL_OS} ({LOCAL_OS} repeated)
Included section for host = {LOCAL_HOSTNAME} ({LOCAL_HOSTNAME} again)
Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated)
Included section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again)
end of template
Expand Down Expand Up @@ -149,12 +149,12 @@ def test_template_default(runner, yadm, tmpdir):
script = f"""
YADM_TEST=1 source {yadm}
set_awk
local_class="{LOCAL_CLASS}"
local_arch="{LOCAL_ARCH}"
local_system="{LOCAL_SYSTEM}"
local_host="{LOCAL_HOST}"
local_user="{LOCAL_USER}"
local_distro="{LOCAL_DISTRO}"
YADM_CLASS="{LOCAL_CLASS}"
YADM_ARCH="{LOCAL_ARCH}"
YADM_OS="{LOCAL_OS}"
YADM_HOSTNAME="{LOCAL_HOSTNAME}"
YADM_USER="{LOCAL_USER}"
YADM_DISTRO="{LOCAL_DISTRO}"
template_default "{input_file}" "{output_file}"
"""
run = runner(command=['bash'], inp=script)
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_include(runner, yadm, tmpdir):
basic_file = tmpdir.join('basic')
basic_file.write(INCLUDE_BASIC)

variables_file = tmpdir.join(f'variables.{LOCAL_SYSTEM}')
variables_file = tmpdir.join(f'variables.{LOCAL_OS}')
variables_file.write(INCLUDE_VARIABLES)

nested_file = tmpdir.join('dir').join('nested')
Expand All @@ -207,8 +207,8 @@ def test_include(runner, yadm, tmpdir):
script = f"""
YADM_TEST=1 source {yadm}
set_awk
local_class="{LOCAL_CLASS}"
local_system="{LOCAL_SYSTEM}"
YADM_CLASS="{LOCAL_CLASS}"
YADM_OS="{LOCAL_OS}"
template_default "{input_file}" "{output_file}"
"""
run = runner(command=['bash'], inp=script)
Expand Down
28 changes: 14 additions & 14 deletions test/test_unit_template_esh.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

LOCAL_CLASS = "esh_Test+@-!^Class"
LOCAL_ARCH = "esh_Test+@-!^Arch"
LOCAL_SYSTEM = "esh_Test+@-!^System"
LOCAL_HOST = "esh_Test+@-!^Host"
LOCAL_OS = "esh_Test+@-!^System"
LOCAL_HOSTNAME = "esh_Test+@-!^Host"
LOCAL_USER = "esh_Test+@-!^User"
LOCAL_DISTRO = "esh_Test+@-!^Distro"
TEMPLATE = f'''
Expand Down Expand Up @@ -38,7 +38,7 @@
<% if [ "$YADM_OS" = "wrongos1" ]; then -%>
wrong os 1
<% fi -%>
<% if [ "$YADM_OS" = "{LOCAL_SYSTEM}" ]; then -%>
<% if [ "$YADM_OS" = "{LOCAL_OS}" ]; then -%>
Included section for os = <%=$YADM_OS%> (<%=$YADM_OS%> repeated)
<% fi -%>
<% if [ "$YADM_OS" = "wrongos2" ]; then -%>
Expand All @@ -47,7 +47,7 @@
<% if [ "$YADM_HOSTNAME" = "wronghost1" ]; then -%>
wrong host 1
<% fi -%>
<% if [ "$YADM_HOSTNAME" = "{LOCAL_HOST}" ]; then -%>
<% if [ "$YADM_HOSTNAME" = "{LOCAL_HOSTNAME}" ]; then -%>
Included section for host = <%=$YADM_HOSTNAME%> (<%=$YADM_HOSTNAME%> again)
<% fi -%>
<% if [ "$YADM_HOSTNAME" = "wronghost2" ]; then -%>
Expand Down Expand Up @@ -77,14 +77,14 @@
start of template
esh class = >{LOCAL_CLASS}<
esh arch = >{LOCAL_ARCH}<
esh os = >{LOCAL_SYSTEM}<
esh host = >{LOCAL_HOST}<
esh os = >{LOCAL_OS}<
esh host = >{LOCAL_HOSTNAME}<
esh user = >{LOCAL_USER}<
esh distro = >{LOCAL_DISTRO}<
Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated)
Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated)
Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated)
Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again)
Included section for os = {LOCAL_OS} ({LOCAL_OS} repeated)
Included section for host = {LOCAL_HOSTNAME} ({LOCAL_HOSTNAME} again)
Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated)
Included section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again)
end of template
Expand All @@ -107,12 +107,12 @@ def test_template_esh(runner, yadm, tmpdir):

script = f"""
YADM_TEST=1 source {yadm}
local_class="{LOCAL_CLASS}"
local_arch="{LOCAL_ARCH}"
local_system="{LOCAL_SYSTEM}"
local_host="{LOCAL_HOST}"
local_user="{LOCAL_USER}"
local_distro="{LOCAL_DISTRO}"
export YADM_CLASS="{LOCAL_CLASS}"
export YADM_ARCH="{LOCAL_ARCH}"
export YADM_OS="{LOCAL_OS}"
export YADM_HOSTNAME="{LOCAL_HOSTNAME}"
export YADM_USER="{LOCAL_USER}"
export YADM_DISTRO="{LOCAL_DISTRO}"
template_esh "{input_file}" "{output_file}"
"""
run = runner(command=['bash'], inp=script)
Expand Down
Loading