Skip to content

Commit

Permalink
Merge pull request #28 from dtantsur/test
Browse files Browse the repository at this point in the history
Exercise Ironic in the functional job
  • Loading branch information
metal3-io-bot committed Apr 4, 2024
2 parents 2c36b03 + 9191c06 commit 356e0c6
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- uses: helm/kind-action@v1
with:
cluster_name: kind
config: ./test/kind.yaml
- name: Prepare tests
run: LOGDIR=/tmp/logs ./test/prepare.sh
- name: Run tests
Expand Down
5 changes: 3 additions & 2 deletions test/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/metal3-io/ironic-standalone-operator/test

go 1.21
go 1.21.6

require (
github.com/gophercloud/gophercloud/v2 v2.0.0-beta.2
github.com/metal3-io/ironic-standalone-operator v0.0.0
github.com/onsi/ginkgo/v2 v2.14.0
github.com/onsi/gomega v1.30.0
Expand Down Expand Up @@ -54,7 +55,7 @@ require (
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions test/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJY
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gophercloud/gophercloud/v2 v2.0.0-beta.2 h1:JWv6L7eg3+aIS57n11YlVvtn1pVCKpVlMo24ANj/OVc=
github.com/gophercloud/gophercloud/v2 v2.0.0-beta.2/go.mod h1:Sy5GHwY4iazyaRf94rzL/VxJToVWn8WnIH+1cXqoAks=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
Expand Down Expand Up @@ -141,8 +143,8 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
14 changes: 14 additions & 0 deletions test/kind.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 6180
hostPort: 6180
listenAddress: "127.0.0.1"
- containerPort: 6183
hostPort: 6183
listenAddress: "127.0.0.1"
- containerPort: 6385
hostPort: 6385
listenAddress: "127.0.0.1"
71 changes: 71 additions & 0 deletions test/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ import (
"context"
"fmt"
"io"
"math/rand"
"os"
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/gophercloud/gophercloud/v2"
"github.com/gophercloud/gophercloud/v2/openstack/baremetal/httpbasic"
"github.com/gophercloud/gophercloud/v2/openstack/baremetal/noauth"
"github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/conductors"
"github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -84,6 +90,20 @@ var _ = BeforeSuite(func() {

})

func NewNoAuthClient(endpoint string) (*gophercloud.ServiceClient, error) {
return noauth.NewBareMetalNoAuth(noauth.EndpointOpts{
IronicEndpoint: endpoint,
})
}

func NewHTTPBasicClient(endpoint string, secret *corev1.Secret) (*gophercloud.ServiceClient, error) {
return httpbasic.NewBareMetalHTTPBasic(httpbasic.EndpointOpts{
IronicEndpoint: endpoint,
IronicUser: string(secret.Data[corev1.BasicAuthUsernameKey]),
IronicUserPassword: string(secret.Data[corev1.BasicAuthPasswordKey]),
})
}

func WaitForIronic(name types.NamespacedName) *metal3api.Ironic {
ironic := &metal3api.Ironic{}

Expand Down Expand Up @@ -151,6 +171,57 @@ func VerifyIronic(ironic *metal3api.Ironic) {
Expect(err).NotTo(HaveOccurred())

writeYAML(svc, svc.Namespace, svc.Name, "service")

Expect(svc.Spec.ClusterIPs).ToNot(BeEmpty())

By("fetching the authentication secret")

secret, err := clientset.CoreV1().Secrets(ironic.Namespace).Get(ctx, ironic.Spec.CredentialsRef.Name, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

By("checking Ironic authentication")

// Do not let the test get stuck here in case of connection issues
withTimeout, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

cli, err := NewNoAuthClient("http://127.0.0.1:6385")
Expect(err).NotTo(HaveOccurred())
_, err = nodes.List(cli, nodes.ListOpts{}).AllPages(withTimeout)
Expect(err).To(HaveOccurred())

By("checking Ironic conductor list")

cli, err = NewHTTPBasicClient("http://127.0.0.1:6385", secret)
Expect(err).NotTo(HaveOccurred())
cli.Microversion = "1.81" // minimum version supported by BMO

conductorPager, err := conductors.List(cli, conductors.ListOpts{}).AllPages(withTimeout)
Expect(err).NotTo(HaveOccurred())
conductors, err := conductors.ExtractConductors(conductorPager)
Expect(err).NotTo(HaveOccurred())
Expect(conductors).NotTo(BeEmpty())

By("creating and deleting a lot of Nodes")

withTimeout, cancel = context.WithTimeout(ctx, 2*time.Minute)
defer cancel()

drivers := []string{"ipmi", "redfish"}
var nodeUUIDs []string
for idx := 0; idx < 100; idx++ {
node, err := nodes.Create(withTimeout, cli, nodes.CreateOpts{
Driver: drivers[rand.Intn(len(drivers))],
Name: fmt.Sprintf("node-%d", idx),
}).Extract()
Expect(err).NotTo(HaveOccurred())
nodeUUIDs = append(nodeUUIDs, node.UUID)
}

for _, nodeUUID := range nodeUUIDs {
err = nodes.Delete(withTimeout, cli, nodeUUID).ExtractErr()
Expect(err).NotTo(HaveOccurred())
}
}

func CollectLogs(namespace string) {
Expand Down

0 comments on commit 356e0c6

Please sign in to comment.