Esempio n. 1
0
		It("returns the repo record", func() {
			record, err := compiler.Compile(pkg)
			Expect(err).ToNot(HaveOccurred())

			Expect(record).To(Equal(bistatepkg.CompiledPackageRecord{
				BlobID:   "fake-blob-id",
				BlobSHA1: "fake-fingerprint",
			}))
		})

		It("cleans up the packages dir", func() {
			_, err := compiler.Compile(pkg)
			Expect(err).ToNot(HaveOccurred())

			Expect(fs.FileExists(packagesDir)).To(BeFalse())
		})

		Context("when dependency installation fails", func() {
			JustBeforeEach(func() {
				fakeExtractor.ExtractReturns(errors.New("fake-install-error"))
			})

			It("returns an error", func() {
				_, err := compiler.Compile(pkg)
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-install-error"))
			})
		})

		Context("when the packaging script does not exist", func() {
Esempio n. 2
0
func init() {
	Describe("settingsService", func() {
		var (
			fs                         *fakesys.FakeFileSystem
			fakeDefaultNetworkResolver *fakenet.FakeDefaultNetworkResolver
			fakeSettingsSource         *fakes.FakeSettingsSource
		)

		BeforeEach(func() {
			fs = fakesys.NewFakeFileSystem()
			fakeDefaultNetworkResolver = &fakenet.FakeDefaultNetworkResolver{}
			fakeSettingsSource = &fakes.FakeSettingsSource{}
		})

		buildService := func() (Service, *fakesys.FakeFileSystem) {
			logger := boshlog.NewLogger(boshlog.LevelNone)
			service := NewService(fs, "/setting/path.json", fakeSettingsSource, fakeDefaultNetworkResolver, logger)
			return service, fs
		}

		Describe("LoadSettings", func() {
			var (
				fetchedSettings Settings
				fetcherFuncErr  error
				service         Service
			)

			BeforeEach(func() {
				fetchedSettings = Settings{}
				fetcherFuncErr = nil
			})

			JustBeforeEach(func() {
				fakeSettingsSource.SettingsValue = fetchedSettings
				fakeSettingsSource.SettingsErr = fetcherFuncErr
				service, fs = buildService()
			})

			Context("when settings fetcher succeeds fetching settings", func() {
				BeforeEach(func() {
					fetchedSettings = Settings{AgentID: "some-new-agent-id"}
				})

				Context("when settings contain at most one dynamic network", func() {
					BeforeEach(func() {
						fetchedSettings.Networks = Networks{
							"fake-net-1": Network{Type: NetworkTypeDynamic},
						}
					})

					It("updates the service with settings from the fetcher", func() {
						err := service.LoadSettings()
						Expect(err).NotTo(HaveOccurred())
						Expect(service.GetSettings().AgentID).To(Equal("some-new-agent-id"))
					})

					It("persists settings to the settings file", func() {
						err := service.LoadSettings()
						Expect(err).NotTo(HaveOccurred())

						json, err := json.Marshal(fetchedSettings)
						Expect(err).NotTo(HaveOccurred())

						fileContent, err := fs.ReadFile("/setting/path.json")
						Expect(err).NotTo(HaveOccurred())
						Expect(fileContent).To(Equal(json))
					})

					It("returns any error from writing to the setting file", func() {
						fs.WriteFileError = errors.New("fs-write-file-error")

						err := service.LoadSettings()
						Expect(err).To(HaveOccurred())
						Expect(err.Error()).To(ContainSubstring("fs-write-file-error"))
					})
				})
			})

			Context("when settings fetcher fails fetching settings", func() {
				BeforeEach(func() {
					fetcherFuncErr = errors.New("fake-fetch-error")
				})

				Context("when a settings file exists", func() {
					Context("when settings contain at most one dynamic network", func() {
						BeforeEach(func() {
							fs.WriteFile("/setting/path.json", []byte(`{
								"agent_id":"some-agent-id",
								"networks": {"fake-net-1": {"type": "dynamic"}}
							}`))

							fakeDefaultNetworkResolver.GetDefaultNetworkNetwork = Network{
								IP:      "fake-resolved-ip",
								Netmask: "fake-resolved-netmask",
								Gateway: "fake-resolved-gateway",
							}
						})

						It("returns settings from the settings file with resolved network", func() {
							err := service.LoadSettings()
							Expect(err).ToNot(HaveOccurred())
							Expect(service.GetSettings()).To(Equal(Settings{
								AgentID: "some-agent-id",
								Networks: Networks{
									"fake-net-1": Network{
										Type:     NetworkTypeDynamic,
										IP:       "fake-resolved-ip",
										Netmask:  "fake-resolved-netmask",
										Gateway:  "fake-resolved-gateway",
										Resolved: true,
									},
								},
							}))
						})
					})
				})

				Context("when non-unmarshallable settings file exists", func() {
					It("returns any error from the fetcher", func() {
						fs.WriteFile("/setting/path.json", []byte(`$%^&*(`))

						err := service.LoadSettings()
						Expect(err).To(HaveOccurred())
						Expect(err.Error()).To(ContainSubstring("fake-fetch-error"))

						Expect(service.GetSettings()).To(Equal(Settings{}))
					})
				})

				Context("when no settings file exists", func() {
					It("returns any error from the fetcher", func() {
						err := service.LoadSettings()
						Expect(err).To(HaveOccurred())
						Expect(err.Error()).To(ContainSubstring("fake-fetch-error"))

						Expect(service.GetSettings()).To(Equal(Settings{}))
					})
				})
			})
		})

		Describe("InvalidateSettings", func() {
			It("removes the settings file", func() {
				fakeSettingsSource.SettingsValue = Settings{}
				fakeSettingsSource.SettingsErr = nil
				service, fs := buildService()

				fs.WriteFile("/setting/path.json", []byte(`{}`))

				err := service.InvalidateSettings()
				Expect(err).ToNot(HaveOccurred())

				Expect(fs.FileExists("/setting/path.json")).To(BeFalse())
			})

			It("returns err if removing settings file errored", func() {
				fakeSettingsSource.SettingsValue = Settings{}
				fakeSettingsSource.SettingsErr = nil
				service, fs := buildService()

				fs.RemoveAllError = errors.New("fs-remove-all-error")

				err := service.InvalidateSettings()
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fs-remove-all-error"))
			})
		})

		Describe("GetSettings", func() {
			var (
				loadedSettings Settings
				service        Service
			)

			BeforeEach(func() {
				loadedSettings = Settings{AgentID: "some-agent-id"}
			})

			JustBeforeEach(func() {
				fakeSettingsSource.SettingsValue = loadedSettings
				fakeSettingsSource.SettingsErr = nil
				service, _ = buildService()
				err := service.LoadSettings()
				Expect(err).NotTo(HaveOccurred())
			})

			Context("when there is are no dynamic networks", func() {
				It("returns settings without modifying any networks", func() {
					Expect(service.GetSettings()).To(Equal(loadedSettings))
				})

				It("does not try to determine default network", func() {
					_ = service.GetSettings()
					Expect(fakeDefaultNetworkResolver.GetDefaultNetworkCalled).To(BeFalse())
				})
			})

			Context("when there is network that needs to be resolved (ip, netmask, or mac are not set)", func() {
				BeforeEach(func() {
					loadedSettings = Settings{
						Networks: map[string]Network{
							"fake-net1": Network{
								IP:      "fake-net1-ip",
								Netmask: "fake-net1-netmask",
								Mac:     "fake-net1-mac",
								Gateway: "fake-net1-gateway",
							},
							"fake-net2": Network{
								Gateway: "fake-net2-gateway",
								DNS:     []string{"fake-net2-dns"},
							},
						},
					}
				})

				Context("when default network can be retrieved", func() {
					BeforeEach(func() {
						fakeDefaultNetworkResolver.GetDefaultNetworkNetwork = Network{
							IP:      "fake-resolved-ip",
							Netmask: "fake-resolved-netmask",
							Gateway: "fake-resolved-gateway",
						}
					})

					It("returns settings with resolved dynamic network ip, netmask, gateway and keeping everything else the same", func() {
						settings := service.GetSettings()
						Expect(settings).To(Equal(Settings{
							Networks: map[string]Network{
								"fake-net1": Network{
									IP:      "fake-net1-ip",
									Netmask: "fake-net1-netmask",
									Mac:     "fake-net1-mac",
									Gateway: "fake-net1-gateway",
								},
								"fake-net2": Network{
									IP:       "fake-resolved-ip",
									Netmask:  "fake-resolved-netmask",
									Gateway:  "fake-resolved-gateway",
									DNS:      []string{"fake-net2-dns"},
									Resolved: true,
								},
							},
						}))
					})
				})

				Context("when default network fails to be retrieved", func() {
					BeforeEach(func() {
						fakeDefaultNetworkResolver.GetDefaultNetworkErr = errors.New("fake-get-default-network-err")
					})

					It("returns error", func() {
						settings := service.GetSettings()
						Expect(settings).To(Equal(loadedSettings))
					})
				})
			})
		})
	})
}
Esempio n. 3
0
		Context("when the job does not exist", func() {
			It("returns nil and false", func() {
				_, ok := release.FindJobByName("fake-non-existent-job")
				Expect(ok).To(BeFalse())
			})
		})
	})

	Describe("Delete", func() {
		BeforeEach(func() {
			fakeFS.WriteFileString("fake-extracted-path", "")
		})

		It("deletes the extracted release path", func() {
			Expect(fakeFS.FileExists("fake-extracted-path")).To(BeTrue())
			err := release.Delete()
			Expect(err).ToNot(HaveOccurred())
			Expect(fakeFS.FileExists("fake-extracted-path")).To(BeFalse())
		})
	})

	Describe("Exists", func() {
		BeforeEach(func() {
			fakeFS.WriteFileString("fake-extracted-path", "")
		})

		It("returns false after deletion", func() {
			Expect(release.Exists()).To(BeTrue())
			err := release.Delete()
			Expect(err).ToNot(HaveOccurred())
Esempio n. 4
0
		fs.WriteFileString("source-path", "")

		err := cache.Save("source-path", &fakeSource{
			sha1:        "fake-sha1",
			url:         "http://foo.bar.com",
			description: "some tarball",
		})
		Expect(err).ToNot(HaveOccurred())

		path, found := cache.Get(&fakeSource{
			sha1:        "fake-sha1",
			url:         "http://foo.bar.com",
			description: "some tarball",
		})
		Expect(found).To(BeTrue())
		Expect(fs.FileExists(path)).To(BeTrue())
	})

	It("is a cache miss when a tarball from a different url has been downloaded, even if SHA1 matches", func() {
		fs.WriteFileString("source-path", "")

		err := cache.Save("source-path", &fakeSource{
			sha1:        "fake-sha1",
			url:         "http://foo.bar.com",
			description: "some tarball",
		})
		Expect(err).ToNot(HaveOccurred())

		_, found := cache.Get(&fakeSource{
			sha1:        "fake-sha1",
			url:         "http://baz.bar.com",
Esempio n. 5
0
		blobSHA1 = "fake-sha1"
		fileName = "tarball.tgz"
		blobstore.GetFileName = fileName
		fakeError = errors.New("Initial error")

		extractor = NewExtractor(fs, compressor, blobstore, logger)
	})

	Describe("Cleanup", func() {
		BeforeEach(func() {
			err := extractor.Extract(blobID, blobSHA1, targetDir)
			Expect(err).ToNot(HaveOccurred())
		})

		It("deletes the extracted temp file", func() {
			Expect(fs.FileExists(targetDir)).To(BeTrue())
			err := extractor.Cleanup(blobID, targetDir)
			Expect(err).ToNot(HaveOccurred())
			Expect(fs.FileExists(targetDir)).To(BeFalse())
		})

		It("deletes the stored blob", func() {
			err := extractor.Cleanup(blobID, targetDir)
			Expect(err).ToNot(HaveOccurred())
			Expect(blobstore.DeleteBlobID).To(Equal(blobID))
		})
	})

	Describe("Extract", func() {
		Context("when the specified blobID exists in the blobstore", func() {
			It("creates the installed package dir if it does not exist", func() {
			Expect(deploymentState.DirectorID).To(Equal("fake-director-id"))
			Expect(deploymentState.Stemcells).To(Equal(stemcells))
			Expect(deploymentState.CurrentVMCID).To(Equal("fake-vm-cid"))
			Expect(deploymentState.CurrentDiskID).To(Equal("fake-disk-id"))
			Expect(deploymentState.Disks).To(Equal(disks))
		})

		Context("when the config does not exist", func() {
			It("returns a new DeploymentState with generated defaults", func() {
				deploymentState, err := service.Load()
				Expect(err).NotTo(HaveOccurred())
				Expect(deploymentState).To(Equal(DeploymentState{
					DirectorID: "fake-uuid-0",
				}))

				Expect(fakeFs.FileExists(deploymentStatePath)).To(BeTrue())
			})
		})

		Context("when reading config file fails", func() {
			BeforeEach(func() {
				fakeFs.WriteFileString(deploymentStatePath, "{}")
				fakeFs.ReadFileError = errors.New("fake-read-error")
			})

			It("returns an error", func() {
				_, err := service.Load()
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-read-error"))
			})
		})
Esempio n. 7
0
	})

	Describe("Path", func() {
		It("returns the rendered job path", func() {
			Expect(renderedJob.Path()).To(Equal(renderedJobPath))
		})
	})

	Describe("Delete", func() {
		It("deletes the rendered job path from the file system", func() {
			err := fs.MkdirAll(renderedJobPath, os.ModePerm)
			Expect(err).ToNot(HaveOccurred())

			err = renderedJob.Delete()
			Expect(err).ToNot(HaveOccurred())
			Expect(fs.FileExists(renderedJobPath)).To(BeFalse())
		})

		Context("when deleting from the file system fails", func() {
			JustBeforeEach(func() {
				fs.RemoveAllError = bosherr.Error("fake-delete-error")
			})

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

			It("calculates the SHA1 of the archive", func() {
				fakeCompressor.CompressFilesInDirTarballPath = "fake-archive-path"

				fakeSHA1Calculator.SetCalculateBehavior(map[string]fakebicrypto.CalculateInput{
					"fake-archive-path": fakebicrypto.CalculateInput{Sha1: "fake-sha1"},
				})

				archive, err := renderedJobListCompressor.Compress(renderedJobList)
				Expect(err).ToNot(HaveOccurred())

				Expect(archive.SHA1()).To(Equal("fake-sha1"))
			})

			It("deletes the temp dir compressed into the archive", func() {
				fakeFS.TempDirDir = "fake-rendered-job-list-path"
				err := fakeFS.MkdirAll("fake-rendered-job-list-path", os.ModePerm)
				Expect(err).ToNot(HaveOccurred())

				_, err = renderedJobListCompressor.Compress(renderedJobList)
				Expect(err).ToNot(HaveOccurred())

				Expect(fakeFS.FileExists("fake-rendered-job-list-path")).To(BeFalse())
			})
		})
	})
})
Esempio n. 9
0
			Expect(count).To(Equal(0))
		})
	})

	Describe("cert.Manager implementations", func() {
		var (
			fakeFs      *fakesys.FakeFileSystem
			fakeCmd     *fakesys.FakeCmdRunner
			certManager cert.Manager
		)

		SharedLinuxCertManagerExamples := func(certBasePath, certUpdateProgram string) {
			It("writes 1 cert to a file", func() {
				err := certManager.UpdateCertificates(cert1)
				Expect(err).NotTo(HaveOccurred())
				Expect(fakeFs.FileExists(fmt.Sprintf("%s/bosh-trusted-cert-1.crt", certBasePath))).To(BeTrue())
			})

			It("writes each cert to its own file", func() {
				certs := fmt.Sprintf("%s\n%s\n", cert1, cert1)

				err := certManager.UpdateCertificates(certs)
				Expect(err).NotTo(HaveOccurred())
				Expect(fakeFs.FileExists(fmt.Sprintf("%s/bosh-trusted-cert-1.crt", certBasePath))).To(BeTrue())
				Expect(fakeFs.FileExists(fmt.Sprintf("%s/bosh-trusted-cert-2.crt", certBasePath))).To(BeTrue())
				Expect(countFiles(fakeFs, certBasePath)).To(Equal(2))
			})

			It("deletes all certs when passed an empty string", func() {
				fakeFs.WriteFileString(fmt.Sprintf("%s/bosh-trusted-cert-1.crt", certBasePath), "goodbye")
				fakeFs.SetGlob(fmt.Sprintf("%s/bosh-trusted-cert-*", certBasePath), []string{
Esempio n. 10
0
		It("errs when copy file errs", func() {
			tempFile, err := fs.TempFile("bosh-blobstore-local-TestLocalGetErrsWhenCopyFileErrs")
			Expect(err).ToNot(HaveOccurred())

			fs.ReturnTempFile = tempFile
			defer fs.RemoveAll(tempFile.Name())

			fs.CopyFileError = errors.New("fake-copy-file-error")

			fileName, err := blobstore.Get("fake-blob-id", "")
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-copy-file-error"))

			Expect(fileName).To(BeEmpty())
			Expect(fs.FileExists(tempFile.Name())).To(BeFalse())
		})
	})

	Describe("CleanUp", func() {
		It("removes the path given by Get", func() {
			file, err := fs.TempFile("bosh-blobstore-local-TestLocalCleanUp")
			Expect(err).ToNot(HaveOccurred())
			fileName := file.Name()

			defer fs.RemoveAll(fileName)

			err = blobstore.CleanUp(fileName)
			Expect(err).ToNot(HaveOccurred())
			Expect(fs.FileExists(fileName)).To(BeFalse())
		})
Esempio n. 11
0
		fs     *fakesys.FakeFileSystem
		cdrom  *fakecdrom.FakeCdrom
		cdutil boshdevutil.DeviceUtil
		logger boshlog.Logger
	)

	BeforeEach(func() {
		fs = fakesys.NewFakeFileSystem()
		cdrom = fakecdrom.NewFakeCdrom(fs, "env", "fake env contents")
		logger = boshlog.NewLogger(boshlog.LevelNone)
	})

	JustBeforeEach(func() {
		cdutil = boshcdrom.NewCdUtil("/fake/settings/dir", fs, cdrom, logger)
	})

	It("gets file contents from CDROM", func() {
		contents, err := cdutil.GetFilesContents([]string{"env"})
		Expect(err).NotTo(HaveOccurred())

		Expect(cdrom.Mounted).To(Equal(false))
		Expect(cdrom.MediaAvailable).To(Equal(false))
		Expect(fs.FileExists("/fake/settings/dir")).To(Equal(true))
		Expect(cdrom.MountMountPath).To(Equal("/fake/settings/dir"))

		Expect(len(contents)).To(Equal(1))
		Expect(contents[0]).To(Equal([]byte("fake env contents")))
	})

})
Esempio n. 12
0
							_, err := provider.Get(source, fakeStage)
							Expect(err).To(HaveOccurred())
							Expect(err.Error()).To(ContainSubstring("'fake-sha2' does not match expected SHA1 'fake-sha1'"))
						})

						It("retries downloading up to 3 times", func() {
							_, err := provider.Get(source, fakeStage)
							Expect(err).To(HaveOccurred())

							Expect(httpClient.GetInputs).To(HaveLen(3))
						})

						It("removes the downloaded file", func() {
							_, err := provider.Get(source, fakeStage)
							Expect(err).To(HaveOccurred())
							Expect(fs.FileExists(tempDownloadFilePath)).To(BeFalse())
						})
					})

					Context("when saving to cache fails", func() {
						BeforeEach(func() {
							// Creating cache base directory fails
							fs.MkdirAllError = errors.New("fake-mkdir-error")
						})

						It("returns an error", func() {
							_, err := provider.Get(source, fakeStage)
							Expect(err).To(HaveOccurred())
							Expect(err.Error()).To(ContainSubstring("fake-mkdir-error"))
						})
		fakeUUIDGenerator = fakeuuid.NewFakeGenerator()
		legacyDeploymentStateFilePath = "/path/to/legacy/bosh-deployment.yml"
		modernDeploymentStateFilePath = "/path/to/legacy/deployment.json"
		logger := boshlog.NewLogger(boshlog.LevelNone)
		deploymentStateService = NewFileSystemDeploymentStateService(fakeFs, fakeUUIDGenerator, logger, modernDeploymentStateFilePath)
		migrator = NewLegacyDeploymentStateMigrator(deploymentStateService, fakeFs, fakeUUIDGenerator, logger)
	})

	Describe("MigrateIfExists", func() {
		Context("when no legacy deploment config file exists", func() {
			It("does nothing", func() {
				migrated, err := migrator.MigrateIfExists(legacyDeploymentStateFilePath)
				Expect(migrated).To(BeFalse())
				Expect(err).ToNot(HaveOccurred())

				Expect(fakeFs.FileExists(modernDeploymentStateFilePath)).To(BeFalse())
			})
		})

		Context("when legacy deploment config file exists (but is unparseable)", func() {
			BeforeEach(func() {
				fakeFs.WriteFileString(legacyDeploymentStateFilePath, `xyz`)
			})

			It("does not delete the legacy deployment state file", func() {
				migrated, err := migrator.MigrateIfExists(legacyDeploymentStateFilePath)
				Expect(migrated).To(BeFalse())
				Expect(err).To(HaveOccurred())

				Expect(fakeFs.FileExists(modernDeploymentStateFilePath)).To(BeFalse())
				Expect(fakeFs.FileExists(legacyDeploymentStateFilePath)).To(BeTrue())
	})

	Describe("SHA1", func() {
		It("returns the rendered job list archive sha1", func() {
			Expect(renderedJobListArchive.SHA1()).To(Equal(renderedJobListArchiveSHA1))
		})
	})

	Describe("Delete", func() {
		It("deletes the rendered job list archive from the file system", func() {
			err := fs.MkdirAll(renderedJobListArchivePath, os.ModePerm)
			Expect(err).ToNot(HaveOccurred())

			err = renderedJobListArchive.Delete()
			Expect(err).ToNot(HaveOccurred())
			Expect(fs.FileExists(renderedJobListArchivePath)).To(BeFalse())
		})

		Context("when deleting from the file system fails", func() {
			JustBeforeEach(func() {
				fs.RemoveAllError = bosherr.Error("fake-delete-error")
			})

			It("returns an error", func() {
				err := renderedJobListArchive.Delete()
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-delete-error"))
			})
		})
	})
Esempio n. 15
0
			It("extracts and parses the stemcell manifest", func() {
				stemcell, err := extractor.Extract(stemcellTarballPath)
				Expect(err).ToNot(HaveOccurred())
				Expect(stemcell).To(Equal(expectedExtractedStemcell))

				Expect(reader.ReadInputs).To(Equal([]fakebistemcell.ReadInput{
					{
						StemcellTarballPath: stemcellTarballPath,
						DestPath:            stemcellExtractionDir,
					},
				}))
			})

			It("does not delete the destination file path", func() {
				extractor.Extract(stemcellTarballPath)
				Expect(fs.FileExists(stemcellExtractionDir)).To(BeTrue())
			})
		})

		Context("when the read fails", func() {
			BeforeEach(func() {
				reader.SetReadBehavior(stemcellTarballPath, stemcellExtractionDir, expectedExtractedStemcell, errors.New("fake-read-error"))
			})

			It("returns an error", func() {
				_, err := extractor.Extract(stemcellTarballPath)
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-read-error"))
			})

			It("deletes the destination file path", func() {
Esempio n. 16
0
				Expect(string(contents[0])).To(Equal("fake-contents-1"))
				Expect(string(contents[1])).To(Equal("fake-contents-2"))
			})

			It("unmount disk path", func() {
				_, err := diskUtil.GetFilesContents([]string{"fake-file-path-1"})
				Expect(err).ToNot(HaveOccurred())

				Expect(mounter.UnmountPartitionPathOrMountPoint).To(Equal("fake-tempdir"))
			})

			It("cleans up temporary directory after reading settings", func() {
				_, err := diskUtil.GetFilesContents([]string{"fake-file-path-1"})
				Expect(err).ToNot(HaveOccurred())

				Expect(fs.FileExists("fake-tempdir")).To(BeFalse())
			})

			It("returns error if it fails to create temporary mount directory", func() {
				fs.TempDirError = errors.New("fake-tempdir-error")

				_, err := diskUtil.GetFilesContents([]string{"fake-file-path-1"})
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-tempdir-error"))
			})

			It("returns error if it fails to mount disk path", func() {
				mounter.MountErr = errors.New("fake-mount-error")

				_, err := diskUtil.GetFilesContents([]string{"fake-file-path-1"})
				Expect(err).To(HaveOccurred())
Esempio n. 17
0
		It("deletes the rendered jobs", func() {
			err := fs.MkdirAll("fake-path-0", os.ModePerm)
			Expect(err).ToNot(HaveOccurred())

			err = fs.MkdirAll("fake-path-1", os.ModePerm)
			Expect(err).ToNot(HaveOccurred())

			renderedJob0 := NewRenderedJob(bireljob.Job{Name: "fake-job-0"}, "fake-path-0", fs, logger)
			renderedJob1 := NewRenderedJob(bireljob.Job{Name: "fake-job-1"}, "fake-path-1", fs, logger)
			renderedJobList.Add(renderedJob0)
			renderedJobList.Add(renderedJob1)

			err = renderedJobList.Delete()
			Expect(err).ToNot(HaveOccurred())

			Expect(fs.FileExists("fake-path-0")).To(BeFalse())
			Expect(fs.FileExists("fake-path-1")).To(BeFalse())
		})

		Context("when deleting from the file system fails", func() {
			JustBeforeEach(func() {
				fs.RemoveAllError = bosherr.Error("fake-delete-error")
			})

			It("returns an error", func() {
				renderedJob0 := NewRenderedJob(bireljob.Job{Name: "fake-job-0"}, "fake-path-0", fs, logger)
				renderedJobList.Add(renderedJob0)

				err := renderedJobList.Delete()
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-delete-error"))
Esempio n. 18
0
								PackageNames: []string{
									"fake-release-package-name",
								},
								Packages:   []*birelpkg.Package{expectedPackage},
								Properties: map[string]bireljob.PropertyDefinition{},
							},
						},
						[]*birelpkg.Package{expectedPackage},
						"/extracted-release-path",
						fakeFS,
						false,
					)

					Expect(release).To(Equal(expectedRelease))

					Expect(fakeFS.FileExists("/extracted-release-path")).To(BeTrue())
					Expect(fakeFS.FileExists("/extracted-release-path/extracted_packages/fake-release-package-name")).To(BeTrue())
					Expect(fakeFS.FileExists("/extracted-release-path/extracted_jobs/cpi")).To(BeTrue())
				})
			})

			Context("and the tarball is not a valid BOSH release", func() {
				BeforeEach(func() {
					fakeFS.WriteFileString("/extracted-release-path/release.MF", `{}`)
					fakeReleaseValidator.ValidateError = bosherr.Error("fake-error")
				})

				It("returns an error", func() {
					_, err := releaseExtractor.Extract(releaseTarballPath)
					Expect(err).To(HaveOccurred())
					Expect(err.Error()).To(ContainSubstring("fake-error"))
					gomock.InOrder(
						expectCPIExtractRelease.Times(1),
						expectCPIInstall.Times(1),
						expectNewCloud.Times(1),
					)

					err := newDeploymentDeleter().DeleteDeployment(fakeStage)
					Expect(err).NotTo(HaveOccurred())
				})

				It("deletes the extracted CPI release", func() {
					expectDeleteAndCleanup(true)

					err := newDeploymentDeleter().DeleteDeployment(fakeStage)
					Expect(err).NotTo(HaveOccurred())
					Expect(fs.FileExists("fake-cpi-extracted-dir")).To(BeFalse())
				})

				It("deletes the deployment & cleans up orphans", func() {
					expectDeleteAndCleanup(true)

					err := newDeploymentDeleter().DeleteDeployment(fakeStage)
					Expect(err).ToNot(HaveOccurred())
					Expect(fakeUI.Errors).To(BeEmpty())
				})

				It("deletes the local CPI installation", func() {
					expectDeleteAndCleanup(false)
					mockCpiUninstaller.EXPECT().Uninstall(gomock.Any()).Return(nil)

					err := newDeploymentDeleter().DeleteDeployment(fakeStage)
Esempio n. 20
0
	})

	Describe("Path", func() {
		It("returns the local blob path", func() {
			Expect(localBlob.Path()).To(Equal(localBlobPath))
		})
	})

	Describe("Delete", func() {
		It("deletes the local blob from the file system", func() {
			err := fs.WriteFileString(localBlobPath, "fake-local-blob-content")
			Expect(err).ToNot(HaveOccurred())

			err = localBlob.Delete()
			Expect(err).ToNot(HaveOccurred())
			Expect(fs.FileExists(localBlobPath)).To(BeFalse())
		})

		Context("when deleting from the file system fails", func() {
			JustBeforeEach(func() {
				fs.RemoveAllError = bosherr.Error("fake-delete-error")
			})

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