2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-10-12 08:12:33 +00:00
Files
xcat-core/xCAT-test/xCAT-test.spec
T
Daniel Hilst 008f83d2e4 test(xCAT-test): add dhcptest, a wire-level DHCP client test tool
xCAT's DHCP behaviour is tested from two directions today, neither of which
touches the wire: xCAT-test/unit/dhcp_*.t assert on generated config text, and
xCAT-test/integration/dhcp_{isc,kea}_config_validation.t feed that config to a
real daemon and check it parses. Both stop at "the server accepted our
config". Nothing verifies that a client sending option 93 = 0x000b actually
gets an aarch64 loader back.

The one existing wire tool, xCAT-probe/subcmds/detect_dhcpd, hand-packs a
fixed DISCOVER carrying no option 60, 77 or 93 (so it never reaches any arch
branch), parses replies by regexing tcpdump output, and binds an
IO::Socket::INET to a local address, so it cannot run on a provisioning NIC
that has no address yet.

dhcptest fills that gap. It is a Python 3 tool using only the standard library
plus Scapy, speaking raw Layer 2, driving DHCP transactions declared in INI
files and asserting on what came back:

  dhcptest run      -i eth1 --set net=10.0.0.0/24 conf/full-lease.conf
  dhcptest validate conf/*.conf      # no root, no network, no scapy
  dhcptest list     conf/*.conf
  dhcptest discover -i eth1          # ad-hoc, no conf file

Scenarios cover DISCOVER/OFFER, the full lease, renew and rebind, reserved
versus pooled addresses, deliberate silence, the PXE architecture matrix and
the iPXE user-class split. Assertions are a small DSL -- target, operator,
value -- over message type, BOOTP header fields, options by number or name,
subnet membership, and the boot file a client would actually use (option 67
or the header, since servers differ on which they fill).

Two boundaries are enforced by unit test rather than by convention:

  - The tool is implementation-agnostic. It exchanges packets and checks
    fields; it never reads the xCAT database, never runs an xCAT command, and
    names no DHCP implementation. Anything that differs between servers is
    expressed by whoever writes the .conf.
  - Only runner.py imports scapy, so validate and list stay usable in CI on a
    host with neither scapy nor root.

Host networking is never modified. The client MAC defaults to a synthetic
locally-administered address, everything goes over a raw L2 socket, no leased
address is ever configured, and the ARP responder answers only for addresses
the session was actually granted.

Variables in .conf files are configparser's own BasicInterpolation, %(name)s,
fed from [vars] and --set. $offer.address and friends are resolved separately
at step-execution time, because they name a reply that has not arrived when
the file is read; BasicInterpolation gives $ no meaning, so the two coexist
without escaping.

Packaging and CI:

  - xCAT-test.spec installs dhcptest alongside unit/ and integration/, and
    only recommends python3-scapy: it lives in EPEL on EL, and a hard Requires
    would make xCAT-test uninstallable on a management node without EPEL.
    The deb depends on it outright.
  - github_action_xcat_test.pl runs the unit tests and `dhcptest validate`
    last, after the fast regression.
  - autotest/testcase/dhcptest/cases0 carries the two offline cases plus a
    wire case that stands down with an explanation when no provisioning NIC
    is available.

Verified against a real DHCP server in a network namespace: 34 lease, renew,
rebind, reservation and silence assertions and 22 PXE/iPXE assertions all
pass, and host networking is untouched before and after.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-09-10 08:19:41 -03:00

97 lines
3.2 KiB
RPMSpec

Summary: xCAT automated test tool
Name: xCAT-test
Version: %{?version:%{version}}%{!?version:%(cat Version)}
Release: %{?release:%{release}}%{!?release:%(cat Release)}
Epoch: 4
License: EPL
Group: Applications/System
Source: xCAT-test-%{version}.tar.gz
Packager: IBM Corp.
Vendor: IBM Corp.
Distribution: %{?_distribution:%{_distribution}}%{!?_distribution:%{_vendor}}
Prefix: /opt/xcat
BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root
# Pod::Html ships inside the core perl package on SUSE; there is no perl-Pod-Html
%if !0%{?suse_version}
BuildRequires: perl-Pod-Html
%endif
# AIX will build with an arch of "ppc"
%ifos linux
BuildArch: noarch
%endif
# dhcptest needs scapy, which lives in EPEL on EL rather than in the base
# repositories. A hard Requires: would make this package uninstallable on a
# management node without EPEL, so it is only recommended: dhcptest exits 3
# with an actionable message when scapy is absent, and nothing else in
# xCAT-test needs it. Recommends: is not understood by rpm before EL 8.
%if 0%{?suse_version} || 0%{?rhel} >= 8
Recommends: python3-scapy
%endif
%description
Provides automated test tool and buckets to help test xCAT commands automatically.
%prep
%setup -q -n xCAT-test
%build
# Convert pods to man pages and html pages
mkdir -p share/man/man1
mkdir -p share/doc/man1
pod2man pods/man1/xcattest.1.pod > share/man/man1/xcattest.1
pod2man pods/man1/xcatperftest.1.pod > share/man/man1/xcatperftest.1
pod2html pods/man1/xcattest.1.pod > share/doc/man1/xcattest.1.html
pod2html pods/man1/xcatperftest.1.pod > share/doc/man1/xcatperftest.1.html
%install
# The install phase puts all of the files in the paths they should be in when the rpm is
# installed on a system. The RPM_BUILD_ROOT is a simulated root file system and usually
# has a value like: /var/tmp/xCAT-test-2.0-snap200802270932-root
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/%{prefix}/bin
mkdir -p $RPM_BUILD_ROOT/%{prefix}/sbin
mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/xcat/tools/autotest
mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/man/man1
mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/doc/man1
cp bin/* $RPM_BUILD_ROOT/%{prefix}/bin
cp xcattest $RPM_BUILD_ROOT/%{prefix}/bin
chmod 755 $RPM_BUILD_ROOT/%{prefix}/bin/*
cp restapitest $RPM_BUILD_ROOT/%{prefix}/sbin
chmod 755 $RPM_BUILD_ROOT/%{prefix}/sbin/*
# These were built dynamically in the build phase
cp share/man/man1/* $RPM_BUILD_ROOT/%{prefix}/share/man/man1
chmod 444 $RPM_BUILD_ROOT/%{prefix}/share/man/man1/*
cp share/doc/man1/* $RPM_BUILD_ROOT/%{prefix}/share/doc/man1
chmod 644 $RPM_BUILD_ROOT/%{prefix}/share/doc/man1/*
cp -r autotest $RPM_BUILD_ROOT/%{prefix}/share/xcat/tools
cp -r unit $RPM_BUILD_ROOT/%{prefix}/share/xcat/tools/autotest
cp -r integration $RPM_BUILD_ROOT/%{prefix}/share/xcat/tools/autotest
cp -r dhcptest $RPM_BUILD_ROOT/%{prefix}/share/xcat/tools/autotest
chmod 755 $RPM_BUILD_ROOT/%{prefix}/share/xcat/tools/autotest/dhcptest/src/dhcptest
%clean
# This step does not happen until *after* the %files packaging below
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
#%doc LICENSE.html
# Just package everything that has been copied into RPM_BUILD_ROOT
%{prefix}
%changelog
* Tue Sep 14 2010 - Airong Zheng <zhengar@us.ibm.com>
- "Create xCAT autotest package"
%post
%preun