-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1453 from Nordix/e2e-live-iso-ssh-implementation/max
🌱E2e live iso ssh implementation
- Loading branch information
Showing
10 changed files
with
240 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package e2e | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
. "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" | ||
|
||
metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" | ||
|
||
capm3_e2e "github.com/metal3-io/cluster-api-provider-metal3/test/e2e" | ||
) | ||
|
||
var _ = Describe("Live-ISO", func() { | ||
var ( | ||
specName = "live-iso-ops" | ||
secretName = "bmc-credentials" | ||
namespace *corev1.Namespace | ||
cancelWatches context.CancelFunc | ||
bmcUser string | ||
bmcPassword string | ||
bmcAddress string | ||
bootMacAddress string | ||
imageURL string | ||
) | ||
|
||
BeforeEach(func() { | ||
bmcUser = e2eConfig.GetVariable("BMC_USER") | ||
bmcPassword = e2eConfig.GetVariable("BMC_PASSWORD") | ||
bmcAddress = e2eConfig.GetVariable("BMC_ADDRESS") | ||
bootMacAddress = e2eConfig.GetVariable("BOOT_MAC_ADDRESS") | ||
imageURL = e2eConfig.GetVariable("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") | ||
CreateBMHCredentialsSecret(ctx, clusterProxy.GetClient(), namespace.Name, secretName, bmcUser, bmcPassword) | ||
|
||
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: bmcAddress, | ||
CredentialsName: secretName, | ||
}, | ||
Image: &metal3api.Image{ | ||
URL: imageURL, | ||
DiskFormat: pointer.String("live-iso"), | ||
}, | ||
BootMode: metal3api.Legacy, | ||
BootMACAddress: bootMacAddress, | ||
AutomatedCleaningMode: "disabled", | ||
RootDeviceHints: &metal3api.RootDeviceHints{ | ||
DeviceName: "/dev/vda", | ||
}, | ||
}, | ||
} | ||
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") | ||
|
||
// Set up SSH client configuration | ||
config := &ssh.ClientConfig{ | ||
User: "cirros", | ||
Auth: []ssh.AuthMethod{ | ||
ssh.Password("gocubsgo"), | ||
}, | ||
HostKeyCallback: ssh.InsecureIgnoreHostKey(), // #nosec G106 | ||
} | ||
|
||
ip := e2eConfig.GetVariable("IP_BMO_E2E_0") | ||
sshPort := e2eConfig.GetVariable("SSH_PORT") | ||
address := fmt.Sprintf("%s:%s", ip, sshPort) | ||
|
||
// Establish an SSH connection | ||
var client *ssh.Client | ||
var err error | ||
|
||
Eventually(func() error { | ||
client, err = ssh.Dial("tcp", address, config) | ||
return err | ||
}, e2eConfig.GetIntervals(specName, "wait-connect-ssh")...).Should(Succeed(), "Failed to establish SSH connection") | ||
|
||
defer func() { | ||
if client != nil { | ||
client.Close() | ||
} | ||
}() | ||
isDisk, err := IsBootedFromDisk(client) | ||
Expect(err).NotTo(HaveOccurred(), "Error in verifying boot mode") | ||
Expect(isDisk).To(Equal(false), "Error booting from disk when live ISO is expected") | ||
} else { | ||
capm3_e2e.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() { | ||
cleanup(ctx, clusterProxy, namespace, cancelWatches, e2eConfig.GetIntervals("default", "wait-namespace-deleted")...) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters