parent
c092b7c099
commit
8c2f833b43
4 changed files with 55 additions and 56 deletions
|
@ -139,6 +139,8 @@ def supported_configs():
|
|||
return [
|
||||
"local.arch",
|
||||
"local.class",
|
||||
"local.distro",
|
||||
"local.distro-family",
|
||||
"local.hostname",
|
||||
"local.os",
|
||||
"local.user",
|
||||
|
|
|
@ -13,6 +13,8 @@ import utils
|
|||
"os",
|
||||
"hostname",
|
||||
"user",
|
||||
"distro",
|
||||
"distro-family",
|
||||
],
|
||||
ids=[
|
||||
"no-override",
|
||||
|
@ -21,11 +23,15 @@ import utils
|
|||
"override-os",
|
||||
"override-hostname",
|
||||
"override-user",
|
||||
"override-distro",
|
||||
"override-distro-family",
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("ds1_copy")
|
||||
def test_set_local_alt_values(runner, yadm, paths, tst_arch, tst_sys, tst_host, tst_user, override):
|
||||
"""Use issue_legacy_path_warning"""
|
||||
def test_set_local_alt_values(
|
||||
runner, yadm, paths, tst_arch, tst_sys, tst_host, tst_user, tst_distro, tst_distro_family, override
|
||||
):
|
||||
"""Test handling of local alt values"""
|
||||
script = f"""
|
||||
YADM_TEST=1 source {yadm} &&
|
||||
set_operating_system &&
|
||||
|
@ -34,8 +40,10 @@ def test_set_local_alt_values(runner, yadm, paths, tst_arch, tst_sys, tst_host,
|
|||
echo "class='$local_class'"
|
||||
echo "arch='$local_arch'"
|
||||
echo "os='$local_system'"
|
||||
echo "host='$local_host'"
|
||||
echo "hostname='$local_host'"
|
||||
echo "user='$local_user'"
|
||||
echo "distro='$local_distro'"
|
||||
echo "distro-family='$local_distro_family'"
|
||||
"""
|
||||
|
||||
if override == "class":
|
||||
|
@ -48,46 +56,18 @@ def test_set_local_alt_values(runner, yadm, paths, tst_arch, tst_sys, tst_host,
|
|||
assert run.success
|
||||
assert run.err == ""
|
||||
|
||||
if override == "class":
|
||||
assert "class='override'" in run.out
|
||||
else:
|
||||
assert "class=''" in run.out
|
||||
default_values = {
|
||||
"class": "",
|
||||
"arch": tst_arch,
|
||||
"os": tst_sys,
|
||||
"hostname": tst_host,
|
||||
"user": tst_user,
|
||||
"distro": tst_distro,
|
||||
"distro-family": tst_distro_family,
|
||||
}
|
||||
|
||||
if override == "arch":
|
||||
assert "arch='override'" in run.out
|
||||
else:
|
||||
assert f"arch='{tst_arch}'" in run.out
|
||||
|
||||
if override == "os":
|
||||
assert "os='override'" in run.out
|
||||
else:
|
||||
assert f"os='{tst_sys}'" in run.out
|
||||
|
||||
if override == "hostname":
|
||||
assert "host='override'" in run.out
|
||||
else:
|
||||
assert f"host='{tst_host}'" in run.out
|
||||
|
||||
if override == "user":
|
||||
assert "user='override'" in run.out
|
||||
else:
|
||||
assert f"user='{tst_user}'" in run.out
|
||||
|
||||
|
||||
def test_distro_and_family(runner, yadm):
|
||||
"""Assert that local_distro/local_distro_family are set"""
|
||||
|
||||
script = f"""
|
||||
YADM_TEST=1 source {yadm}
|
||||
function config() {{ echo "$1"; }}
|
||||
function query_distro() {{ echo "testdistro"; }}
|
||||
function query_distro_family() {{ echo "testfamily"; }}
|
||||
set_local_alt_values
|
||||
echo "distro='$local_distro'"
|
||||
echo "distro_family='$local_distro_family'"
|
||||
"""
|
||||
run = runner(command=["bash"], inp=script)
|
||||
assert run.success
|
||||
assert run.err == ""
|
||||
assert "distro='testdistro'" in run.out
|
||||
assert "distro_family='testfamily'" in run.out
|
||||
for key, value in default_values.items():
|
||||
if key == override:
|
||||
assert f"{key}='override'" in run.out
|
||||
else:
|
||||
assert f"{key}='{value}'" in run.out
|
||||
|
|
23
yadm
23
yadm
|
@ -649,28 +649,35 @@ function set_local_alt_values() {
|
|||
done <<< "$all_classes"
|
||||
|
||||
local_arch="$(config local.arch)"
|
||||
if [ -z "$local_arch" ] ; then
|
||||
if [[ -z "$local_arch" ]]; then
|
||||
local_arch=$(uname -m)
|
||||
fi
|
||||
|
||||
local_system="$(config local.os)"
|
||||
if [ -z "$local_system" ] ; then
|
||||
if [[ -z "$local_system" ]]; then
|
||||
local_system="$OPERATING_SYSTEM"
|
||||
fi
|
||||
|
||||
local_host="$(config local.hostname)"
|
||||
if [ -z "$local_host" ] ; then
|
||||
if [[ -z "$local_host" ]]; then
|
||||
local_host=$(uname -n)
|
||||
local_host=${local_host%%.*} # trim any domain from hostname
|
||||
fi
|
||||
|
||||
local_user="$(config local.user)"
|
||||
if [ -z "$local_user" ] ; then
|
||||
if [[ -z "$local_user" ]]; then
|
||||
local_user=$(id -u -n)
|
||||
fi
|
||||
|
||||
local_distro="$(query_distro)"
|
||||
local_distro_family="$(query_distro_family)"
|
||||
local_distro="$(config local.distro)"
|
||||
if [[ -z "$local_distro" ]]; then
|
||||
local_distro="$(query_distro)"
|
||||
fi
|
||||
|
||||
local_distro_family="$(config local.distro-family)"
|
||||
if [[ -z "$local_distro_family" ]]; then
|
||||
local_distro_family="$(query_distro_family)"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
@ -849,7 +856,7 @@ EOF
|
|||
function config() {
|
||||
|
||||
use_repo_config=0
|
||||
local_options="^local\.(class|arch|os|hostname|user)$"
|
||||
local_options="^local\.(class|arch|os|hostname|user|distro|distro-family)$"
|
||||
for option in "$@"; do
|
||||
[[ "$option" =~ $local_options ]] && use_repo_config=1
|
||||
done
|
||||
|
@ -1230,6 +1237,8 @@ function introspect_configs() {
|
|||
read -r -d '' msg <<-EOF
|
||||
local.arch
|
||||
local.class
|
||||
local.distro
|
||||
local.distro-family
|
||||
local.hostname
|
||||
local.os
|
||||
local.user
|
||||
|
|
16
yadm.1
16
yadm.1
|
@ -427,7 +427,7 @@ Disable the permission changes to
|
|||
This feature is enabled by default.
|
||||
|
||||
.RE
|
||||
The following five "local" configurations are not stored in the
|
||||
The following "local" configurations are not stored in the
|
||||
.IR $HOME/.config/yadm/config,
|
||||
they are stored in the local repository.
|
||||
|
||||
|
@ -452,6 +452,12 @@ Override the OS for the purpose of symlinking alternate files.
|
|||
.TP
|
||||
.B local.user
|
||||
Override the user for the purpose of symlinking alternate files.
|
||||
.TP
|
||||
.B local.distro
|
||||
Override the distro for the purpose of symlinking alternate files.
|
||||
.TP
|
||||
.B local.distro-family
|
||||
Override the distro family for the purpose of symlinking alternate files.
|
||||
|
||||
.SH ALTERNATES
|
||||
|
||||
|
@ -618,13 +624,15 @@ command. The following sets the class to be "Work".
|
|||
|
||||
yadm config local.class Work
|
||||
|
||||
Similarly, the values of architecture, os, hostname, and user can be manually
|
||||
overridden using the configuration options
|
||||
Similarly, the values of architecture, os, hostname, user, distro, and
|
||||
distro_family can be manually overridden using the configuration options
|
||||
.BR local.arch ,
|
||||
.BR local.os ,
|
||||
.BR local.hostname ,
|
||||
.BR local.user ,
|
||||
.BR local.distro ,
|
||||
and
|
||||
.BR local.user .
|
||||
.BR local.distro-family .
|
||||
|
||||
.SH TEMPLATES
|
||||
|
||||
|
|
Loading…
Reference in a new issue