github.com/looshlee/cilium@v1.6.12/test/runtime/kvstore.go (about)

     1  // Copyright 2017-2019 Authors of Cilium
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package RuntimeTest
    16  
    17  import (
    18  	"context"
    19  
    20  	. "github.com/cilium/cilium/test/ginkgo-ext"
    21  	"github.com/cilium/cilium/test/helpers"
    22  	"github.com/cilium/cilium/test/helpers/constants"
    23  
    24  	. "github.com/onsi/gomega"
    25  )
    26  
    27  var _ = Describe("RuntimeKVStoreTest", func() {
    28  
    29  	var vm *helpers.SSHMeta
    30  
    31  	BeforeAll(func() {
    32  		vm = helpers.InitRuntimeHelper(helpers.Runtime, logger)
    33  		ExpectCiliumReady(vm)
    34  	})
    35  
    36  	containers := func(option string) {
    37  		switch option {
    38  		case helpers.Create:
    39  			vm.NetworkCreate(helpers.CiliumDockerNetwork, "")
    40  			vm.ContainerCreate(helpers.Client, constants.NetperfImage, helpers.CiliumDockerNetwork, "-l id.client")
    41  		case helpers.Delete:
    42  			vm.ContainerRm(helpers.Client)
    43  
    44  		}
    45  	}
    46  
    47  	BeforeEach(func() {
    48  		res := vm.ExecWithSudo("systemctl stop cilium")
    49  		res.ExpectSuccess("Failed trying to stop cilium via systemctl")
    50  		ExpectCiliumNotRunning(vm)
    51  	}, 150)
    52  
    53  	AfterEach(func() {
    54  		containers(helpers.Delete)
    55  		err := vm.RestartCilium()
    56  		Expect(err).Should(BeNil(), "restarting Cilium failed")
    57  	})
    58  
    59  	JustAfterEach(func() {
    60  		vm.ValidateNoErrorsInLogs(CurrentGinkgoTestDescription().Duration)
    61  	})
    62  
    63  	AfterFailed(func() {
    64  		vm.ReportFailed("cilium status")
    65  	})
    66  
    67  	AfterAll(func() {
    68  		vm.CloseSSHClient()
    69  	})
    70  
    71  	It("Consul KVStore", func() {
    72  		ctx, cancel := context.WithCancel(context.Background())
    73  		defer cancel()
    74  		By("Starting Cilium with consul as kvstore")
    75  		vm.ExecInBackground(
    76  			ctx,
    77  			"sudo cilium-agent --kvstore consul --kvstore-opt consul.address=127.0.0.1:8500 --debug")
    78  		err := vm.WaitUntilReady(helpers.CiliumStartTimeout)
    79  		Expect(err).Should(BeNil())
    80  
    81  		By("Restarting cilium-docker service")
    82  		vm.Exec("sudo systemctl restart cilium-docker")
    83  		helpers.Sleep(2)
    84  		containers(helpers.Create)
    85  		vm.WaitEndpointsReady()
    86  		eps, err := vm.GetEndpointsNames()
    87  		Expect(err).Should(BeNil(), "Error getting names of endpoints from cilium")
    88  		Expect(len(eps)).To(Equal(1), "Number of endpoints in Cilium differs from what is expected")
    89  	})
    90  
    91  	It("Etcd KVStore", func() {
    92  		ctx, cancel := context.WithCancel(context.Background())
    93  		defer cancel()
    94  		By("Starting Cilium with etcd as kvstore")
    95  		vm.ExecInBackground(
    96  			ctx,
    97  			"sudo cilium-agent --kvstore etcd --kvstore-opt etcd.address=127.0.0.1:4001 2>&1 | logger -t cilium")
    98  		err := vm.WaitUntilReady(helpers.CiliumStartTimeout)
    99  		Expect(err).Should(BeNil(), "Timed out waiting for VM to be ready after restarting Cilium")
   100  
   101  		By("Restarting cilium-docker service")
   102  		vm.Exec("sudo systemctl restart cilium-docker")
   103  		helpers.Sleep(2)
   104  		containers(helpers.Create)
   105  
   106  		vm.WaitEndpointsReady()
   107  
   108  		eps, err := vm.GetEndpointsNames()
   109  		Expect(err).Should(BeNil(), "Error getting names of endpoints from cilium")
   110  		Expect(len(eps)).To(Equal(1), "Number of endpoints in Cilium differs from what is expected")
   111  	})
   112  })