1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
|
//go:build linux || freebsd
package integration
import (
"os"
"path/filepath"
. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
func setupContainersConfWithSystemConnections() {
// make sure connections are not written to real user config on host
file := filepath.Join(podmanTest.TempDir, "containers.conf")
f, err := os.Create(file)
Expect(err).ToNot(HaveOccurred())
f.Close()
os.Setenv("CONTAINERS_CONF", file)
file = filepath.Join(podmanTest.TempDir, "connections.conf")
f, err = os.Create(file)
Expect(err).ToNot(HaveOccurred())
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"}}}}`
_, err = f.WriteString(connections)
Expect(err).ToNot(HaveOccurred())
f.Close()
os.Setenv("PODMAN_CONNECTIONS_CONF", file)
}
var _ = Describe("podman farm", func() {
BeforeEach(setupContainersConfWithSystemConnections)
Context("without running API service", func() {
It("verify system connections exist", func() {
session := podmanTest.Podman(systemConnectionListCmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(string(session.Out.Contents())).To(Equal(`QA ssh://root@podman.test:2222/run/podman/podman.sock true true
QB ssh://root@podman.test:3333/run/podman/podman.sock false true
`))
})
It("create farm", func() {
// create farm with multiple system connections
cmd := []string{"farm", "create", "farm1", "QA", "QB"}
session := podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" created"))
// create farm with only one system connection
cmd = []string{"farm", "create", "farm2", "QA"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm2\" created"))
// create empty farm
cmd = []string{"farm", "create", "farm3"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm3\" created"))
session = podmanTest.Podman(farmListCmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(string(session.Out.Contents())).To(Equal(`farm1 [QA QB] true true
farm2 [QA] false true
farm3 [] false true
`))
// create existing farm should exit with error
cmd = []string{"farm", "create", "farm3"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(Not(ExitCleanly()))
})
It("update existing farms", func() {
// create farm with multiple system connections
cmd := []string{"farm", "create", "farm1", "QA", "QB"}
session := podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" created"))
// create farm with only one system connection
cmd = []string{"farm", "create", "farm2", "QA"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm2\" created"))
// create empty farm
cmd = []string{"farm", "create", "farm3"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm3\" created"))
session = podmanTest.Podman(farmListCmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(string(session.Out.Contents())).To(Equal(`farm1 [QA QB] true true
farm2 [QA] false true
farm3 [] false true
`))
// update farm1 to remove the QA connection from it
cmd = []string{"farm", "update", "--remove", "QA,QB", "farm1"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" updated"))
// update farm3 to add QA and QB connections to it
cmd = []string{"farm", "update", "--add", "QB", "farm3"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm3\" updated"))
// update farm2 to be the default farm
cmd = []string{"farm", "update", "--default", "farm2"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm2\" updated"))
session = podmanTest.Podman(farmListCmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(string(session.Out.Contents())).To(Equal(`farm1 [] false true
farm2 [QA] true true
farm3 [QB] false true
`))
// update farm2 to not be the default, no farms should be the default
cmd = []string{"farm", "update", "--default=false", "farm2"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm2\" updated"))
session = podmanTest.Podman(farmListCmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(string(session.Out.Contents())).To(Equal(`farm1 [] false true
farm2 [QA] false true
farm3 [QB] false true
`))
})
It("update farm with non-existing connections", func() {
// create farm with multiple system connections
cmd := []string{"farm", "create", "farm1", "QA", "QB"}
session := podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" created"))
// create farm with only one system connection
cmd = []string{"farm", "create", "farm2", "QA"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm2\" created"))
session = podmanTest.Podman(farmListCmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(string(session.Out.Contents())).To(Equal(`farm1 [QA QB] true true
farm2 [QA] false true
`))
// update farm1 to add no-node connection to it
cmd = []string{"farm", "update", "--add", "no-node", "farm1"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitWithError(125, `cannot add to farm, "no-node" is not a system connection`))
// update farm2 to remove node not in farm connections from it
cmd = []string{"farm", "update", "--remove", "QB", "farm2"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitWithError(125, `cannot remove from farm, "QB" is not a connection in the farm`))
// check again to ensure that nothing has changed
session = podmanTest.Podman(farmListCmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(string(session.Out.Contents())).To(Equal(`farm1 [QA QB] true true
farm2 [QA] false true
`))
})
It("update non-existent farm", func() {
// create farm with multiple system connections
cmd := []string{"farm", "create", "farm1", "QA", "QB"}
session := podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" created"))
// update non-existent farm to add QA connection to it
cmd = []string{"farm", "update", "--add", "no-node", "non-existent"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitWithError(125, `cannot update farm, "non-existent" farm doesn't exist`))
// update non-existent farm to default
cmd = []string{"farm", "update", "--default", "non-existent"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitWithError(125, `cannot update farm, "non-existent" farm doesn't exist`))
session = podmanTest.Podman(farmListCmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToString()).To(Equal(`farm1 [QA QB] true true`))
})
It("remove farms", func() {
// create farm with multiple system connections
cmd := []string{"farm", "create", "farm1", "QA", "QB"}
session := podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" created"))
// create farm with only one system connection
cmd = []string{"farm", "create", "farm2", "QA"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm2\" created"))
session = podmanTest.Podman(farmListCmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(string(session.Out.Contents())).To(Equal(`farm1 [QA QB] true true
farm2 [QA] false true
`))
// remove farm1 and a non-existent farm
// farm 1 should be removed and a warning printed for nonexistent-farm
cmd = []string{"farm", "rm", "farm1", "nonexistent-farm"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" deleted"))
Expect(session.ErrorToString()).Should(ContainSubstring("doesn't exist; nothing to remove"))
session = podmanTest.Podman(farmListCmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToString()).To(Equal(`farm2 [QA] true true`))
// remove all non-existent farms and expect an error
cmd = []string{"farm", "rm", "foo", "bar"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(Not(ExitCleanly()))
})
It("remove --all farms", func() {
// create farm with multiple system connections
cmd := []string{"farm", "create", "farm1", "QA", "QB"}
session := podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm1\" created"))
// create farm with only one system connection
cmd = []string{"farm", "create", "farm2", "QA"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("Farm \"farm2\" created"))
// remove --all
cmd = []string{"farm", "rm", "--all"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(ContainSubstring("All farms have been deleted"))
session = podmanTest.Podman(farmListCmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToString()).To(Equal(""))
})
})
})
|