Exemple #1
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"]`)
		})
	})
}
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"))
		})
	})
}
Exemple #3
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("mount disk should be asynchronous", func() {
			settings := &fakesettings.FakeSettingsService{}
			_, action := buildMountDiskAction(settings)
			Expect(action.IsAsynchronous()).To(BeTrue())
		})

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

		It("mount disk", func() {
			settings := &fakesettings.FakeSettingsService{}
			settings.Disks.Persistent = map[string]string{"vol-123": "/dev/sdf"}
			platform, mountDisk := buildMountDiskAction(settings)

			result, err := mountDisk.Run("vol-123")
			Expect(err).NotTo(HaveOccurred())
			boshassert.MatchesJSONString(GinkgoT(), result, "{}")

			Expect(settings.SettingsWereLoaded).To(BeTrue())

			Expect(platform.MountPersistentDiskDevicePath).To(Equal("/dev/sdf"))
			Expect(platform.MountPersistentDiskMountPoint).To(Equal("/foo/store"))
		})

		It("mount disk when store already mounted", func() {
			settings := &fakesettings.FakeSettingsService{}
			settings.Disks.Persistent = map[string]string{"vol-123": "/dev/sdf"}
			platform, mountDisk := buildMountDiskAction(settings)

			platform.IsMountPointResult = true

			result, err := mountDisk.Run("vol-123")
			Expect(err).NotTo(HaveOccurred())
			boshassert.MatchesJSONString(GinkgoT(), result, "{}")

			Expect(platform.IsMountPointPath).To(Equal("/foo/store"))

			Expect(platform.MountPersistentDiskDevicePath).To(Equal("/dev/sdf"))
			Expect(platform.MountPersistentDiskMountPoint).To(Equal("/foo/store_migration_target"))
		})

		It("mount disk when device path not found", func() {
			settings := &fakesettings.FakeSettingsService{}
			settings.Disks.Persistent = map[string]string{"vol-123": "/dev/sdf"}
			_, mountDisk := buildMountDiskAction(settings)

			_, err := mountDisk.Run("vol-456")
			Expect(err).To(HaveOccurred())
		})
	})
}
Exemple #4
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",
			})
		})
	})
}
Exemple #5
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("mount disk should be asynchronous", func() {
			settings := &fakesettings.FakeSettingsService{}
			_, action := buildMountDiskAction(settings)
			assert.True(GinkgoT(), action.IsAsynchronous())
		})
		It("mount disk", func() {

			settings := &fakesettings.FakeSettingsService{}
			settings.Disks.Persistent = map[string]string{"vol-123": "/dev/sdf"}
			platform, mountDisk := buildMountDiskAction(settings)

			result, err := mountDisk.Run("vol-123")
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), result, "{}")

			assert.True(GinkgoT(), settings.SettingsWereRefreshed)

			assert.Equal(GinkgoT(), platform.MountPersistentDiskDevicePath, "/dev/sdf")
			assert.Equal(GinkgoT(), platform.MountPersistentDiskMountPoint, "/foo/store")
		})
		It("mount disk when store already mounted", func() {

			settings := &fakesettings.FakeSettingsService{}
			settings.Disks.Persistent = map[string]string{"vol-123": "/dev/sdf"}
			platform, mountDisk := buildMountDiskAction(settings)

			platform.IsMountPointResult = true

			result, err := mountDisk.Run("vol-123")
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), result, "{}")

			assert.Equal(GinkgoT(), platform.IsMountPointPath, "/foo/store")

			assert.Equal(GinkgoT(), platform.MountPersistentDiskDevicePath, "/dev/sdf")
			assert.Equal(GinkgoT(), platform.MountPersistentDiskMountPoint, "/foo/store_migration_target")
		})
		It("mount disk when device path not found", func() {

			settings := &fakesettings.FakeSettingsService{}
			settings.Disks.Persistent = map[string]string{"vol-123": "/dev/sdf"}
			_, mountDisk := buildMountDiskAction(settings)

			_, err := mountDisk.Run("vol-456")
			assert.Error(GinkgoT(), err)
		})
	})
}
Exemple #6
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("unmount disk should be asynchronous", func() {
			platform := fakeplatform.NewFakePlatform()
			action := buildUnmountDiskAction(platform)
			Expect(action.IsAsynchronous()).To(BeTrue())
		})

		It("is not persistent", func() {
			platform := fakeplatform.NewFakePlatform()
			action := buildUnmountDiskAction(platform)
			Expect(action.IsPersistent()).To(BeFalse())
		})

		It("unmount disk when the disk is mounted", func() {

			platform := fakeplatform.NewFakePlatform()
			platform.UnmountPersistentDiskDidUnmount = true

			unmountDisk := buildUnmountDiskAction(platform)

			result, err := unmountDisk.Run("vol-123")
			Expect(err).ToNot(HaveOccurred())
			boshassert.MatchesJSONString(GinkgoT(), result, `{"message":"Unmounted partition of /dev/sdf"}`)

			Expect(platform.UnmountPersistentDiskDevicePath).To(Equal("/dev/sdf"))
		})
		It("unmount disk when the disk is not mounted", func() {

			platform := fakeplatform.NewFakePlatform()
			platform.UnmountPersistentDiskDidUnmount = false

			mountDisk := buildUnmountDiskAction(platform)

			result, err := mountDisk.Run("vol-123")
			Expect(err).ToNot(HaveOccurred())
			boshassert.MatchesJSONString(GinkgoT(), result, `{"message":"Partition of /dev/sdf is not mounted"}`)

			Expect(platform.UnmountPersistentDiskDevicePath).To(Equal("/dev/sdf"))
		})
		It("unmount disk when device path not found", func() {

			platform := fakeplatform.NewFakePlatform()
			mountDisk := buildUnmountDiskAction(platform)

			_, err := mountDisk.Run("vol-456")
			Expect(err).To(HaveOccurred())
		})
	})
}
Exemple #7
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)
		})
	})
}
Exemple #8
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("logs should be asynchronous", func() {
			_, action := buildLogsAction()
			Expect(action.IsAsynchronous()).To(BeTrue())
		})

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

		It("logs errs if given invalid log type", func() {

			_, action := buildLogsAction()
			_, err := action.Run("other-logs", []string{})
			Expect(err).To(HaveOccurred())
		})
		It("agent logs with filters", func() {

			filters := []string{"**/*.stdout.log", "**/*.stderr.log"}

			expectedFilters := []string{"**/*.stdout.log", "**/*.stderr.log"}
			testLogs(GinkgoT(), "agent", filters, expectedFilters)
		})
		It("agent logs without filters", func() {

			filters := []string{}
			expectedFilters := []string{"**/*"}
			testLogs(GinkgoT(), "agent", filters, expectedFilters)
		})
		It("job logs without filters", func() {

			filters := []string{}
			expectedFilters := []string{"**/*.log"}
			testLogs(GinkgoT(), "job", filters, expectedFilters)
		})
		It("job logs with filters", func() {

			filters := []string{"**/*.stdout.log", "**/*.stderr.log"}

			expectedFilters := []string{"**/*.stdout.log", "**/*.stderr.log"}
			testLogs(GinkgoT(), "job", filters, expectedFilters)
		})
	})
}
Exemple #9
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("unmount disk should be asynchronous", func() {
			platform := fakeplatform.NewFakePlatform()
			action := buildUnmountDiskAction(platform)
			assert.True(GinkgoT(), action.IsAsynchronous())
		})
		It("unmount disk when the disk is mounted", func() {

			platform := fakeplatform.NewFakePlatform()
			platform.UnmountPersistentDiskDidUnmount = true

			unmountDisk := buildUnmountDiskAction(platform)

			result, err := unmountDisk.Run("vol-123")
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), result, `{"message":"Unmounted partition of /dev/sdf"}`)

			assert.Equal(GinkgoT(), platform.UnmountPersistentDiskDevicePath, "/dev/sdf")
		})
		It("unmount disk when the disk is not mounted", func() {

			platform := fakeplatform.NewFakePlatform()
			platform.UnmountPersistentDiskDidUnmount = false

			mountDisk := buildUnmountDiskAction(platform)

			result, err := mountDisk.Run("vol-123")
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), result, `{"message":"Partition of /dev/sdf is not mounted"}`)

			assert.Equal(GinkgoT(), platform.UnmountPersistentDiskDevicePath, "/dev/sdf")
		})
		It("unmount disk when device path not found", func() {

			platform := fakeplatform.NewFakePlatform()
			mountDisk := buildUnmountDiskAction(platform)

			_, err := mountDisk.Run("vol-456")
			assert.Error(GinkgoT(), err)
		})
	})
}
Exemple #10
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("migrate disk should be asynchronous", func() {
			_, action := buildMigrateDiskAction()
			assert.True(GinkgoT(), action.IsAsynchronous())
		})
		It("migrate disk action run", func() {

			platform, action := buildMigrateDiskAction()

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

			assert.Equal(GinkgoT(), platform.MigratePersistentDiskFromMountPoint, "/foo/store")
			assert.Equal(GinkgoT(), platform.MigratePersistentDiskToMountPoint, "/foo/store_migration_target")
		})
	})
}
func init() {
	Describe("Testing with Ginkgo", func() {
		It("prepare network change should be synchronous", func() {
			action, _ := buildPrepareAction()
			assert.False(GinkgoT(), action.IsAsynchronous())
		})
		It("prepare network change", func() {

			action, fs := buildPrepareAction()
			fs.WriteToFile("/etc/udev/rules.d/70-persistent-net.rules", "")

			resp, err := action.Run()

			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), "ok", resp)
			assert.False(GinkgoT(), fs.FileExists("/etc/udev/rules.d/70-persistent-net.rules"))
		})
	})
}
Exemple #12
0
func init() {
	Describe("Testing with Ginkgo", func() {
		var (
			logger   boshlog.Logger
			platform *fakeplatform.FakePlatform
		)

		BeforeEach(func() {
			platform = fakeplatform.NewFakePlatform()
			logger = boshlog.NewLogger(boshlog.LEVEL_NONE)
		})

		It("list disk should be synchronous", func() {
			settings := &fakesettings.FakeSettingsService{}
			action := NewListDisk(settings, platform, logger)
			Expect(action.IsAsynchronous()).To(BeFalse())
		})

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

		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.MountedDevicePaths = []string{"/dev/sdb", "/dev/sdc"}

			action := NewListDisk(settings, platform, logger)
			value, err := action.Run()
			Expect(err).ToNot(HaveOccurred())
			boshassert.MatchesJsonString(GinkgoT(), value, `["volume-2","volume-3"]`)
		})
	})
}
Exemple #13
0
func init() {
	Describe("Ping", func() {
		It("is synchronous", func() {
			action := NewPing()
			Expect(action.IsAsynchronous()).To(BeFalse())
		})

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

		It("ping run returns pong", func() {
			action := NewPing()
			pong, err := action.Run()
			Expect(err).ToNot(HaveOccurred())
			Expect(pong).To(Equal("pong"))
		})
	})
}
Exemple #14
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("logs should be asynchronous", func() {
			_, action := buildLogsAction()
			assert.True(GinkgoT(), action.IsAsynchronous())
		})
		It("logs errs if given invalid log type", func() {

			_, action := buildLogsAction()
			_, err := action.Run("other-logs", []string{})
			assert.Error(GinkgoT(), err)
		})
		It("agent logs with filters", func() {

			filters := []string{"**/*.stdout.log", "**/*.stderr.log"}

			expectedFilters := []string{"**/*.stdout.log", "**/*.stderr.log"}
			testLogs(GinkgoT(), "agent", filters, expectedFilters)
		})
		It("agent logs without filters", func() {

			filters := []string{}
			expectedFilters := []string{"**/*"}
			testLogs(GinkgoT(), "agent", filters, expectedFilters)
		})
		It("job logs without filters", func() {

			filters := []string{}
			expectedFilters := []string{"**/*.log"}
			testLogs(GinkgoT(), "job", filters, expectedFilters)
		})
		It("job logs with filters", func() {

			filters := []string{"**/*.stdout.log", "**/*.stderr.log"}

			expectedFilters := []string{"**/*.stdout.log", "**/*.stderr.log"}
			testLogs(GinkgoT(), "job", filters, expectedFilters)
		})
	})
}
Exemple #15
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)
		})
	})
}
Exemple #16
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("get state should be synchronous", func() {
			settings := &fakesettings.FakeSettingsService{}
			_, _, _, action := buildGetStateAction(settings)
			assert.False(GinkgoT(), action.IsAsynchronous())
		})
		It("get state run", func() {

			settings := &fakesettings.FakeSettingsService{}
			settings.AgentId = "my-agent-id"
			settings.Vm.Name = "vm-abc-def"

			specService, jobSupervisor, _, action := buildGetStateAction(settings)
			jobSupervisor.StatusStatus = "running"

			specService.Spec = boshas.V1ApplySpec{
				Deployment: "fake-deployment",
			}

			expectedSpec := GetStateV1ApplySpec{
				AgentId:      "my-agent-id",
				JobState:     "running",
				BoshProtocol: "1",
				Vm:           boshsettings.Vm{Name: "vm-abc-def"},
				Ntp: boshntp.NTPInfo{
					Offset:    "0.34958",
					Timestamp: "12 Oct 17:37:58",
				},
			}
			expectedSpec.Deployment = "fake-deployment"

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

			assert.Equal(GinkgoT(), state.AgentId, expectedSpec.AgentId)
			assert.Equal(GinkgoT(), state.JobState, expectedSpec.JobState)
			assert.Equal(GinkgoT(), state.Deployment, expectedSpec.Deployment)
			boshassert.LacksJsonKey(GinkgoT(), state, "vitals")

			assert.Equal(GinkgoT(), state, expectedSpec)
		})
		It("get state run without current spec", func() {

			settings := &fakesettings.FakeSettingsService{}
			settings.AgentId = "my-agent-id"
			settings.Vm.Name = "vm-abc-def"

			specService, jobSupervisor, _, action := buildGetStateAction(settings)
			jobSupervisor.StatusStatus = "running"

			specService.GetErr = errors.New("some error")
			specService.Spec = boshas.V1ApplySpec{
				Deployment: "fake-deployment",
			}

			expectedSpec := GetStateV1ApplySpec{
				AgentId:      "my-agent-id",
				JobState:     "running",
				BoshProtocol: "1",
				Vm:           boshsettings.Vm{Name: "vm-abc-def"},
				Ntp: boshntp.NTPInfo{
					Offset:    "0.34958",
					Timestamp: "12 Oct 17:37:58",
				},
			}

			state, err := action.Run()
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonMap(GinkgoT(), expectedSpec.Ntp, map[string]interface{}{
				"offset":    "0.34958",
				"timestamp": "12 Oct 17:37:58",
			})
			assert.Equal(GinkgoT(), state, expectedSpec)
		})
		It("get state run with full format option", func() {

			settings := &fakesettings.FakeSettingsService{}
			settings.AgentId = "my-agent-id"
			settings.Vm.Name = "vm-abc-def"

			specService, jobSupervisor, fakeVitals, action := buildGetStateAction(settings)
			jobSupervisor.StatusStatus = "running"

			specService.Spec = boshas.V1ApplySpec{
				Deployment: "fake-deployment",
			}

			expectedVitals := boshvitals.Vitals{
				Load: []string{"foo", "bar", "baz"},
			}
			fakeVitals.GetVitals = expectedVitals
			expectedVm := map[string]interface{}{"name": "vm-abc-def"}

			state, err := action.Run("full")
			assert.NoError(GinkgoT(), err)

			boshassert.MatchesJsonString(GinkgoT(), state.AgentId, `"my-agent-id"`)
			boshassert.MatchesJsonString(GinkgoT(), state.JobState, `"running"`)
			boshassert.MatchesJsonString(GinkgoT(), state.Deployment, `"fake-deployment"`)
			assert.Equal(GinkgoT(), *state.Vitals, expectedVitals)
			boshassert.MatchesJsonMap(GinkgoT(), state.Vm, expectedVm)
		})
		It("get state run on vitals error", func() {

			settings := &fakesettings.FakeSettingsService{}

			_, _, fakeVitals, action := buildGetStateAction(settings)
			fakeVitals.GetErr = errors.New("Oops, could not get vitals")

			_, err := action.Run("full")
			assert.Error(GinkgoT(), err)
		})
	})
}
Exemple #17
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("apply should be asynchronous", func() {
			_, _, action := buildApplyAction()
			Expect(action.IsAsynchronous()).To(BeTrue())
		})

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

		It("apply returns applied", func() {
			_, _, action := buildApplyAction()

			applySpec := boshas.V1ApplySpec{
				ConfigurationHash: "fake-config-hash",
			}

			value, err := action.Run(applySpec)
			Expect(err).ToNot(HaveOccurred())

			boshassert.MatchesJsonString(GinkgoT(), value, `"applied"`)
		})

		It("apply run saves the first argument to spec json", func() {
			_, specService, action := buildApplyAction()

			applySpec := boshas.V1ApplySpec{
				ConfigurationHash: "fake-config-hash",
			}

			_, err := action.Run(applySpec)
			Expect(err).ToNot(HaveOccurred())
			Expect(applySpec).To(Equal(specService.Spec))
		})

		It("apply run skips applier when apply spec does not have configuration hash", func() {
			applier, _, action := buildApplyAction()

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

			_, err := action.Run(applySpec)
			Expect(err).ToNot(HaveOccurred())
			Expect(applier.Applied).To(BeFalse())
		})

		It("apply run runs applier with apply spec when apply spec has configuration hash", func() {
			applier, _, action := buildApplyAction()

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

			_, err := action.Run(expectedApplySpec)
			Expect(err).ToNot(HaveOccurred())
			Expect(applier.Applied).To(BeTrue())
			Expect(expectedApplySpec).To(Equal(applier.ApplyApplySpec))
		})

		It("apply run errs when applier fails", func() {
			applier, _, action := buildApplyAction()

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

			_, err := action.Run(boshas.V1ApplySpec{ConfigurationHash: "fake-config-hash"})
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-apply-error"))
		})
	})
}
Exemple #18
0
func TestListDiskShouldBeSynchronous(t *testing.T) {
	settings := &fakesettings.FakeSettingsService{}
	platform := fakeplatform.NewFakePlatform()
	action := NewListDisk(settings, platform)
	assert.False(t, action.IsAsynchronous())
}
Exemple #19
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("drain should be asynchronous", func() {
			_, _, action := buildDrain()
			assert.True(GinkgoT(), action.IsAsynchronous())
		})
		It("drain run update skips drain script when without drain script", func() {

			_, fakeDrainProvider, action := buildDrain()

			newSpec := boshas.V1ApplySpec{
				PackageSpecs: map[string]boshas.PackageSpec{
					"foo": boshas.PackageSpec{
						Name: "foo",
						Sha1: "foo-sha1-new",
					},
				},
			}

			fakeDrainProvider.NewDrainScriptDrainScript.ExistsBool = false

			_, err := action.Run(DrainTypeUpdate, newSpec)
			assert.NoError(GinkgoT(), err)
			assert.False(GinkgoT(), fakeDrainProvider.NewDrainScriptDrainScript.DidRun)
		})
		It("drain run shutdown skips drain script when without drain script", func() {

			_, fakeDrainProvider, action := buildDrain()

			newSpec := boshas.V1ApplySpec{
				PackageSpecs: map[string]boshas.PackageSpec{
					"foo": boshas.PackageSpec{
						Name: "foo",
						Sha1: "foo-sha1-new",
					},
				},
			}

			fakeDrainProvider.NewDrainScriptDrainScript.ExistsBool = false

			_, err := action.Run(DrainTypeShutdown, newSpec)
			assert.NoError(GinkgoT(), err)
			assert.False(GinkgoT(), fakeDrainProvider.NewDrainScriptDrainScript.DidRun)
		})
		It("drain run status errs when without drain script", func() {

			_, fakeDrainProvider, action := buildDrain()

			fakeDrainProvider.NewDrainScriptDrainScript.ExistsBool = false

			_, err := action.Run(DrainTypeStatus)
			assert.Error(GinkgoT(), err)
		})
		It("drain errs when drain script exits with error", func() {

			_, fakeDrainScriptProvider, action := buildDrain()

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

			value, err := action.Run(DrainTypeStatus)
			assert.Equal(GinkgoT(), value, 0)
			assert.Error(GinkgoT(), err)
		})
		It("run with update errs if not given new spec", func() {

			_, _, action := buildDrain()
			_, err := action.Run(DrainTypeUpdate)
			assert.Error(GinkgoT(), err)
		})
		It("run with update runs drain with updated packages", func() {

			_, fakeDrainScriptProvider, action := buildDrain()

			newSpec := boshas.V1ApplySpec{
				PackageSpecs: map[string]boshas.PackageSpec{
					"foo": boshas.PackageSpec{
						Name: "foo",
						Sha1: "foo-sha1-new",
					},
				},
			}

			drainStatus, err := action.Run(DrainTypeUpdate, newSpec)
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), 1, drainStatus)
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptTemplateName, "foo")
			assert.True(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.DidRun)
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.JobChange(), "job_new")
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.HashChange(), "hash_new")
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.UpdatedPackages(), []string{"foo"})
		})
		It("run with shutdown", func() {

			fakeNotifier, fakeDrainScriptProvider, action := buildDrain()

			drainStatus, err := action.Run(DrainTypeShutdown)
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), 1, drainStatus)
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptTemplateName, "foo")
			assert.True(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.DidRun)
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.JobChange(), "job_shutdown")
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.HashChange(), "hash_unchanged")
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.UpdatedPackages(), []string{})
			assert.True(GinkgoT(), fakeNotifier.NotifiedShutdown)
		})
		It("run with status", func() {

			_, fakeDrainScriptProvider, action := buildDrain()

			drainStatus, err := action.Run(DrainTypeStatus)
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), 1, drainStatus)
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptTemplateName, "foo")
			assert.True(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.DidRun)
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.JobChange(), "job_check_status")
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.HashChange(), "hash_unchanged")
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.UpdatedPackages(), []string{})
		})
	})
}
Exemple #20
0
func TestGetTaskShouldBeSynchronous(t *testing.T) {
	_, action := buildGetTaskAction()
	assert.False(t, action.IsAsynchronous())
}
Exemple #21
0
func TestPingShouldBeSynchronous(t *testing.T) {
	action := NewPing()
	assert.False(t, action.IsAsynchronous())
}
Exemple #22
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("apply should be asynchronous", func() {
			_, _, action := buildApplyAction()
			assert.True(GinkgoT(), action.IsAsynchronous())
		})
		It("apply returns applied", func() {

			_, _, action := buildApplyAction()

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

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

			boshassert.MatchesJsonString(GinkgoT(), value, `"applied"`)
		})
		It("apply run saves the first argument to spec json", func() {

			_, specService, action := buildApplyAction()

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

			_, err := action.Run(applySpec)
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), applySpec, specService.Spec)
		})
		It("apply run skips applier when apply spec does not have configuration hash", func() {

			applier, _, action := buildApplyAction()

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

			_, err := action.Run(applySpec)
			assert.NoError(GinkgoT(), err)
			assert.False(GinkgoT(), applier.Applied)
		})
		It("apply run runs applier with apply spec when apply spec has configuration hash", func() {

			applier, _, action := buildApplyAction()

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

			_, err := action.Run(expectedApplySpec)
			assert.NoError(GinkgoT(), err)
			assert.True(GinkgoT(), applier.Applied)
			assert.Equal(GinkgoT(), expectedApplySpec, applier.ApplyApplySpec)
		})
		It("apply run errs when applier fails", func() {

			applier, _, action := buildApplyAction()

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

			_, err := action.Run(boshas.V1ApplySpec{ConfigurationHash: "fake-config-hash"})
			assert.Error(GinkgoT(), err)
			assert.Contains(GinkgoT(), err.Error(), "fake-apply-error")
		})
	})
}
Exemple #23
0
func TestStopShouldBeAsynchronous(t *testing.T) {
	_, action := buildStopAction()
	assert.True(t, action.IsAsynchronous())
}
Exemple #24
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("compile package should be asynchronous", func() {
			_, action := buildCompilePackageAction()
			Expect(action.IsAsynchronous()).To(BeTrue())
		})

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

		It("compile package compiles the package abd returns blob id", func() {

			compiler, action := buildCompilePackageAction()
			compiler.CompileBlobID = "my-blob-id"
			compiler.CompileSha1 = "some sha1"

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

			expectedPkg := boshcomp.Package{
				BlobstoreID: blobID,
				Sha1:        sha1,
				Name:        name,
				Version:     version,
			}
			expectedJSON := map[string]interface{}{
				"result": map[string]string{
					"blobstore_id": "my-blob-id",
					"sha1":         "some sha1",
				},
			}
			expectedDeps := []boshmodels.Package{
				{
					Name:    "first_dep",
					Version: "first_dep_version",
					Source: boshmodels.Source{
						Sha1:        "first_dep_sha1",
						BlobstoreID: "first_dep_blobstore_id",
					},
				},
				{
					Name:    "sec_dep",
					Version: "sec_dep_version",
					Source: boshmodels.Source{
						Sha1:        "sec_dep_sha1",
						BlobstoreID: "sec_dep_blobstore_id",
					},
				},
			}

			val, err := action.Run(blobID, sha1, name, version, deps)

			Expect(err).ToNot(HaveOccurred())
			Expect(expectedPkg).To(Equal(compiler.CompilePkg))

			Expect(expectedDeps).To(Equal(compiler.CompileDeps))

			boshassert.MatchesJSONMap(GinkgoT(), val, expectedJSON)
		})
		It("compile package errs when compile fails", func() {

			compiler, action := buildCompilePackageAction()
			compiler.CompileErr = errors.New("fake-compile-error")

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

			_, err := action.Run(blobID, sha1, name, version, deps)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-compile-error"))
		})
	})
}
Exemple #25
0
func TestStartShouldBeSynchronous(t *testing.T) {
	_, action := buildStartAction()
	assert.False(t, action.IsAsynchronous())
}
Exemple #26
0
func TestMigrateDiskShouldBeAsynchronous(t *testing.T) {
	_, action := buildMigrateDiskAction()
	assert.True(t, action.IsAsynchronous())
}
Exemple #27
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("get task should be synchronous", func() {
			_, action := buildGetTaskAction()
			assert.False(GinkgoT(), action.IsAsynchronous())
		})
		It("get task run returns a running task", func() {

			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(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), taskValue, `{"agent_task_id":"found-57-id","state":"running"}`)
		})
		It("get task run returns a failed task", func() {

			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(GinkgoT(), err)
			assert.Equal(GinkgoT(), "Oops we failed...", err.Error())
			boshassert.MatchesJsonString(GinkgoT(), taskValue, `null`)
		})
		It("get task run returns a successful task", func() {

			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(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), taskValue, `"some-task-value"`)
		})
		It("get task run when task is not found", func() {

			taskService, action := buildGetTaskAction()

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

			_, err := action.Run("57")
			assert.Error(GinkgoT(), err)
			assert.Equal(GinkgoT(), "Task with id 57 could not be found", err.Error())
		})
	})
}
Exemple #28
0
func TestLogsShouldBeAsynchronous(t *testing.T) {
	_, action := buildLogsAction()
	assert.True(t, action.IsAsynchronous())
}
Exemple #29
0
func TestCompilePackageShouldBeAsynchronous(t *testing.T) {
	_, action := buildCompilePackageAction()
	assert.True(t, action.IsAsynchronous())
}
Exemple #30
0
func init() {
	Describe("GetState", func() {
		It("get state should be synchronous", func() {
			settings := &fakesettings.FakeSettingsService{}
			_, _, _, action := buildGetStateAction(settings)
			Expect(action.IsAsynchronous()).To(BeFalse())
		})

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

		Describe("Run", func() {
			It("returns state", func() {
				settings := &fakesettings.FakeSettingsService{}
				settings.AgentID = "my-agent-id"
				settings.VM.Name = "vm-abc-def"

				specService, jobSupervisor, _, action := buildGetStateAction(settings)
				jobSupervisor.StatusStatus = "running"

				specService.Spec = boshas.V1ApplySpec{
					Deployment: "fake-deployment",
				}

				expectedSpec := GetStateV1ApplySpec{
					AgentID:      "my-agent-id",
					JobState:     "running",
					BoshProtocol: "1",
					VM:           boshsettings.VM{Name: "vm-abc-def"},
					Ntp: boshntp.NTPInfo{
						Offset:    "0.34958",
						Timestamp: "12 Oct 17:37:58",
					},
				}
				expectedSpec.Deployment = "fake-deployment"

				state, err := action.Run()
				Expect(err).ToNot(HaveOccurred())

				Expect(state.AgentID).To(Equal(expectedSpec.AgentID))
				Expect(state.JobState).To(Equal(expectedSpec.JobState))
				Expect(state.Deployment).To(Equal(expectedSpec.Deployment))
				boshassert.LacksJSONKey(GinkgoT(), state, "vitals")

				Expect(state).To(Equal(expectedSpec))
			})

			It("returns state in full format", func() {
				settings := &fakesettings.FakeSettingsService{}
				settings.AgentID = "my-agent-id"
				settings.VM.Name = "vm-abc-def"

				specService, jobSupervisor, fakeVitals, action := buildGetStateAction(settings)
				jobSupervisor.StatusStatus = "running"

				specService.Spec = boshas.V1ApplySpec{
					Deployment: "fake-deployment",
				}

				expectedVitals := boshvitals.Vitals{
					Load: []string{"foo", "bar", "baz"},
				}
				fakeVitals.GetVitals = expectedVitals
				expectedVM := map[string]interface{}{"name": "vm-abc-def"}

				state, err := action.Run("full")
				Expect(err).ToNot(HaveOccurred())

				boshassert.MatchesJSONString(GinkgoT(), state.AgentID, `"my-agent-id"`)
				boshassert.MatchesJSONString(GinkgoT(), state.JobState, `"running"`)
				boshassert.MatchesJSONString(GinkgoT(), state.Deployment, `"fake-deployment"`)
				Expect(*state.Vitals).To(Equal(expectedVitals))
				boshassert.MatchesJSONMap(GinkgoT(), state.VM, expectedVM)
			})

			Context("when current cannot be retrieved", func() {

				It("without current spec", func() {
					settings := &fakesettings.FakeSettingsService{}
					specService, _, _, action := buildGetStateAction(settings)

					specService.GetErr = errors.New("fake-spec-get-error")

					_, err := action.Run()
					Expect(err).To(HaveOccurred())
					Expect(err.Error()).To(ContainSubstring("fake-spec-get-error"))
				})
			})

			Context("when vitals cannot be retrieved", func() {
				It("returns error", func() {
					settings := &fakesettings.FakeSettingsService{}
					_, _, fakeVitals, action := buildGetStateAction(settings)

					fakeVitals.GetErr = errors.New("fake-vitals-get-error")

					_, err := action.Run("full")
					Expect(err).To(HaveOccurred())
					Expect(err.Error()).To(ContainSubstring("fake-vitals-get-error"))
				})
			})

		})

	})
}