From 1c32f2585fa8c4e8a0f104c2dcded8f2c50fd903 Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Wed, 17 Jan 2024 09:29:54 +0100 Subject: [PATCH 1/7] test: add support for running using tmt Remove dependency on beakerlib for distros other than Fedora. Tests will be executed using tmt and tf on CentOS Stream and RHEL. --- .fmf/README.md | 3 +++ .fmf/version | 1 + Makefile | 2 +- chkconfig.spec | 11 ++++++++++- plans/main.fmf | 5 +++++ tests/alternatives/main.fmf | 13 +++++++++++++ .../alternatives/test-alternatives.sh | 15 ++++++++------- 7 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 .fmf/README.md create mode 100644 .fmf/version create mode 100644 plans/main.fmf create mode 100644 tests/alternatives/main.fmf rename test-alternatives.sh => tests/alternatives/test-alternatives.sh (90%) diff --git a/.fmf/README.md b/.fmf/README.md new file mode 100644 index 00000000..f230b6f6 --- /dev/null +++ b/.fmf/README.md @@ -0,0 +1,3 @@ +# fmf + +Flexible Metadata Format ([doc](https://fmf.readthedocs.io/en/stable/overview.html#description)) diff --git a/.fmf/version b/.fmf/version new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/Makefile b/Makefile index 0e7abd82..99f9166a 100644 --- a/Makefile +++ b/Makefile @@ -78,7 +78,7 @@ install: done && test -z "$$fail" check: alternatives - ./test-alternatives.sh + TEST_PATH=./ ./tests/alternatives/test-alternatives.sh tag: @git tag -a -m "Tag as $(TAG)" -f $(TAG) diff --git a/chkconfig.spec b/chkconfig.spec index 952d0077..88a79f51 100644 --- a/chkconfig.spec +++ b/chkconfig.spec @@ -5,7 +5,13 @@ Release: 1%{?dist} License: GPL-2.0-only URL: https://github.com/fedora-sysv/chkconfig Source: https://github.com/fedora-sysv/chkconfig/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz -BuildRequires: newt-devel gettext popt-devel libselinux-devel beakerlib gcc systemd-devel make + +BuildRequires: newt-devel gettext popt-devel libselinux-devel gcc systemd-devel make +# beakerlib might not be available on CentOS Stream any more +%if 0%{?fedora} +BuildRequires: beakerlib +%endif + Conflicts: initscripts <= 5.30-1 Provides: /sbin/chkconfig @@ -42,8 +48,11 @@ system at the same time. %build %make_build RPM_OPT_FLAGS="$RPM_OPT_FLAGS" LDFLAGS="$RPM_LD_FLAGS" +# tests are executed using tmt and tf on CentOS Stream and RHEL +%if 0%{?fedora} %check make check +%endif %install rm -rf $RPM_BUILD_ROOT diff --git a/plans/main.fmf b/plans/main.fmf new file mode 100644 index 00000000..cc2dfb55 --- /dev/null +++ b/plans/main.fmf @@ -0,0 +1,5 @@ +summary: Tests +discover: + how: fmf +execute: + how: tmt diff --git a/tests/alternatives/main.fmf b/tests/alternatives/main.fmf new file mode 100644 index 00000000..ebeb7ae0 --- /dev/null +++ b/tests/alternatives/main.fmf @@ -0,0 +1,13 @@ +summary: Alternatives integration tests +component: alternatives +framework: beakerlib +contact: Jan Macku +tier: 1 +require: + - gcc + - gettext + - libselinux-devel + - make + - newt-devel + - popt-devel +test: ./test-alternatives.sh diff --git a/test-alternatives.sh b/tests/alternatives/test-alternatives.sh similarity index 90% rename from test-alternatives.sh rename to tests/alternatives/test-alternatives.sh index ac6edb7c..7465e389 100755 --- a/test-alternatives.sh +++ b/tests/alternatives/test-alternatives.sh @@ -7,7 +7,8 @@ TEST="Test Alternatives" # Package being tested -PACKAGE="chkconfig" +PACKAGE="alternatives" +TEST_BIN="${TEST_PATH}${PACKAGE}" # We need to test both new "leader/follower" and legacy "master/slave" options FOLLOWER_OR_SLAVE="follower" @@ -43,7 +44,7 @@ function add_alternative { spath="${testdir}/$1/$follower" touch ${spath} - rlRun "./alternatives --altdir ${altdir} --admindir ${admindir} --install ${link} ${name} ${path} ${prio} --${FOLLOWER_OR_SLAVE} ${slink} ${sname} ${spath} ${family}" 0 "NEW\tlink: $1\tPrio: $prio\tFamily: $3" + rlRun "${TEST_BIN} --altdir ${altdir} --admindir ${admindir} --install ${link} ${name} ${path} ${prio} --${FOLLOWER_OR_SLAVE} ${slink} ${sname} ${spath} ${family}" 0 "NEW\tlink: $1\tPrio: $prio\tFamily: $3" } function remove_alternative { @@ -51,13 +52,13 @@ function remove_alternative { rm ${testdir}/$1/* rmdir ${testdir}/$1 - rlRun "./alternatives --altdir ${altdir} --admindir ${admindir} --remove ${name} ${path}" 0 "REMOVE\tlink: $1" + rlRun "${TEST_BIN} --altdir ${altdir} --admindir ${admindir} --remove ${name} ${path}" 0 "REMOVE\tlink: $1" } function set_alternative { path="${testdir}/$1/main" - rlRun "./alternatives --altdir ${altdir} --admindir ${admindir} --set ${name} ${path}" 0 "SET\tlink: $1" + rlRun "${TEST_BIN} --altdir ${altdir} --admindir ${admindir} --set ${name} ${path}" 0 "SET\tlink: $1" } function add_follower { @@ -69,7 +70,7 @@ function add_follower { spath="${testdir}/$1/$follower" touch ${spath} - rlRun "./alternatives --altdir ${altdir} --admindir ${admindir} --add-${FOLLOWER_OR_SLAVE} ${name} ${path} ${slink} ${sname} ${spath}" 0 "NEW_FOLLOWER\tlink: $spath" + rlRun "${TEST_BIN} --altdir ${altdir} --admindir ${admindir} --add-${FOLLOWER_OR_SLAVE} ${name} ${path} ${slink} ${sname} ${spath}" 0 "NEW_FOLLOWER\tlink: $spath" } function remove_follower { @@ -78,7 +79,7 @@ function remove_follower { touch $path [ -n "$2" ] && follower=${2} - rlRun "./alternatives --altdir ${altdir} --admindir ${admindir} --remove-${FOLLOWER_OR_SLAVE} ${name} ${path} ${sname}" 0 "NEW_FOLLOWER\tlink: $spath" + rlRun "${TEST_BIN} --altdir ${altdir} --admindir ${admindir} --remove-${FOLLOWER_OR_SLAVE} ${name} ${path} ${sname}" 0 "NEW_FOLLOWER\tlink: $spath" } function check_alternative { @@ -103,7 +104,7 @@ function check_alternative { cur_path=$(readlink ${altdir}/${name} | xargs dirname | xargs basename) cur_state=$(head -1 ${admindir}/${name}) - cur_best=$(LC_ALL=C ./alternatives --altdir ${altdir} --admindir ${admindir} --display TEST | grep best | cut -d " " -f5 | sed -e 's/\.$//' | xargs dirname | xargs basename) + cur_best=$(LC_ALL=C ${TEST_BIN} --altdir "${altdir}" --admindir "${admindir}" --display TEST | grep best | cut -d " " -f5 | sed -e 's/\.$//' | xargs dirname | xargs basename) cur_spath=$(readlink ${altdir}/${sname} | xargs basename) echo $cur_spath rlAssertEquals "Mode:" "${state}" "${cur_state}" From be239f5c932ddc5fe9f94c5c0af3a0078bee1714 Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Wed, 17 Jan 2024 09:30:20 +0100 Subject: [PATCH 2/7] ci: fix typo in test workflow --- .github/workflows/integration_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index cd54329d..3cd512cd 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -31,7 +31,7 @@ jobs: run: shell: bash - needs: buildcheck + needs: buildCheck steps: - name: Repository checkout From 8f0a713a0208a0e551db548bf5722900ab2cdc85 Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Wed, 17 Jan 2024 09:30:47 +0100 Subject: [PATCH 3/7] build: update `.pot` file --- po/chkconfig.pot | 121 ++++++++++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 58 deletions(-) diff --git a/po/chkconfig.pot b/po/chkconfig.pot index abc4d902..a31f5ce3 100644 --- a/po/chkconfig.pot +++ b/po/chkconfig.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-23 13:27+0100\n" +"POT-Creation-Date: 2024-01-09 12:58+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -325,254 +325,259 @@ msgstr "" msgid " --altdir --admindir \n" msgstr "" -#: ../alternatives.c:292 +#: ../alternatives.c:293 #, c-format msgid "reading %s\n" msgstr "" -#: ../alternatives.c:297 +#: ../alternatives.c:298 #, c-format msgid "failed to open %s: %s\n" msgstr "" -#: ../alternatives.c:305 +#: ../alternatives.c:306 #, c-format msgid "failed to read %s: %s\n" msgstr "" -#: ../alternatives.c:313 +#: ../alternatives.c:314 #, c-format msgid "%s empty!\n" msgstr "" -#: ../alternatives.c:322 +#: ../alternatives.c:323 #, c-format msgid "bad mode on line 1 of %s\n" msgstr "" -#: ../alternatives.c:329 +#: ../alternatives.c:330 #, c-format msgid "bad primary link in %s\n" msgstr "" -#: ../alternatives.c:341 +#: ../alternatives.c:342 #, c-format msgid "path %s unexpected in %s\n" msgstr "" -#: ../alternatives.c:350 +#: ../alternatives.c:351 #, c-format msgid "missing path for follower %s in %s\n" msgstr "" -#: ../alternatives.c:360 +#: ../alternatives.c:361 #, c-format msgid "unexpected end of file in %s\n" msgstr "" -#: ../alternatives.c:369 +#: ../alternatives.c:370 #, c-format msgid "path to alternate expected in %s\n" msgstr "" -#: ../alternatives.c:370 ../alternatives.c:396 ../alternatives.c:408 -#: ../alternatives.c:426 ../alternatives.c:446 +#: ../alternatives.c:371 ../alternatives.c:397 ../alternatives.c:409 +#: ../alternatives.c:427 ../alternatives.c:447 #, c-format msgid "unexpected line in %s: %s\n" msgstr "" -#: ../alternatives.c:394 +#: ../alternatives.c:395 #, c-format msgid "closing '@' missing or the family is empty in %s\n" msgstr "" -#: ../alternatives.c:407 +#: ../alternatives.c:408 #, c-format msgid "numeric priority expected in %s\n" msgstr "" -#: ../alternatives.c:425 +#: ../alternatives.c:426 #, c-format msgid "follower path expected in %s\n" msgstr "" -#: ../alternatives.c:454 +#: ../alternatives.c:456 #, c-format msgid "failed to read link %s: %s\n" msgstr "" -#: ../alternatives.c:470 +#: ../alternatives.c:472 #, c-format msgid "link points to no alternative -- setting mode to manual\n" msgstr "" -#: ../alternatives.c:475 +#: ../alternatives.c:477 #, c-format msgid "link changed -- setting mode to manual\n" msgstr "" -#: ../alternatives.c:512 ../alternatives.c:519 +#: ../alternatives.c:517 ../alternatives.c:524 #, c-format msgid "would remove %s\n" msgstr "" -#: ../alternatives.c:514 ../alternatives.c:523 ../alternatives.c:570 +#: ../alternatives.c:519 ../alternatives.c:528 ../alternatives.c:581 #, c-format msgid "failed to remove link %s: %s\n" msgstr "" -#: ../alternatives.c:541 ../alternatives.c:563 +#: ../alternatives.c:547 #, c-format -msgid "would link %s -> %s\n" +msgid "failed to link %s -> %s: %s exists and it is not a symlink\n" msgstr "" -#: ../alternatives.c:550 ../alternatives.c:576 +#: ../alternatives.c:552 #, c-format -msgid "failed to link %s -> %s: %s\n" +msgid "" +"failed to link %s -> %s: --keep-foreign was set and link %s points outside " +"%s\n" msgstr "" -#: ../alternatives.c:559 +#: ../alternatives.c:556 ../alternatives.c:574 #, c-format -msgid "" -"failed to link %s -> %s: %s exists and it is either not a symlink or --keep-" -"foreign was set and link points outside %s\n" +msgid "would link %s -> %s\n" +msgstr "" + +#: ../alternatives.c:565 ../alternatives.c:587 +#, c-format +msgid "failed to link %s -> %s: %s\n" msgstr "" -#: ../alternatives.c:609 +#: ../alternatives.c:620 #, c-format msgid "%s already exists\n" msgstr "" -#: ../alternatives.c:611 +#: ../alternatives.c:622 #, c-format msgid "failed to create %s: %s\n" msgstr "" -#: ../alternatives.c:644 +#: ../alternatives.c:655 #, c-format msgid "failed to replace %s with %s: %s\n" msgstr "" -#: ../alternatives.c:672 ../alternatives.c:678 ../alternatives.c:690 -#: ../alternatives.c:697 +#: ../alternatives.c:683 ../alternatives.c:689 ../alternatives.c:701 +#: ../alternatives.c:708 #, c-format msgid "running %s\n" msgstr "" -#: ../alternatives.c:770 +#: ../alternatives.c:781 #, c-format msgid "link %s incorrect for follower %s (%s %s)\n" msgstr "" -#: ../alternatives.c:844 ../alternatives.c:881 ../alternatives.c:1095 -#: ../alternatives.c:1126 +#: ../alternatives.c:855 ../alternatives.c:892 ../alternatives.c:1106 +#: ../alternatives.c:1137 #, c-format msgid "%s has not been configured as an alternative for %s\n" msgstr "" -#: ../alternatives.c:862 +#: ../alternatives.c:873 #, c-format msgid "%s has not been configured as an follower alternative for %s (%s)\n" msgstr "" -#: ../alternatives.c:920 +#: ../alternatives.c:931 #, c-format msgid "the primary link for %s must be %s\n" msgstr "" -#: ../alternatives.c:972 +#: ../alternatives.c:983 #, c-format msgid "%s - status is auto.\n" msgstr "" -#: ../alternatives.c:974 +#: ../alternatives.c:985 #, c-format msgid "%s - status is manual.\n" msgstr "" -#: ../alternatives.c:976 +#: ../alternatives.c:987 #, c-format msgid " link currently points to %s\n" msgstr "" -#: ../alternatives.c:981 +#: ../alternatives.c:992 #, c-format msgid "family %s " msgstr "" -#: ../alternatives.c:982 +#: ../alternatives.c:993 #, c-format msgid "priority %d\n" msgstr "" -#: ../alternatives.c:984 +#: ../alternatives.c:995 #, c-format msgid " follower %s: %s\n" msgstr "" -#: ../alternatives.c:989 +#: ../alternatives.c:1000 #, c-format msgid "Current `best' version is %s.\n" msgstr "" -#: ../alternatives.c:1024 +#: ../alternatives.c:1035 #, c-format msgid "There is %d program that provides '%s'.\n" msgstr "" -#: ../alternatives.c:1025 +#: ../alternatives.c:1036 #, c-format msgid "There are %d programs which provide '%s'.\n" msgstr "" -#: ../alternatives.c:1029 +#: ../alternatives.c:1040 #, c-format msgid " Selection Command\n" msgstr "" -#: ../alternatives.c:1044 +#: ../alternatives.c:1055 #, c-format msgid "Enter to keep the current selection[+], or type selection number: " msgstr "" -#: ../alternatives.c:1048 +#: ../alternatives.c:1059 #, c-format msgid "" "\n" "error reading choice\n" msgstr "" -#: ../alternatives.c:1075 +#: ../alternatives.c:1086 #, c-format msgid "cannot access %s/%s: No such file or directory\n" msgstr "" -#: ../alternatives.c:1142 +#: ../alternatives.c:1153 #, c-format msgid "(would remove %s\n" msgstr "" -#: ../alternatives.c:1144 +#: ../alternatives.c:1155 #, c-format msgid "failed to remove %s: %s\n" msgstr "" -#: ../alternatives.c:1312 +#: ../alternatives.c:1323 #, c-format msgid "--family can't contain the symbol '@'\n" msgstr "" -#: ../alternatives.c:1374 +#: ../alternatives.c:1385 #, c-format msgid "altdir %s invalid\n" msgstr "" -#: ../alternatives.c:1379 +#: ../alternatives.c:1390 #, c-format msgid "admindir %s invalid\n" msgstr "" -#: ../alternatives.c:1389 +#: ../alternatives.c:1400 #, c-format msgid "alternatives version %s\n" msgstr "" From 607dcd6b9cd80d14488fa3bd4a8c8a696773e566 Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Wed, 17 Jan 2024 13:07:52 +0100 Subject: [PATCH 4/7] ci: run tests using Packit and Testing Farm --- .packit.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.packit.yml b/.packit.yml index 05d8eda6..9b817d01 100644 --- a/.packit.yml +++ b/.packit.yml @@ -9,3 +9,8 @@ jobs: trigger: pull_request targets: - fedora-all + + - job: tests + trigger: pull_request + targets: + - fedora-all From 9704885bc2119ec4ac885f95e23b2e6851837578 Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Wed, 17 Jan 2024 13:54:04 +0100 Subject: [PATCH 5/7] fix(test): remove dangling `rlPhase` fn call --- tests/alternatives/test-alternatives.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/alternatives/test-alternatives.sh b/tests/alternatives/test-alternatives.sh index 7465e389..e4b7627b 100755 --- a/tests/alternatives/test-alternatives.sh +++ b/tests/alternatives/test-alternatives.sh @@ -306,8 +306,6 @@ rlJournalStart check_alternative link_a auto EMPTY clean_dir rlPhaseEnd - - rlPhase done # Cleanup phase: Remove test directory From 9b3e3475127eaec896700128a264a3bbfe9b5390 Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Wed, 17 Jan 2024 13:58:40 +0100 Subject: [PATCH 6/7] spec: sort BuildRequires alphabetically --- chkconfig.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chkconfig.spec b/chkconfig.spec index 88a79f51..d646166a 100644 --- a/chkconfig.spec +++ b/chkconfig.spec @@ -6,7 +6,7 @@ License: GPL-2.0-only URL: https://github.com/fedora-sysv/chkconfig Source: https://github.com/fedora-sysv/chkconfig/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz -BuildRequires: newt-devel gettext popt-devel libselinux-devel gcc systemd-devel make +BuildRequires: gcc gettext libselinux-devel make newt-devel popt-devel systemd-devel # beakerlib might not be available on CentOS Stream any more %if 0%{?fedora} BuildRequires: beakerlib From e9d46eb3bc6a92ffc555c6e539464d8b4f9fde9a Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Wed, 17 Jan 2024 14:35:07 +0100 Subject: [PATCH 7/7] fix(test): dot't call `basename` with empty string --- tests/alternatives/test-alternatives.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/alternatives/test-alternatives.sh b/tests/alternatives/test-alternatives.sh index e4b7627b..e182db69 100755 --- a/tests/alternatives/test-alternatives.sh +++ b/tests/alternatives/test-alternatives.sh @@ -105,7 +105,9 @@ function check_alternative { cur_path=$(readlink ${altdir}/${name} | xargs dirname | xargs basename) cur_state=$(head -1 ${admindir}/${name}) cur_best=$(LC_ALL=C ${TEST_BIN} --altdir "${altdir}" --admindir "${admindir}" --display TEST | grep best | cut -d " " -f5 | sed -e 's/\.$//' | xargs dirname | xargs basename) - cur_spath=$(readlink ${altdir}/${sname} | xargs basename) + cur_spath="" + # basename fails if the path is empty + [ ! "$1" = EMPTY ] && cur_spath=$(readlink "${altdir}/${sname}" | xargs basename) echo $cur_spath rlAssertEquals "Mode:" "${state}" "${cur_state}" rlAssertEquals "Highest Priority:" "${best}" "${cur_best}"