Code Review
/
clamp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Random error message when op_failed
[clamp.git]
/
extra
/
docker
/
elk
/
tools
/
DMaaPServiceMocker
/
ds_mocker.py
diff --git
a/extra/docker/elk/tools/DMaaPServiceMocker/ds_mocker.py
b/extra/docker/elk/tools/DMaaPServiceMocker/ds_mocker.py
index
c111606
..
bd6caec
100755
(executable)
--- a/
extra/docker/elk/tools/DMaaPServiceMocker/ds_mocker.py
+++ b/
extra/docker/elk/tools/DMaaPServiceMocker/ds_mocker.py
@@
-18,11
+18,11
@@
def now_notification_time():
return datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f+00:00")
CONTROL_LOOP_NAMES = [
return datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f+00:00")
CONTROL_LOOP_NAMES = [
- 'C
losedLoop-vUSP-SIG-d925ed73-8231-4d02-9545-db4e101f88f8
',
- 'C
losedLoop-vUSP-SIG-37b1c91e-fd6b-4abd-af15-771902d5fdb1
',
- 'C
losedLoop-vUSP-SIG-c2597657-7113-4efb-a1f9-397a7a24c3e1
',
- 'C
losedLoop-vUSP-SIG-a11318ba-4c61-46b8-a9da-bd40bec11d45
',
- 'C
losedLoop-vUSP-SIG-5321c558-2254-4efb-ac24-99dd54edc94f
',
+ 'C
L-vCPE-d925ed73
',
+ 'C
L-vCPE-37b1c91e
',
+ 'C
L-vCPE-c2597657
',
+ 'C
L-vCPE-a11318ba
',
+ 'C
L-vCPE-5321c558
',
]
TEMPLATES = {
]
TEMPLATES = {
@@
-39,6
+39,13
@@
TEMPLATES = {
'notification_rejected_missing' :'notification_rejected_missing.json',
}
'notification_rejected_missing' :'notification_rejected_missing.json',
}
+ERROR_MESSAGES = [
+ ('APPC', 'APPC1 : timeout on restart','RESTART'),
+ ('APPC', 'APPC2 : cannot restart','RESTART'),
+ ('SO', 'SO1 : scale up failed', 'SCALEUP'),
+ ('SO', 'SO2 : scale down failed', 'SCALEDOWN'),
+]
+
for key in TEMPLATES:
with open(TEMPLATES[key]) as f:
content = f.read()
for key in TEMPLATES:
with open(TEMPLATES[key]) as f:
content = f.read()
@@
-110,7
+117,11
@@
class Notification(DMaaPMessage):
return FinalNotification.from_template('notification_final_success', **kwargs)
@staticmethod
def failed(**kwargs):
return FinalNotification.from_template('notification_final_success', **kwargs)
@staticmethod
def failed(**kwargs):
- return FinalNotification.from_template('notification_final_failed', **kwargs)
+ msg = FinalNotification.from_template('notification_final_failed', **kwargs)
+ error = ERROR_MESSAGES[random.randint(0, len(ERROR_MESSAGES) - 1)]
+ h = msg['history'][-1]
+ h['actor'],h['message'],h['operation'] = error[0],error[1],error[2]
+ return msg
@staticmethod
def open(**kwargs):
return FinalNotification.from_template('notification_final_open', **kwargs)
@staticmethod
def open(**kwargs):
return FinalNotification.from_template('notification_final_open', **kwargs)
@@
-149,7
+160,7
@@
class CLStatus(object):
def __init__(self, dmaap_url=None,
missing=None, disabled=None, op_failure=None):
self._stopped = False
def __init__(self, dmaap_url=None,
missing=None, disabled=None, op_failure=None):
self._stopped = False
- def maybe(thing):
+ def maybe(thing
,
):
if thing is None:
thing = not luck(10)
return thing
if thing is None:
thing = not luck(10)
return thing
@@
-202,7
+213,7
@@
def print_usage():
def push(test_datas):
for current_i, status in enumerate(test_datas):
def push(test_datas):
for current_i, status in enumerate(test_datas):
- time.sleep(random.randint(0,
6
))
+ time.sleep(random.randint(0,
3
))
for s in status:
# print(s)
status_code = s.publish()
for s in status:
# print(s)
status_code = s.publish()
@@
-213,15
+224,26
@@
def push(test_datas):
print("%03d,missing:%5s,disabled:%5s,op_failure:%5s - %s" % (current_i, status._missing, status._disabled, status._op_failure, status._config))
print("%03d,missing:%5s,disabled:%5s,op_failure:%5s - %s" % (current_i, status._missing, status._disabled, status._op_failure, status._config))
+
def generate_dataset_1():
def generate_dataset_1():
- test_datas = [CLStatus(missing=False, disabled=False, op_failure=False) for i in range(
45
)] \
+ test_datas = [CLStatus(missing=False, disabled=False, op_failure=False) for i in range(
300
)] \
+ [CLStatus(missing=True, disabled=False, op_failure=False) for i in range(5)] \
+ [CLStatus(missing=False, disabled=True, op_failure=False) for i in range(6)] \
+ [CLStatus(missing=True, disabled=False, op_failure=False) for i in range(5)] \
+ [CLStatus(missing=False, disabled=True, op_failure=False) for i in range(6)] \
- + [CLStatus(missing=False, disabled=False, op_failure=True) for i in range(7)]
+ + [CLStatus(missing=False, disabled=False, op_failure=True) for i in range(12)]
+ random.shuffle(test_datas)
+ return test_datas
+
+def generate_error_dataset_1():
+ test_datas = [CLStatus(missing=False, disabled=False, op_failure=True) for i in range(60)]
random.shuffle(test_datas)
return test_datas
random.shuffle(test_datas)
return test_datas
+DATASETS = {
+ 'dataset_1': generate_dataset_1,
+ 'op_failure_1': generate_error_dataset_1,
+}
+
if __name__ == "__main__":
import sys
if len(sys.argv) < 3:
if __name__ == "__main__":
import sys
if len(sys.argv) < 3:
@@
-231,4
+253,5
@@
if __name__ == "__main__":
Event.topic = sys.argv[2]
Notification.topic = len(sys.argv) > 3 and sys.argv[3] or sys.argv[2]
# Request.topic = len(sys.argv) > 4 or Notification.topic
Event.topic = sys.argv[2]
Notification.topic = len(sys.argv) > 3 and sys.argv[3] or sys.argv[2]
# Request.topic = len(sys.argv) > 4 or Notification.topic
- push(generate_dataset_1())
+ #push(DATASETS['op_failure_1']())
+ push(DATASETS['dataset_1']())