7
. "github.com/containers/podman/v5/test/utils"
8
. "github.com/onsi/ginkgo/v2"
9
. "github.com/onsi/gomega"
10
. "github.com/onsi/gomega/gexec"
13
func setupContainersConfWithSystemConnections() {
14
// make sure connections are not written to real user config on host
15
file := filepath.Join(podmanTest.TempDir, "containers.conf")
16
f, err := os.Create(file)
17
Expect(err).ToNot(HaveOccurred())
19
os.Setenv("CONTAINERS_CONF", file)
21
file = filepath.Join(podmanTest.TempDir, "connections.conf")
22
f, err = os.Create(file)
23
Expect(err).ToNot(HaveOccurred())
24
connections := `{"connection":{"default":"QA","connections":{"QA":{"uri":"ssh://root@podman.test:2222/run/podman/podman.sock"},"QB":{"uri":"ssh://root@podman.test:3333/run/podman/podman.sock"}}}}`
25
_, err = f.WriteString(connections)
26
Expect(err).ToNot(HaveOccurred())
28
os.Setenv("PODMAN_CONNECTIONS_CONF", file)
31
var _ = Describe("podman farm", func() {
33
BeforeEach(setupContainersConfWithSystemConnections)
35
Context("without running API service", func() {
36
It("verify system connections exist", func() {
37
session := podmanTest.Podman(systemConnectionListCmd)
38
session.WaitWithDefaultTimeout()
39
Expect(session).Should(ExitCleanly())
40
Expect(string(session.Out.Contents())).To(Equal(`QA ssh://root@podman.test:2222/run/podman/podman.sock true true
41
QB ssh://root@podman.test:3333/run/podman/podman.sock false true
45
It("create farm", func() {
46
// create farm with multiple system connections
47
cmd := []string{"farm", "create", "farm1", "QA", "QB"}
48
session := podmanTest.Podman(cmd)
49
session.WaitWithDefaultTimeout()
50
Expect(session).Should(ExitCleanly())
51
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" created"))
53
// create farm with only one system connection
54
cmd = []string{"farm", "create", "farm2", "QA"}
55
session = podmanTest.Podman(cmd)
56
session.WaitWithDefaultTimeout()
57
Expect(session).Should(ExitCleanly())
58
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm2\" created"))
61
cmd = []string{"farm", "create", "farm3"}
62
session = podmanTest.Podman(cmd)
63
session.WaitWithDefaultTimeout()
64
Expect(session).Should(ExitCleanly())
65
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm3\" created"))
67
session = podmanTest.Podman(farmListCmd)
68
session.WaitWithDefaultTimeout()
69
Expect(session).Should(ExitCleanly())
70
Expect(string(session.Out.Contents())).To(Equal(`farm1 [QA QB] true true
75
// create existing farm should exit with error
76
cmd = []string{"farm", "create", "farm3"}
77
session = podmanTest.Podman(cmd)
78
session.WaitWithDefaultTimeout()
79
Expect(session).Should(Not(ExitCleanly()))
82
It("update existing farms", func() {
83
// create farm with multiple system connections
84
cmd := []string{"farm", "create", "farm1", "QA", "QB"}
85
session := podmanTest.Podman(cmd)
86
session.WaitWithDefaultTimeout()
87
Expect(session).Should(ExitCleanly())
88
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" created"))
90
// create farm with only one system connection
91
cmd = []string{"farm", "create", "farm2", "QA"}
92
session = podmanTest.Podman(cmd)
93
session.WaitWithDefaultTimeout()
94
Expect(session).Should(ExitCleanly())
95
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm2\" created"))
98
cmd = []string{"farm", "create", "farm3"}
99
session = podmanTest.Podman(cmd)
100
session.WaitWithDefaultTimeout()
101
Expect(session).Should(ExitCleanly())
102
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm3\" created"))
104
session = podmanTest.Podman(farmListCmd)
105
session.WaitWithDefaultTimeout()
106
Expect(session).Should(ExitCleanly())
107
Expect(string(session.Out.Contents())).To(Equal(`farm1 [QA QB] true true
112
// update farm1 to remove the QA connection from it
113
cmd = []string{"farm", "update", "--remove", "QA,QB", "farm1"}
114
session = podmanTest.Podman(cmd)
115
session.WaitWithDefaultTimeout()
116
Expect(session).Should(ExitCleanly())
117
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" updated"))
119
// update farm3 to add QA and QB connections to it
120
cmd = []string{"farm", "update", "--add", "QB", "farm3"}
121
session = podmanTest.Podman(cmd)
122
session.WaitWithDefaultTimeout()
123
Expect(session).Should(ExitCleanly())
124
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm3\" updated"))
126
// update farm2 to be the default farm
127
cmd = []string{"farm", "update", "--default", "farm2"}
128
session = podmanTest.Podman(cmd)
129
session.WaitWithDefaultTimeout()
130
Expect(session).Should(ExitCleanly())
131
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm2\" updated"))
133
session = podmanTest.Podman(farmListCmd)
134
session.WaitWithDefaultTimeout()
135
Expect(session).Should(ExitCleanly())
136
Expect(string(session.Out.Contents())).To(Equal(`farm1 [] false true
141
// update farm2 to not be the default, no farms should be the default
142
cmd = []string{"farm", "update", "--default=false", "farm2"}
143
session = podmanTest.Podman(cmd)
144
session.WaitWithDefaultTimeout()
145
Expect(session).Should(ExitCleanly())
146
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm2\" updated"))
148
session = podmanTest.Podman(farmListCmd)
149
session.WaitWithDefaultTimeout()
150
Expect(session).Should(ExitCleanly())
151
Expect(string(session.Out.Contents())).To(Equal(`farm1 [] false true
157
It("update farm with non-existing connections", func() {
158
// create farm with multiple system connections
159
cmd := []string{"farm", "create", "farm1", "QA", "QB"}
160
session := podmanTest.Podman(cmd)
161
session.WaitWithDefaultTimeout()
162
Expect(session).Should(ExitCleanly())
163
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" created"))
165
// create farm with only one system connection
166
cmd = []string{"farm", "create", "farm2", "QA"}
167
session = podmanTest.Podman(cmd)
168
session.WaitWithDefaultTimeout()
169
Expect(session).Should(ExitCleanly())
170
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm2\" created"))
172
session = podmanTest.Podman(farmListCmd)
173
session.WaitWithDefaultTimeout()
174
Expect(session).Should(ExitCleanly())
175
Expect(string(session.Out.Contents())).To(Equal(`farm1 [QA QB] true true
179
// update farm1 to add no-node connection to it
180
cmd = []string{"farm", "update", "--add", "no-node", "farm1"}
181
session = podmanTest.Podman(cmd)
182
session.WaitWithDefaultTimeout()
183
Expect(session).Should(ExitWithError(125, `cannot add to farm, "no-node" is not a system connection`))
185
// update farm2 to remove node not in farm connections from it
186
cmd = []string{"farm", "update", "--remove", "QB", "farm2"}
187
session = podmanTest.Podman(cmd)
188
session.WaitWithDefaultTimeout()
189
Expect(session).Should(ExitWithError(125, `cannot remove from farm, "QB" is not a connection in the farm`))
191
// check again to ensure that nothing has changed
192
session = podmanTest.Podman(farmListCmd)
193
session.WaitWithDefaultTimeout()
194
Expect(session).Should(ExitCleanly())
195
Expect(string(session.Out.Contents())).To(Equal(`farm1 [QA QB] true true
200
It("update non-existent farm", func() {
201
// create farm with multiple system connections
202
cmd := []string{"farm", "create", "farm1", "QA", "QB"}
203
session := podmanTest.Podman(cmd)
204
session.WaitWithDefaultTimeout()
205
Expect(session).Should(ExitCleanly())
206
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" created"))
208
// update non-existent farm to add QA connection to it
209
cmd = []string{"farm", "update", "--add", "no-node", "non-existent"}
210
session = podmanTest.Podman(cmd)
211
session.WaitWithDefaultTimeout()
212
Expect(session).Should(ExitWithError(125, `cannot update farm, "non-existent" farm doesn't exist`))
214
// update non-existent farm to default
215
cmd = []string{"farm", "update", "--default", "non-existent"}
216
session = podmanTest.Podman(cmd)
217
session.WaitWithDefaultTimeout()
218
Expect(session).Should(ExitWithError(125, `cannot update farm, "non-existent" farm doesn't exist`))
220
session = podmanTest.Podman(farmListCmd)
221
session.WaitWithDefaultTimeout()
222
Expect(session).Should(ExitCleanly())
223
Expect(session.OutputToString()).To(Equal(`farm1 [QA QB] true true`))
226
It("remove farms", func() {
227
// create farm with multiple system connections
228
cmd := []string{"farm", "create", "farm1", "QA", "QB"}
229
session := podmanTest.Podman(cmd)
230
session.WaitWithDefaultTimeout()
231
Expect(session).Should(ExitCleanly())
232
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" created"))
234
// create farm with only one system connection
235
cmd = []string{"farm", "create", "farm2", "QA"}
236
session = podmanTest.Podman(cmd)
237
session.WaitWithDefaultTimeout()
238
Expect(session).Should(ExitCleanly())
239
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm2\" created"))
241
session = podmanTest.Podman(farmListCmd)
242
session.WaitWithDefaultTimeout()
243
Expect(session).Should(ExitCleanly())
244
Expect(string(session.Out.Contents())).To(Equal(`farm1 [QA QB] true true
248
// remove farm1 and a non-existent farm
249
// farm 1 should be removed and a warning printed for nonexistent-farm
250
cmd = []string{"farm", "rm", "farm1", "nonexistent-farm"}
251
session = podmanTest.Podman(cmd)
252
session.WaitWithDefaultTimeout()
253
Expect(session).Should(Exit(0))
254
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" deleted"))
255
Expect(session.ErrorToString()).Should(ContainSubstring("doesn't exist; nothing to remove"))
257
session = podmanTest.Podman(farmListCmd)
258
session.WaitWithDefaultTimeout()
259
Expect(session).Should(ExitCleanly())
260
Expect(session.OutputToString()).To(Equal(`farm2 [QA] true true`))
262
// remove all non-existent farms and expect an error
263
cmd = []string{"farm", "rm", "foo", "bar"}
264
session = podmanTest.Podman(cmd)
265
session.WaitWithDefaultTimeout()
266
Expect(session).Should(Not(ExitCleanly()))
269
It("remove --all farms", func() {
270
// create farm with multiple system connections
271
cmd := []string{"farm", "create", "farm1", "QA", "QB"}
272
session := podmanTest.Podman(cmd)
273
session.WaitWithDefaultTimeout()
274
Expect(session).Should(ExitCleanly())
275
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" created"))
277
// create farm with only one system connection
278
cmd = []string{"farm", "create", "farm2", "QA"}
279
session = podmanTest.Podman(cmd)
280
session.WaitWithDefaultTimeout()
281
Expect(session).Should(ExitCleanly())
282
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm2\" created"))
285
cmd = []string{"farm", "rm", "--all"}
286
session = podmanTest.Podman(cmd)
287
session.WaitWithDefaultTimeout()
288
Expect(session).Should(ExitCleanly())
289
Expect(session.Out.Contents()).Should(ContainSubstring("All farms have been deleted"))
291
session = podmanTest.Podman(farmListCmd)
292
session.WaitWithDefaultTimeout()
293
Expect(session).Should(ExitCleanly())
294
Expect(session.OutputToString()).To(Equal(""))