Skip to content

Commit f1450bd

Browse files
Guest OS Imagescopybara-github
authored andcommitted
Create validation test suites for customer customized images.
PiperOrigin-RevId: 922848139
1 parent 9148985 commit f1450bd

3 files changed

Lines changed: 66 additions & 0 deletions

File tree

cmd/manager/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
"github.com/GoogleCloudPlatform/cloud-image-tests/test_suites/hostnamevalidation"
4646
"github.com/GoogleCloudPlatform/cloud-image-tests/test_suites/hotattach"
4747
"github.com/GoogleCloudPlatform/cloud-image-tests/test_suites/imageboot"
48+
"github.com/GoogleCloudPlatform/cloud-image-tests/test_suites/imagebuilder"
4849
"github.com/GoogleCloudPlatform/cloud-image-tests/test_suites/licensevalidation"
4950
"github.com/GoogleCloudPlatform/cloud-image-tests/test_suites/livemigrate"
5051
"github.com/GoogleCloudPlatform/cloud-image-tests/test_suites/loadbalancer"
@@ -344,6 +345,10 @@ func main() {
344345
imageboot.Name,
345346
imageboot.TestSetup,
346347
},
348+
{
349+
imagebuilder.Name,
350+
imagebuilder.TestSetup,
351+
},
347352
{
348353
licensevalidation.Name,
349354
licensevalidation.TestSetup,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Package imagebuilder is a CIT suite for testing customer images built by the GCE Image Builder.
2+
package imagebuilder
3+
4+
import (
5+
"net"
6+
"testing"
7+
)
8+
9+
func TestNetworkInterfacesUp(t *testing.T) {
10+
interfaces, err := net.Interfaces()
11+
if err != nil {
12+
t.Fatalf("Failed to retrieve network interfaces via net.Interfaces() (equivalent command: 'ip -j a'): %v", err)
13+
}
14+
15+
// Validate that we have at least one valid, UP network interface
16+
var upCount int
17+
var foundNonLoopback bool
18+
19+
for _, iface := range interfaces {
20+
// Skip the loopback interface via FlagLoopback or name "lo"
21+
if iface.Name == "lo" || (iface.Flags&net.FlagLoopback) != 0 {
22+
continue
23+
}
24+
25+
foundNonLoopback = true
26+
27+
// Check if the interface has the FlagUp set
28+
if (iface.Flags & net.FlagUp) != 0 {
29+
upCount++
30+
t.Logf("Found active network interface: %s (Flags: %v)", iface.Name, iface.Flags)
31+
}
32+
}
33+
34+
if !foundNonLoopback {
35+
t.Error("Failure: No non-loopback network interfaces were discovered on this system (equivalent command: 'ip -j a').")
36+
}
37+
38+
if upCount == 0 {
39+
t.Error("Failure: Found network interfaces, but zero non-loopback interfaces are 'UP' (equivalent command: 'ip -j a').")
40+
}
41+
}

test_suites/imagebuilder/setup.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Package imagebuilder is a CIT suite for testing customer images built by the GCE Image Builder.
2+
package imagebuilder
3+
4+
import (
5+
"github.com/GoogleCloudPlatform/cloud-image-tests"
6+
)
7+
8+
// Name is the name of the test package. It must match the directory name.
9+
var Name = "imagebuilder"
10+
11+
// TestSetup sets up the test workflow.
12+
func TestSetup(t *imagetest.TestWorkflow) error {
13+
vm1, err := t.CreateTestVM("networkinterfacesup")
14+
if err != nil {
15+
return err
16+
}
17+
vm1.RunTests("TestNetworkInterfacesUp")
18+
19+
return nil
20+
}

0 commit comments

Comments
 (0)