selftest: Add basic test framework
Now, by execute `make test-run` in tests/, kexec-tools sanity tests
will be performed using VMs. There are currently 3 test cases, for local
kdump, nfs kdump and ssh kdump.
For each test VM, the selftest framework will create a snapshot layer,
do setup as required by the test case, this ensure each test runs in a
clean VM.
This framework will install a custom systemd service that starts when
system have finished booting, and the service will do basic routine
(fetch and set boot counter, etc..), then call the test case which is
installed in /kexec-kdump-test/test.sh in VM.
Each VM will have two serial consoles, one for ordinary console usage,
one for the test communication and log. The test script will watch the
second test console to know the test status.
The test cases are located in tests/scripts/testcases, documents about
the test cases structure will be provided in following commits.
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
2020-07-31 07:34:40 +00:00
|
|
|
TEST_CASE ?=
|
selftest: Add basic infrastructure to build test image
The Makefile In tests/ could help build a VM image using Fedora cloud
image as base image, or, user can specify a base image using
BASE_IMAGE=<path/to/file>. The current repo will be packeged and
installed in the image, so the image could be used as a test image to
test kexec-tools.
The image building is splited into two steps:
The first step, it either convert the base image to qcow2 or create
a snapshot on it, and install basic packages (dracut, grubby, ...)
and do basic setups (setup crashkernel=, disable selinux, ...).
See tests/scripts/build-scripts/base-image.sh for detail.
The second step, it creates a snapshot on top of the image produced by
the previous step, and install the packaged kexec-tools of current
repo. See tests/scripts/build-scripts/test-base-image.sh for detail.
In this way, if repo's content is changes, `make` will detect it and
only rebuild the second snapshot which speed up the rebuild by a lot.
The image will be located as tests/output/test-base-image, and in qcow2
format. And default user/password is set to root/fedora.
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
2020-07-31 07:34:39 +00:00
|
|
|
BASE_IMAGE ?=
|
|
|
|
|
|
|
|
TEST_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
|
|
|
BUILD_ROOT := $(TEST_ROOT)/build
|
|
|
|
REPO = $(shell realpath $(TEST_ROOT)/../)
|
|
|
|
ARCH ?= $(shell arch)
|
|
|
|
SPEC = kexec-tools.spec
|
|
|
|
|
|
|
|
DIST ?= fedora
|
|
|
|
DIST_ABR ?= f
|
|
|
|
DIST_ABRL ?= fc
|
|
|
|
DIST_UNSET ?= rhel
|
|
|
|
RELEASE ?= 32
|
|
|
|
|
|
|
|
DEFAULT_BASE_IMAGE_VER ?= 1.6
|
|
|
|
DEFAULT_BASE_IMAGE ?= Fedora-Cloud-Base-$(RELEASE)-$(DEFAULT_BASE_IMAGE_VER).$(ARCH).raw.xz
|
|
|
|
DEFAULT_BASE_IMAGE_URL ?= https://dl.fedoraproject.org/pub/fedora/linux/releases/$(RELEASE)/Cloud/$(ARCH)/images/$(DEFAULT_BASE_IMAGE)
|
|
|
|
|
|
|
|
BUILD_ROOT = $(TEST_ROOT)/build
|
|
|
|
RPMDEFINE = --define '_sourcedir $(REPO)'\
|
|
|
|
--define '_specdir $(REPO)'\
|
|
|
|
--define '_builddir $(BUILD_ROOT)'\
|
|
|
|
--define '_srcrpmdir $(BUILD_ROOT)'\
|
|
|
|
--define '_rpmdir $(BUILD_ROOT)'\
|
|
|
|
--define 'dist %{?distprefix}.$(DIST_ABRL)$(RELEASE)'\
|
|
|
|
--define '$(DIST) $(RELEASE)'\
|
|
|
|
--eval '%undefine $(DIST_UNSET)'\
|
|
|
|
--define '$(DIST_ABRL)$(RELEASE) 1'\
|
|
|
|
|
|
|
|
KEXEC_TOOLS_SRC = $(filter-out $(REPO)/tests,$(wildcard $(REPO)/*))
|
|
|
|
KEXEC_TOOLS_TEST_SRC = $(wildcard $(REPO)/tests/scripts/**/*)
|
|
|
|
KEXEC_TOOLS_NVR = $(shell rpm $(RPMDEFINE) -q --specfile $(REPO)/$(SPEC) 2>/dev/null | grep -m 1 .)
|
|
|
|
KEXEC_TOOLS_RPM = $(BUILD_ROOT)/$(ARCH)/$(KEXEC_TOOLS_NVR).rpm
|
|
|
|
|
|
|
|
all: $(TEST_ROOT)/output/test-base-image
|
|
|
|
|
|
|
|
# Use either:
|
|
|
|
# fedpkg --release $(DIST_ABR)$(RELEASE) --path ../../ local
|
|
|
|
# or
|
|
|
|
# rpmbuild $(RPMDEFINE) -ba $(REPO)/$(SPEC)
|
|
|
|
# to rebuild the rpm, currently use rpmbuild to have better control over the rpm building process
|
|
|
|
#
|
|
|
|
$(KEXEC_TOOLS_RPM): $(KEXEC_TOOLS_SRC)
|
|
|
|
sh -c "cd .. && fedpkg sources"
|
|
|
|
@echo Rebuilding RPM due to modification of sources: $?
|
|
|
|
rpmbuild $(RPMDEFINE) -ba $(REPO)/$(SPEC)
|
|
|
|
|
|
|
|
$(BUILD_ROOT)/base-image:
|
|
|
|
mkdir -p $(BUILD_ROOT)
|
|
|
|
ifeq ($(strip $(BASE_IMAGE)),)
|
|
|
|
wget $(DEFAULT_BASE_IMAGE_URL) -O $(BUILD_ROOT)/$(DEFAULT_BASE_IMAGE)
|
|
|
|
$(TEST_ROOT)/scripts/build-image.sh \
|
|
|
|
$(BUILD_ROOT)/$(DEFAULT_BASE_IMAGE)\
|
|
|
|
$(BUILD_ROOT)/base-image
|
|
|
|
else
|
|
|
|
$(TEST_ROOT)/scripts/build-image.sh \
|
|
|
|
$(BASE_IMAGE)\
|
|
|
|
$(BUILD_ROOT)/base-image
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(BUILD_ROOT)/inst-base-image: $(BUILD_ROOT)/base-image
|
|
|
|
@echo "Building installation base image"
|
|
|
|
echo $(KEXEC_TOOLS_NVR)
|
|
|
|
$(TEST_ROOT)/scripts/build-image.sh \
|
|
|
|
$(BUILD_ROOT)/base-image \
|
|
|
|
$(BUILD_ROOT)/inst-base-image \
|
|
|
|
$(TEST_ROOT)/scripts/build-scripts/base-image.sh
|
|
|
|
|
|
|
|
$(TEST_ROOT)/output/test-base-image: $(BUILD_ROOT)/inst-base-image $(KEXEC_TOOLS_RPM) $(KEXEC_TOOLS_TEST_SRC)
|
|
|
|
@echo "Building test base image"
|
|
|
|
mkdir -p $(TEST_ROOT)/output
|
|
|
|
$(TEST_ROOT)/scripts/build-image.sh \
|
|
|
|
$(BUILD_ROOT)/inst-base-image \
|
|
|
|
$(TEST_ROOT)/output/test-base-image \
|
|
|
|
$(TEST_ROOT)/scripts/build-scripts/test-base-image.sh \
|
|
|
|
$(KEXEC_TOOLS_RPM)
|
|
|
|
|
selftest: Add basic test framework
Now, by execute `make test-run` in tests/, kexec-tools sanity tests
will be performed using VMs. There are currently 3 test cases, for local
kdump, nfs kdump and ssh kdump.
For each test VM, the selftest framework will create a snapshot layer,
do setup as required by the test case, this ensure each test runs in a
clean VM.
This framework will install a custom systemd service that starts when
system have finished booting, and the service will do basic routine
(fetch and set boot counter, etc..), then call the test case which is
installed in /kexec-kdump-test/test.sh in VM.
Each VM will have two serial consoles, one for ordinary console usage,
one for the test communication and log. The test script will watch the
second test console to know the test status.
The test cases are located in tests/scripts/testcases, documents about
the test cases structure will be provided in following commits.
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
2020-07-31 07:34:40 +00:00
|
|
|
test-run: $(TEST_ROOT)/output/test-base-image
|
|
|
|
ifeq ($(strip $(TEST_CASE)),)
|
|
|
|
$(TEST_ROOT)/scripts/run-test.sh
|
|
|
|
else
|
|
|
|
$(TEST_ROOT)/scripts/run-test.sh --console $(TEST_CASE)
|
|
|
|
endif
|
|
|
|
|
selftest: Add basic infrastructure to build test image
The Makefile In tests/ could help build a VM image using Fedora cloud
image as base image, or, user can specify a base image using
BASE_IMAGE=<path/to/file>. The current repo will be packeged and
installed in the image, so the image could be used as a test image to
test kexec-tools.
The image building is splited into two steps:
The first step, it either convert the base image to qcow2 or create
a snapshot on it, and install basic packages (dracut, grubby, ...)
and do basic setups (setup crashkernel=, disable selinux, ...).
See tests/scripts/build-scripts/base-image.sh for detail.
The second step, it creates a snapshot on top of the image produced by
the previous step, and install the packaged kexec-tools of current
repo. See tests/scripts/build-scripts/test-base-image.sh for detail.
In this way, if repo's content is changes, `make` will detect it and
only rebuild the second snapshot which speed up the rebuild by a lot.
The image will be located as tests/output/test-base-image, and in qcow2
format. And default user/password is set to root/fedora.
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
2020-07-31 07:34:39 +00:00
|
|
|
clean:
|
|
|
|
rm -rf $(TEST_ROOT)/build
|
|
|
|
rm -rf $(TEST_ROOT)/output
|