Skip to content

Commit

Permalink
build CONTEST_CONTENT in a TMT plan prepare step
Browse files Browse the repository at this point in the history
This is because building takes a long time (10+ minutes) on some
slow systems and that easily exceeds a 5/10 minute 'duration'
of a small test that never anticipated the extra delay.

Moving it to a plan moves it outside the 'duration' count.

Also, it's probably a better central place given that all tests
always share the built content so the ./build_product options
have to be considered globally.

Finally, this is not a great fix given that we are still left
with the 'build' argument to get_content(),

    def get_content(build=True):
        ...

and its SRPM-based building code, which still runs within test
'duration', however there is no easy solution for that (other than
getting rid of SRPM support entirely), so this commit at least
tries to bump things in a right direction.

Signed-off-by: Jiri Jaburek <[email protected]>
  • Loading branch information
comps committed Aug 30, 2024
1 parent 2c376e4 commit 8c16a4d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
19 changes: 1 addition & 18 deletions lib/util/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def _find_datastreams(force_ssg):
return ssg_path
# if CONTEST_CONTENT was specified
if user_content:
build_content(user_content)
return user_content / 'build'
# default to the OS-wide scap-security-guide content
return ssg_path
Expand Down Expand Up @@ -53,7 +52,6 @@ def _find_playbooks(force_ssg):
return ssg_path
# if CONTEST_CONTENT was specified
if user_content:
build_content(user_content)
return user_content / 'build' / 'ansible'
# default to the OS-wide scap-security-guide content
return ssg_path
Expand All @@ -66,7 +64,6 @@ def _find_per_rule_playbooks(force_ssg):
return ssg_path
# if CONTEST_CONTENT was specified
if user_content:
build_content(user_content)
return user_content / 'build' / f'rhel{rhel.major}' / 'playbooks' / 'all'
# default to the OS-wide scap-security-guide content
return ssg_path
Expand Down Expand Up @@ -97,7 +94,6 @@ def iter_playbooks(force_ssg=False):

def get_kickstart(profile):
if user_content:
build_content(user_content)
kickstart = (
user_content / 'products' / f'rhel{rhel.major}' / 'kickstart'
/ f'ssg-rhel{rhel.major}-{profile}-ks.cfg'
Expand All @@ -115,18 +111,6 @@ def content_is_built(path):
return (Path(path) / 'build' / f'ssg-rhel{rhel.major}-ds.xml').exists()


def build_content(path):
if content_is_built(path):
return
util.log(f"building content from source in {path}")
# install dependencies
cmd = ['dnf', '-y', 'builddep', '--spec', 'scap-security-guide.spec']
util.subprocess_run(cmd, check=True, cwd=path)
# build content
cmd = ['./build_product', '--playbook-per-rule', f'rhel{rhel.major}']
util.subprocess_run(cmd, check=True, cwd=path)


@contextlib.contextmanager
def get_content(build=True):
"""
Expand All @@ -137,8 +121,7 @@ def get_content(build=True):
plain files or executing utils and need just the content source.
"""
if user_content:
if build:
build_content(user_content)
# content already built by a TMT plan prepare step
yield user_content
else:
# fall back to SRPM
Expand Down
3 changes: 0 additions & 3 deletions main.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ recommend:
- python36-pyyaml
- python3-rpm
- python36-rpm
# these are needed for CONTEST_CONTENT or get_content():
# - builddep on scap-security-guide.spec
- python-srpm-macros
# - preparing/patching downloaded SRPM
- rpm-build
component:
Expand Down
18 changes: 18 additions & 0 deletions plans/main.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ execute:
adjust:
- prepare+:
- how: install
name: Install dependencies for further prepare steps
package:
# for git-fetch downloading of CONTEST_CONTENT_*
- git-core
# for building CONTEST_CONTENT
- python-srpm-macros

- prepare+:
- how: shell
name: Download and build latest or pull request content
script: |
Expand All @@ -33,6 +39,18 @@ adjust:
git checkout FETCH_HEAD
fi
echo "CONTEST_CONTENT=$content_dir" >> "$TMT_PLAN_ENVIRONMENT_FILE"
- how: shell
name: Build CONTEST_CONTENT (if specified)
script: |
set -xe
. "$TMT_PLAN_ENVIRONMENT_FILE" # not done automatically
[ -z "$CONTEST_CONTENT" ] && exit 0
cd "$CONTEST_CONTENT"
major=$(. /etc/os-release && echo "${VERSION_ID%%.*}")
# already built
[ -e "build/ssg-rhel${major}-ds.xml" ] && exit 0
dnf -y builddep --spec scap-security-guide.spec
./build_product --playbook-per-rule "rhel${major}"
- prepare+:
- how: shell
Expand Down

0 comments on commit 8c16a4d

Please sign in to comment.