Example #1
0
func (context *OpsManager) copyDeployments() (err error) {
	var file *os.File
	defer file.Close()

	if file, err = osutils.SafeCreate(context.TargetDir, context.OpsmanagerBackupDir, OPSMGR_DEPLOYMENTS_FILENAME); err == nil {
		command := "cd /var/tempest/workspaces/default && tar cz deployments"
		err = context.Executer.Execute(file, command)
	}
	return
}
Example #2
0
func (context *OpsManager) exportUrlToFile(urlFormat string, filename string) (err error) {
	var settingsFileRef *os.File
	defer settingsFileRef.Close()

	url := fmt.Sprintf(urlFormat, context.Hostname)

	context.Logger.Debug("Exporting url '%s' to file '%s'", log.Data{"url": url, "filename": filename})

	if settingsFileRef, err = osutils.SafeCreate(context.TargetDir, context.OpsmanagerBackupDir, filename); err == nil {
		err = context.exportUrlToWriter(url, settingsFileRef, context.SettingsRequestor)
	}
	return
}
Example #3
0
func (context *OpsManager) extract() (err error) {
	var keyFileRef *os.File
	defer keyFileRef.Close()
	context.Logger.Debug("Extracting Ops Manager")

	if keyFileRef, err = osutils.SafeCreate(context.TargetDir, context.OpsmanagerBackupDir, OPSMGR_ENCRYPTIONKEY_FILENAME); err == nil {
		context.Logger.Debug("Extracting encryption key")
		backupDir := path.Join(context.TargetDir, context.OpsmanagerBackupDir)
		deployment := path.Join(backupDir, OPSMGR_DEPLOYMENTS_FILENAME)
		cmd := "tar -xf " + deployment + " -C " + backupDir
		context.Logger.Debug("Extracting : %s", log.Data{"command": cmd})
		context.LocalExecuter.Execute(nil, cmd)

		err = ExtractEncryptionKey(keyFileRef, context.DeploymentDir)
	}
	return
}
Example #4
0
func (context *ElasticRuntime) getReadWriter(fpath string, action int) (rw io.ReadWriter, err error) {
	switch action {
	case IMPORT_ARCHIVE:
		var exists bool

		if exists, err = osutils.Exists(fpath); exists && err == nil {
			rw, err = os.Open(fpath)

		} else {
			var pathError os.PathError
			pathError = *ER_ERROR_INVALID_PATH
			pathError.Path = fpath
			err = &pathError
		}

	case EXPORT_ARCHIVE:
		rw, err = osutils.SafeCreate(fpath)
	}
	return
}
Example #5
0
// Writer returns an io.WriteCloser for the specified path
func (d *DiskProvider) Writer(path ...string) (io.WriteCloser, error) {
	return osutils.SafeCreate(path...)
}
				gw := &fakes.MockHTTPGateway{}

				opsMgr = &OpsManager{
					SettingsUploader:    fakeSettingsUploader.Upload,
					AssetsUploader:      fakeAssetsUploader.Upload,
					SettingsRequestor:   gw,
					AssetsRequestor:     gw,
					Hostname:            "localhost",
					Username:            "******",
					Password:            "******",
					BackupContext:       fakes.NewFakeBackupContext(path.Join(tmpDir, "backup"), cfenv.CurrentEnv(), new(cfbackup.DiskProvider)),
					Executer:            &fakes.SuccessExecuter{},
					DeploymentDir:       "fixtures/encryptionkey",
					OpsmanagerBackupDir: "opsmanager",
				}
				f, _ := osutils.SafeCreate(opsMgr.TargetDir, opsMgr.OpsmanagerBackupDir, OpsMgrInstallationSettingsFilename)
				f.Write(controlSettingsContents)
				f.Close()
				f, _ = osutils.SafeCreate(opsMgr.TargetDir, opsMgr.OpsmanagerBackupDir, OpsMgrInstallationAssetsFileName)
				f.Write(controlAssetsContents)
				f.Close()
				opsMgr.Restore()
			})
			It("then it should import the assets archive", func() {
				Ω(fakeAssetsUploader.UploadCallCount).ShouldNot(Equal(0))
				Ω(fakeAssetsUploader.SpyFileContents).Should(Equal(controlAssetsContents))
			})
			It("then it should not import the settings archive", func() {
				Ω(fakeSettingsUploader.UploadCallCount).Should(Equal(0))
				Ω(fakeSettingsUploader.SpyFileContents).Should(BeNil())
			})
Example #7
0
					SettingsUploader:  MockMultiPartUploadFunc,
					AssetsUploader:    MockMultiPartUploadFunc,
					SettingsRequestor: gw,
					AssetsRequestor:   gw,
					Hostname:          "localhost",
					Username:          "******",
					Password:          "******",
					BackupContext: BackupContext{
						TargetDir: path.Join(tmpDir, "backup"),
					},
					Executer:            &failExecuter{},
					DeploymentDir:       "fixtures/encryptionkey",
					OpsmanagerBackupDir: "opsmanager",
					Logger:              Logger(),
				}
				f, _ := osutils.SafeCreate(opsManager.TargetDir, opsManager.OpsmanagerBackupDir, OPSMGR_INSTALLATION_SETTINGS_FILENAME)
				f.Close()
				f, _ = osutils.SafeCreate(opsManager.TargetDir, opsManager.OpsmanagerBackupDir, OPSMGR_INSTALLATION_ASSETS_FILENAME)
				f.Close()
			})

			It("Should yield error", func() {
				err := opsManager.Restore()
				Ω(err).ShouldNot(BeNil())
			})
		})

		Context("calling restore successfully", func() {

			BeforeEach(func() {
				tmpDir, _ = ioutil.TempDir("/tmp", "test")
Example #8
0
		AfterEach(func() {
			os.RemoveAll(dir)
		})

		Context("called w/ successful sftp connection", func() {
			var output bytes.Buffer
			BeforeEach(func() {
				pgDumpInstance.RemoteOps = &mockRemoteOps{
					Writer: &output,
				}
			})

			It("should copy local file to remote file and return nil error", func() {
				controlString := "hello there"
				l, _ := osutils.SafeCreate(localFilePath)
				l.WriteString(controlString)
				l.Close()
				l, _ = os.Open(localFilePath)
				err := pgDumpInstance.Import(l)
				l.Close()
				lf, _ := os.Open(localFilePath)
				defer lf.Close()
				larray, _ := ioutil.ReadAll(lf)
				Ω(err).Should(BeNil())
				Ω(output.String()).Should(Equal(string(larray[:])))
			})
		})

		Context("called w/ failed sftp connection", func() {
			var output bytes.Buffer
Example #9
0
func getReadWriter(fpath string) (rw io.ReadWriter, err error) {
	rw, err = osutils.SafeCreate(fpath)
	return
}
Example #10
0
	Describe("BackupNfs", func() {
		var origExecuterFunction func(command.SshConfig) (command.Executer, error)
		var tmpfile *os.File
		var tmpfilepath string
		Context("called with valid arguments", func() {
			BeforeEach(func() {
				origExecuterFunction = NfsNewRemoteExecuter
				NfsNewRemoteExecuter = func(command.SshConfig) (ce command.Executer, err error) {
					ce = &SuccessMockNFSExecuter{}
					return
				}

				tmpdir, _ := ioutil.TempDir("/tmp", "spec")
				filename := "nfs.tar.gz"
				tmpfilepath = path.Join(tmpdir, filename)
				tmpfile, _ = osutils.SafeCreate(tmpfilepath)
			})

			AfterEach(func() {
				NfsNewRemoteExecuter = origExecuterFunction
				tmpfile.Close()
				os.Remove(tmpfilepath)
			})

			It("should return nil error and write success output to an outfile", func() {
				err := BackupNfs("pass", "1.2.3.4", tmpfile)
				b, _ := ioutil.ReadFile(tmpfilepath)
				Ω(b).Should(Equal([]byte(nfsSuccessString)))
				Ω(err).Should(BeNil())
			})
		})