code.cloudfoundry.org/diego-upgrade-stability-tests@v0.0.0-20210607152719-27f1f0151c54/dusts_test.go (about)

     1  package dusts_test
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"io/ioutil"
     7  	"os"
     8  	"os/exec"
     9  	"path/filepath"
    10  	"strconv"
    11  	"strings"
    12  
    13  	auctioneerconfig "code.cloudfoundry.org/auctioneer/cmd/auctioneer/config"
    14  	bbsconfig "code.cloudfoundry.org/bbs/cmd/bbs/config"
    15  	"code.cloudfoundry.org/guardian/gqt/runner"
    16  	"code.cloudfoundry.org/inigo/helpers"
    17  	"code.cloudfoundry.org/inigo/world"
    18  	"code.cloudfoundry.org/lager"
    19  	"code.cloudfoundry.org/localip"
    20  	repconfig "code.cloudfoundry.org/rep/cmd/rep/config"
    21  	routeemitterconfig "code.cloudfoundry.org/route-emitter/cmd/route-emitter/config"
    22  	vizziniconfig "code.cloudfoundry.org/vizzini/config"
    23  	. "github.com/onsi/ginkgo"
    24  	. "github.com/onsi/gomega"
    25  	"github.com/tedsuo/ifrit"
    26  	"github.com/tedsuo/ifrit/ginkgomon"
    27  	"github.com/tedsuo/ifrit/grouper"
    28  )
    29  
    30  var (
    31  	repV0UnsupportedVizziniTests = []string{"MaxPids", "CF_INSTANCE_INTERNAL_IP", "sidecar"}
    32  	// security_group_tests in V0 vizzini won't pass since they try to access the
    33  	// router (as opposed to www.example.com in recent versions). Security groups
    34  	// don't affect access to the host machine, therefore they cannot block
    35  	// traffic which causes both tests in that file to fail
    36  	securityGroupV0Tests = "should allow access to an internal IP"
    37  
    38  	vizziniConfigFile *os.File
    39  )
    40  
    41  var _ = Describe("UpgradeVizzini", func() {
    42  	disableAuctioneerSSL := func(cfg *auctioneerconfig.AuctioneerConfig) {
    43  		cfg.CACertFile = ""
    44  		cfg.ServerCertFile = ""
    45  		cfg.ServerKeyFile = ""
    46  	}
    47  	skipLocketForBBS := func(cfg *bbsconfig.BBSConfig) {
    48  		cfg.LocksLocketEnabled = false
    49  		cfg.CellRegistrationsLocketEnabled = false
    50  	}
    51  	fallbackToHTTPAuctioneer := func(cfg *bbsconfig.BBSConfig) {
    52  		cfg.AuctioneerRequireTLS = false
    53  	}
    54  	disableLocketForAuctioneer := func(cfg *auctioneerconfig.AuctioneerConfig) {
    55  		cfg.LocksLocketEnabled = false
    56  	}
    57  	exportNetworkConfigs := func(cfg *repconfig.RepConfig) {
    58  		cfg.ExportNetworkEnvVars = true
    59  	}
    60  	var (
    61  		plumbing                                             ifrit.Process
    62  		locket, bbs, routeEmitter, sshProxy, auctioneer, rep ifrit.Process
    63  		locketRunner                                         ifrit.Runner
    64  		bbsRunner                                            ifrit.Runner
    65  		routeEmitterRunner                                   ifrit.Runner
    66  		sshProxyRunner                                       ifrit.Runner
    67  		auctioneerRunner                                     ifrit.Runner
    68  		repRunner                                            ifrit.Runner
    69  		bbsClientGoPathEnvVar                                string
    70  		setRouteEmitterCellID                                func(config *routeemitterconfig.RouteEmitterConfig)
    71  	)
    72  
    73  	BeforeEach(func() {
    74  		var err error
    75  		vizziniConfigFile, err = ioutil.TempFile(os.TempDir(), "vizzini_config-")
    76  		Expect(err).ToNot(HaveOccurred())
    77  	})
    78  
    79  	AfterEach(func() {
    80  		err := os.Remove(vizziniConfigFile.Name())
    81  		Expect(err).ToNot(HaveOccurred())
    82  	})
    83  
    84  	if os.Getenv("DIEGO_VERSION_V0") == diegoGAVersion {
    85  		Context(fmt.Sprintf("from %s", diegoGAVersion), func() {
    86  			QuietBeforeEach(func() {
    87  				logger = lager.NewLogger("test")
    88  				logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.DEBUG))
    89  
    90  				bbsClientGoPathEnvVar = "GOPATH_V0"
    91  
    92  				ComponentMakerV0 = world.MakeV0ComponentMaker(oldArtifacts, addresses, allocator, certAuthority)
    93  				ComponentMakerV0.Setup()
    94  
    95  				fileServer, _ := ComponentMakerV1.FileServer()
    96  
    97  				plumbing = ginkgomon.Invoke(grouper.NewParallel(os.Kill, grouper.Members{
    98  					{Name: "nats", Runner: ComponentMakerV1.NATS()},
    99  					{Name: "sql", Runner: ComponentMakerV1.SQL()},
   100  					{Name: "consul", Runner: ComponentMakerV1.Consul()},
   101  					{Name: "file-server", Runner: fileServer},
   102  					{Name: "garden", Runner: ComponentMakerV1.Garden(func(cfg *runner.GdnRunnerConfig) {
   103  						poolSize := 100
   104  						cfg.PortPoolSize = &poolSize
   105  					})},
   106  					{Name: "router", Runner: ComponentMakerV1.Router()},
   107  				}))
   108  				helpers.ConsulWaitUntilReady(ComponentMakerV0.Addresses())
   109  
   110  				bbsRunner = ComponentMakerV0.BBS()
   111  				routeEmitterRunner = ComponentMakerV0.RouteEmitter()
   112  				auctioneerRunner = ComponentMakerV0.Auctioneer()
   113  				repRunner = ComponentMakerV0.Rep()
   114  				sshProxyRunner = ComponentMakerV0.SSHProxy()
   115  			})
   116  
   117  			QuietJustBeforeEach(func() {
   118  				bbs = ginkgomon.Invoke(bbsRunner)
   119  				routeEmitter = ginkgomon.Invoke(routeEmitterRunner)
   120  				auctioneer = ginkgomon.Invoke(auctioneerRunner)
   121  				rep = ginkgomon.Invoke(repRunner)
   122  				sshProxy = ginkgomon.Invoke(sshProxyRunner)
   123  			})
   124  
   125  			AfterEach(func() {
   126  				destroyContainerErrors := helpers.CleanupGarden(ComponentMakerV1.GardenClient())
   127  
   128  				helpers.StopProcesses(
   129  					auctioneer,
   130  					rep,
   131  					routeEmitter,
   132  					sshProxy,
   133  					bbs,
   134  					plumbing,
   135  				)
   136  
   137  				Expect(destroyContainerErrors).To(
   138  					BeEmpty(),
   139  					"%d containers failed to be destroyed!",
   140  					len(destroyContainerErrors),
   141  				)
   142  			})
   143  
   144  			Context("v0 configuration", func() {
   145  				It("runs vizzini successfully", func() {
   146  					runVizziniTests(ComponentMakerV0.BBSSSLConfig(), bbsClientGoPathEnvVar, securityGroupV0Tests)
   147  				})
   148  			})
   149  
   150  			Context("upgrading the BBS API", func() {
   151  				BeforeEach(func() {
   152  					bbsRunner = ComponentMakerV1.BBS(skipLocketForBBS, fallbackToHTTPAuctioneer)
   153  					auctioneerRunner = ComponentMakerV0.Auctioneer(disableAuctioneerSSL)
   154  					sshProxyRunner = ComponentMakerV1.SSHProxy()
   155  				})
   156  
   157  				It("runs vizzini successfully", func() {
   158  					runVizziniTests(ComponentMakerV1.BBSSSLConfig(), bbsClientGoPathEnvVar, securityGroupV0Tests)
   159  				})
   160  			})
   161  
   162  			Context("upgrading the BBS API and BBS client", func() {
   163  				BeforeEach(func() {
   164  					bbsClientGoPathEnvVar = "GOPATH"
   165  
   166  					bbsRunner = ComponentMakerV1.BBS(skipLocketForBBS, fallbackToHTTPAuctioneer)
   167  					auctioneerRunner = ComponentMakerV0.Auctioneer(disableAuctioneerSSL)
   168  					sshProxyRunner = ComponentMakerV1.SSHProxy()
   169  				})
   170  
   171  				It("runs vizzini successfully", func() {
   172  					runVizziniTests(ComponentMakerV1.BBSSSLConfig(), bbsClientGoPathEnvVar, repV0UnsupportedVizziniTests...)
   173  				})
   174  			})
   175  
   176  			Context("upgrading the BBS API, BBS client, sshProxy, and Auctioneer", func() {
   177  				BeforeEach(func() {
   178  					bbsClientGoPathEnvVar = "GOPATH"
   179  					bbsRunner = ComponentMakerV1.BBS(skipLocketForBBS, fallbackToHTTPAuctioneer)
   180  					auctioneerRunner = ComponentMakerV1.Auctioneer(disableLocketForAuctioneer, disableAuctioneerSSL)
   181  					sshProxyRunner = ComponentMakerV1.SSHProxy()
   182  				})
   183  
   184  				It("runs vizzini successfully", func() {
   185  					runVizziniTests(ComponentMakerV1.BBSSSLConfig(), bbsClientGoPathEnvVar, repV0UnsupportedVizziniTests...)
   186  				})
   187  			})
   188  
   189  			Context("upgrading the BBS API, BBS client, sshProxy, Auctioneer, and Rep", func() {
   190  				BeforeEach(func() {
   191  					bbsClientGoPathEnvVar = "GOPATH"
   192  					bbsRunner = ComponentMakerV1.BBS(skipLocketForBBS, fallbackToHTTPAuctioneer)
   193  					auctioneerRunner = ComponentMakerV1.Auctioneer(disableLocketForAuctioneer, disableAuctioneerSSL)
   194  					sshProxyRunner = ComponentMakerV1.SSHProxy()
   195  					repRunner = ComponentMakerV1.Rep(exportNetworkConfigs)
   196  				})
   197  
   198  				It("runs vizzini successfully", func() {
   199  					runVizziniTests(ComponentMakerV1.BBSSSLConfig(), bbsClientGoPathEnvVar)
   200  				})
   201  			})
   202  
   203  			Context("upgrading the BBS API, BBS client, sshProxy, Auctioneer, Rep, and Route Emitter", func() {
   204  				BeforeEach(func() {
   205  					bbsClientGoPathEnvVar = "GOPATH"
   206  					bbsRunner = ComponentMakerV1.BBS(skipLocketForBBS, fallbackToHTTPAuctioneer)
   207  					auctioneerRunner = ComponentMakerV1.Auctioneer(disableLocketForAuctioneer)
   208  					sshProxyRunner = ComponentMakerV1.SSHProxy()
   209  					repRunner = ComponentMakerV1.Rep(exportNetworkConfigs)
   210  					routeEmitterRunner = ComponentMakerV1.RouteEmitter()
   211  				})
   212  
   213  				It("runs vizzini successfully", func() {
   214  					runVizziniTests(ComponentMakerV1.BBSSSLConfig(), bbsClientGoPathEnvVar)
   215  				})
   216  			})
   217  		})
   218  	} else if os.Getenv("DIEGO_VERSION_V0") == diegoLocketLocalREVersion {
   219  		Context(fmt.Sprintf("from %s", diegoLocketLocalREVersion), func() {
   220  			QuietBeforeEach(func() {
   221  				logger = lager.NewLogger("test")
   222  				logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.DEBUG))
   223  
   224  				bbsClientGoPathEnvVar = "GOPATH_V0"
   225  
   226  				ComponentMakerV0 = world.MakeComponentMaker(oldArtifacts, addresses, allocator, certAuthority)
   227  				ComponentMakerV0.Setup()
   228  
   229  				fileServer, _ := ComponentMakerV1.FileServer()
   230  
   231  				plumbing = ginkgomon.Invoke(grouper.NewParallel(os.Kill, grouper.Members{
   232  					{Name: "nats", Runner: ComponentMakerV1.NATS()},
   233  					{Name: "sql", Runner: ComponentMakerV1.SQL()},
   234  					{Name: "consul", Runner: ComponentMakerV1.Consul()},
   235  					{Name: "file-server", Runner: fileServer},
   236  					{Name: "garden", Runner: ComponentMakerV1.Garden(func(cfg *runner.GdnRunnerConfig) {
   237  						poolSize := 100
   238  						cfg.PortPoolSize = &poolSize
   239  					})},
   240  					{Name: "router", Runner: ComponentMakerV1.Router()},
   241  				}))
   242  				helpers.ConsulWaitUntilReady(ComponentMakerV0.Addresses())
   243  
   244  				locketRunner = ComponentMakerV0.Locket()
   245  				bbsRunner = ComponentMakerV0.BBS()
   246  				setRouteEmitterCellID = func(config *routeemitterconfig.RouteEmitterConfig) {
   247  					config.CellID = "the-cell-id-" + strconv.Itoa(GinkgoParallelNode()) + "-" + strconv.Itoa(0)
   248  				}
   249  				routeEmitterRunner = ComponentMakerV0.RouteEmitterN(0, setRouteEmitterCellID)
   250  				auctioneerRunner = ComponentMakerV0.Auctioneer()
   251  				repRunner = ComponentMakerV0.Rep(func(cfg *repconfig.RepConfig) {
   252  					cfg.ExportNetworkEnvVars = true
   253  				})
   254  				sshProxyRunner = ComponentMakerV0.SSHProxy()
   255  			})
   256  
   257  			QuietJustBeforeEach(func() {
   258  				locket = ginkgomon.Invoke(locketRunner)
   259  				bbs = ginkgomon.Invoke(bbsRunner)
   260  				routeEmitter = ginkgomon.Invoke(routeEmitterRunner)
   261  				auctioneer = ginkgomon.Invoke(auctioneerRunner)
   262  				rep = ginkgomon.Invoke(repRunner)
   263  				sshProxy = ginkgomon.Invoke(sshProxyRunner)
   264  			})
   265  
   266  			AfterEach(func() {
   267  				destroyContainerErrors := helpers.CleanupGarden(ComponentMakerV1.GardenClient())
   268  
   269  				helpers.StopProcesses(
   270  					auctioneer,
   271  					rep,
   272  					routeEmitter,
   273  					sshProxy,
   274  					bbs,
   275  					locket,
   276  					plumbing,
   277  				)
   278  
   279  				Expect(destroyContainerErrors).To(
   280  					BeEmpty(),
   281  					"%d containers failed to be destroyed!",
   282  					len(destroyContainerErrors),
   283  				)
   284  			})
   285  
   286  			Context("v0 configuration", func() {
   287  				It("runs vizzini successfully", func() {
   288  					runVizziniTests(ComponentMakerV0.BBSSSLConfig(), bbsClientGoPathEnvVar, securityGroupV0Tests)
   289  				})
   290  			})
   291  
   292  			Context("upgrading the Locket API", func() {
   293  				BeforeEach(func() {
   294  					locketRunner = ComponentMakerV1.Locket()
   295  				})
   296  
   297  				It("runs vizzini successfully", func() {
   298  					runVizziniTests(ComponentMakerV0.BBSSSLConfig(), bbsClientGoPathEnvVar, securityGroupV0Tests)
   299  				})
   300  			})
   301  
   302  			Context("upgrading the BBS API", func() {
   303  				BeforeEach(func() {
   304  					bbsRunner = ComponentMakerV1.BBS(fallbackToHTTPAuctioneer)
   305  					auctioneerRunner = ComponentMakerV0.Auctioneer(disableAuctioneerSSL)
   306  				})
   307  
   308  				It("runs vizzini successfully", func() {
   309  					runVizziniTests(ComponentMakerV1.BBSSSLConfig(), bbsClientGoPathEnvVar, securityGroupV0Tests)
   310  				})
   311  			})
   312  
   313  			Context("upgrading the Locket and BBS API", func() {
   314  				BeforeEach(func() {
   315  					locketRunner = ComponentMakerV1.Locket()
   316  					bbsRunner = ComponentMakerV1.BBS(fallbackToHTTPAuctioneer)
   317  					auctioneerRunner = ComponentMakerV0.Auctioneer(disableAuctioneerSSL)
   318  				})
   319  
   320  				It("runs vizzini successfully", func() {
   321  					runVizziniTests(ComponentMakerV1.BBSSSLConfig(), bbsClientGoPathEnvVar, securityGroupV0Tests)
   322  				})
   323  			})
   324  
   325  			Context("upgrading the Locket, BBS API and BBS client", func() {
   326  				BeforeEach(func() {
   327  					bbsClientGoPathEnvVar = "GOPATH"
   328  					locketRunner = ComponentMakerV1.Locket()
   329  					bbsRunner = ComponentMakerV1.BBS(fallbackToHTTPAuctioneer)
   330  					auctioneerRunner = ComponentMakerV0.Auctioneer(disableAuctioneerSSL)
   331  				})
   332  
   333  				It("runs vizzini successfully", func() {
   334  					runVizziniTests(ComponentMakerV1.BBSSSLConfig(), bbsClientGoPathEnvVar, repV0UnsupportedVizziniTests...)
   335  				})
   336  			})
   337  
   338  			Context("upgrading the Locket, BBS API, BBS client, sshProxy, and Auctioneer", func() {
   339  				BeforeEach(func() {
   340  					bbsClientGoPathEnvVar = "GOPATH"
   341  					locketRunner = ComponentMakerV1.Locket()
   342  					sshProxyRunner = ComponentMakerV1.SSHProxy()
   343  					bbsRunner = ComponentMakerV1.BBS(fallbackToHTTPAuctioneer)
   344  					auctioneerRunner = ComponentMakerV1.Auctioneer(disableLocketForAuctioneer)
   345  				})
   346  
   347  				It("runs vizzini successfully", func() {
   348  					runVizziniTests(ComponentMakerV1.BBSSSLConfig(), bbsClientGoPathEnvVar, repV0UnsupportedVizziniTests...)
   349  				})
   350  			})
   351  
   352  			Context("upgrading the Locket, BBS API, BBS client, sshProxy, Auctioneer, and Rep", func() {
   353  				BeforeEach(func() {
   354  					bbsClientGoPathEnvVar = "GOPATH"
   355  					fallbackToHTTPAuctioneer := func(cfg *bbsconfig.BBSConfig) {
   356  						cfg.AuctioneerRequireTLS = false
   357  					}
   358  					locketRunner = ComponentMakerV1.Locket()
   359  					bbsRunner = ComponentMakerV1.BBS(fallbackToHTTPAuctioneer)
   360  					auctioneerRunner = ComponentMakerV1.Auctioneer(disableLocketForAuctioneer)
   361  					sshProxyRunner = ComponentMakerV1.SSHProxy()
   362  					repRunner = ComponentMakerV1.Rep(exportNetworkConfigs)
   363  					routeEmitterRunner = ComponentMakerV1.RouteEmitterN(0, setRouteEmitterCellID)
   364  				})
   365  
   366  				It("runs vizzini successfully", func() {
   367  					runVizziniTests(ComponentMakerV1.BBSSSLConfig(), bbsClientGoPathEnvVar)
   368  				})
   369  			})
   370  		})
   371  	}
   372  })
   373  
   374  func runVizziniTests(sslConfig world.SSLConfig, gopathEnvVar string, skips ...string) {
   375  	ip, err := localip.LocalIP()
   376  	Expect(err).NotTo(HaveOccurred())
   377  
   378  	vizziniPath := filepath.Join(os.Getenv(gopathEnvVar), "src/code.cloudfoundry.org/vizzini")
   379  	defaultRootFS := os.Getenv("DEFAULT_ROOTFS")
   380  	flags := []string{
   381  		"-nodes", "4",
   382  		"-randomizeAllSpecs",
   383  		"-r",
   384  		"-slowSpecThreshold", "60",
   385  		"-skip", strings.Join(skips, "|"),
   386  	}
   387  
   388  	vizziniConfig := vizziniconfig.VizziniConfig{
   389  		BBSAddress:                     "https://" + ComponentMakerV1.Addresses().BBS,
   390  		BBSClientCertPath:              sslConfig.ClientCert,
   391  		BBSClientKeyPath:               sslConfig.ClientKey,
   392  		SSHAddress:                     ComponentMakerV1.Addresses().SSHProxy,
   393  		SSHPassword:                    "",
   394  		RoutableDomainSuffix:           "test.internal", // Served by dnsmasq using setup_inigo script
   395  		HostAddress:                    ip,
   396  		EnableDeclarativeHealthcheck:   false,
   397  		EnableContainerProxyTests:      false,
   398  		EnablePrivilegedContainerTests: true,
   399  		RepPlacementTags:               []string{},
   400  		MaxTaskRetries:                 0,
   401  		DefaultRootFS:                  defaultRootFS,
   402  		GraceTarballURL:                "https://storage.googleapis.com/diego-assets-bucket/grace.tar.gz",
   403  		GraceTarballChecksum:           graceTarballChecksum,
   404  		GraceBusyboxImageURL:           "docker:///cfdiegodocker/grace",
   405  		FileServerAddress:              "http://" + ComponentMakerV1.Addresses().FileServer,
   406  	}
   407  
   408  	bytes, err := json.Marshal(&vizziniConfig)
   409  	Expect(err).ToNot(HaveOccurred())
   410  
   411  	_, err = vizziniConfigFile.Write(bytes)
   412  	Expect(err).ToNot(HaveOccurred())
   413  
   414  	err = vizziniConfigFile.Close()
   415  	Expect(err).ToNot(HaveOccurred())
   416  
   417  	env := append(
   418  		os.Environ(),
   419  		fmt.Sprintf("GOPATH=%s", os.Getenv(gopathEnvVar)),
   420  		fmt.Sprintf("VIZZINI_CONFIG_PATH=%s", vizziniConfigFile.Name()),
   421  		"GO111MODULE=auto",
   422  	)
   423  
   424  	cmd := exec.Command("ginkgo", flags...)
   425  	cmd.Env = env
   426  	cmd.Dir = vizziniPath
   427  	cmd.Stdout = os.Stdout
   428  	cmd.Stderr = os.Stderr
   429  
   430  	Expect(cmd.Run()).To(Succeed())
   431  }