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