-
Notifications
You must be signed in to change notification settings - Fork 259
/
Copy pathlive_iso_test.go
146 lines (130 loc) · 5.17 KB
/
live_iso_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//go:build e2e
// +build e2e
package e2e
import (
"context"
"fmt"
"os"
"path"
metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
metal3bmc "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"golang.org/x/crypto/ssh"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/patch"
)
var _ = Describe("Live-ISO", Label("required", "live-iso"), func() {
var (
specName = "live-iso-ops"
secretName = "bmc-credentials"
namespace *corev1.Namespace
cancelWatches context.CancelFunc
imageURL string
)
BeforeEach(func() {
// Check what kind of BMC we are dealing with
// It may be *possible* to boot a live-ISO over (i)PXE, but there are severe limitations.
// Therefore we skip the test if it doesn't support ISO preprovisioning images.
// See https://docs.openstack.org/ironic/latest/admin/ramdisk-boot.html
accessDetails, err := metal3bmc.NewAccessDetails(bmc.Address, false)
Expect(err).NotTo(HaveOccurred())
if !accessDetails.SupportsISOPreprovisioningImage() {
Skip(fmt.Sprintf("BMC does not support ISO images. It does not make sense to test live-ISO here. BMC address: %s", bmc.Address))
}
imageURL = e2eConfig.GetVariable("ISO_IMAGE_URL")
namespace, cancelWatches = framework.CreateNamespaceAndWatchEvents(ctx, framework.CreateNamespaceAndWatchEventsInput{
Creator: clusterProxy.GetClient(),
ClientSet: clusterProxy.GetClientSet(),
Name: fmt.Sprintf("%s-%s", specName, util.RandomString(6)),
LogFolder: artifactFolder,
})
})
It("should provision a BMH with live ISO and then deprovision it", func() {
By("Creating a secret with BMH credentials")
bmcCredentialsData := map[string]string{
"username": bmc.User,
"password": bmc.Password,
}
CreateSecret(ctx, clusterProxy.GetClient(), namespace.Name, secretName, bmcCredentialsData)
By("Creating a BMH with inspection disabled and hardware details added")
bmh := metal3api.BareMetalHost{
ObjectMeta: metav1.ObjectMeta{
Name: specName,
Namespace: namespace.Name,
Annotations: map[string]string{
metal3api.InspectAnnotationPrefix: "disabled",
metal3api.HardwareDetailsAnnotation: hardwareDetails,
},
},
Spec: metal3api.BareMetalHostSpec{
Online: true,
BMC: metal3api.BMCDetails{
Address: bmc.Address,
CredentialsName: secretName,
},
Image: &metal3api.Image{
URL: imageURL,
DiskFormat: pointer.String("live-iso"),
},
BootMode: metal3api.Legacy,
BootMACAddress: bmc.BootMacAddress,
AutomatedCleaningMode: metal3api.CleaningModeDisabled,
},
}
err := clusterProxy.GetClient().Create(ctx, &bmh)
Expect(err).NotTo(HaveOccurred())
By("Waiting for the BMH to be in provisioning state")
WaitForBmhInProvisioningState(ctx, WaitForBmhInProvisioningStateInput{
Client: clusterProxy.GetClient(),
Bmh: bmh,
State: metal3api.StateProvisioning,
}, e2eConfig.GetIntervals(specName, "wait-provisioning")...)
By("Waiting for the BMH to become provisioned")
WaitForBmhInProvisioningState(ctx, WaitForBmhInProvisioningStateInput{
Client: clusterProxy.GetClient(),
Bmh: bmh,
State: metal3api.StateProvisioned,
}, e2eConfig.GetIntervals(specName, "wait-provisioned")...)
// The ssh check is not possible in all situations (e.g. fixture) so it can be skipped
if e2eConfig.GetVariable("SSH_CHECK_PROVISIONED") == "true" {
By("Verifying the node booted from live ISO image")
keyPath := e2eConfig.GetVariable("SSH_PRIV_KEY")
key, err := os.ReadFile(keyPath)
Expect(err).NotTo(HaveOccurred(), "unable to read private key")
signer, err := ssh.ParsePrivateKey(key)
Expect(err).NotTo(HaveOccurred(), "unable to parse private key")
auth := ssh.PublicKeys(signer)
PerformSSHBootCheck(e2eConfig, "memory", auth, fmt.Sprintf("%s:%s", bmc.IPAddress, bmc.SSHPort))
} else {
Logf("WARNING: Skipping SSH check since SSH_CHECK_PROVISIONED != true")
}
By("Triggering the deprovisioning of the BMH")
helper, err := patch.NewHelper(&bmh, clusterProxy.GetClient())
Expect(err).NotTo(HaveOccurred())
bmh.Spec.Image = nil
Expect(helper.Patch(ctx, &bmh)).To(Succeed())
By("Waiting for the BMH to be in deprovisioning state")
WaitForBmhInProvisioningState(ctx, WaitForBmhInProvisioningStateInput{
Client: clusterProxy.GetClient(),
Bmh: bmh,
State: metal3api.StateDeprovisioning,
}, e2eConfig.GetIntervals(specName, "wait-deprovisioning")...)
By("Waiting for the BMH to become available again")
WaitForBmhInProvisioningState(ctx, WaitForBmhInProvisioningStateInput{
Client: clusterProxy.GetClient(),
Bmh: bmh,
State: metal3api.StateAvailable,
}, e2eConfig.GetIntervals(specName, "wait-available")...)
})
AfterEach(func() {
DumpResources(ctx, e2eConfig, clusterProxy, namespace.Name, path.Join(artifactFolder, specName))
if !skipCleanup {
cleanup(ctx, clusterProxy, namespace, cancelWatches, e2eConfig.GetIntervals("default", "wait-namespace-deleted")...)
}
})
})