/
statshandler.py
64 lines (52 loc) · 1.87 KB
/
statshandler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import time
from constants import *
from lib.mc_bin_client import MemcachedClient as McdClient
class Stats():
def __init__(self, bucket_type):
self.bucket_type = bucket_type
@staticmethod
def get_stat(client, stat, type=''):
response = client.stats(type)
return response[stat]
@staticmethod
def check(client, stat, exp, type=''):
op = client.stats(type)
response = op.next_response()
assert response['status'] == SUCCESS
assert response['value'][stat] == exp
@staticmethod
def exists(client, stat, type=''):
op = client.stats(type)
response = op.next_response()
assert response['status'] == SUCCESS
return stat in response['value']
def wait_for_persistence(self, client):
if self.bucket_type == 'ephemeral': return
while int(Stats.get_stat(client, 'ep_queue_size')) > 0:
time.sleep(1)
while int(Stats.get_stat(client, 'ep_commit_num')) == 0:
time.sleep(1)
@staticmethod
def wait_for_stat(client, stat, val, type=''):
for i in range(60):
resp = client.stats(type)
assert stat in resp
if resp[stat] == str(val):
return True
time.sleep(1)
return False
def wait_for_warmup(self, host, port):
if self.bucket_type == 'ephemeral': return
while True:
client = McdClient(host, port)
try:
client.bucket_select("default")
response = client.stats()
# check the old style or new style (as of 4.5) results
mode = response.get('ep_degraded_mode')
if mode is not None:
if mode == '0' or mode == 'false':
break
except Exception as ex:
pass
time.sleep(1)