Skip to content
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
74 changes: 74 additions & 0 deletions tests/prepare/artifact/install-cases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1
. ../../images.sh || exit 1
. ./lib/common.sh || exit 1

rlJournalStart
rlPhaseStartSetup "Prepare test environment"
rlRun "testdir=$(mktemp -d)" 0 "Create test directory"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Escape the $ in the mktemp command so that it is executed inside rlRun. This allows rlRun to properly check the exit status of mktemp and report a failure if it fails.

Suggested change
rlRun "testdir=$(mktemp -d)" 0 "Create test directory"
rlRun "testdir=\$(mktemp -d)" 0 "Create test directory"


build_rpms

rlRun "cp -a install-cases $testdir/data" 0 "Copy test data"
rlRun "cp -a rpms $testdir/data/" 0 "Copy rpms data"
rlRun "pushd $testdir/data" 0 "Enter test directory"
rlRun "run=$(mktemp -d)" 0 "Create run directory"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Remove this line as the run directory is now created uniquely per test case inside the loop.


setup_distro_environment
rlPhaseEnd

xfail_plans=(
"/verified-artifacts/pre-installed"
)

while IFS= read -r image; do
if ! is_fedora "$image" && ! is_centos "$image"; then
# Can only test rpm artifacts right now
continue
fi

extra_env=""
if is_centos_7 "$image"; then
extra_env="-e DNF_CMD=yum"
# TODO: centos7 is hard
continue
fi

if is_centos_stream_9 "$image" || is_centos_stream_10 "$image"; then
# TODO(#4941):
# dnf repoquery fails
# - Error: 'Package' object has no attribute 'full_nevra'
# - Or gives an output of
# 'bar':
# - nevra: '%{full_nevra}'
# repo_id: 'tmt-artifact-shared'
continue
fi

phase_prefix="$(test_phase_prefix $image)"

for plan in $(tmt plans ls); do
xfail=""
expected_result=0
for check_pattern in ${xfail_plans[@]}; do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Double quote the array expansion ${xfail_plans[@]} to prevent word splitting and globbing.

Suggested change
for check_pattern in ${xfail_plans[@]}; do
for check_pattern in "${xfail_plans[@]}"; do

if [[ "$plan" =~ $check_pattern ]]; then
xfail="(XFAIL)"
expected_result=2
break
fi
done
rlPhaseStartTest "$phase_prefix $plan $xfail"
rlRun "tmt run $extra_env -i $run --scratch -vvv --all \
plan --name $plan \
provision -h $PROVISION_HOW --image $image" \
$expected_result "Run test case $plan $xfail"
Comment on lines +60 to +64
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Create a unique run directory for each test case inside the loop to preserve logs for debugging. Reusing a single $run directory with --scratch sequentially overwrites the logs of previous runs, making it very difficult to debug failures.

Suggested change
rlPhaseStartTest "$phase_prefix $plan $xfail"
rlRun "tmt run $extra_env -i $run --scratch -vvv --all \
plan --name $plan \
provision -h $PROVISION_HOW --image $image" \
$expected_result "Run test case $plan $xfail"
rlRun "run_dir=\$(mktemp -d -p \"\$testdir\")" 0 "Create run directory"
rlPhaseStartTest "$phase_prefix $plan $xfail"
rlRun "tmt run $extra_env -i \$run_dir --scratch -vvv --all \
plan --name $plan \
provision -h $PROVISION_HOW --image $image" \
$expected_result "Run test case $plan $xfail"

rlPhaseEnd
done
done <<< "$IMAGES"


rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -rf $run $testdir" 0 "Remove temporary files directories"
rlPhaseEnd
rlJournalEnd
1 change: 1 addition & 0 deletions tests/prepare/artifact/install-cases/.fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
23 changes: 23 additions & 0 deletions tests/prepare/artifact/install-cases/available-artifacts/basic.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
summary: Basic case (non-verified)
description: |
System repo: foo-1.4 (baseline)
Pre-installed: None
Artifacts: foo-2.2 or foo-1.2

Normal installation case with an non-verified artifact available

/upgrade:
summary: " (upgrading)"
context+:
available_artifact: foo-2.2
environment+:
EXPECTED_PACKAGE: foo-2.2

/downgrade:
summary: " (downgrading)"
context+:
available_artifact: foo-1.2
environment+:
# TODO: This downgraded because of the forced artifact priority
# change this when the repo priority is opt-in
EXPECTED_PACKAGE: foo-1.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
summary: Pre-installed package present (non-verified)
description: |
System repo: foo-1.4 (baseline)
Pre-installed: foo-1.4
Artifacts: foo-2.2 or foo-1.2

Pre-installed package should be respected in this case

environment+:
PRE_INSTALLED_PACKAGE: rpms/foo-1.4/foo-1.4*.rpm

/upgrade:
summary: " (upgrading)"
context+:
available_artifact: foo-2.2
environment+:
EXPECTED_PACKAGE: foo-1.4

/downgrade:
summary: " (downgrading)"
context+:
available_artifact: foo-1.2
environment+:
EXPECTED_PACKAGE: foo-1.4
10 changes: 10 additions & 0 deletions tests/prepare/artifact/install-cases/baseline/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
summary: Baseline case
description: |
System repo: foo-1.4 (baseline)
Pre-installed: None
Artifacts: None

Normal installation case with no artifacts or anything special

environment+:
EXPECTED_PACKAGE: foo-1.4
56 changes: 56 additions & 0 deletions tests/prepare/artifact/install-cases/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
discover:
- how: fmf
test:
- /test
prepare:
- name: Setup system
order: 20
how: shell
script: |
# Prepare the system repo
mkdir system_repo
for pkg in $SYSTEM_PACKAGE; do
cp rpms/$pkg/*.rpm system_repo/
done

# Running dnf/createrepo commands manually to bypass prepare/install handling
$DNF_CMD install -y createrepo
createrepo system_repo
cat > /etc/yum.repos.d/system-test-repo.repo <<EOF
[system-test-repo]
baseurl=file://$(pwd)/system_repo
gpgcheck=0
EOF

# Install packages expected to be pre-installed (if any)
if [[ -n "$PRE_INSTALLED_PACKAGE" ]]; then
$DNF_CMD install -y $PRE_INSTALLED_PACKAGE
fi
- name: Main artifact to test and verify
order: 40
how: artifact
provide:
- file:rpms/$@{verified_artifact}/*.rpm
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Remove the leading $ from the fmf context interpolation syntax. The correct syntax is @{verified_artifact}.

      - file:rpms/@{verified_artifact}/*.rpm

verify: true
when: verified_artifact is defined
- name: Secondary artifacts made available (not verified)
order: 40
how: artifact
provide:
- file:rpms/$@{available_artifact}/*.rpm
verify: false
when: available_artifact is defined

execute:
how: tmt

context:
want_devel: "false"
with_bar: "false"
xfail: "false"
Comment on lines +47 to +50
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to lookup what want_devel means, it would be good to drop here some comments so it is explained what these context variables are intended for, would definitely help me at lesat for the first one.


environment:
SYSTEM_PACKAGE: foo-1.4
EXPECTED_PACKAGE: ""
PRE_INSTALLED_PACKAGE: ""
DNF_CMD: dnf
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we will be also later testing wiht yum? Would it not be better to prepare for that here now?

23 changes: 23 additions & 0 deletions tests/prepare/artifact/install-cases/no-artifacts/upgrade.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
summary: Newer version on system
description: |
System repo: foo-1.4 (baseline)
Pre-installed: foo-1.0
Artifacts: None

`foo` is pre-installed but we do not really want to upgrade it.

environment+:
EXPECTED_PACKAGE: foo-1.0
PRE_INSTALLED_PACKAGE: rpms/foo-1.0/foo-1.0*.rpm

/only-foo:
summary+: " (only foo requested)"

/with-bar:
summary+: " (foo and bar requested)"
description+: |
Installing another dependency (`bar`) should not upgrade `foo`.
context+:
with_bar: "true"
environment+:
SYSTEM_PACKAGE+: " bar"
17 changes: 17 additions & 0 deletions tests/prepare/artifact/install-cases/test.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/:
inherit: false

test: |
rpm -q $EXPECTED_PACKAGE
require:
- foo

adjust:
- when: want_devel == true
require:
- foo-devel
- when: with_bar == true
require+:
- bar
- when: xfail == true
result: xfail
21 changes: 21 additions & 0 deletions tests/prepare/artifact/install-cases/verified-artifacts/basic.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
summary: Basic case
description: |
System repo: foo-1.4 (baseline)
Pre-installed: None
Artifacts: foo-2.4 or foo-1.1

Normal installation case with an artifact

/upgrade:
summary: " (upgrading)"
context+:
verified_artifact: foo-2.4
environment+:
EXPECTED_PACKAGE: foo-2.4

/downgrade:
summary: " (downgrading)"
context+:
verified_artifact: foo-1.1
environment+:
EXPECTED_PACKAGE: foo-1.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
summary: Pre-installed package present
description: |
System repo: foo-1.4 (baseline)
Pre-installed: foo-1.4
Artifacts: foo-2.4 or foo-1.1

Pre-installed package should be ignored in this case

environment+:
PRE_INSTALLED_PACKAGE: rpms/foo-1.4/foo-1.4*.rpm
context+:
# Because presence check gets in the way.
# It should fail at verify phase and test execution.
xfail: "true"

/upgrade:
summary: " (upgrading)"
context+:
verified_artifact: foo-2.4
environment+:
EXPECTED_PACKAGE: foo-2.4

/downgrade:
summary: " (downgrading)"
context+:
verified_artifact: foo-1.1
environment+:
EXPECTED_PACKAGE: foo-1.1
6 changes: 6 additions & 0 deletions tests/prepare/artifact/main.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ order: 60
Test that the verify-installation phase is injected
when verify=true (default) and suppressed when verify=false.
test: ./verify-installation.sh

/install-cases:
summary: Test installation scenarios
description: |
See the plans in `install-cases` for more details.
test: ./install-cases.sh
20 changes: 20 additions & 0 deletions tests/prepare/artifact/rpms/foo-1.0/foo.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Name: foo
Version: 1.0
Release: 1
BuildArch: noarch
Summary: Main test package
License: none

%description
Pre-installed version, lower than current system package (foo-1.4)

%files

%package devel
Summary: Main test sub-package
Requires: foo-%{version} == %{version}-%{release}

%description devel
Version locked sub-package

%files devel
23 changes: 23 additions & 0 deletions tests/prepare/artifact/rpms/foo-1.1-bad/foo.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Name: foo
Version: 1.1
Release: 1
BuildArch: noarch
Summary: Main test package
License: none

# Arbitrary broken dependency at install time
Requires: some-non-existent-package

%description
Older version in verified artifacts (Broken)

%files

%package devel
Summary: Main test sub-package
Requires: foo-%{version} == %{version}-%{release}

%description devel
Version locked sub-package

%files devel
20 changes: 20 additions & 0 deletions tests/prepare/artifact/rpms/foo-1.1/foo.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Name: foo
Version: 1.1
Release: 1
BuildArch: noarch
Summary: Main test package
License: none

%description
Older version in verified artifacts

%files

%package devel
Summary: Main test sub-package
Requires: foo-%{version} == %{version}-%{release}

%description devel
Version locked sub-package

%files devel
23 changes: 23 additions & 0 deletions tests/prepare/artifact/rpms/foo-1.2-bad/foo.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Name: foo
Version: 1.2
Release: 1
BuildArch: noarch
Summary: Main test package
License: none

# Arbitrary broken dependency at install time
Requires: some-non-existent-package

%description
Older version (not verified, Broken)

%files

%package devel
Summary: Main test sub-package
Requires: foo-%{version} == %{version}-%{release}

%description devel
Version locked sub-package

%files devel
Loading
Loading