Skip to content

Commit

Permalink
Merge pull request #28495 from ardaguclu/ocpbugs-25142
Browse files Browse the repository at this point in the history
OCPBUGS-25142: Retry with different node port to make oc service test stable
  • Loading branch information
openshift-merge-bot[bot] committed Jan 8, 2024
2 parents 544cbb0 + 4b7dfef commit ad7a60d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions test/extended/cli/service.go
@@ -1,8 +1,10 @@
package cli

import (
"fmt"
"os"
"regexp"
"strings"

g "github.com/onsi/ginkgo/v2"
o "github.com/onsi/gomega"
Expand Down Expand Up @@ -30,11 +32,18 @@ var _ = g.Describe("[sig-cli] oc service", func() {
o.Expect(err).NotTo(o.HaveOccurred())

g.By("validate the 'create service nodeport' command and its --node-port and --tcp options")
out, err := oc.Run("create").Args("service", "nodeport", "mynodeport", "--tcp=8080:7777", "--node-port=30000").Output()
nodePort := 30000
out, err := oc.Run("create").Args("service", "nodeport", "mynodeport", "--tcp=8080:7777", fmt.Sprintf("--node-port=%d", nodePort)).Output()
if err != nil && strings.Contains(err.Error(), "provided port is already allocated") {
// another service may use port number 30000 and instead of failing, we can try our chance
// with another port to have a stable test.
nodePort = 30001
out, err = oc.Run("create").Args("service", "nodeport", "mynodeport", "--tcp=8080:7777", fmt.Sprintf("--node-port=%d", nodePort)).Output()
}
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("service/mynodeport created"))

out, err = oc.Run("create").Args("service", "nodeport", "mynodeport", "--tcp=8080:7777", "--node-port=30000").Output()
out, err = oc.Run("create").Args("service", "nodeport", "mynodeport", "--tcp=8080:7777", fmt.Sprintf("--node-port=%d", nodePort)).Output()
o.Expect(err).To(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("provided port is already allocated"))

Expand All @@ -44,7 +53,7 @@ var _ = g.Describe("[sig-cli] oc service", func() {

out, err = oc.Run("describe").Args("service", "mynodeport").Output()
o.Expect(err).NotTo(o.HaveOccurred())
npReg1 := "NodePort:.*30000"
npReg1 := fmt.Sprintf("NodePort:.*%d", nodePort)
m1, err := regexp.MatchString(npReg1, out)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(m1).To(o.BeTrue())
Expand Down

0 comments on commit ad7a60d

Please sign in to comment.