@@ -29,6 +29,7 @@ import (
29
29
. "github.com/onsi/gomega"
30
30
31
31
corev1 "k8s.io/api/core/v1"
32
+ k8serrors "k8s.io/apimachinery/pkg/api/errors"
32
33
"k8s.io/apimachinery/pkg/api/meta"
33
34
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34
35
"k8s.io/apimachinery/pkg/types"
@@ -82,6 +83,42 @@ var _ = BeforeSuite(func() {
82
83
83
84
})
84
85
86
+ func WaitForIronic (name types.NamespacedName ) * metal3api.Ironic {
87
+ GinkgoHelper ()
88
+
89
+ ironic := & metal3api.Ironic {}
90
+
91
+ By ("waiting for Ironic deployment" )
92
+
93
+ var cond * metav1.Condition
94
+ for attempt := 0 ; attempt < 10 ; attempt += 1 {
95
+ err := k8sClient .Get (ctx , name , ironic )
96
+ Expect (err ).NotTo (HaveOccurred ())
97
+
98
+ cond = meta .FindStatusCondition (ironic .Status .Conditions , string (metal3api .IronicStatusAvailable ))
99
+ if cond != nil && cond .Status == metav1 .ConditionTrue {
100
+ break
101
+ }
102
+
103
+ time .Sleep (5 * time .Second )
104
+ }
105
+
106
+ if cond == nil || cond .Status != metav1 .ConditionTrue {
107
+ Fail ("Ironic deployment never succeded" )
108
+ }
109
+
110
+ return ironic
111
+ }
112
+
113
+ func VerifyIronic (ironic * metal3api.Ironic ) {
114
+ GinkgoHelper ()
115
+
116
+ By ("checking the service" )
117
+
118
+ _ , err := clientset .CoreV1 ().Services (ironic .Namespace ).Get (ctx , ironic .Name , metav1.GetOptions {})
119
+ Expect (err ).NotTo (HaveOccurred ())
120
+ }
121
+
85
122
var _ = Describe ("Ironic object tests" , func () {
86
123
var namespace string
87
124
@@ -93,6 +130,16 @@ var _ = Describe("Ironic object tests", func() {
93
130
Expect (err ).NotTo (HaveOccurred ())
94
131
DeferCleanup (func () {
95
132
_ = clientset .CoreV1 ().Namespaces ().Delete (ctx , namespace , metav1.DeleteOptions {})
133
+ for attempt := 0 ; attempt < 10 ; attempt += 1 {
134
+ _ , err := clientset .CoreV1 ().Namespaces ().Get (ctx , namespace , metav1.GetOptions {})
135
+ if err != nil && k8serrors .IsNotFound (err ) {
136
+ break
137
+ } else {
138
+ Expect (err ).NotTo (HaveOccurred ())
139
+ }
140
+
141
+ time .Sleep (5 * time .Second )
142
+ }
96
143
})
97
144
})
98
145
@@ -102,33 +149,53 @@ var _ = Describe("Ironic object tests", func() {
102
149
Namespace : namespace ,
103
150
}
104
151
105
- ironic := metal3api.Ironic {
152
+ ironic := & metal3api.Ironic {
106
153
ObjectMeta : metav1.ObjectMeta {
107
154
Name : name .Name ,
108
155
Namespace : name .Namespace ,
109
156
},
110
157
}
111
- err := k8sClient .Create (ctx , & ironic )
158
+ err := k8sClient .Create (ctx , ironic )
112
159
Expect (err ).NotTo (HaveOccurred ())
113
160
114
- var cond * metav1.Condition
115
- for attempt := 0 ; attempt < 10 ; attempt += 1 {
116
- err = k8sClient .Get (ctx , name , & ironic )
117
- Expect (err ).NotTo (HaveOccurred ())
161
+ ironic = WaitForIronic (name )
162
+ VerifyIronic (ironic )
163
+ })
118
164
119
- cond = meta .FindStatusCondition (ironic .Status .Conditions , string (metal3api .IronicStatusAvailable ))
120
- if cond != nil && cond .Status == metav1 .ConditionTrue {
121
- break
122
- }
165
+ It ("creates distributed Ironic" , func () {
166
+ name := types.NamespacedName {
167
+ Name : "test-ironic" ,
168
+ Namespace : namespace ,
169
+ }
123
170
124
- time .Sleep (5 * time .Second )
171
+ ironicDb := & metal3api.IronicDatabase {
172
+ ObjectMeta : metav1.ObjectMeta {
173
+ Name : fmt .Sprintf ("%s-db" , name .Name ),
174
+ Namespace : name .Namespace ,
175
+ },
125
176
}
126
177
127
- if cond == nil || cond .Status != metav1 .ConditionTrue {
128
- Fail ("Ironic deployment never succeded" )
178
+ err := k8sClient .Create (ctx , ironicDb )
179
+ Expect (err ).NotTo (HaveOccurred ())
180
+
181
+ ironic := & metal3api.Ironic {
182
+ ObjectMeta : metav1.ObjectMeta {
183
+ Name : name .Name ,
184
+ Namespace : name .Namespace ,
185
+ },
186
+ Spec : metal3api.IronicSpec {
187
+ DatabaseRef : corev1.LocalObjectReference {
188
+ Name : ironicDb .Name ,
189
+ },
190
+ Distributed : true ,
191
+ },
129
192
}
130
- })
193
+ err = k8sClient .Create (ctx , ironic )
194
+ Expect (err ).NotTo (HaveOccurred ())
131
195
196
+ ironic = WaitForIronic (name )
197
+ VerifyIronic (ironic )
198
+ })
132
199
})
133
200
134
201
var _ = AfterSuite (func () {
0 commit comments