github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/topgun/pcf/bbr_test.go (about) 1 package topgun_test 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path" 7 "strings" 8 9 . "github.com/pf-qiu/concourse/v6/topgun" 10 . "github.com/pf-qiu/concourse/v6/topgun/common" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 ) 14 15 var _ = Describe("BBR", func() { 16 17 var ( 18 atcs []BoshInstance 19 atc0URL string 20 deployArgs []string 21 ) 22 23 BeforeEach(func() { 24 if !strings.Contains(string(Bosh("releases").Out.Contents()), "backup-and-restore-sdk") { 25 Skip("backup-and-restore-sdk release not uploaded") 26 } 27 deployArgs = []string{} 28 }) 29 30 JustBeforeEach(func() { 31 Deploy("deployments/concourse.yml", deployArgs...) 32 33 atcs = JobInstances("web") 34 atc0URL = "http://" + atcs[0].IP + ":8080" 35 36 Fly.Login(AtcUsername, AtcPassword, atc0URL) 37 }) 38 39 Context("using different property providers", func() { 40 41 BeforeEach(func() { 42 deployArgs = append(deployArgs, "-v", "worker_instances=0") 43 }) 44 45 var successfullyExecutesBackup = func() { 46 It("successfully executes backup", func() { 47 Run(nil, "bbr", "deployment", "-d", DeploymentName, "backup") 48 }) 49 } 50 51 Context("consuming concourse_db links", func() { 52 BeforeEach(func() { 53 deployArgs = append(deployArgs, "-o", "operations/bbr-concourse-link.yml") 54 }) 55 56 successfullyExecutesBackup() 57 }) 58 59 Context("passing properties", func() { 60 BeforeEach(func() { 61 deployArgs = append(deployArgs, "-o", "operations/bbr-with-properties.yml") 62 }) 63 64 successfullyExecutesBackup() 65 }) 66 67 }) 68 69 Context("regardless of property provider", func() { 70 71 BeforeEach(func() { 72 deployArgs = append(deployArgs, "-o", "operations/bbr-with-properties.yml") 73 }) 74 75 JustBeforeEach(func() { 76 WaitForRunningWorker() 77 }) 78 79 Context("restoring a deployment with data to a deployment with less data", func() { 80 var tmpDir string 81 82 BeforeEach(func() { 83 var err error 84 tmpDir, err = ioutil.TempDir("", "") 85 Expect(err).NotTo(HaveOccurred()) 86 }) 87 88 AfterEach(func() { 89 os.RemoveAll(tmpDir) 90 }) 91 92 It("backups and restores", func() { 93 By("creating a new pipeline") 94 Fly.Run("set-pipeline", "-n", "-p", "pipeline", "-c", "pipelines/get-task.yml") 95 pipelines := Fly.GetPipelines() 96 Expect(pipelines).ToNot(BeEmpty()) 97 Expect(pipelines[0].Name).To(Equal("pipeline")) 98 99 By("unpausing the pipeline") 100 Fly.Run("unpause-pipeline", "-p", "pipeline") 101 102 By("triggering a build") 103 Fly.Run("trigger-job", "-w", "-j", "pipeline/simple-job") 104 105 By("creating a database backup") 106 backupArgs := []string{ 107 "deployment", 108 "-d", DeploymentName, 109 "backup", 110 "--artifact-path", tmpDir, 111 } 112 Run(nil, "bbr", backupArgs...) 113 entries, err := ioutil.ReadDir(tmpDir) 114 Expect(err).ToNot(HaveOccurred()) 115 Expect(entries).To(HaveLen(1)) 116 117 By("deleting the deployment") 118 WaitForDeploymentAndCompileLocks() 119 Bosh("delete-deployment") 120 121 By("creating a new deployment") 122 Deploy( 123 "deployments/concourse.yml", 124 "-o", "operations/bbr-with-properties.yml", 125 ) 126 WaitForRunningWorker() 127 128 atcs = JobInstances("web") 129 atc0URL = "http://" + atcs[0].IP + ":8080" 130 131 Fly.Login(AtcUsername, AtcPassword, atc0URL) 132 133 By("restoring the backup") 134 restoreArgs := []string{ 135 "deployment", 136 "-d", DeploymentName, 137 "restore", 138 "--artifact-path", path.Join(tmpDir, entries[0].Name()), 139 } 140 Run(nil, "bbr", restoreArgs...) 141 pipelines = Fly.GetPipelines() 142 Expect(pipelines).ToNot(BeEmpty()) 143 Expect(pipelines[0].Name).To(Equal("pipeline")) 144 }) 145 }) 146 147 Context("when restoring fails", func() { 148 var tmpDir string 149 150 BeforeEach(func() { 151 var err error 152 tmpDir, err = ioutil.TempDir("", "") 153 Expect(err).NotTo(HaveOccurred()) 154 }) 155 156 AfterEach(func() { 157 os.RemoveAll(tmpDir) 158 }) 159 160 It("rolls back the partial restore", func() { 161 By("creating new pipeline") 162 Fly.Run("set-pipeline", "-n", "-p", "pipeline", "-c", "pipelines/get-task.yml") 163 pipelines := Fly.GetPipelines() 164 Expect(pipelines).ToNot(BeEmpty()) 165 Expect(pipelines[0].Name).To(Equal("pipeline")) 166 167 By("unpausing the pipeline") 168 Fly.Run("unpause-pipeline", "-p", "pipeline") 169 170 By("triggering a build") 171 Fly.Run("trigger-job", "-w", "-j", "pipeline/simple-job") 172 173 By("creating a database backup") 174 backupArgs := []string{ 175 "deployment", 176 "-d", DeploymentName, 177 "backup", 178 "--artifact-path", tmpDir, 179 } 180 Run(nil, "bbr", backupArgs...) 181 entries, err := ioutil.ReadDir(tmpDir) 182 Expect(err).ToNot(HaveOccurred()) 183 Expect(entries).To(HaveLen(1)) 184 185 By("creating new pipeline and triggering the new pipeling (this will fail the restore)") 186 187 Fly.Run("set-pipeline", "-n", "-p", "pipeline-2", "-c", "pipelines/get-task.yml") 188 pipelines = Fly.GetPipelines() 189 Expect(pipelines).ToNot(BeEmpty()) 190 Expect(pipelines[1].Name).To(Equal("pipeline-2")) 191 192 By("unpausing the pipeline") 193 Fly.Run("unpause-pipeline", "-p", "pipeline-2") 194 195 By("triggering a build") 196 Fly.Run("trigger-job", "-w", "-j", "pipeline-2/simple-job") 197 198 By("restoring concourse") 199 200 restoreArgs := []string{ 201 "deployment", 202 "-d", DeploymentName, 203 "restore", 204 "--artifact-path", path.Join(tmpDir, entries[0].Name()), 205 } 206 session := Start(nil, "bbr", restoreArgs...) 207 <-session.Exited 208 Expect(session.ExitCode()).To(Equal(1)) 209 210 By("checking pipeline") 211 pipelines = Fly.GetPipelines() 212 Expect(pipelines).ToNot(BeEmpty()) 213 Expect(len(pipelines)).To(Equal(2)) 214 }) 215 }) 216 217 }) 218 })