From 794e6c3c2112c0afb93ae437cc2483f1c0aa6da1 Mon Sep 17 00:00:00 2001 From: Isabella Janssen Date: Tue, 23 Jun 2026 07:08:08 -0400 Subject: [PATCH] tests: update custom containerfile OCB test to work in disconnected environments --- test/extended/mco_ocb.go | 25 +++++++++++++++++++++++-- test/extended/util.go | 12 ++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/test/extended/mco_ocb.go b/test/extended/mco_ocb.go index 0bf1d2bc5b..2f90e9b36f 100644 --- a/test/extended/mco_ocb.go +++ b/test/extended/mco_ocb.go @@ -108,7 +108,28 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/disruptive g.It("PolarionID:83140-A MachineOSConfig with custom containerfile definition can be successfully applied", func() { var ( - mcp = GetCompactCompatiblePool(oc.AsAdmin()) + mcp = GetCompactCompatiblePool(oc.AsAdmin()) + containerFileContent string + checkers []Checker + ) + + if IsDisconnectedCluster(oc.AsAdmin()) { + logger.Infof("Disconnected cluster detected, using containerfile that does not require network access") + containerFileContent = ` + FROM configs AS final + RUN echo "disconnected-containerfile-test" > /etc/disconnected-containerfile-test && \ + ostree container commit +` + + checkers = []Checker{ + CommandOutputChecker{ + Command: []string{"cat", "/etc/disconnected-containerfile-test"}, + Matcher: o.ContainSubstring("disconnected-containerfile-test"), + ErrorMsg: fmt.Sprintf("Test file was not created by the custom containerfile"), + Desc: fmt.Sprintf("Check that the custom containerfile test file exists"), + }, + } + } else { containerFileContent = ` # Pull the centos base image and enable the EPEL repository. @@ -140,7 +161,7 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/disruptive Desc: fmt.Sprintf("Check that cowsay is installed and working"), }, } - ) + } testContainerFile([]ContainerFile{{Content: containerFileContent}}, MachineConfigNamespace, mcp, checkers, false) }) diff --git a/test/extended/util.go b/test/extended/util.go index eb9f4c7c36..f3d2eb518d 100644 --- a/test/extended/util.go +++ b/test/extended/util.go @@ -439,3 +439,15 @@ func IsCompactOrSNOCluster(oc *exutil.CLI) bool { return wMcp.IsEmpty() && len(mcpList.GetAllOrFail()) == 2 } + +// IsDisconnectedCluster returns true if the cluster has no external network +// access by attempting to reach an external endpoint from a node. +func IsDisconnectedCluster(oc *exutil.CLI) bool { + nodes, err := NewNodeList(oc.AsAdmin()).GetAll() + if err != nil || len(nodes) == 0 { + return false + } + output, _ := nodes[0].DebugNodeWithChroot("sh", "-c", + "curl -s --connect-timeout 5 https://fedoraproject.org/static/hotspot.txt &>/dev/null && echo Connected || echo Disconnected") + return !strings.Contains(output, "Connected") +}