Example #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",
			})
		})
	})
}
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"))
		})
	})
}
Example #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)
}
Example #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"))
}
Example #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"]`)
		})
	})
}
Example #6
0
func TestStartRunReturnsStarted(t *testing.T) {
	_, action := buildStartAction()

	started, err := action.Run()
	assert.NoError(t, err)
	assert.Equal(t, "started", started)
}
Example #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"}`)
}
Example #8
0
func TestStartRunStartsMonitorServices(t *testing.T) {
	jobSupervisor, action := buildStartAction()

	_, err := action.Run()
	assert.NoError(t, err)
	assert.True(t, jobSupervisor.Started)
}
Example #9
0
func TestStopRunStopsJobSupervisorServices(t *testing.T) {
	jobSupervisor, action := buildStopAction()

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

	assert.True(t, jobSupervisor.Stopped)
}
Example #10
0
func TestDrainRunStatusErrsWhenWithoutDrainScript(t *testing.T) {
	_, fakeDrainProvider, action := buildDrain()

	fakeDrainProvider.NewDrainScriptDrainScript.ExistsBool = false

	_, err := action.Run(DrainTypeStatus)
	assert.Error(t, err)
}
Example #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())
}
Example #12
0
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")
}
Example #13
0
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)
}
Example #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")
}
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"))
}
Example #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"}})
}
Example #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())
}
Example #18
0
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{})
}
Example #19
0
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)
}
Example #20
0
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)
}
Example #21
0
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")
}
Example #22
0
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"`)
}
Example #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"}`)
}
Example #24
0
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",
	})
}
Example #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"`)
}
Example #26
0
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)
}
Example #27
0
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)
		})
	})
}
Example #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`)
}
Example #29
0
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)
		})
	})
}
Example #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"}})
		})
	})
}