Skip to content

Commit

Permalink
Merge pull request #13085 from gyuho/c
Browse files Browse the repository at this point in the history
[backport 3.5] etcdserver: don't activate alarm w/missing AlarmType
  • Loading branch information
gyuho authored Jun 4, 2021
2 parents ab20aa2 + ae194c1 commit abe57c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion server/etcdserver/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@ func (a *applierV3backend) Alarm(ar *pb.AlarmRequest) (*pb.AlarmResponse, error)
case pb.AlarmRequest_GET:
resp.Alarms = a.s.alarmStore.Get(ar.Alarm)
case pb.AlarmRequest_ACTIVATE:
if ar.Alarm == pb.AlarmType_NONE {
break
}
m := a.s.alarmStore.Activate(types.ID(ar.MemberID), ar.Alarm)
if m == nil {
break
Expand All @@ -738,7 +741,7 @@ func (a *applierV3backend) Alarm(ar *pb.AlarmRequest) (*pb.AlarmResponse, error)
case pb.AlarmType_NOSPACE:
a.s.applyV3 = newApplierV3Capped(a)
default:
lg.Warn("unimplemented alarm activation", zap.String("alarm", fmt.Sprintf("%+v", m)))
lg.Panic("unimplemented alarm activation", zap.String("alarm", fmt.Sprintf("%+v", m)))
}
case pb.AlarmRequest_DEACTIVATE:
m := a.s.alarmStore.Deactivate(types.ID(ar.MemberID), ar.Alarm)
Expand Down
15 changes: 15 additions & 0 deletions tests/e2e/v3_curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,21 @@ func testV3CurlResignMissiongLeaderKey(cx ctlCtx) {
}
}

func TestV3CurlMaintenanceAlarmMissiongAlarm(t *testing.T) {
for _, p := range apiPrefix {
testCtl(t, testV3CurlMaintenanceAlarmMissiongAlarm, withApiPrefix(p), withCfg(*newConfigNoTLS()))
}
}

func testV3CurlMaintenanceAlarmMissiongAlarm(cx ctlCtx) {
if err := cURLPost(cx.epc, cURLReq{
endpoint: path.Join(cx.apiPrefix, "/maintenance/alarm"),
value: `{"action": "ACTIVATE"}`,
}); err != nil {
cx.t.Fatalf("failed post maintenance alarm (%s) (%v)", cx.apiPrefix, err)
}
}

// to manually decode; JSON marshals integer fields with
// string types, so can't unmarshal with epb.CampaignResponse
type campaignResponse struct {
Expand Down

0 comments on commit abe57c1

Please sign in to comment.