Skip to content

Commit

Permalink
cnf ran: ztp hub templating and node delete migration (openshift-kni#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
klaskosk authored and Gregory Kopels committed Aug 19, 2024
1 parent 3edd8c7 commit 136c00a
Show file tree
Hide file tree
Showing 22 changed files with 2,687 additions and 21 deletions.
111 changes: 111 additions & 0 deletions tests/cnf/core/network/metallb/internal/metallbenv/metallbenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,117 @@ func CreateNewMetalLbDaemonSetAndWaitUntilItsRunning(timeout time.Duration, node
return fmt.Errorf("metallb daemonSet is not ready")
}

func CreateNewMetalLbDaemonSetAndWaitUntilItsRunningWithAlwaysBlock(timeout time.Duration,

Check failure on line 120 in tests/cnf/core/network/metallb/internal/metallbenv/metallbenv.go

View workflow job for this annotation

GitHub Actions / build

exported: exported function CreateNewMetalLbDaemonSetAndWaitUntilItsRunningWithAlwaysBlock should have comment or be unexported (revive)
nodeLabel map[string]string, prefixes []string) error {
glog.V(90).Infof("Verifying if metalLb daemonset is running")

metalLbIo, err := metallb.Pull(APIClient, tsparams.MetalLbIo, NetConfig.MlbOperatorNamespace)

if err == nil {
glog.V(90).Infof("MetalLb daemonset is running. Removing daemonset.")

_, err = metalLbIo.Delete()

if err != nil {
return err
}
}

glog.V(90).Infof("Create new metalLb speaker's daemonSet.")

metalLbIo = metallb.NewBuilder(
APIClient, tsparams.MetalLbIo, NetConfig.MlbOperatorNamespace, nodeLabel)

metalLbIo.WithFRRconfigAlwaysBlock(prefixes)
_, err = metalLbIo.Create()

if err != nil {
return err
}

var metalLbDs *daemonset.Builder

err = wait.PollUntilContextTimeout(
context.TODO(), 3*time.Second, timeout, true, func(ctx context.Context) (bool, error) {
metalLbDs, err = daemonset.Pull(APIClient, tsparams.MetalLbDsName, NetConfig.MlbOperatorNamespace)
if err != nil {
glog.V(90).Infof("Error to pull daemonset %s namespace %s, retry",
tsparams.MetalLbDsName, NetConfig.MlbOperatorNamespace)

return false, nil
}

return true, nil
})

if err != nil {
return err
}

glog.V(90).Infof("Waiting until the new metalLb daemonset is in Ready state.")

if metalLbDs.IsReady(timeout) {
return nil
}

return fmt.Errorf("metallb daemonSet is not ready")
}

//func CreateNewMetalLbDaemonSetAndWaitUntilItsRunningWithAlwaysBlock(timeout time.Duration, nodeLabel map[string]string,

Check failure on line 176 in tests/cnf/core/network/metallb/internal/metallbenv/metallbenv.go

View workflow job for this annotation

GitHub Actions / build

commentFormatting: put a space between `//` and comment text (gocritic)
// prefixes []string) error {
// glog.V(90).Infof("Verifying if metalLb daemonset is running")
//
// metalLbIo, err := metallb.Pull(APIClient, tsparams.MetalLbIo, NetConfig.MlbOperatorNamespace)
//
// if err == nil {
// glog.V(90).Infof("MetalLb daemonset is running. Removing daemonset.")
//
// _, err = metalLbIo.Delete()
//
// if err != nil {
// return err
// }
// }
//
// glog.V(90).Infof("Create new metalLb speaker's daemonSet.")
//
// metalLbIo = metallb.NewBuilder(
// APIClient, tsparams.MetalLbIo, NetConfig.MlbOperatorNamespace, nodeLabel)
//
// metalLbIo.WithFRRconfigAlwaysBlock(prefixes)
// _, err = metalLbIo.Create()
//
// if err != nil {
// return err
// }
//
// var metalLbDs *daemonset.Builder
// err = wait.PollUntilContextTimeout(
// context.TODO(), 3*time.Second, timeout, true, func(ctx context.Context) (bool, error) {
// metalLbDs, err = daemonset.Pull(APIClient, tsparams.MetalLbDsName, NetConfig.MlbOperatorNamespace)
// if err != nil {
// glog.V(90).Infof("Error to pull daemonset %s namespace %s, retry",
// tsparams.MetalLbDsName, NetConfig.MlbOperatorNamespace)
//
// return false, nil
// }
//
// return true, nil
// })
//
// if err != nil {
// return err
// }
//
// glog.V(90).Infof("Waiting until the new metalLb daemonset is in Ready state.")
//
// if metalLbDs.IsReady(timeout) {
// return nil
// }
//
// return fmt.Errorf("metallb daemonSet is not ready")
//}

// GetMetalLbIPByIPStack returns metalLb IP addresses from env var typo:ECO_CNF_CORE_NET_MLB_ADDR_LIST
// sorted by IPStack.
func GetMetalLbIPByIPStack() ([]string, []string, error) {
Expand Down
2 changes: 2 additions & 0 deletions tests/cnf/core/network/metallb/internal/tsparams/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const (
LabelBFDTestCases = "bfd"
// LabelBGPTestCases represents bgp label that can be used for test cases selection.
LabelBGPTestCases = "bgp"
// LabelFRRTestCases represents frr label that can be used for test cases selection.
LabelFRRTestCases = "frr"
// LabelLayer2TestCases represents layer2 label that can be used for test cases selection.
LabelLayer2TestCases = "layer2"
// BGPPassword var is used to set password for BGP session between FRR speakers.
Expand Down
2 changes: 2 additions & 0 deletions tests/cnf/core/network/metallb/internal/tsparams/mlbvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ var (
MetalLbDsName = "speaker"
// MetalLbDefaultSpeakerLabel represents the default metalLb speaker label.
MetalLbDefaultSpeakerLabel = "component=speaker"
// FRRK8SLabelSelector represents the default frr node label.
FRRK8SLabelSelector = "component=frr-k8s"
// ExternalMacVlanNADName represents default external NetworkAttachmentDefinition name.
ExternalMacVlanNADName = "external"
// SleepCMD represents shel sleep command.
Expand Down
16 changes: 11 additions & 5 deletions tests/cnf/core/network/metallb/tests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tests

import (
"fmt"
"net"
"time"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -102,24 +103,29 @@ func createExternalNad() {
}

func createBGPPeerAndVerifyIfItsReady(
peerIP, bfdProfileName string, remoteAsn uint32, eBgpMultiHop bool, speakerPods []*pod.Builder) {
peerIP, bfdProfileName string, remoteAsn uint32, eBgpMultiHop bool, frrPods []*pod.Builder) {
By("Creating BGP Peer")

bgpPeer := metallb.NewBPGPeerBuilder(APIClient, "testpeer", NetConfig.MlbOperatorNamespace,
bgpPeerName := "bgppeer-ipv4"
ip, n, err := net.ParseCIDR(peerIP)

Check failure on line 110 in tests/cnf/core/network/metallb/tests/common.go

View workflow job for this annotation

GitHub Actions / build

ineffectual assignment to err (ineffassign)

fmt.Println("IP", ip, "NET", n)

bgpPeer := metallb.NewBPGPeerBuilder(APIClient, bgpPeerName, NetConfig.MlbOperatorNamespace,
peerIP, tsparams.LocalBGPASN, remoteAsn).WithPassword(tsparams.BGPPassword).WithEBGPMultiHop(eBgpMultiHop)

if bfdProfileName != "" {
bgpPeer.WithBFDProfile(bfdProfileName)
}

_, err := bgpPeer.Create()
_, err = bgpPeer.Create()
Expect(err).ToNot(HaveOccurred(), "Failed to create BGP peer")

By("Verifying if BGP protocol configured")

for _, speakerPod := range speakerPods {
for _, frrPod := range frrPods {
Eventually(frr.IsProtocolConfigured,
time.Minute, tsparams.DefaultRetryInterval).WithArguments(speakerPod, "router bgp").
time.Minute, tsparams.DefaultRetryInterval).WithArguments(frrPod, "router bgp").
Should(BeTrue(), "BGP is not configured on the Speakers")
}
}
Expand Down
Loading

0 comments on commit 136c00a

Please sign in to comment.