func makeActualLRPGroup(index int32, state string, placementError string) *models.ActualLRPGroup { actual := model_helpers.NewValidActualLRP("guid", index) actual.PlacementError = placementError actual.State = state return &models.ActualLRPGroup{Instance: actual} }
func makeActualLRPGroup(processGuid, instanceGuid string, index, since, crashCount int32, domain string) *models.ActualLRPGroup { lrp := model_helpers.NewValidActualLRP(processGuid, index) lrp.InstanceGuid = instanceGuid lrp.Since = int64(since) lrp.CrashCount = crashCount lrp.Domain = domain return &models.ActualLRPGroup{Instance: lrp} }
err := response.Unmarshal(responseRecorder.Body.Bytes()) Expect(err).NotTo(HaveOccurred()) Expect(response.Error).NotTo(BeNil()) Expect(response.Error).To(Equal(models.ErrResourceNotFound)) }) }) }) Describe("EvacuateClaimedActualLRP", func() { var request *http.Request var requestBody *models.EvacuateClaimedActualLRPRequest var actual *models.ActualLRP BeforeEach(func() { actual = model_helpers.NewValidActualLRP("process-guid", 1) requestBody = &models.EvacuateClaimedActualLRPRequest{ ActualLrpKey: &actual.ActualLRPKey, ActualLrpInstanceKey: &actual.ActualLRPInstanceKey, } request = newTestRequest(requestBody) }) JustBeforeEach(func() { handler.EvacuateClaimedActualLRP(responseRecorder, request) }) It("sends the request to the db", func() { Expect(fakeEvacuationDB.EvacuateClaimedActualLRPCallCount()).To(Equal(1)) _, key, instanceKey := fakeEvacuationDB.EvacuateClaimedActualLRPArgsForCall(0)
_, err := rep.UnmarshalStackPathMap([]byte(`{"foo": ["bar"]}`)) Expect(err).To(MatchError(ContainSubstring("unmarshal"))) }) }) Describe("NewRunRequestFromDesiredLRP", func() { var ( containerGuid string desiredLRP *models.DesiredLRP actualLRP *models.ActualLRP ) BeforeEach(func() { containerGuid = "the-container-guid" desiredLRP = model_helpers.NewValidDesiredLRP("the-process-guid") actualLRP = model_helpers.NewValidActualLRP("the-process-guid", 9) desiredLRP.RootFs = "preloaded://foobar" }) It("returns a valid run request", func() { runReq, err := rep.NewRunRequestFromDesiredLRP(containerGuid, desiredLRP, &actualLRP.ActualLRPKey, &actualLRP.ActualLRPInstanceKey) Expect(err).NotTo(HaveOccurred()) Expect(runReq.Tags).To(Equal(executor.Tags{})) Expect(runReq.RunInfo).To(Equal(executor.RunInfo{ CPUWeight: uint(desiredLRP.CpuWeight), DiskScope: executor.ExclusiveDiskLimit, Ports: rep.ConvertPortMappings(desiredLRP.Ports), LogConfig: executor.LogConfig{ Guid: desiredLRP.LogGuid, Index: int(actualLRP.Index), SourceName: desiredLRP.LogSource,
expectedDesiredLRP *models.DesiredLRP expectedActualLRP, expectedEvacuatingActualLRP *models.ActualLRP expectedTask *models.Task migrationErr error ) BeforeEach(func() { // DesiredLRP expectedDesiredLRP = model_helpers.NewValidDesiredLRP("process-guid") jsonValue, err := json.Marshal(expectedDesiredLRP) Expect(err).NotTo(HaveOccurred()) _, err = storeClient.Set(deprecations.DesiredLRPSchemaPath(expectedDesiredLRP), jsonValue, 0) Expect(err).NotTo(HaveOccurred()) // ActualLRP expectedActualLRP = model_helpers.NewValidActualLRP("process-guid", 1) jsonValue, err = json.Marshal(expectedActualLRP) Expect(err).NotTo(HaveOccurred()) _, err = storeClient.Set(etcd.ActualLRPSchemaPath(expectedActualLRP.ProcessGuid, 1), jsonValue, 0) Expect(err).NotTo(HaveOccurred()) // Evacuating ActualLRP expectedEvacuatingActualLRP = model_helpers.NewValidActualLRP("process-guid", 4) jsonValue, err = json.Marshal(expectedEvacuatingActualLRP) Expect(err).NotTo(HaveOccurred()) _, err = storeClient.Set( etcd.EvacuatingActualLRPSchemaPath(expectedEvacuatingActualLRP.ProcessGuid, 1), jsonValue, 0, ) Expect(err).NotTo(HaveOccurred())
func (t *ETCDHelper) CreateValidEvacuatingLRP(guid string, index int32) { t.SetRawEvacuatingActualLRP(model_helpers.NewValidActualLRP(guid, index), 100) }
func (t *ETCDHelper) CreateValidActualLRP(guid string, index int32) { t.SetRawActualLRP(model_helpers.NewValidActualLRP(guid, index)) }
) var _ = Describe("Evacuation", func() { Describe("EvacuateActualLRP", func() { var ( actualLRP *models.ActualLRP index int32 guid string ttl uint64 ) BeforeEach(func() { guid = "the-guid" index = 1 ttl = 60 actualLRP = model_helpers.NewValidActualLRP(guid, index) etcdHelper.SetRawEvacuatingActualLRP(actualLRP, ttl) node, err := storeClient.Get(etcd.EvacuatingActualLRPSchemaPath(guid, index), false, false) fakeStoreClient.GetReturns(node, err) }) Context("when the something about the actual LRP has changed", func() { BeforeEach(func() { clock.IncrementBySeconds(5) actualLRP.Since = clock.Now().UnixNano() }) Context("when the lrp key changes", func() { BeforeEach(func() {
logger = lagertest.NewTestLogger("test") fakeBBS = new(fake_bbs.FakeClient) responseRecorder = httptest.NewRecorder() var err error request, err = http.NewRequest("POST", "", nil) Expect(err).NotTo(HaveOccurred()) request.Form = url.Values{ ":process_guid": []string{"process-guid-0"}, ":index": []string{"1"}, } fakeBBS.ActualLRPGroupByProcessGuidAndIndexStub = func(processGuid string, index int) (*models.ActualLRPGroup, error) { return &models.ActualLRPGroup{ Instance: model_helpers.NewValidActualLRP(processGuid, int32(index)), }, nil } }) JustBeforeEach(func() { killHandler := handlers.NewKillIndexHandler(logger, fakeBBS) killHandler.KillIndex(responseRecorder, request) }) It("invokes the bbs to retire", func() { Expect(fakeBBS.RetireActualLRPCallCount()).To(Equal(1)) actualLRPKey := fakeBBS.RetireActualLRPArgsForCall(0) Expect(actualLRPKey.ProcessGuid).To(Equal("process-guid-0")) Expect(actualLRPKey.Index).To(BeEquivalentTo(1))
}) Describe("EvacuateClaimedActualLRP", func() { var ( request *http.Request requestBody *models.EvacuateClaimedActualLRPRequest actual *models.ActualLRP afterActual *models.ActualLRP desiredLRP *models.DesiredLRP ) BeforeEach(func() { desiredLRP = model_helpers.NewValidDesiredLRP("the-guid") fakeDesiredLRPDB.DesiredLRPByProcessGuidReturns(desiredLRP, nil) actual = model_helpers.NewValidActualLRP("process-guid", 1) requestBody = &models.EvacuateClaimedActualLRPRequest{ ActualLrpKey: &actual.ActualLRPKey, ActualLrpInstanceKey: &actual.ActualLRPInstanceKey, } afterActual = model_helpers.NewValidActualLRP("process-guid", 1) afterActual.State = models.ActualLRPStateUnclaimed fakeActualLRPDB.ActualLRPGroupByProcessGuidAndIndexReturns(&models.ActualLRPGroup{Evacuating: actual}, nil) fakeActualLRPDB.UnclaimActualLRPReturns(&models.ActualLRPGroup{Instance: actual}, &models.ActualLRPGroup{Instance: afterActual}, nil) request = newTestRequest(requestBody) }) JustBeforeEach(func() { handler.EvacuateClaimedActualLRP(responseRecorder, request) Expect(responseRecorder.Code).To(Equal(http.StatusOK))
Expect(desiredLRPs).To(ConsistOf(existingDesiredLRPs)) }) }) Describe("Actual LRPs", func() { var ( existingActualLRPs []migrations.ETCDToSQLActualLRP instanceLRPsToCreate int ) BeforeEach(func() { instanceLRPsToCreate = 3 for i := 0; i < instanceLRPsToCreate; i++ { processGuid := fmt.Sprintf("process-guid-%d", i) actualLRP := model_helpers.NewValidActualLRP(processGuid, int32(i)) actualLRPData, err := serializer.Marshal(logger, format.ENCRYPTED_PROTO, actualLRP) Expect(err).NotTo(HaveOccurred()) _, err = storeClient.Set(etcddb.ActualLRPSchemaPath(processGuid, int32(i)), actualLRPData, 0) Expect(err).NotTo(HaveOccurred()) encoder := format.NewEncoder(cryptor) encryptedNetInfo, err := serializer.Marshal(logger, format.ENCRYPTED_PROTO, &actualLRP.ActualLRPNetInfo) Expect(err).NotTo(HaveOccurred()) netInfoData, err := encoder.Decode(encryptedNetInfo) Expect(err).NotTo(HaveOccurred()) existingActualLRPs = append(existingActualLRPs, migrations.ETCDToSQLActualLRP{ ProcessGuid: actualLRP.ProcessGuid, Index: actualLRP.Index,