コード例 #1
0
func TestGettingVitalsWhenMissingDisks(t *testing.T) {
	statsCollector, service := buildVitalsService()
	statsCollector.DiskStats = map[string]boshstats.DiskStats{
		"/": boshstats.DiskStats{
			DiskUsage:  boshstats.Usage{Used: 100, Total: 200},
			InodeUsage: boshstats.Usage{Used: 50, Total: 500},
		},
	}

	vitals, err := service.Get()
	assert.NoError(t, err)

	boshassert.LacksJsonKey(t, vitals.Disk, "ephemeral")
	boshassert.LacksJsonKey(t, vitals.Disk, "persistent")
}
コード例 #2
0
func TestGetStateRun(t *testing.T) {
	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(t, err)

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

	assert.Equal(t, state, expectedSpec)
}
コード例 #3
0
ファイル: get_state_test.go プロジェクト: nkuacac/bosh
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)
		})
	})
}
コード例 #4
0
ファイル: service_test.go プロジェクト: velankanisys/bosh
func init() {
	Describe("Testing with Ginkgo", func() {
		It("vitals construction", func() {
			_, service := buildVitalsService()
			vitals, err := service.Get()

			expectedVitals := map[string]interface{}{
				"cpu": map[string]string{
					"sys":  "10.0",
					"user": "******",
					"wait": "1.0",
				},
				"disk": map[string]interface{}{
					"system": map[string]string{
						"percent":       "50",
						"inode_percent": "10",
					},
					"ephemeral": map[string]string{
						"percent":       "75",
						"inode_percent": "20",
					},
					"persistent": map[string]string{
						"percent":       "100",
						"inode_percent": "75",
					},
				},
				"load": []string{"0.20", "4.55", "1.12"},
				"mem": map[string]string{
					"kb":      "700",
					"percent": "70",
				},
				"swap": map[string]string{
					"kb":      "600",
					"percent": "60",
				},
			}

			Expect(err).ToNot(HaveOccurred())

			boshassert.MatchesJsonMap(GinkgoT(), vitals, expectedVitals)
		})
		It("getting vitals when missing disks", func() {

			statsCollector, service := buildVitalsService()
			statsCollector.DiskStats = map[string]boshstats.DiskStats{
				"/": boshstats.DiskStats{
					DiskUsage:  boshstats.Usage{Used: 100, Total: 200},
					InodeUsage: boshstats.Usage{Used: 50, Total: 500},
				},
			}

			vitals, err := service.Get()
			Expect(err).ToNot(HaveOccurred())

			boshassert.LacksJsonKey(GinkgoT(), vitals.Disk, "ephemeral")
			boshassert.LacksJsonKey(GinkgoT(), vitals.Disk, "persistent")
		})
		It("get getting vitals on system disk error", func() {

			statsCollector, service := buildVitalsService()
			statsCollector.DiskStats = map[string]boshstats.DiskStats{}

			_, err := service.Get()
			Expect(err).To(HaveOccurred())
		})
	})
}
コード例 #5
0
ファイル: get_state_test.go プロジェクト: velankanisys/bosh
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"))
				})
			})

		})

	})
}