@@ -20,6 +20,7 @@ package main
20
20
import (
21
21
"context"
22
22
"fmt"
23
+ "io"
23
24
"math/rand"
24
25
"os"
25
26
"testing"
@@ -98,10 +99,34 @@ func WaitForIronic(name types.NamespacedName) *metal3api.Ironic {
98
99
if cond != nil && cond .Status == metav1 .ConditionTrue {
99
100
return true
100
101
}
102
+ GinkgoWriter .Printf ("Current status of Ironic: %+v\n " , ironic .Status )
103
+
104
+ deployName := fmt .Sprintf ("%s-service" , name .Name )
105
+ if ironic .Spec .Distributed {
106
+ deploy , err := clientset .AppsV1 ().DaemonSets (name .Namespace ).Get (ctx , deployName , metav1.GetOptions {})
107
+ if err == nil {
108
+ GinkgoWriter .Printf (".. status of daemon set: %+v\n " , deploy .Status )
109
+ } else if ! k8serrors .IsNotFound (err ) {
110
+ Expect (err ).NotTo (HaveOccurred ())
111
+ }
112
+ } else {
113
+ deploy , err := clientset .AppsV1 ().Deployments (name .Namespace ).Get (ctx , deployName , metav1.GetOptions {})
114
+ if err == nil {
115
+ GinkgoWriter .Printf (".. status of deployment: %+v\n " , deploy .Status )
116
+ } else if ! k8serrors .IsNotFound (err ) {
117
+ Expect (err ).NotTo (HaveOccurred ())
118
+ }
119
+ }
120
+
121
+ pods , err := clientset .CoreV1 ().Pods (name .Namespace ).List (ctx , metav1.ListOptions {})
122
+ Expect (err ).NotTo (HaveOccurred ())
123
+
124
+ for _ , pod := range pods .Items {
125
+ GinkgoWriter .Printf ("... status of pod %s: %+v\n " , pod .Name , pod .Status )
126
+ }
101
127
102
- GinkgoWriter .Printf ("Current status of Ironic: %+v\n " , ironic )
103
128
return false
104
- }).WithTimeout (15 * time .Minute ).WithPolling (10 * time .Second ).Should (BeTrue ())
129
+ }).WithTimeout (5 * time .Minute ).WithPolling (10 * time .Second ).Should (BeTrue ())
105
130
106
131
return ironic
107
132
}
@@ -116,6 +141,30 @@ func VerifyIronic(ironic *metal3api.Ironic) {
116
141
Expect (err ).NotTo (HaveOccurred ())
117
142
}
118
143
144
+ func CollectLogs (namespace string ) {
145
+ GinkgoHelper ()
146
+
147
+ pods , err := clientset .CoreV1 ().Pods (namespace ).List (ctx , metav1.ListOptions {})
148
+ Expect (err ).NotTo (HaveOccurred ())
149
+
150
+ for _ , pod := range pods .Items {
151
+ for _ , cont := range pod .Spec .Containers {
152
+ podLogOpts := corev1.PodLogOptions {Container : cont .Name }
153
+ req := clientset .CoreV1 ().Pods (pod .Namespace ).GetLogs (pod .Name , & podLogOpts )
154
+ podLogs , err := req .Stream (ctx )
155
+ Expect (err ).NotTo (HaveOccurred ())
156
+ defer podLogs .Close ()
157
+
158
+ logFile , err := os .Create (fmt .Sprintf ("%s.%s.%s.log" , namespace , pod .Name , cont .Name ))
159
+ Expect (err ).NotTo (HaveOccurred ())
160
+ defer logFile .Close ()
161
+
162
+ _ , err = io .Copy (logFile , podLogs )
163
+ Expect (err ).NotTo (HaveOccurred ())
164
+ }
165
+ }
166
+ }
167
+
119
168
func DeleteAndWait (ironic * metal3api.Ironic ) {
120
169
GinkgoHelper ()
121
170
@@ -177,6 +226,46 @@ var _ = Describe("Ironic object tests", func() {
177
226
err := k8sClient .Create (ctx , ironic )
178
227
Expect (err ).NotTo (HaveOccurred ())
179
228
DeferCleanup (func () {
229
+ CollectLogs (namespace )
230
+ DeleteAndWait (ironic )
231
+ })
232
+
233
+ ironic = WaitForIronic (name )
234
+ VerifyIronic (ironic )
235
+ })
236
+
237
+ It ("creates distributed Ironic" , func () {
238
+ name := types.NamespacedName {
239
+ Name : "test-ironic" ,
240
+ Namespace : namespace ,
241
+ }
242
+
243
+ ironicDb := & metal3api.IronicDatabase {
244
+ ObjectMeta : metav1.ObjectMeta {
245
+ Name : fmt .Sprintf ("%s-db" , name .Name ),
246
+ Namespace : name .Namespace ,
247
+ },
248
+ }
249
+
250
+ err := k8sClient .Create (ctx , ironicDb )
251
+ Expect (err ).NotTo (HaveOccurred ())
252
+
253
+ ironic := & metal3api.Ironic {
254
+ ObjectMeta : metav1.ObjectMeta {
255
+ Name : name .Name ,
256
+ Namespace : name .Namespace ,
257
+ },
258
+ Spec : metal3api.IronicSpec {
259
+ DatabaseRef : corev1.LocalObjectReference {
260
+ Name : ironicDb .Name ,
261
+ },
262
+ Distributed : true ,
263
+ },
264
+ }
265
+ err = k8sClient .Create (ctx , ironic )
266
+ Expect (err ).NotTo (HaveOccurred ())
267
+ DeferCleanup (func () {
268
+ CollectLogs (namespace )
180
269
DeleteAndWait (ironic )
181
270
})
182
271
0 commit comments