github.com/cloudfoundry/diego-upgrade-stability-tests@v0.0.0-20210607152719-27f1f0151c54/dusts_suite_test.go (about) 1 package dusts_test 2 3 import ( 4 "fmt" 5 "os" 6 "path" 7 "path/filepath" 8 "time" 9 10 "code.cloudfoundry.org/bbs" 11 "code.cloudfoundry.org/bbs/serviceclient" 12 "code.cloudfoundry.org/consuladapter/consulrunner" 13 "code.cloudfoundry.org/inigo/helpers" 14 "code.cloudfoundry.org/inigo/helpers/certauthority" 15 "code.cloudfoundry.org/inigo/helpers/portauthority" 16 "code.cloudfoundry.org/inigo/world" 17 "code.cloudfoundry.org/lager" 18 . "github.com/onsi/ginkgo" 19 "github.com/onsi/ginkgo/config" 20 . "github.com/onsi/gomega" 21 "github.com/onsi/gomega/gexec" 22 23 "testing" 24 ) 25 26 const ( 27 diegoGAVersion = "v1.0.0" 28 diegoLocketLocalREVersion = "v1.25.2" 29 ) 30 31 var ( 32 ComponentMakerV0, ComponentMakerV1 world.ComponentMaker 33 34 componentLogs *os.File 35 36 oldArtifacts, newArtifacts world.BuiltArtifacts 37 addresses world.ComponentAddresses 38 upgrader Upgrader 39 40 bbsClient bbs.InternalClient 41 bbsServiceClient serviceclient.ServiceClient 42 logger lager.Logger 43 allocator portauthority.PortAllocator 44 certAuthority certauthority.CertAuthority 45 46 graceTarballChecksum string 47 48 suiteTempDir string 49 ) 50 51 func TestDusts(t *testing.T) { 52 helpers.RegisterDefaultTimeouts() 53 RegisterFailHandler(Fail) 54 RunSpecs(t, "Dusts Suite") 55 } 56 57 var _ = BeforeSuite(func() { 58 suiteTempDir = world.TempDir("before-suite") 59 60 if version := os.Getenv("DIEGO_VERSION_V0"); version != diegoGAVersion && version != diegoLocketLocalREVersion { 61 Fail("DIEGO_VERSION_V0 not set") 62 } 63 64 if graceTarballChecksum = os.Getenv("GRACE_TARBALL_CHECKSUM"); graceTarballChecksum == "" { 65 Fail("GRACE_TARBALL_CHECKSUM not set") 66 } 67 68 oldArtifacts = world.BuiltArtifacts{ 69 Lifecycles: world.BuiltLifecycles{}, 70 } 71 72 oldArtifacts.Lifecycles.BuildLifecycles("dockerapplifecycle", suiteTempDir) 73 oldArtifacts.Lifecycles.BuildLifecycles("buildpackapplifecycle", suiteTempDir) 74 oldArtifacts.Executables = compileTestedExecutablesV0() 75 76 newArtifacts = world.BuiltArtifacts{ 77 Lifecycles: world.BuiltLifecycles{}, 78 } 79 80 newArtifacts.Lifecycles.BuildLifecycles("dockerapplifecycle", suiteTempDir) 81 newArtifacts.Lifecycles.BuildLifecycles("buildpackapplifecycle", suiteTempDir) 82 newArtifacts.Executables = compileTestedExecutablesV1() 83 84 _, dbBaseConnectionString := world.DBInfo() 85 86 // TODO: the hard coded addresses for router and file server prevent running multiple dusts tests at the same time 87 addresses = world.ComponentAddresses{ 88 Garden: fmt.Sprintf("127.0.0.1:%d", 10000+config.GinkgoConfig.ParallelNode), 89 NATS: fmt.Sprintf("127.0.0.1:%d", 11000+config.GinkgoConfig.ParallelNode), 90 Consul: fmt.Sprintf("127.0.0.1:%d", 12750+config.GinkgoConfig.ParallelNode*consulrunner.PortOffsetLength), 91 Rep: fmt.Sprintf("127.0.0.1:%d", 14000+config.GinkgoConfig.ParallelNode), 92 FileServer: fmt.Sprintf("127.0.0.1:%d", 8080), 93 Router: fmt.Sprintf("127.0.0.1:%d", 80), 94 BBS: fmt.Sprintf("127.0.0.1:%d", 20500+config.GinkgoConfig.ParallelNode*2), 95 Health: fmt.Sprintf("127.0.0.1:%d", 20500+config.GinkgoConfig.ParallelNode*2+1), 96 Auctioneer: fmt.Sprintf("127.0.0.1:%d", 23000+config.GinkgoConfig.ParallelNode), 97 SSHProxy: fmt.Sprintf("127.0.0.1:%d", 23500+config.GinkgoConfig.ParallelNode), 98 SSHProxyHealthCheck: fmt.Sprintf("127.0.0.1:%d", 24500+config.GinkgoConfig.ParallelNode), 99 FakeVolmanDriver: fmt.Sprintf("127.0.0.1:%d", 25500+config.GinkgoConfig.ParallelNode), 100 Locket: fmt.Sprintf("127.0.0.1:%d", 26500+config.GinkgoConfig.ParallelNode), 101 SQL: fmt.Sprintf("%sdiego_%d", dbBaseConnectionString, config.GinkgoConfig.ParallelNode), 102 } 103 104 node := GinkgoParallelNode() 105 startPort := 2000 * node 106 portRange := 5000 107 endPort := startPort + portRange 108 109 allocator, err := portauthority.New(startPort, endPort) 110 Expect(err).NotTo(HaveOccurred()) 111 112 depotDir := world.TempDirWithParent(suiteTempDir, "depotDir") 113 114 certAuthority, err = certauthority.NewCertAuthority(depotDir, "ca") 115 Expect(err).NotTo(HaveOccurred()) 116 117 componentLogPath := os.Getenv("DUSTS_COMPONENT_LOG_PATH") 118 if componentLogPath == "" { 119 componentLogPath = fmt.Sprintf("dusts-component-logs.0.0.0.%d.log", time.Now().Unix()) 120 } 121 componentLogs, err = os.Create(componentLogPath) 122 Expect(err).NotTo(HaveOccurred()) 123 fmt.Printf("Writing component logs to %s\n", componentLogPath) 124 125 ComponentMakerV1 = world.MakeComponentMaker(newArtifacts, addresses, allocator, certAuthority) 126 ComponentMakerV1.Setup() 127 128 oldGinkgoWriter := GinkgoWriter 129 GinkgoWriter = componentLogs 130 defer func() { 131 GinkgoWriter = oldGinkgoWriter 132 }() 133 ComponentMakerV1.GrootFSInitStore() 134 }) 135 136 var _ = AfterSuite(func() { 137 oldGinkgoWriter := GinkgoWriter 138 GinkgoWriter = componentLogs 139 defer func() { 140 GinkgoWriter = oldGinkgoWriter 141 }() 142 if ComponentMakerV1 != nil { 143 ComponentMakerV1.GrootFSDeleteStore() 144 } 145 146 Expect(os.RemoveAll(suiteTempDir)).To(Succeed()) 147 componentLogs.Close() 148 }) 149 150 func QuietBeforeEach(f func()) { 151 BeforeEach(func() { 152 oldGinkgoWriter := GinkgoWriter 153 GinkgoWriter = componentLogs 154 defer func() { 155 GinkgoWriter = oldGinkgoWriter 156 }() 157 f() 158 }) 159 } 160 161 func QuietJustBeforeEach(f func()) { 162 JustBeforeEach(func() { 163 oldGinkgoWriter := GinkgoWriter 164 GinkgoWriter = componentLogs 165 defer func() { 166 GinkgoWriter = oldGinkgoWriter 167 }() 168 f() 169 }) 170 } 171 172 func buildWithGopath(binariesPath, gopath, packagePath string, args ...string) string { 173 Expect(os.MkdirAll(binariesPath, 0777)).To(Succeed()) 174 binaryName := filepath.Base(packagePath) 175 expectedBinaryPath := path.Join(binariesPath, binaryName) 176 cwd, err := os.Getwd() 177 Expect(err).To(Succeed()) 178 if _, err := os.Stat(expectedBinaryPath); os.IsNotExist(err) { 179 fmt.Printf("Building %s with Gopath %s \n", packagePath, gopath) 180 Expect(os.Chdir(gopath)).To(Succeed()) 181 binaryPath, err := gexec.BuildIn(gopath, packagePath, args...) 182 Expect(err).NotTo(HaveOccurred()) 183 Expect(os.Rename(binaryPath, path.Join(binariesPath, binaryName))).To(Succeed()) 184 Expect(os.Chdir(cwd)).To(Succeed()) 185 } 186 return expectedBinaryPath 187 } 188 189 func buildAsModule(binariesPath, modulepath, packagePath string, args ...string) string { 190 Expect(os.MkdirAll(binariesPath, 0777)).To(Succeed()) 191 binaryName := filepath.Base(packagePath) 192 expectedBinaryPath := path.Join(binariesPath, binaryName) 193 cwd, err := os.Getwd() 194 Expect(err).To(Succeed()) 195 if _, err := os.Stat(expectedBinaryPath); os.IsNotExist(err) { 196 fmt.Printf("Building %s as Module \n", packagePath) 197 Expect(os.Chdir(modulepath)).To(Succeed()) 198 binaryPath, err := gexec.Build(packagePath, args...) 199 Expect(err).NotTo(HaveOccurred()) 200 Expect(os.Rename(binaryPath, path.Join(binariesPath, binaryName))).To(Succeed()) 201 Expect(os.Chdir(cwd)).To(Succeed()) 202 } 203 return expectedBinaryPath 204 } 205 206 func compileTestedExecutablesV1() world.BuiltExecutables { 207 binariesPath := "/tmp/v1_binaries" 208 builtExecutables := world.BuiltExecutables{} 209 210 builtExecutables["garden"] = buildAsModule(binariesPath, os.Getenv("GARDEN_GOPATH"), "./cmd/gdn", "-race", "-a", "-tags", "daemon") 211 builtExecutables["auctioneer"] = buildAsModule(binariesPath, os.Getenv("AUCTIONEER_GOPATH"), "code.cloudfoundry.org/auctioneer/cmd/auctioneer", "-race") 212 builtExecutables["rep"] = buildAsModule(binariesPath, os.Getenv("REP_GOPATH"), "code.cloudfoundry.org/rep/cmd/rep", "-race") 213 builtExecutables["bbs"] = buildAsModule(binariesPath, os.Getenv("BBS_GOPATH"), "code.cloudfoundry.org/bbs/cmd/bbs", "-race") 214 builtExecutables["locket"] = buildAsModule(binariesPath, os.Getenv("LOCKET_GOPATH"), "code.cloudfoundry.org/locket/cmd/locket", "-race") 215 builtExecutables["file-server"] = buildAsModule(binariesPath, os.Getenv("FILE_SERVER_GOPATH"), "code.cloudfoundry.org/fileserver/cmd/file-server", "-race") 216 builtExecutables["route-emitter"] = buildAsModule(binariesPath, os.Getenv("ROUTE_EMITTER_GOPATH"), "code.cloudfoundry.org/route-emitter/cmd/route-emitter", "-race") 217 218 Expect(os.Setenv("GO111MODULE", "auto")).To(Succeed()) 219 builtExecutables["router"] = buildWithGopath(binariesPath, os.Getenv("ROUTER_GOPATH"), "code.cloudfoundry.org/gorouter", "-race") 220 builtExecutables["routing-api"] = buildAsModule(binariesPath, os.Getenv("ROUTING_API_GOPATH"), "code.cloudfoundry.org/routing-api/cmd/routing-api", "-race") 221 Expect(os.Setenv("GO111MODULE", "")).To(Succeed()) 222 223 builtExecutables["ssh-proxy"] = buildAsModule(binariesPath, os.Getenv("SSH_PROXY_GOPATH"), "code.cloudfoundry.org/diego-ssh/cmd/ssh-proxy", "-race") 224 225 os.Setenv("CGO_ENABLED", "0") 226 builtExecutables["sshd"] = buildAsModule(binariesPath, os.Getenv("SSHD_GOPATH"), "code.cloudfoundry.org/diego-ssh/cmd/sshd", "-a", "-installsuffix", "static") 227 os.Unsetenv("CGO_ENABLED") 228 229 return builtExecutables 230 } 231 232 func compileTestedExecutablesV0() world.BuiltExecutables { 233 binariesPath := "/tmp/v0_binaries" 234 builtExecutables := world.BuiltExecutables{} 235 236 Expect(os.Setenv("GO111MODULE", "auto")).To(Succeed()) 237 238 builtExecutables["auctioneer"] = buildWithGopath(binariesPath, os.Getenv("AUCTIONEER_GOPATH_V0"), "code.cloudfoundry.org/auctioneer/cmd/auctioneer", "-race") 239 builtExecutables["rep"] = buildWithGopath(binariesPath, os.Getenv("REP_GOPATH_V0"), "code.cloudfoundry.org/rep/cmd/rep", "-race") 240 builtExecutables["bbs"] = buildWithGopath(binariesPath, os.Getenv("BBS_GOPATH_V0"), "code.cloudfoundry.org/bbs/cmd/bbs", "-race") 241 builtExecutables["route-emitter"] = buildWithGopath(binariesPath, os.Getenv("ROUTE_EMITTER_GOPATH_V0"), "code.cloudfoundry.org/route-emitter/cmd/route-emitter", "-race") 242 builtExecutables["ssh-proxy"] = buildWithGopath(binariesPath, os.Getenv("SSH_PROXY_GOPATH_V0"), "code.cloudfoundry.org/diego-ssh/cmd/ssh-proxy", "-race") 243 244 if os.Getenv("DIEGO_VERSION_V0") == diegoLocketLocalREVersion { 245 builtExecutables["locket"] = buildWithGopath(binariesPath, os.Getenv("GOPATH_V0"), "code.cloudfoundry.org/locket/cmd/locket", "-race") 246 } 247 248 os.Setenv("CGO_ENABLED", "0") 249 builtExecutables["sshd"] = buildWithGopath(binariesPath, os.Getenv("SSHD_GOPATH_V0"), "code.cloudfoundry.org/diego-ssh/cmd/sshd", "-a", "-installsuffix", "static") 250 os.Unsetenv("CGO_ENABLED") 251 252 Expect(os.Setenv("GO111MODULE", "")).To(Succeed()) 253 return builtExecutables 254 }