예제 #1
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("ssh should be synchronous", func() {
			settings := &fakesettings.FakeSettingsService{}
			_, action := buildSshAction(settings)
			Expect(action.IsAsynchronous()).To(BeFalse())
		})

		It("is not persistent", func() {
			settings := &fakesettings.FakeSettingsService{}
			_, action := buildSshAction(settings)
			Expect(action.IsPersistent()).To(BeFalse())
		})

		It("ssh setup without default ip", func() {

			settings := &fakesettings.FakeSettingsService{}
			_, action := buildSshAction(settings)

			params := SshParams{
				User:      "******",
				Password:  "******",
				PublicKey: "some-key",
			}
			_, err := action.Run("setup", params)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("No default ip"))
		})
		It("ssh setup with username and password", func() {

			testSshSetupWithGivenPassword(GinkgoT(), "some-password")
		})
		It("ssh setup without password", func() {

			testSshSetupWithGivenPassword(GinkgoT(), "")
		})
		It("ssh run cleanup deletes ephemeral user", func() {

			settings := &fakesettings.FakeSettingsService{}
			platform, action := buildSshAction(settings)

			params := SshParams{UserRegex: "^foobar.*"}
			response, err := action.Run("cleanup", params)
			Expect(err).ToNot(HaveOccurred())
			Expect("^foobar.*").To(Equal(platform.DeleteEphemeralUsersMatchingRegex))

			boshassert.MatchesJsonMap(GinkgoT(), response, map[string]interface{}{
				"command": "cleanup",
				"status":  "success",
			})
		})
	})
}
예제 #2
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("migrate disk should be asynchronous", func() {
			_, action := buildMigrateDiskAction()
			Expect(action.IsAsynchronous()).To(BeTrue())
		})

		It("is not persistent", func() {
			_, action := buildMigrateDiskAction()
			Expect(action.IsPersistent()).To(BeFalse())
		})

		It("migrate disk action run", func() {

			platform, action := buildMigrateDiskAction()

			value, err := action.Run()
			Expect(err).ToNot(HaveOccurred())
			boshassert.MatchesJSONString(GinkgoT(), value, "{}")

			Expect(platform.MigratePersistentDiskFromMountPoint).To(Equal("/foo/store"))
			Expect(platform.MigratePersistentDiskToMountPoint).To(Equal("/foo/store_migration_target"))
		})
	})
}
예제 #3
0
func testSshSetupWithGivenPassword(t assert.TestingT, expectedPwd string) {
	settings := &fakesettings.FakeSettingsService{}
	settings.DefaultIp = "ww.xx.yy.zz"

	platform, action := buildSshAction(settings)

	expectedUser := "******"
	expectedKey := "some public key content"

	params := SshParams{
		User:      expectedUser,
		PublicKey: expectedKey,
		Password:  expectedPwd,
	}

	response, err := action.Run("setup", params)
	assert.NoError(t, err)

	assert.Equal(t, expectedUser, platform.CreateUserUsername)
	assert.Equal(t, expectedPwd, platform.CreateUserPassword)
	assert.Equal(t, "/foo/bosh_ssh", platform.CreateUserBasePath)
	assert.Equal(t, []string{boshsettings.VCAP_USERNAME, boshsettings.ADMIN_GROUP}, platform.AddUserToGroupsGroups[expectedUser])
	assert.Equal(t, expectedKey, platform.SetupSshPublicKeys[expectedUser])

	expectedJson := map[string]interface{}{
		"command": "setup",
		"status":  "success",
		"ip":      "ww.xx.yy.zz",
	}

	boshassert.MatchesJsonMap(t, response, expectedJson)
}
예제 #4
0
func testSSHSetupWithGivenPassword(expectedPwd string) {
	settingsService := &fakesettings.FakeSettingsService{}
	settingsService.Settings.Networks = boshsettings.Networks{
		"fake-net": boshsettings.Network{IP: "ww.xx.yy.zz"},
	}

	platform, action := buildSSHAction(settingsService)

	params := SSHParams{
		User:      "******",
		PublicKey: "fake-public-key",
		Password:  expectedPwd,
	}

	response, err := action.Run("setup", params)
	Expect(err).ToNot(HaveOccurred())
	Expect(response).To(Equal(SSHResult{
		Command: "setup",
		Status:  "success",
		IP:      "ww.xx.yy.zz",
	}))

	Expect(platform.CreateUserUsername).To(Equal("fake-user"))
	Expect(platform.CreateUserPassword).To(Equal(expectedPwd))
	Expect(platform.CreateUserBasePath).To(Equal("/foo/bosh_ssh"))

	Expect(platform.AddUserToGroupsGroups["fake-user"]).To(Equal(
		[]string{boshsettings.VCAPUsername, boshsettings.AdminGroup},
	))

	Expect(platform.SetupSSHPublicKeys["fake-user"]).To(Equal("fake-public-key"))
}
예제 #5
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("list disk should be synchronous", func() {

			settings := &fakesettings.FakeSettingsService{}
			platform := fakeplatform.NewFakePlatform()
			action := NewListDisk(settings, platform)
			assert.False(GinkgoT(), action.IsAsynchronous())
		})
		It("list disk run", func() {

			settings := &fakesettings.FakeSettingsService{
				Disks: boshsettings.Disks{
					Persistent: map[string]string{
						"volume-1": "/dev/sda",
						"volume-2": "/dev/sdb",
						"volume-3": "/dev/sdc",
					},
				},
			}
			platform := fakeplatform.NewFakePlatform()
			platform.MountedDevicePaths = []string{"/dev/sdb", "/dev/sdc"}

			action := NewListDisk(settings, platform)
			value, err := action.Run()
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), value, `["volume-2","volume-3"]`)
		})
	})
}
예제 #6
0
파일: start_test.go 프로젝트: reneedv/bosh
func TestStartRunReturnsStarted(t *testing.T) {
	_, action := buildStartAction()

	started, err := action.Run()
	assert.NoError(t, err)
	assert.Equal(t, "started", started)
}
예제 #7
0
func testLogs(t assert.TestingT, logType string, filters []string, expectedFilters []string) {
	deps, action := buildLogsAction()

	deps.copier.FilteredCopyToTempTempDir = "/fake-temp-dir"
	deps.compressor.CompressFilesInDirTarballPath = "logs_test.go"
	deps.blobstore.CreateBlobId = "my-blob-id"

	logs, err := action.Run(logType, filters)
	assert.NoError(t, err)

	var expectedPath string
	switch logType {
	case "job":
		expectedPath = filepath.Join("/fake", "dir", "sys", "log")
	case "agent":
		expectedPath = filepath.Join("/fake", "dir", "bosh", "log")
	}

	assert.Equal(t, expectedPath, deps.copier.FilteredCopyToTempDir)
	assert.Equal(t, expectedFilters, deps.copier.FilteredCopyToTempFilters)

	assert.Equal(t, deps.copier.FilteredCopyToTempTempDir, deps.compressor.CompressFilesInDirDir)
	assert.Equal(t, deps.copier.CleanUpTempDir, deps.compressor.CompressFilesInDirDir)

	assert.Equal(t, deps.compressor.CompressFilesInDirTarballPath, deps.blobstore.CreateFileName)

	boshassert.MatchesJsonString(t, logs, `{"blobstore_id":"my-blob-id"}`)
}
예제 #8
0
파일: start_test.go 프로젝트: reneedv/bosh
func TestStartRunStartsMonitorServices(t *testing.T) {
	jobSupervisor, action := buildStartAction()

	_, err := action.Run()
	assert.NoError(t, err)
	assert.True(t, jobSupervisor.Started)
}
예제 #9
0
파일: stop_test.go 프로젝트: reneedv/bosh
func TestStopRunStopsJobSupervisorServices(t *testing.T) {
	jobSupervisor, action := buildStopAction()

	_, err := action.Run()
	assert.NoError(t, err)

	assert.True(t, jobSupervisor.Stopped)
}
예제 #10
0
파일: drain_test.go 프로젝트: reneedv/bosh
func TestDrainRunStatusErrsWhenWithoutDrainScript(t *testing.T) {
	_, fakeDrainProvider, action := buildDrain()

	fakeDrainProvider.NewDrainScriptDrainScript.ExistsBool = false

	_, err := action.Run(DrainTypeStatus)
	assert.Error(t, err)
}
예제 #11
0
func TestGetTaskRunWhenTaskIsNotFound(t *testing.T) {
	taskService, action := buildGetTaskAction()

	taskService.Tasks = map[string]boshtask.Task{}

	_, err := action.Run("57")
	assert.Error(t, err)
	assert.Equal(t, "Task with id 57 could not be found", err.Error())
}
예제 #12
0
파일: apply_test.go 프로젝트: reneedv/bosh
func TestApplyRunErrsWhenApplierFails(t *testing.T) {
	applier, _, action := buildApplyAction()

	applier.ApplyError = errors.New("fake-apply-error")

	_, err := action.Run(boshas.V1ApplySpec{ConfigurationHash: "fake-config-hash"})
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "fake-apply-error")
}
예제 #13
0
파일: drain_test.go 프로젝트: reneedv/bosh
func TestDrainErrsWhenDrainScriptExitsWithError(t *testing.T) {
	_, fakeDrainScriptProvider, action := buildDrain()

	fakeDrainScriptProvider.NewDrainScriptDrainScript.RunExitStatus = 0
	fakeDrainScriptProvider.NewDrainScriptDrainScript.RunError = errors.New("Fake error")

	value, err := action.Run(DrainTypeStatus)
	assert.Equal(t, value, 0)
	assert.Error(t, err)
}
예제 #14
0
func TestMigrateDiskActionRun(t *testing.T) {
	platform, action := buildMigrateDiskAction()

	value, err := action.Run()
	assert.NoError(t, err)
	boshassert.MatchesJsonString(t, value, "{}")

	assert.Equal(t, platform.MigratePersistentDiskFromMountPoint, "/foo/store")
	assert.Equal(t, platform.MigratePersistentDiskToMountPoint, "/foo/store_migration_target")
}
예제 #15
0
func TestPrepareNetworkChange(t *testing.T) {
	action, fs := buildPrepareAction()
	fs.WriteToFile("/etc/udev/rules.d/70-persistent-net.rules", "")

	resp, err := action.Run()

	assert.NoError(t, err)
	assert.Equal(t, "ok", resp)
	assert.False(t, fs.FileExists("/etc/udev/rules.d/70-persistent-net.rules"))
}
예제 #16
0
func TestRun(t *testing.T) {
	platform := fakeplatform.NewFakePlatform()
	_, err := platform.GetFs().WriteToFile("/var/vcap/micro/apply_spec.json", `{"json":["objects"]}`)
	assert.NoError(t, err)
	action := NewReleaseApplySpec(platform)

	value, err := action.Run()
	assert.NoError(t, err)

	assert.Equal(t, value, map[string]interface{}{"json": []interface{}{"objects"}})
}
예제 #17
0
func TestCompilePackageErrsWhenCompileFails(t *testing.T) {
	compiler, action := buildCompilePackageAction()
	compiler.CompileErr = errors.New("Oops")

	blobId, sha1, name, version, deps := getCompileActionArguments()

	_, err := action.Run(blobId, sha1, name, version, deps)

	assert.Error(t, err)
	assert.Contains(t, err.Error(), compiler.CompileErr.Error())
}
예제 #18
0
파일: drain_test.go 프로젝트: reneedv/bosh
func TestRunWithStatus(t *testing.T) {
	_, fakeDrainScriptProvider, action := buildDrain()

	drainStatus, err := action.Run(DrainTypeStatus)
	assert.NoError(t, err)
	assert.Equal(t, 1, drainStatus)
	assert.Equal(t, fakeDrainScriptProvider.NewDrainScriptTemplateName, "foo")
	assert.True(t, fakeDrainScriptProvider.NewDrainScriptDrainScript.DidRun)
	assert.Equal(t, fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.JobChange(), "job_check_status")
	assert.Equal(t, fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.HashChange(), "hash_unchanged")
	assert.Equal(t, fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.UpdatedPackages(), []string{})
}
예제 #19
0
파일: apply_test.go 프로젝트: reneedv/bosh
func TestApplyRunSavesTheFirstArgumentToSpecJson(t *testing.T) {
	_, specService, action := buildApplyAction()

	applySpec := boshas.V1ApplySpec{
		JobSpec: boshas.JobSpec{
			Name: "router",
		},
	}

	_, err := action.Run(applySpec)
	assert.NoError(t, err)
	assert.Equal(t, applySpec, specService.Spec)
}
예제 #20
0
파일: apply_test.go 프로젝트: reneedv/bosh
func TestApplyRunSkipsApplierWhenApplySpecDoesNotHaveConfigurationHash(t *testing.T) {
	applier, _, action := buildApplyAction()

	applySpec := boshas.V1ApplySpec{
		JobSpec: boshas.JobSpec{
			Template: "fake-job-template",
		},
	}

	_, err := action.Run(applySpec)
	assert.NoError(t, err)
	assert.False(t, applier.Applied)
}
예제 #21
0
파일: ssh_test.go 프로젝트: reneedv/bosh
func TestSshSetupWithoutDefaultIp(t *testing.T) {
	settings := &fakesettings.FakeSettingsService{}
	_, action := buildSshAction(settings)

	params := SshParams{
		User:      "******",
		Password:  "******",
		PublicKey: "some-key",
	}
	_, err := action.Run("setup", params)
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "No default ip")
}
예제 #22
0
파일: apply_test.go 프로젝트: reneedv/bosh
func TestApplyReturnsApplied(t *testing.T) {
	_, _, action := buildApplyAction()

	applySpec := boshas.V1ApplySpec{
		JobSpec: boshas.JobSpec{
			Name: "router",
		},
	}

	value, err := action.Run(applySpec)
	assert.NoError(t, err)

	boshassert.MatchesJsonString(t, value, `"applied"`)
}
예제 #23
0
func TestGetTaskRunReturnsARunningTask(t *testing.T) {
	taskService, action := buildGetTaskAction()

	taskService.Tasks = map[string]boshtask.Task{
		"57": boshtask.Task{
			Id:    "found-57-id",
			State: boshtask.TaskStateRunning,
		},
	}

	taskValue, err := action.Run("57")
	assert.NoError(t, err)
	boshassert.MatchesJsonString(t, taskValue, `{"agent_task_id":"found-57-id","state":"running"}`)
}
예제 #24
0
파일: ssh_test.go 프로젝트: reneedv/bosh
func TestSshRunCleanupDeletesEphemeralUser(t *testing.T) {
	settings := &fakesettings.FakeSettingsService{}
	platform, action := buildSshAction(settings)

	params := SshParams{UserRegex: "^foobar.*"}
	response, err := action.Run("cleanup", params)
	assert.NoError(t, err)
	assert.Equal(t, "^foobar.*", platform.DeleteEphemeralUsersMatchingRegex)

	boshassert.MatchesJsonMap(t, response, map[string]interface{}{
		"command": "cleanup",
		"status":  "success",
	})
}
예제 #25
0
func TestGetTaskRunReturnsASuccessfulTask(t *testing.T) {
	taskService, action := buildGetTaskAction()

	taskService.Tasks = map[string]boshtask.Task{
		"57": boshtask.Task{
			Id:    "found-57-id",
			State: boshtask.TaskStateDone,
			Value: "some-task-value",
		},
	}

	taskValue, err := action.Run("57")
	assert.NoError(t, err)
	boshassert.MatchesJsonString(t, taskValue, `"some-task-value"`)
}
예제 #26
0
파일: apply_test.go 프로젝트: reneedv/bosh
func TestApplyRunRunsApplierWithApplySpecWhenApplySpecHasConfigurationHash(t *testing.T) {
	applier, _, action := buildApplyAction()

	expectedApplySpec := boshas.V1ApplySpec{
		JobSpec: boshas.JobSpec{
			Template: "fake-job-template",
		},
		ConfigurationHash: "fake-config-hash",
	}

	_, err := action.Run(expectedApplySpec)
	assert.NoError(t, err)
	assert.True(t, applier.Applied)
	assert.Equal(t, expectedApplySpec, applier.ApplyApplySpec)
}
예제 #27
0
파일: stop_test.go 프로젝트: nkuacac/bosh
func init() {
	Describe("Testing with Ginkgo", func() {
		It("stop should be asynchronous", func() {
			_, action := buildStopAction()
			assert.True(GinkgoT(), action.IsAsynchronous())
		})
		It("stop run returns stopped", func() {

			_, action := buildStopAction()
			stopped, err := action.Run()
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), "stopped", stopped)
		})
		It("stop run stops job supervisor services", func() {

			jobSupervisor, action := buildStopAction()

			_, err := action.Run()
			assert.NoError(GinkgoT(), err)

			assert.True(GinkgoT(), jobSupervisor.Stopped)
		})
	})
}
예제 #28
0
func TestGetTaskRunReturnsAFailedTask(t *testing.T) {
	taskService, action := buildGetTaskAction()

	taskService.Tasks = map[string]boshtask.Task{
		"57": boshtask.Task{
			Id:    "found-57-id",
			State: boshtask.TaskStateFailed,
			Error: errors.New("Oops we failed..."),
		},
	}

	taskValue, err := action.Run("57")
	assert.Error(t, err)
	assert.Equal(t, "Oops we failed...", err.Error())
	boshassert.MatchesJsonString(t, taskValue, `null`)
}
예제 #29
0
파일: ping_test.go 프로젝트: nkuacac/bosh
func init() {
	Describe("Testing with Ginkgo", func() {
		It("ping should be synchronous", func() {

			action := NewPing()
			assert.False(GinkgoT(), action.IsAsynchronous())
		})
		It("ping run returns pong", func() {

			action := NewPing()
			pong, err := action.Run()
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), "pong", pong)
		})
	})
}
예제 #30
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("run", func() {

			platform := fakeplatform.NewFakePlatform()
			_, err := platform.GetFs().WriteToFile("/var/vcap/micro/apply_spec.json", `{"json":["objects"]}`)
			assert.NoError(GinkgoT(), err)
			action := NewReleaseApplySpec(platform)

			value, err := action.Run()
			assert.NoError(GinkgoT(), err)

			assert.Equal(GinkgoT(), value, map[string]interface{}{"json": []interface{}{"objects"}})
		})
	})
}