Exemple #1
0
				Expect(fakeStage.PerformCalls).To(Equal([]*fakebiui.PerformCall{
					{Name: "Waiting for the agent on VM 'fake-vm-cid'"},
					{Name: "Stopping jobs on instance 'fake-job-name/0'"},
					{
						Name:  "Deleting VM 'fake-vm-cid'",
						Error: deleteError,
					},
				}))
			})
		})

		Context("when VM does not exist (deleted manually)", func() {
			BeforeEach(func() {
				fakeVM.ExistsFound = false
				fakeVM.DeleteErr = bicloud.NewCPIError("delete_vm", bicloud.CmdError{
					Type:    bicloud.VMNotFoundError,
					Message: "fake-vm-not-found-message",
				})
			})

			It("deletes existing vm", func() {
				err := instance.Delete(pingTimeout, pingDelay, fakeStage)
				Expect(err).NotTo(HaveOccurred())

				Expect(fakeVM.DeleteCalled).To(Equal(1))
			})

			It("does not contact the agent", func() {
				err := instance.Delete(pingTimeout, pingDelay, fakeStage)
				Expect(err).NotTo(HaveOccurred())

				Expect(fakeVM.WaitUntilReadyInputs).To(HaveLen(0))
Exemple #2
0
				// shutdown old vm
				mockAgentClient.EXPECT().Ping().Return("any-state", nil),
				mockAgentClient.EXPECT().Stop(),
				mockAgentClient.EXPECT().ListDisk().Return([]string{oldDiskCID}, nil),
				mockAgentClient.EXPECT().UnmountDisk(oldDiskCID),
				mockCloud.EXPECT().DeleteVM(oldVMCID),

				// create new vm
				mockCloud.EXPECT().CreateVM(agentID, stemcellCID, vmCloudProperties, networkInterfaces, vmEnv).Return(newVMCID, nil),
				mockCloud.EXPECT().SetVMMetadata(newVMCID, gomock.Any()).Return(nil),
				mockAgentClient.EXPECT().Ping().Return("any-state", nil),

				// attaching a missing disk will fail
				mockCloud.EXPECT().AttachDisk(newVMCID, oldDiskCID).Return(
					bicloud.NewCPIError("attach_disk", bicloud.CmdError{
						Type:    bicloud.DiskNotFoundError,
						Message: "fake-disk-not-found-message",
					}),
				),
			)
		}

		var expectDeployWithDiskMigrationFailure = func() {
			agentID := "fake-uuid-1"
			oldVMCID := "fake-vm-cid-1"
			newVMCID := "fake-vm-cid-2"
			oldDiskCID := "fake-disk-cid-1"
			newDiskCID := "fake-disk-cid-2"
			newDiskSize := 2048

			gomock.InOrder(
				mockCloud.EXPECT().HasVM(oldVMCID).Return(true, nil),
Exemple #3
0
			It("logs delete stage", func() {
				mockCloud.EXPECT().DeleteDisk("orphan-disk-cid")

				err := deploymentManager.Cleanup(fakeStage)
				Expect(err).ToNot(HaveOccurred())

				Expect(fakeStage.PerformCalls).To(ContainElement(&fakebiui.PerformCall{
					Name: "Deleting unused disk 'orphan-disk-cid'",
				}))
			})

			Context("when disks have been deleted manually (in the infrastructure)", func() {
				It("deletes the unused disks, ignoring DiskNotFoundError", func() {
					mockCloud.EXPECT().DeleteDisk("orphan-disk-cid").Return(bicloud.NewCPIError("delete_disk", bicloud.CmdError{
						Type:    bicloud.DiskNotFoundError,
						Message: "fake-disk-not-found-message",
					}))

					err := deploymentManager.Cleanup(fakeStage)
					Expect(err).ToNot(HaveOccurred())

					diskRecords, err := diskRepo.All()
					Expect(err).ToNot(HaveOccurred())
					Expect(diskRecords).To(BeEmpty(), "expected no disk records")
				})

				It("logs disk deletion as skipped", func() {
					mockCloud.EXPECT().DeleteDisk("orphan-disk-cid").Return(bicloud.NewCPIError("delete_disk", bicloud.CmdError{
						Type:    bicloud.DiskNotFoundError,
						Message: "fake-disk-not-found-message",
					}))
Exemple #4
0
			It("returns an error", func() {
				_, err := manager.Create(stemcell, deploymentManifest)
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-set-metadata-error"))
			})

			It("still updates the current vm record", func() {
				_, err := manager.Create(stemcell, deploymentManifest)
				Expect(err).To(HaveOccurred())
				Expect(fakeVMRepo.UpdateCurrentCID).To(Equal("fake-vm-cid"))
			})

			It("ignores not implemented error", func() {
				notImplementedCloudError := cloud.NewCPIError("set_vm_metadata", cloud.CmdError{
					Type:      "Bosh::Clouds::NotImplemented",
					Message:   "set_vm_metadata is not implemented by VCloudCloud::Cloud",
					OkToRetry: false,
				})
				fakeCloud.SetVMMetadataError = notImplementedCloudError

				_, err := manager.Create(stemcell, deploymentManifest)
				Expect(err).ToNot(HaveOccurred())
			})
		})

		Context("when creating the vm fails", func() {
			BeforeEach(func() {
				fakeCloud.CreateVMErr = errors.New("fake-create-error")
			})

			It("returns an error", func() {
		Context("when deleting stemcell in the cloud fails", func() {
			BeforeEach(func() {
				fakeCloud.DeleteStemcellErr = errors.New("fake-delete-stemcell-error")
			})

			It("returns an error", func() {
				err := cloudStemcell.Delete()
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-delete-stemcell-error"))
			})
		})

		Context("when deleting stemcell in the cloud fails with StemcellNotFoundError", func() {
			var deleteErr = bicloud.NewCPIError("delete_stemcell", bicloud.CmdError{
				Type:    bicloud.StemcellNotFoundError,
				Message: "fake-stemcell-not-found-message",
			})

			BeforeEach(func() {
				stemcellRecord, err := stemcellRepo.Save("fake-stemcell-name", "fake-stemcell-version", "fake-stemcell-cid")
				Expect(err).ToNot(HaveOccurred())

				err = stemcellRepo.UpdateCurrent(stemcellRecord.ID)
				Expect(err).ToNot(HaveOccurred())

				fakeCloud.DeleteStemcellErr = deleteErr
			})

			It("deletes stemcell in the cloud", func() {
				err := cloudStemcell.Delete()
				Expect(err).To(HaveOccurred())
Exemple #6
0
		Context("when deleting disk in the cloud fails", func() {
			BeforeEach(func() {
				fakeCloud.DeleteDiskErr = errors.New("fake-delete-disk-error")
			})

			It("returns an error", func() {
				err := disk.Delete()
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-delete-disk-error"))
			})
		})

		Context("when deleting disk in the cloud fails with DiskNotFoundError", func() {
			var deleteErr = bicloud.NewCPIError("delete_vm", bicloud.CmdError{
				Type:    bicloud.DiskNotFoundError,
				Message: "fake-disk-not-found-message",
			})

			BeforeEach(func() {
				diskRecord, err := diskRepo.Save("fake-disk-cid", 1024, diskCloudProperties)
				Expect(err).ToNot(HaveOccurred())

				err = diskRepo.UpdateCurrent(diskRecord.ID)
				Expect(err).ToNot(HaveOccurred())

				fakeCloud.DeleteDiskErr = deleteErr
			})

			It("deletes disk in the cloud", func() {
				err := disk.Delete()
				Expect(err).To(HaveOccurred())