From f7c06f30845ca61ae6a57ce9b6839b02edb35d7a Mon Sep 17 00:00:00 2001 From: Giuseppe Capizzi Date: Mon, 13 Mar 2017 14:08:32 +0000 Subject: [PATCH 1/2] Refactored tests related to multiple instances into a single context [#131726841] Signed-off-by: Jatin Naik --- integration/backup_test.go | 266 +++++++++++++++++++------------------ 1 file changed, 135 insertions(+), 131 deletions(-) diff --git a/integration/backup_test.go b/integration/backup_test.go index eb7ff0494..782c90688 100644 --- a/integration/backup_test.go +++ b/integration/backup_test.go @@ -67,7 +67,8 @@ var _ = Describe("Backup", func() { }, } } - Context("and there is a plausible backup script", func() { + + Context("when there is a plausible backup script", func() { BeforeEach(func() { instance1 = testcluster.NewInstance() By("creating a dummy backup script") @@ -316,7 +317,7 @@ exit 1`) }) }) - Context("if a deployment can't be backed up", func() { + Context("when a deployment can't be backed up", func() { BeforeEach(func() { instance1 = testcluster.NewInstance() mockDirectorWith(director, @@ -344,7 +345,7 @@ exit 1`) }) }) - Context("instance backup script fails", func() { + Context("when the instance backup script fails", func() { BeforeEach(func() { instance1 = testcluster.NewInstance() mockDirectorWith(director, @@ -364,7 +365,7 @@ exit 1`) }) }) - Context("both instance backup script and cleanup fail", func() { + Context("when both the instance backup script and cleanup fail", func() { BeforeEach(func() { instance1 = testcluster.NewInstance() mockDirectorWith(director, @@ -392,7 +393,7 @@ exit 1`) }) }) - Context("backup succeeds but cleanup fails", func() { + Context("when backup succeeds but cleanup fails", func() { BeforeEach(func() { instance1 = testcluster.NewInstance() mockDirectorWith(director, @@ -453,7 +454,7 @@ echo "not valid yaml }) - Context("if the artifact exists locally", func() { + Context("when the artifact exists locally", func() { BeforeEach(func() { deploymentName = "already-backed-up-deployment" err := os.Mkdir(path.Join(backupWorkspace, deploymentName), 0777) @@ -474,158 +475,161 @@ echo "not valid yaml }) }) - twoInstancesResponse := func(firstInstanceGroupName, secondInstanceGroupName string) []mockbosh.VMsOutput { - - return []mockbosh.VMsOutput{ - { - IPs: []string{"10.0.0.1"}, - JobName: firstInstanceGroupName, - }, - { - IPs: []string{"10.0.0.2"}, - JobName: secondInstanceGroupName, - }, + Context("When there is a deployment which has two instances", func() { + twoInstancesResponse := func(firstInstanceGroupName, secondInstanceGroupName string) []mockbosh.VMsOutput { + + return []mockbosh.VMsOutput{ + { + IPs: []string{"10.0.0.1"}, + JobName: firstInstanceGroupName, + }, + { + IPs: []string{"10.0.0.2"}, + JobName: secondInstanceGroupName, + }, + } } - } - Context("When there is a deployment which has two instances, one backupable", func() { - var backupableInstance, nonBackupableInstance *testcluster.Instance - BeforeEach(func() { - deploymentName = "my-bigger-deployment" - backupableInstance = testcluster.NewInstance() - nonBackupableInstance = testcluster.NewInstance() - mockDirectorWith(director, - VmsForDeployment(deploymentName, twoInstancesResponse("redis-dedicated-node", "redis-broker")), - append(SetupSSH(deploymentName, "redis-dedicated-node", "fake-uuid", 0, backupableInstance), - SetupSSH(deploymentName, "redis-broker", "fake-uuid-2", 0, nonBackupableInstance)...), - DownloadManifest(deploymentName, "not being asserted"), - append(CleanupSSH(deploymentName, "redis-dedicated-node"), - CleanupSSH(deploymentName, "redis-broker")...), - ) - backupableInstance.CreateFiles( - "/var/vcap/jobs/redis/bin/b-backup", - ) + Context("one backupable", func() { + var backupableInstance, nonBackupableInstance *testcluster.Instance - }) + BeforeEach(func() { + deploymentName = "my-bigger-deployment" + backupableInstance = testcluster.NewInstance() + nonBackupableInstance = testcluster.NewInstance() + mockDirectorWith(director, + VmsForDeployment(deploymentName, twoInstancesResponse("redis-dedicated-node", "redis-broker")), + append(SetupSSH(deploymentName, "redis-dedicated-node", "fake-uuid", 0, backupableInstance), + SetupSSH(deploymentName, "redis-broker", "fake-uuid-2", 0, nonBackupableInstance)...), + DownloadManifest(deploymentName, "not being asserted"), + append(CleanupSSH(deploymentName, "redis-dedicated-node"), + CleanupSSH(deploymentName, "redis-broker")...), + ) + backupableInstance.CreateFiles( + "/var/vcap/jobs/redis/bin/b-backup", + ) - AfterEach(func() { - backupableInstance.DieInBackground() - nonBackupableInstance.DieInBackground() - }) + }) - It("backs up deployment successfully", func() { - Expect(session.ExitCode()).To(BeZero()) - Expect(path.Join(backupWorkspace, deploymentName)).To(BeADirectory()) - Expect(path.Join(backupWorkspace, deploymentName, "/redis-dedicated-node-0.tgz")).To(BeARegularFile()) - Expect(path.Join(backupWorkspace, deploymentName, "/redis-broker-0.tgz")).ToNot(BeAnExistingFile()) + AfterEach(func() { + backupableInstance.DieInBackground() + nonBackupableInstance.DieInBackground() + }) + + It("backs up deployment successfully", func() { + Expect(session.ExitCode()).To(BeZero()) + Expect(path.Join(backupWorkspace, deploymentName)).To(BeADirectory()) + Expect(path.Join(backupWorkspace, deploymentName, "/redis-dedicated-node-0.tgz")).To(BeARegularFile()) + Expect(path.Join(backupWorkspace, deploymentName, "/redis-broker-0.tgz")).ToNot(BeAnExistingFile()) + }) }) - }) - Context("When there is a deployment which has two instance, both backupable", func() { - var backupableInstance1, backupableInstance2 *testcluster.Instance + Context("both backupable", func() { + var backupableInstance1, backupableInstance2 *testcluster.Instance - BeforeEach(func() { - deploymentName = "my-two-instance-deployment" - backupableInstance1 = testcluster.NewInstance() - backupableInstance2 = testcluster.NewInstance() - mockDirectorWith(director, - VmsForDeployment(deploymentName, twoInstancesResponse("redis-dedicated-node", "redis-broker")), - append(SetupSSH(deploymentName, "redis-dedicated-node", "fake-uuid", 0, backupableInstance1), - SetupSSH(deploymentName, "redis-broker", "fake-uuid-2", 0, backupableInstance2)...), - DownloadManifest(deploymentName, "not being asserted"), - append(CleanupSSH(deploymentName, "redis-dedicated-node"), - CleanupSSH(deploymentName, "redis-broker")...), - ) - - backupableInstance1.CreateFiles( - "/var/vcap/jobs/redis/bin/b-backup", - ) - - backupableInstance2.CreateFiles( - "/var/vcap/jobs/redis/bin/b-backup", - ) + BeforeEach(func() { + deploymentName = "my-two-instance-deployment" + backupableInstance1 = testcluster.NewInstance() + backupableInstance2 = testcluster.NewInstance() + mockDirectorWith(director, + VmsForDeployment(deploymentName, twoInstancesResponse("redis-dedicated-node", "redis-broker")), + append(SetupSSH(deploymentName, "redis-dedicated-node", "fake-uuid", 0, backupableInstance1), + SetupSSH(deploymentName, "redis-broker", "fake-uuid-2", 0, backupableInstance2)...), + DownloadManifest(deploymentName, "not being asserted"), + append(CleanupSSH(deploymentName, "redis-dedicated-node"), + CleanupSSH(deploymentName, "redis-broker")...), + ) - }) + backupableInstance1.CreateFiles( + "/var/vcap/jobs/redis/bin/b-backup", + ) - AfterEach(func() { - backupableInstance1.DieInBackground() - backupableInstance2.DieInBackground() - }) + backupableInstance2.CreateFiles( + "/var/vcap/jobs/redis/bin/b-backup", + ) - It("backs up both instances successfully", func() { - Expect(session.ExitCode()).To(BeZero()) - Expect(path.Join(backupWorkspace, deploymentName)).To(BeADirectory()) - Expect(path.Join(backupWorkspace, deploymentName, "/redis-dedicated-node-0.tgz")).To(BeARegularFile()) - Expect(path.Join(backupWorkspace, deploymentName, "/redis-broker-0.tgz")).To(BeARegularFile()) - }) + }) - It("prints the backup progress to the screen", func() { - assertOutput(session, []string{ - fmt.Sprintf("Starting backup of %s...", deploymentName), - "Backing up redis on redis-dedicated-node/fake-uuid...", - "Backing up redis on redis-broker/fake-uuid-2...", - "Done.", - "Copying backup --", - "from redis-dedicated-node/fake-uuid...", - "from redis-broker/fake-uuid-2...", - "Done.", - fmt.Sprintf("Backup created of %s on", deploymentName), + AfterEach(func() { + backupableInstance1.DieInBackground() + backupableInstance2.DieInBackground() + }) + + It("backs up both instances successfully", func() { + Expect(session.ExitCode()).To(BeZero()) + Expect(path.Join(backupWorkspace, deploymentName)).To(BeADirectory()) + Expect(path.Join(backupWorkspace, deploymentName, "/redis-dedicated-node-0.tgz")).To(BeARegularFile()) + Expect(path.Join(backupWorkspace, deploymentName, "/redis-broker-0.tgz")).To(BeARegularFile()) }) + + It("prints the backup progress to the screen", func() { + assertOutput(session, []string{ + fmt.Sprintf("Starting backup of %s...", deploymentName), + "Backing up redis on redis-dedicated-node/fake-uuid...", + "Backing up redis on redis-broker/fake-uuid-2...", + "Done.", + "Copying backup --", + "from redis-dedicated-node/fake-uuid...", + "from redis-broker/fake-uuid-2...", + "Done.", + fmt.Sprintf("Backup created of %s on", deploymentName), + }) + }) + }) - }) + Context("both specify the same backup name in their metadata", func() { + var backupableInstance1, backupableInstance2 *testcluster.Instance - Context("When multiple instances specify the same backup name in their metadata", func() { - var backupableInstance1, backupableInstance2 *testcluster.Instance + BeforeEach(func() { + deploymentName = "my-two-instance-deployment" + backupableInstance1 = testcluster.NewInstance() + backupableInstance2 = testcluster.NewInstance() + mockDirectorWith(director, + VmsForDeployment(deploymentName, twoInstancesResponse("redis-dedicated-node", "redis-broker")), + append(SetupSSH(deploymentName, "redis-dedicated-node", "fake-uuid", 0, backupableInstance1), + SetupSSH(deploymentName, "redis-broker", "fake-uuid-2", 0, backupableInstance2)...), + ManifestIsNotDownloaded(), + append(CleanupSSH(deploymentName, "redis-dedicated-node"), + CleanupSSH(deploymentName, "redis-broker")...), + ) - BeforeEach(func() { - deploymentName = "my-two-instance-deployment" - backupableInstance1 = testcluster.NewInstance() - backupableInstance2 = testcluster.NewInstance() - mockDirectorWith(director, - VmsForDeployment(deploymentName, twoInstancesResponse("redis-dedicated-node", "redis-broker")), - append(SetupSSH(deploymentName, "redis-dedicated-node", "fake-uuid", 0, backupableInstance1), - SetupSSH(deploymentName, "redis-broker", "fake-uuid-2", 0, backupableInstance2)...), - ManifestIsNotDownloaded(), - append(CleanupSSH(deploymentName, "redis-dedicated-node"), - CleanupSSH(deploymentName, "redis-broker")...), - ) - - backupableInstance1.CreateFiles( - "/var/vcap/jobs/redis/bin/b-backup", - ) - - backupableInstance2.CreateFiles( - "/var/vcap/jobs/redis/bin/b-backup", - ) - - backupableInstance1.CreateScript("/var/vcap/jobs/redis/bin/b-metadata", `#!/usr/bin/env sh + backupableInstance1.CreateFiles( + "/var/vcap/jobs/redis/bin/b-backup", + ) + + backupableInstance2.CreateFiles( + "/var/vcap/jobs/redis/bin/b-backup", + ) + + backupableInstance1.CreateScript("/var/vcap/jobs/redis/bin/b-metadata", `#!/usr/bin/env sh echo "--- backup_name: duplicate_name "`) - backupableInstance2.CreateScript("/var/vcap/jobs/redis/bin/b-metadata", `#!/usr/bin/env sh + backupableInstance2.CreateScript("/var/vcap/jobs/redis/bin/b-metadata", `#!/usr/bin/env sh echo "--- backup_name: duplicate_name "`) - }) + }) - AfterEach(func() { - backupableInstance1.DieInBackground() - backupableInstance2.DieInBackground() - }) + AfterEach(func() { + backupableInstance1.DieInBackground() + backupableInstance2.DieInBackground() + }) - It("files with the name are not created", func() { - Expect(path.Join(backupWorkspace, deploymentName, "/duplicate_name.tgz")).NotTo(BeARegularFile()) - }) + It("files with the name are not created", func() { + Expect(path.Join(backupWorkspace, deploymentName, "/duplicate_name.tgz")).NotTo(BeARegularFile()) + }) - It("refuses to perform backup", func() { - Expect(session.Err.Contents()).To(ContainSubstring( - "Multiple jobs in deployment 'my-two-instance-deployment' specified the same backup name", - )) - }) + It("refuses to perform backup", func() { + Expect(session.Err.Contents()).To(ContainSubstring( + "Multiple jobs in deployment 'my-two-instance-deployment' specified the same backup name", + )) + }) - It("returns exit code 1", func() { - Expect(session.ExitCode()).To(Equal(1)) + It("returns exit code 1", func() { + Expect(session.ExitCode()).To(Equal(1)) + }) }) }) From c3da0d0a95847c23645fbae992e2275dbb2e1e2a Mon Sep 17 00:00:00 2001 From: Jatin Naik Date: Mon, 13 Mar 2017 15:30:19 +0000 Subject: [PATCH 2/2] Updated fixtures/releases Signed-off-by: Giuseppe Capizzi --- fixtures/releases | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fixtures/releases b/fixtures/releases index 6ea1ce5a3..8349a98f8 160000 --- a/fixtures/releases +++ b/fixtures/releases @@ -1 +1 @@ -Subproject commit 6ea1ce5a3a59e6053aadbab23e6be636976f5c34 +Subproject commit 8349a98f8e7f5dcbdf27107c708408be474c5090