Merge pull request #9052 from gyuho/lease-timetolive-output

etcdctl/ctlv3: clarify "lease timetolive" output on expired lease
This commit is contained in:
Gyuho Lee 2017-12-20 09:49:34 -08:00 committed by GitHub
commit e378b9831c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 6 deletions

View File

@ -94,12 +94,8 @@ func leaseTestTimeToLiveExpire(cx ctlCtx, ttl int) error {
// eliminate false positive
time.Sleep(time.Duration(ttl+1) * time.Second)
cmdArgs := append(cx.PrefixArgs(), "lease", "timetolive", leaseID)
proc, err := spawnCmd(cmdArgs)
if err != nil {
return err
}
_, err = proc.Expect("TTL(0s), remaining(-1s)") // expect expired lease
if err != nil {
exp := fmt.Sprintf("lease %s already expired", leaseID)
if err = spawnWithExpect(cmdArgs, exp); err != nil {
return err
}
if err := ctlV3Get(cx, []string{"key"}); err != nil {

View File

@ -468,6 +468,9 @@ Prints lease information.
./etcdctl lease timetolive 2d8257079fa1bc0c --write-out=json --keys
# {"cluster_id":17186838941855831277,"member_id":4845372305070271874,"revision":3,"raft_term":2,"id":3279279168933706764,"ttl":459,"granted-ttl":500,"keys":["Zm9vMQ==","Zm9vMg=="]}
./etcdctl lease timetolive 2d8257079fa1bc0c
# lease 2d8257079fa1bc0c already expired
```
### LEASE LIST

View File

@ -93,6 +93,11 @@ func (p *simplePrinter) KeepAlive(resp v3.LeaseKeepAliveResponse) {
}
func (s *simplePrinter) TimeToLive(resp v3.LeaseTimeToLiveResponse, keys bool) {
if resp.GrantedTTL == 0 && resp.TTL == -1 {
fmt.Printf("lease %016x already expired\n", resp.ID)
return
}
txt := fmt.Sprintf("lease %016x granted with TTL(%ds), remaining(%ds)", resp.ID, resp.GrantedTTL, resp.TTL)
if keys {
ks := make([]string, len(resp.Keys))