@@ -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,39 @@ 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
+ Eventually (func () bool {
94
+ err := k8sClient .Get (ctx , name , ironic )
95
+ Expect (err ).NotTo (HaveOccurred ())
96
+
97
+ cond := meta .FindStatusCondition (ironic .Status .Conditions , string (metal3api .IronicStatusAvailable ))
98
+ if cond != nil && cond .Status == metav1 .ConditionTrue {
99
+ return true
100
+ }
101
+
102
+ GinkgoWriter .Printf ("Current status of Ironic: %+v\n " , ironic )
103
+ return false
104
+ }).WithTimeout (10 * time .Minute ).WithPolling (10 * time .Second ).Should (BeTrue ())
105
+
106
+ return ironic
107
+ }
108
+
109
+ func VerifyIronic (ironic * metal3api.Ironic ) {
110
+ GinkgoHelper ()
111
+
112
+ By ("checking the service" )
113
+
114
+ svc , err := clientset .CoreV1 ().Services (ironic .Namespace ).Get (ctx , ironic .Name , metav1.GetOptions {})
115
+ GinkgoWriter .Printf ("Ironic service: %+v\n " , svc )
116
+ Expect (err ).NotTo (HaveOccurred ())
117
+ }
118
+
85
119
var _ = Describe ("Ironic object tests" , func () {
86
120
var namespace string
87
121
@@ -93,6 +127,15 @@ var _ = Describe("Ironic object tests", func() {
93
127
Expect (err ).NotTo (HaveOccurred ())
94
128
DeferCleanup (func () {
95
129
_ = clientset .CoreV1 ().Namespaces ().Delete (ctx , namespace , metav1.DeleteOptions {})
130
+ Eventually (func () bool {
131
+ _ , err := clientset .CoreV1 ().Namespaces ().Get (ctx , namespace , metav1.GetOptions {})
132
+ if err != nil && k8serrors .IsNotFound (err ) {
133
+ return true
134
+ }
135
+ GinkgoWriter .Println ("Namespace" , namespace , "not deleted yet, error is" , err )
136
+ Expect (err ).NotTo (HaveOccurred ())
137
+ return false
138
+ }).WithTimeout (2 * time .Minute ).WithPolling (5 * time .Second ).Should (BeTrue ())
96
139
})
97
140
})
98
141
@@ -102,33 +145,53 @@ var _ = Describe("Ironic object tests", func() {
102
145
Namespace : namespace ,
103
146
}
104
147
105
- ironic := metal3api.Ironic {
148
+ ironic := & metal3api.Ironic {
106
149
ObjectMeta : metav1.ObjectMeta {
107
150
Name : name .Name ,
108
151
Namespace : name .Namespace ,
109
152
},
110
153
}
111
- err := k8sClient .Create (ctx , & ironic )
154
+ err := k8sClient .Create (ctx , ironic )
112
155
Expect (err ).NotTo (HaveOccurred ())
113
156
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 ())
157
+ ironic = WaitForIronic (name )
158
+ VerifyIronic (ironic )
159
+ })
118
160
119
- cond = meta .FindStatusCondition (ironic .Status .Conditions , string (metal3api .IronicStatusAvailable ))
120
- if cond != nil && cond .Status == metav1 .ConditionTrue {
121
- break
122
- }
161
+ It ("creates distributed Ironic" , func () {
162
+ name := types.NamespacedName {
163
+ Name : "test-ironic" ,
164
+ Namespace : namespace ,
165
+ }
123
166
124
- time .Sleep (5 * time .Second )
167
+ ironicDb := & metal3api.IronicDatabase {
168
+ ObjectMeta : metav1.ObjectMeta {
169
+ Name : fmt .Sprintf ("%s-db" , name .Name ),
170
+ Namespace : name .Namespace ,
171
+ },
125
172
}
126
173
127
- if cond == nil || cond .Status != metav1 .ConditionTrue {
128
- Fail ("Ironic deployment never succeded" )
174
+ err := k8sClient .Create (ctx , ironicDb )
175
+ Expect (err ).NotTo (HaveOccurred ())
176
+
177
+ ironic := & metal3api.Ironic {
178
+ ObjectMeta : metav1.ObjectMeta {
179
+ Name : name .Name ,
180
+ Namespace : name .Namespace ,
181
+ },
182
+ Spec : metal3api.IronicSpec {
183
+ DatabaseRef : corev1.LocalObjectReference {
184
+ Name : ironicDb .Name ,
185
+ },
186
+ Distributed : true ,
187
+ },
129
188
}
130
- })
189
+ err = k8sClient .Create (ctx , ironic )
190
+ Expect (err ).NotTo (HaveOccurred ())
131
191
192
+ ironic = WaitForIronic (name )
193
+ VerifyIronic (ironic )
194
+ })
132
195
})
133
196
134
197
var _ = AfterSuite (func () {
0 commit comments