Skip to content

Commit 4d16e01

Browse files
authored
Merge pull request #3059 from yuwang-RH/new1027
OCM-19783 | test: automate ids: 65793,38801
2 parents 0d70412 + bd2b695 commit 4d16e01

File tree

4 files changed

+176
-10
lines changed

4 files changed

+176
-10
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package e2e
2+
3+
import (
4+
. "github.com/onsi/ginkgo/v2"
5+
. "github.com/onsi/gomega"
6+
7+
"github.com/openshift/rosa/tests/ci/labels"
8+
"github.com/openshift/rosa/tests/utils/exec/rosacli"
9+
"github.com/openshift/rosa/tests/utils/helper"
10+
)
11+
12+
var _ = Describe("DNS domain tests",
13+
labels.Feature.Ingress,
14+
func() {
15+
defer GinkgoRecover()
16+
17+
var (
18+
rosaClient *rosacli.Client
19+
dnsDomainService rosacli.OCMResourceService
20+
dnsDomainC string
21+
dnsDomainH string
22+
)
23+
24+
BeforeEach(func() {
25+
26+
By("Init the client")
27+
rosaClient = rosacli.NewClient()
28+
dnsDomainService = rosaClient.OCMResource
29+
30+
})
31+
32+
It("can create/list/delete dns-domain via rosacli - [id:65793]",
33+
labels.Critical, labels.Runtime.OCMResources,
34+
func() {
35+
By("Create dns-domain for classic cluster")
36+
outputC, err := dnsDomainService.CreateDNSDomain()
37+
Expect(err).ToNot(HaveOccurred())
38+
defer func() {
39+
By("Delete the created dns-domain for classic cluster")
40+
output, err := dnsDomainService.DeleteDNSDomain(dnsDomainC)
41+
Expect(err).ToNot(HaveOccurred())
42+
Expect(output.String()).To(ContainSubstring("Successfully deleted dns domain '%s'", dnsDomainC))
43+
44+
By("Check the created dns-domain for classic cluster delete")
45+
out, err := dnsDomainService.ListDNSDomain()
46+
Expect(err).ToNot(HaveOccurred())
47+
Expect(out.String()).ToNot(ContainSubstring(dnsDomainC))
48+
}()
49+
dnsDomainC, err = helper.ExtractDNSDomainID(outputC)
50+
Expect(err).ToNot(HaveOccurred())
51+
52+
By("List the created dns-domain for classic cluster")
53+
out, err := dnsDomainService.ListDNSDomain()
54+
Expect(err).ToNot(HaveOccurred())
55+
dnsDomainList, err := dnsDomainService.ReflectDNSDomainList(out)
56+
Expect(err).ToNot(HaveOccurred())
57+
dnsDomain := dnsDomainList.GetDNSDomain(dnsDomainC)
58+
Expect(dnsDomain.ID).To(Equal(dnsDomainC))
59+
Expect(dnsDomain.UserDefined).To(Equal("Yes"))
60+
Expect(dnsDomain.Architecture).To(Equal("classic"))
61+
62+
By("Create dns-domain for hosted-cp cluster")
63+
outputH, err := dnsDomainService.CreateDNSDomain("--hosted-cp")
64+
Expect(err).ToNot(HaveOccurred())
65+
defer func() {
66+
By("Delete the created dns-domain for hosted-cp cluster")
67+
output, err := dnsDomainService.DeleteDNSDomain(dnsDomainH)
68+
Expect(err).ToNot(HaveOccurred())
69+
Expect(output.String()).To(ContainSubstring("Successfully deleted dns domain '%s'", dnsDomainH))
70+
71+
By("Check the created dns-domain for hosted-cp cluster delete")
72+
out, err := dnsDomainService.ListDNSDomain()
73+
Expect(err).ToNot(HaveOccurred())
74+
Expect(out.String()).ToNot(ContainSubstring(dnsDomainH))
75+
}()
76+
dnsDomainH, err = helper.ExtractDNSDomainID(outputH)
77+
Expect(err).ToNot(HaveOccurred())
78+
79+
By("List the created dns-domain for hosted-cp cluster")
80+
out, err = dnsDomainService.ListDNSDomain()
81+
Expect(err).ToNot(HaveOccurred())
82+
dnsDomainList, err = dnsDomainService.ReflectDNSDomainList(out)
83+
Expect(err).ToNot(HaveOccurred())
84+
dnsDomain = dnsDomainList.GetDNSDomain(dnsDomainH)
85+
Expect(dnsDomain.ID).To(Equal(dnsDomainH))
86+
Expect(dnsDomain.UserDefined).To(Equal("Yes"))
87+
Expect(dnsDomain.Architecture).To(Equal("hcp"))
88+
89+
By("List the created dns-domain with '--hosted-cp' flag")
90+
out, err = dnsDomainService.ListDNSDomain("--hosted-cp")
91+
Expect(err).ToNot(HaveOccurred())
92+
dnsDomainList, err = dnsDomainService.ReflectDNSDomainList(out)
93+
Expect(err).ToNot(HaveOccurred())
94+
dnsDomain = dnsDomainList.GetDNSDomain(dnsDomainH)
95+
Expect(dnsDomain.ID).To(Equal(dnsDomainH))
96+
Expect(dnsDomain.UserDefined).To(Equal("Yes"))
97+
Expect(dnsDomain.Architecture).To(Equal("hcp"))
98+
})
99+
100+
})

tests/e2e/test_rosacli_version.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ var _ = Describe("Get CLI version",
114114
versionService := rosaClient.Version
115115

116116
By("Display the version help page")
117-
buf, err := rosaClient.Runner.Cmd("list", "version", "-h").Run()
117+
output, err := versionService.ListVersions("", false, "-h")
118118
Expect(err).ToNot(HaveOccurred())
119-
stdout := rosaClient.Parser.TextData.Input(buf).Parse().Output()
119+
stdout := rosaClient.Parser.TextData.Input(output).Parse().Output()
120120

121121
By("Check the output of the help page")
122122
Expect(stdout).To(ContainSubstring("rosa list versions [flags]"))
@@ -125,9 +125,11 @@ var _ = Describe("Get CLI version",
125125

126126
By("Display the version on the stable channel")
127127
rosaClient.Runner.UnsetArgs()
128-
buf, err = rosaClient.Runner.Cmd("list", "version").Run()
128+
output, err = versionService.ListVersions(STABLE_CHANNEL, false)
129129
Expect(err).ToNot(HaveOccurred())
130-
stdout = rosaClient.Parser.TextData.Input(buf).Parse().Output()
130+
Expect(output.String()).To(ContainSubstring("DEPRECATED: Available upgrades in 'rosa list versions' are deprecated"))
131+
Expect(output.String()).To(ContainSubstring("please use 'rosa list upgrades --cluster <cluster_id>'"))
132+
stdout = rosaClient.Parser.TextData.Input(output).Parse().Output()
131133

132134
By("Check the output of the stable versions")
133135
Expect(stdout).To(ContainSubstring("AVAILABLE UPGRADES"))
@@ -144,9 +146,9 @@ var _ = Describe("Get CLI version",
144146

145147
By("Display the version on the candidate channel")
146148
rosaClient.Runner.UnsetArgs()
147-
buf, err = rosaClient.Runner.Cmd("list", "version", "--channel-group", CANDIDATE_CHANNEL).Run()
149+
output, err = versionService.ListVersions(CANDIDATE_CHANNEL, false)
148150
Expect(err).ToNot(HaveOccurred())
149-
stdout = rosaClient.Parser.TextData.Input(buf).Parse().Output()
151+
stdout = rosaClient.Parser.TextData.Input(output).Parse().Output()
150152

151153
By("Check the output of the candidate versions")
152154
Expect(stdout).To(ContainSubstring("AVAILABLE UPGRADES"))
@@ -163,19 +165,19 @@ var _ = Describe("Get CLI version",
163165

164166
By("Display the version on the stable channel with the debug flag")
165167
rosaClient.Runner.UnsetArgs()
166-
buf, err = rosaClient.Runner.Cmd("list", "version", "--debug").Run()
168+
output, err = versionService.ListVersions("", false, "--debug")
167169
Expect(err).ToNot(HaveOccurred())
168-
stdout = rosaClient.Parser.TextData.Input(buf).Parse().Output()
170+
stdout = rosaClient.Parser.TextData.Input(output).Parse().Output()
169171

170172
By("Check the output of the stable versions with the debug flag")
171173
Expect(stdout).To(ContainSubstring("level=debug"))
172174
Expect(stdout).To(ContainSubstring("AVAILABLE UPGRADES"))
173175

174176
By("Display the version on the stable channel with an invalid flag")
175177
rosaClient.Runner.UnsetArgs()
176-
buf, err = rosaClient.Runner.Cmd("list", "version", "--invalidflag").Run()
178+
output, err = versionService.ListVersions("", false, "--debug", "--invalidflag")
177179
Expect(err).To(HaveOccurred())
178-
stdout = rosaClient.Parser.TextData.Input(buf).Parse().Output()
180+
stdout = rosaClient.Parser.TextData.Input(output).Parse().Output()
179181

180182
By("Check the output of the stable versions with an invalid flag")
181183
Expect(stdout).To(ContainSubstring("unknown flag"))

tests/utils/exec/rosacli/ocm_resource_service.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ type OCMResourceService interface {
7575

7676
CreateDNSDomain(flags ...string) (bytes.Buffer, error)
7777
DeleteDNSDomain(domainID string, flags ...string) (bytes.Buffer, error)
78+
ListDNSDomain(flags ...string) (bytes.Buffer, error)
79+
ReflectDNSDomainList(result bytes.Buffer) (dnsDomainlist DNSDomainList, err error)
7880

7981
Token(flags ...string) (bytes.Buffer, error)
8082

@@ -187,6 +189,18 @@ type OIDCConfigList struct {
187189
OIDCConfigList []OIDCConfig `json:"OIDCConfigList,omitempty"`
188190
}
189191

192+
type DNSDomain struct {
193+
ID string `json:"ID,omitempty"`
194+
ClusterID string `json:"CLUSTER ID,omitempty"`
195+
ReservedTime string `json:"RESERVED TIME,omitempty"`
196+
UserDefined string `json:"USER DEFINED,omitempty"`
197+
Architecture string `json:"ARCHITECTURE,omitempty"`
198+
}
199+
200+
type DNSDomainList struct {
201+
DNSDomainList []*DNSDomain `json:"DNSDomainList,omitempty"`
202+
}
203+
190204
// Pasrse the result of 'rosa list instance-types' to InstanceTypes struct
191205
func (ors *ocmResourceService) ReflectInstanceTypesList(result bytes.Buffer) (url InstanceTypesList, err error) {
192206
url = InstanceTypesList{}
@@ -705,6 +719,37 @@ func (ors *ocmResourceService) DeleteDNSDomain(domainID string, flags ...string)
705719
return deleteDNSDomain.Run()
706720
}
707721

722+
// run `rosa list dns-domain`
723+
func (ors *ocmResourceService) ListDNSDomain(flags ...string) (bytes.Buffer, error) {
724+
listDNSDomain := ors.client.Runner
725+
listDNSDomain = listDNSDomain.Cmd("list", "dns-domain").CmdFlags(flags...)
726+
return listDNSDomain.Run()
727+
}
728+
729+
func (ors *ocmResourceService) ReflectDNSDomainList(result bytes.Buffer) (dnsDomainlist DNSDomainList, err error) {
730+
dnsDomainlist = DNSDomainList{}
731+
theMap := ors.client.Parser.TableData.Input(result).Parse().Output()
732+
for _, dnsDomainItem := range theMap {
733+
dnsDomain := &DNSDomain{}
734+
err = MapStructure(dnsDomainItem, dnsDomain)
735+
if err != nil {
736+
return
737+
}
738+
dnsDomainlist.DNSDomainList = append(dnsDomainlist.DNSDomainList, dnsDomain)
739+
}
740+
return dnsDomainlist, err
741+
}
742+
743+
// Get specified DNS domain by ID
744+
func (dnsDomainlist DNSDomainList) GetDNSDomain(id string) (dnsDomain DNSDomain) {
745+
for _, dnsDomainItem := range dnsDomainlist.DNSDomainList {
746+
if dnsDomainItem.ID == id {
747+
return *dnsDomainItem
748+
}
749+
}
750+
return
751+
}
752+
708753
func (ors *ocmResourceService) CleanResources(clusterID string) (errors []error) {
709754
Logger.Debugf("Nothing releated to cluster was done there")
710755
return

tests/utils/helper/dns_domain.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package helper
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
"regexp"
7+
)
8+
9+
// Extract the DNS domain ID from the output of `rosa create dns-domain`
10+
func ExtractDNSDomainID(output bytes.Buffer) (string, error) {
11+
outputStr := output.String()
12+
re := regexp.MustCompile(`DNS domain ‘([^’]+)’ has been created`)
13+
matches := re.FindStringSubmatch(outputStr)
14+
15+
if len(matches) < 2 {
16+
return "", fmt.Errorf("failed to extract dns-domain id from the output %s", outputStr)
17+
}
18+
return matches[1], nil
19+
}

0 commit comments

Comments
 (0)