github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/test/e2e/system_connection_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  	"io/ioutil"
     6  	"os"
     7  
     8  	"github.com/containers/common/pkg/config"
     9  	. "github.com/containers/podman/v2/test/utils"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gbytes"
    13  	. "github.com/onsi/gomega/gexec"
    14  )
    15  
    16  var _ = Describe("podman system connection", func() {
    17  	ConfPath := struct {
    18  		Value string
    19  		IsSet bool
    20  	}{}
    21  
    22  	var (
    23  		podmanTest *PodmanTestIntegration
    24  	)
    25  
    26  	BeforeEach(func() {
    27  		ConfPath.Value, ConfPath.IsSet = os.LookupEnv("CONTAINERS_CONF")
    28  		conf, err := ioutil.TempFile("", "containersconf")
    29  		if err != nil {
    30  			panic(err)
    31  		}
    32  		os.Setenv("CONTAINERS_CONF", conf.Name())
    33  
    34  		tempdir, err := CreateTempDirInTempDir()
    35  		if err != nil {
    36  			panic(err)
    37  		}
    38  		podmanTest = PodmanTestCreate(tempdir)
    39  		podmanTest.Setup()
    40  	})
    41  
    42  	AfterEach(func() {
    43  		podmanTest.Cleanup()
    44  		os.Remove(os.Getenv("CONTAINERS_CONF"))
    45  		if ConfPath.IsSet {
    46  			os.Setenv("CONTAINERS_CONF", ConfPath.Value)
    47  		} else {
    48  			os.Unsetenv("CONTAINERS_CONF")
    49  		}
    50  
    51  		f := CurrentGinkgoTestDescription()
    52  		timedResult := fmt.Sprintf("Test: %s completed in %f seconds", f.TestText, f.Duration.Seconds())
    53  		GinkgoWriter.Write([]byte(timedResult))
    54  	})
    55  
    56  	It("add", func() {
    57  		cmd := []string{"system", "connection", "add",
    58  			"--default",
    59  			"--identity", "~/.ssh/id_rsa",
    60  			"QA",
    61  			"ssh://root@server.fubar.com:2222/run/podman/podman.sock",
    62  		}
    63  		session := podmanTest.Podman(cmd)
    64  		session.WaitWithDefaultTimeout()
    65  		Expect(session).Should(Exit(0))
    66  		Expect(session.Out).Should(Say(""))
    67  
    68  		cfg, err := config.ReadCustomConfig()
    69  		Expect(err).ShouldNot(HaveOccurred())
    70  		Expect(cfg.Engine.ActiveService).To(Equal("QA"))
    71  		Expect(cfg.Engine.ServiceDestinations["QA"]).To(Equal(
    72  			config.Destination{
    73  				URI:      "ssh://root@server.fubar.com:2222/run/podman/podman.sock",
    74  				Identity: "~/.ssh/id_rsa",
    75  			},
    76  		))
    77  
    78  		cmd = []string{"system", "connection", "rename",
    79  			"QA",
    80  			"QE",
    81  		}
    82  		session = podmanTest.Podman(cmd)
    83  		session.WaitWithDefaultTimeout()
    84  		Expect(session).Should(Exit(0))
    85  
    86  		cfg, err = config.ReadCustomConfig()
    87  		Expect(err).ShouldNot(HaveOccurred())
    88  		Expect(cfg.Engine.ActiveService).To(Equal("QE"))
    89  		Expect(cfg.Engine.ServiceDestinations["QE"]).To(Equal(
    90  			config.Destination{
    91  				URI:      "ssh://root@server.fubar.com:2222/run/podman/podman.sock",
    92  				Identity: "~/.ssh/id_rsa",
    93  			},
    94  		))
    95  	})
    96  
    97  	It("remove", func() {
    98  		cmd := []string{"system", "connection", "add",
    99  			"--default",
   100  			"--identity", "~/.ssh/id_rsa",
   101  			"QA",
   102  			"ssh://root@server.fubar.com:2222/run/podman/podman.sock",
   103  		}
   104  		session := podmanTest.Podman(cmd)
   105  		session.WaitWithDefaultTimeout()
   106  		Expect(session).Should(Exit(0))
   107  
   108  		for i := 0; i < 2; i++ {
   109  			cmd = []string{"system", "connection", "remove", "QA"}
   110  			session = podmanTest.Podman(cmd)
   111  			session.WaitWithDefaultTimeout()
   112  			Expect(session).Should(Exit(0))
   113  			Expect(session.Out).Should(Say(""))
   114  
   115  			cfg, err := config.ReadCustomConfig()
   116  			Expect(err).ShouldNot(HaveOccurred())
   117  			Expect(cfg.Engine.ActiveService).To(BeEmpty())
   118  			Expect(cfg.Engine.ServiceDestinations).To(BeEmpty())
   119  		}
   120  	})
   121  
   122  	It("default", func() {
   123  		for _, name := range []string{"devl", "qe"} {
   124  			cmd := []string{"system", "connection", "add",
   125  				"--default",
   126  				"--identity", "~/.ssh/id_rsa",
   127  				name,
   128  				"ssh://root@server.fubar.com:2222/run/podman/podman.sock",
   129  			}
   130  			session := podmanTest.Podman(cmd)
   131  			session.WaitWithDefaultTimeout()
   132  			Expect(session).Should(Exit(0))
   133  		}
   134  
   135  		cmd := []string{"system", "connection", "default", "devl"}
   136  		session := podmanTest.Podman(cmd)
   137  		session.WaitWithDefaultTimeout()
   138  		Expect(session).Should(Exit(0))
   139  		Expect(session.Out).Should(Say(""))
   140  
   141  		cfg, err := config.ReadCustomConfig()
   142  		Expect(err).ShouldNot(HaveOccurred())
   143  		Expect(cfg.Engine.ActiveService).To(Equal("devl"))
   144  
   145  		cmd = []string{"system", "connection", "list"}
   146  		session = podmanTest.Podman(cmd)
   147  		session.WaitWithDefaultTimeout()
   148  		Expect(session).Should(Exit(0))
   149  		Expect(session.Out).Should(Say("Name *Identity *URI"))
   150  	})
   151  
   152  	It("failed default", func() {
   153  		cmd := []string{"system", "connection", "default", "devl"}
   154  		session := podmanTest.Podman(cmd)
   155  		session.WaitWithDefaultTimeout()
   156  		Expect(session).ShouldNot(Exit(0))
   157  		Expect(session.Err).Should(Say("destination is not defined"))
   158  	})
   159  
   160  	It("failed rename", func() {
   161  		cmd := []string{"system", "connection", "rename", "devl", "QE"}
   162  		session := podmanTest.Podman(cmd)
   163  		session.WaitWithDefaultTimeout()
   164  		Expect(session).ShouldNot(Exit(0))
   165  		Expect(session.Err).Should(Say("destination is not defined"))
   166  	})
   167  
   168  	It("empty list", func() {
   169  		cmd := []string{"system", "connection", "list"}
   170  		session := podmanTest.Podman(cmd)
   171  		session.WaitWithDefaultTimeout()
   172  		Expect(session).Should(Exit(0))
   173  		Expect(session.Out).Should(Say(""))
   174  		Expect(session.Err).Should(Say(""))
   175  	})
   176  })