-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mohammed boukhalfa
committed
Oct 12, 2023
1 parent
7c007b6
commit f94b916
Showing
7 changed files
with
266 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package e2e | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
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" | ||
|
||
capm3_e2e "github.com/metal3-io/cluster-api-provider-metal3/test/e2e" | ||
|
||
metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" | ||
) | ||
|
||
var _ = Describe("basic", func() { | ||
var ( | ||
specName = "basic-ops" | ||
namespace *corev1.Namespace | ||
cancelWatches context.CancelFunc | ||
bmcUser string | ||
bmcPassword string | ||
bmcAddress string | ||
bootMacAddress string | ||
vmName string | ||
) | ||
const ( | ||
rebootAnnotation = "reboot.metal3.io" | ||
poweroffAnnotation = "reboot.metal3.io/poweroff" | ||
) | ||
BeforeEach(func() { | ||
bmcUser = e2eConfig.GetVariable("BMC_USER") | ||
bmcPassword = e2eConfig.GetVariable("BMC_PASSWORD") | ||
bmcAddress = e2eConfig.GetVariable("BMC_ADDRESS") | ||
bootMacAddress = e2eConfig.GetVariable("BOOT_MAC_ADDRESS") | ||
vmName = e2eConfig.GetVariable("VM_NAME") | ||
|
||
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 power cycle a newly created BMH", func() { | ||
By("creating a secret with BMH credentials") | ||
bmcCredentials := corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "bmc-credentials", | ||
Namespace: namespace.Name, | ||
}, | ||
StringData: map[string]string{ | ||
"username": bmcUser, | ||
"password": bmcPassword, | ||
}, | ||
} | ||
err := clusterProxy.GetClient().Create(ctx, &bmcCredentials) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("creating a BMH") | ||
bmh := metal3api.BareMetalHost{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: specName + "-powercycle", | ||
Namespace: namespace.Name, | ||
Annotations: map[string]string{ | ||
"inspect.metal3.io": "disabled", | ||
}, | ||
}, | ||
Spec: metal3api.BareMetalHostSpec{ | ||
Online: true, | ||
BMC: metal3api.BMCDetails{ | ||
Address: bmcAddress, | ||
CredentialsName: "bmc-credentials", | ||
}, | ||
BootMode: metal3api.Legacy, | ||
BootMACAddress: bootMacAddress, | ||
}, | ||
} | ||
err = clusterProxy.GetClient().Create(ctx, &bmh) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("waiting for the BMH to be in registering state") | ||
WaitForBmhInState(ctx, WaitForBmhInStateInput{ | ||
Client: clusterProxy.GetClient(), | ||
Bmh: bmh, | ||
State: metal3api.StateRegistering, | ||
}, e2eConfig.GetIntervals("inspection", "wait-registering")...) | ||
|
||
By("waiting for the BMH to become available") | ||
WaitForBmhInState(ctx, WaitForBmhInStateInput{ | ||
Client: clusterProxy.GetClient(), | ||
Bmh: bmh, | ||
State: metal3api.StateAvailable, | ||
}, e2eConfig.GetIntervals("inspection", "wait-available")...) | ||
|
||
By("testing the reboot BMH") | ||
capm3_e2e.AnnotateBmh(ctx, clusterProxy.GetClient(), bmh, rebootAnnotation, pointer.String("{\"force\": true}")) | ||
waitForVmsState([]string{vmName}, shutoff, specName, e2eConfig.GetIntervals(specName, "wait-vm-state")...) | ||
waitForVmsState([]string{vmName}, running, specName, e2eConfig.GetIntervals(specName, "wait-vm-state")...) | ||
|
||
By("checking the power off BMH") | ||
capm3_e2e.AnnotateBmh(ctx, clusterProxy.GetClient(), bmh, poweroffAnnotation, pointer.String("{\"force\": true}")) | ||
waitForVmsState([]string{vmName}, shutoff, specName, e2eConfig.GetIntervals(specName, "wait-vm-state")...) | ||
|
||
// power on | ||
By("checking the power on BMH") | ||
capm3_e2e.AnnotateBmh(ctx, clusterProxy.GetClient(), bmh, poweroffAnnotation, nil) | ||
waitForVmsState([]string{vmName}, running, specName, e2eConfig.GetIntervals(specName, "wait-vm-state")...) | ||
}) | ||
|
||
AfterEach(func() { | ||
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{ | ||
Deleter: clusterProxy.GetClient(), | ||
Name: namespace.Name, | ||
}) | ||
cancelWatches() | ||
}) | ||
}) |
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
Oops, something went wrong.