-
Notifications
You must be signed in to change notification settings - Fork 1
/
perfrepo-cli
executable file
·919 lines (839 loc) · 34.2 KB
/
perfrepo-cli
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
#! /usr/bin/env python2
"""
Copyright 2015 Red Hat, Inc.
Licensed under the GNU General Public License, version 2 as
published by the Free Software Foundation; see COPYING for details.
"""
from __future__ import print_function
__author__ = """
[email protected] (Ondrej Lichtner)
"""
import sys
import logging
import os
import re
import datetime
import perfrepo
from perfrepo.Config import config
EC_SYNTAX = -1
EC_NOTIMPLEMENTED = -2
EC_NOTFOUND = -3
EC_CREATEFAILED = -4
EC_DELETEFAILED = -5
EC_UPDATEFAILED = -6
def usage(retval=0, f=sys.stderr):
"""
Print usage of this app
"""
print("Usage: %s [OPTIONS...] OBJECT {COMMAND | help} [COMMAND_OPTS]" % sys.argv[0], file=f)
print("", file=f)
print("OBJECT := { report | testexec | test }", file=f)
print("OPTIONS := { -u URL | --url URL |", file=f)
print(" -n USERNAME | --username USERNAME |", file=f)
print(" -p PASSWORD | --password PASSWORD |", file=f)
print(" -c FILE | --config FILE}", file=f)
sys.exit(retval)
class GenericCLI(object):
def __init__(self, url, username, password, argv):
if url is not None:
self._url = url
else:
self._url = config.get_option("perfrepo", "url")
if username is not None:
self._username = username
else:
self._username = config.get_option("perfrepo", "username")
if password is not None:
self._password = password
else:
self._password = config.get_option("perfrepo", "password")
self._argv = argv
self._perf_api = perfrepo.PerfRepoRESTAPI(self._url,
self._username,
self._password)
def usage(self, f=sys.stderr):
pass
def run(self):
print("Not implemented yet!", file=sys.stderr)
self.usage()
return EC_NOTIMPLEMENTED
class TestCLI(GenericCLI):
def usage(self, f=sys.stderr):
"""
Print usage for the Test object
"""
print("Usage: %s test help" % sys.argv[0], file=f)
print("", file=f)
print(" %s test get { [id] ID | [uid] UID}" % sys.argv[0], file=f)
print(" %s test show { [id] ID | [uid] UID}" % sys.argv[0], file=f)
print("", file=f)
print(" %s test create" % sys.argv[0], file=f)
print(" name NAME", file=f)
print(" uid UID", file=f)
print(" groupid GID", file=f)
print(" [description DESCRIPTION]", file=f)
print(" [metric ID ...]", file=f)
print("", file=f)
print(" %s test delete ID" % sys.argv[0], file=f)
def _do_create(self, argv):
test = perfrepo.PerfRepoTest()
i = 0
try:
while i < len(argv):
if argv[i] == "name":
test.set_name(argv[i+1])
i += 2
continue
elif argv[i] == "uid":
test.set_uid(argv[i+1])
i += 2
continue
elif argv[i] == "groupid":
test.set_groupid(argv[i+1])
i += 2
continue
elif argv[i] == "description":
test.set_description(argv[i+1])
i += 2
continue
elif argv[i] == "metric":
metric = perfrepo.PerfRepoMetric()
metric.set_id(argv[i+1])
test.add_metric(metric)
i += 2
continue
else:
print("Argument '%s' not supported for test create!" % argv[i])
return EC_SYNTAX
except IndexError:
print("Parameter '%s' requires a value!" % argv[i])
return EC_SYNTAX
if test.get_name() is None:
print("Name not specified!")
return EC_SYNTAX
elif test.get_uid() is None:
print("UID not specified!")
return EC_SYNTAX
elif test.get_groupid() is None:
print("GID not specified!")
return EC_SYNTAX
test = self._perf_api.test_create(test)
if test == None:
print("Failed to create test!")
return EC_CREATEFAILED
print("Created test with url: %s" % self._perf_api.get_obj_url(test))
return 0
def _do_delete(self, argv):
if len(argv) < 1:
print("Test delete requires an ID!")
return EC_SYNTAX
if self._perf_api.test_delete(argv[0]):
print("Test deleted")
else:
print("Test not found")
return EC_NOTFOUND
return 0
def run(self):
argv = self._argv
if len(argv) == 0:
return EC_SYNTAX
elif argv[0] == "help":
self.usage(sys.stdout)
return 0
elif argv[0] in ["get", "show"]:
selector = None
test = None
i = 1
try:
if argv[i] in [ 'id', 'uid' ]:
selector = argv[i]
i += 1
except IndexError:
print("No ID specified!", file=sys.stderr)
return EC_SYNTAX
try:
test_id = int(argv[i])
if selector != 'uid':
test = self._perf_api.test_get_by_id(test_id)
if test is None and selector != 'id':
test = self._perf_api.test_get_by_uid(argv[i])
except IndexError:
print("No ID specified!", file=sys.stderr)
return EC_SYNTAX
except ValueError:
if selector == 'id':
print("ID must be number, explicit 'id' selector was "\
"specified.", file=sys.stderr)
return EC_SYNTAX
test = self._perf_api.test_get_by_uid(argv[i])
if test is None:
print("Test not found.")
return EC_NOTFOUND
else:
print(test)
elif argv[0] == "create":
self._do_create(argv[1:])
elif argv[0] == "delete":
self._do_delete(argv[1:])
else:
print("Command '%s' not implemented for Tests." % argv[0], file=sys.stderr)
return EC_NOTIMPLEMENTED
return 0
class TestExecCLI(GenericCLI):
def usage(self, f=sys.stderr):
"""
Print usage for the TestExecution object
"""
print("Usage: %s texec help" % sys.argv[0], file=f)
print("", file=f)
print(" %s texec get ID" % sys.argv[0], file=f)
print(" %s texec show ID" % sys.argv[0], file=f)
print("", file=f)
print(" %s testexec create" % sys.argv[0], file=f)
print(" name NAME", file=f)
print(" {testid ID | testuid UID}", file=f)
print(" [comment COMMENT]", file=f)
print(" value NAME=VAL [value NAME=value ...]", file=f)
print(" tags TAG,[TAG,...]", file=f)
print(" [param NAME=VAL ...]", file=f)
print("", file=f)
print(" %s testexec update" % sys.argv[0], file=f)
print(" id ID", file=f)
print(" [name NAME]", file=f)
print(" [comment COMMENT]", file=f)
print(" [+tags TAG[,TAG ...]]", file=f)
print(" [-tags TAG[,TAG ...]]", file=f)
print("", file=f)
print(" %s testexec search" % sys.argv[0], file=f)
print(" [ids ID[,ID]]", file=f)
print(" [testuid UID]", file=f)
print(" [testname NAME]", file=f)
print(" [tags TAG[,TAG ...]]", file=f)
print(" [param NAME=VAL]", file=f)
print("", file=f)
print(" %s testexec delete ID" % sys.argv[0], file=f)
def _do_create(self, argv):
texec = perfrepo.PerfRepoTestExecution()
i = 0
try:
while i < len(argv):
if argv[i] == "name":
texec.set_name(argv[i+1])
i += 2
continue
elif argv[i] == "testid":
texec.set_testId(argv[i+1])
i += 2
continue
elif argv[i] == "testuid":
texec.set_testUid(argv[i+1])
i += 2
continue
elif argv[i] == "comment":
texec.set_comment(argv[i+1])
i += 2
continue
elif argv[i] == "tags":
tags = argv[i+1].split(",")
for tag in tags:
texec.add_tag(tag)
i += 2
continue
elif argv[i] == "param":
param = argv[i+1].split("=")
try:
param_name = param[0]
param_val = param[1]
except:
print("Invalid param '%s'" % argv[i+1])
texec.add_parameter(param_name, param_val)
i += 2
elif argv[i] == "value":
value = argv[i+1].split("=")
try:
value_name = value[0]
value_val = float(value[1])
except:
print("Invalid value '%s'" % argv[i+1])
value = perfrepo.PerfRepoValue()
value.set_metricName(value_name)
value.set_result(value_val)
texec.add_value(value)
i += 2
continue
else:
print("Argument '%s' not supported for test create!" % argv[i])
return EC_SYNTAX
except IndexError:
print("Parameter '%s' requires a value!" % argv[i])
return EC_SYNTAX
if texec.get_name() is None:
print("Name not specified!")
return EC_SYNTAX
elif texec.get_testUid() is None and texec.get_testId() is None:
print("Test ID/UID not specified!")
return EC_SYNTAX
texec = self._perf_api.testExecution_create(texec)
print("Created TestExecution with url: %s" % self._perf_api.get_obj_url(texec))
return 0
def _do_update(self, argv):
testexec_id = None
try:
if argv[1] != "id":
print("Parameter 'id' is required!", file=sys.stderr)
return EC_SYNTAX
testexec_id = str(int(argv[2]))
except IndexError:
print("Parameter 'id' is required!", file=sys.stderr)
return EC_SYNTAX
except ValueError:
print("Value of parameter 'id' must be a number!", file=sys.stderr)
return EC_SYNTAX
testexec = self._perf_api.testExecution_get(testexec_id)
if testexec is None:
print("Invalid ID specified!", file=sys.stderr)
return EC_SYNTAX
i = 3
while i < len(argv):
if argv[i] == "name":
testexec.set_name(argv[i+1])
i += 2
elif argv[i] == 'comment':
testexec.set_comment(argv[i+1])
i += 2
elif argv[i] == '+tags':
i += 1
(offset, tags) = self._parse_tags(argv[i:])
for tag in tags:
testexec.add_tag(tag)
i += offset
elif argv[i] == '-tags':
i += 1
(offset, tags) = self._parse_tags(argv[i:])
for tag in tags:
testexec.remove_tag(tag)
i += offset
else:
print("Unknown parameter '%s'!" % argv[i])
return EC_SYNTAX
self._perf_api.testExecution_update(testexec)
return 0
def _do_search(self, argv):
i = 1
search_criteria = perfrepo.PerfRepoTestExecutionSearch()
# TODO: group, order-by, limit-from, how-many,
# executed-before, executed-after
while i < len(argv):
if argv[i] == "ids":
ids = argv[i+1].split(',')
search_criteria.set_ids(ids)
i += 2
elif argv[i] == "testuid":
search_criteria.set_testUid(argv[i+1])
i += 2
elif argv[i] == "testname":
search_criteria.set_testName(argv[i+1])
i += 2
elif argv[i] == 'tags':
tags = argv[i+1].split(',')
for tag in tags:
search_criteria.add_tag(tag)
i += 2
elif argv[i] == 'param':
param = argv[i+1].split("=")
try:
param_name = param[0]
param_val = param[1]
except:
print("Invalid param '%s'" % argv[i+1])
search_criteria.add_parameter(param_name, param_val)
i += 2
else:
print("Unknown parameter '%s'!" % argv[i])
return EC_SYNTAX
texecs = self._perf_api.testExecution_search(search_criteria)
for texec in texecs:
print("%s" % texec.get_id())
return 0
def _parse_tags(self, argv):
i = 0
while i < len(argv) and \
argv[i] not in [ '+tags', '-tags', 'name', 'comment' ]:
tag_str = argv[i]
tags = tag_str.split(',')
i += 1
return (i, tags)
def _do_delete(self, argv):
if len(argv) < 1:
print("TestExecution delete requires an ID!")
return EC_SYNTAX
if self._perf_api.testExecution_delete(argv[0]):
print("TestExecution removed")
else:
print("TestExecution not found")
return EC_NOTFOUND
return 0
def run(self):
argv = self._argv
if len(argv) == 0:
return EC_SYNTAX
elif argv[0] == "help":
self.usage(sys.stdout)
return 0
elif argv[0] in ["get", "show"]:
try:
exec_id = int(argv[1])
texec = self._perf_api.testExecution_get(exec_id)
if texec is None:
print("TestExecution not found.")
return EC_NOTFOUND
else:
print(texec)
except IndexError:
print("No ID specified!", file=sys.stderr)
return EC_SYNTAX
except ValueError:
print("ID needs to be an integer!", file=sys.stderr)
return EC_SYNTAX
elif argv[0] == "create":
self._do_create(argv[1:])
return 0
elif argv[0] == "update":
self._do_update(argv)
return 0
elif argv[0] == "search":
self._do_search(argv)
return 0
elif argv[0] == "delete":
self._do_delete(argv[1:])
return 0
else:
print("Command '%s' not implemented for TestExecutions." % argv[0], file=sys.stderr)
return EC_NOTIMPLEMENTED
return 0
class ReportCLI(GenericCLI):
def usage(self, f=sys.stderr):
"""
Print usage for the Report object
"""
print("Usage: %s report help" % sys.argv[0], file=f)
print("", file=f)
print(" %s report get ID" % sys.argv[0], file=f)
print(" %s report show ID" % sys.argv[0], file=f)
print("", file=f)
print(" %s report create" % sys.argv[0], file=f)
print(" name NAME [type TYPE]", file=f)
print(" chart NAME", file=f)
print(" {testid ID | testuid UID}", file=f)
print(" series NAME", file=f)
print(" metric ID", file=f)
print(" tags TAG[,TAG,...]", file=f)
print(" baseline NAME", file=f)
print(" execid ID", file=f)
print(" metric ID", file=f)
print(" %s report update" % sys.argv[0], file=f)
print(" id ID", file=f)
print(" [name NAME]", file=f)
print(" OP chart [NUM | NAME]", file=f)
print(" [testid ID | testuid UID]", file=f)
print(" [name NAME]", file=f)
print(" [ OP series [NUM | NAME] ]", file=f)
print(" [name NAME]", file=f)
print(" [metric ID]", file=f)
print(" [+tags TAG[,TAG,...] ]", file=f)
print(" [-tags TAG[,TAG,...] ]", file=f)
print(" [ OP baseline [ NUM | NAME] ]", file=f)
print(" [name NAME]", file=f)
print(" [execid ID]", file=f)
print(" [metric ID]", file=f)
print(" WHERE OP is [add | del | edit]", file=f)
print(" edit is implicit - noOP == 'edit'", file=f)
print(" OPs 'edit' and 'del' require NUM, whereas 'add' requires NAME", file=f)
print(" if chart OP == 'add' then all further OPs are 'add' as in the 'report create' command", file=f)
def _parse_baseline(self, argv):
baseline = {}
baseline["name"] = argv[0]
i = 1
try:
while i < len(argv):
if argv[i] == "execid":
baseline["execid"] = argv[i+1]
i += 2
continue
elif argv[i] == "metric":
baseline["metric"] = argv[i+1]
i += 2
continue
else:
return (baseline, i)
except IndexError:
print("Parameter '%s' requires a value!" % argv[i])
return ({}, 0)
return (baseline, i)
def _parse_series(self, argv):
series = {"tags": []}
series["name"] = argv[0]
i = 1
try:
while i < len(argv):
if argv[i] == "tags":
tags = argv[i+1].split(",")
series["tags"] = tags
i += 2
continue
elif argv[i] == "metric":
series["metric"] = argv[i+1]
i += 2
continue
else:
return (series, i)
except IndexError:
print("Parameter '%s' requires a value!" % argv[i])
return ({}, 0)
return (series, i)
def _parse_chart_add(self, argv):
chart = {"series": [], "baselines": []}
baseline = None
series = None
chart["name"] = argv[0]
i = 1
try:
while i < len(argv):
if argv[i] == "testid":
chart["test"] = argv[i+1]
i += 2
continue
elif argv[i] == "testuid":
test = self._perf_api.test_get_by_uid(argv[i+1])
chart["test"] = test.get_id()
i += 2
continue
elif argv[i] == "series":
series, new_i = self._parse_series(argv[i+1:])
chart["series"].append(series)
i += 1 + new_i
elif argv[i] == "baseline":
baseline, new_i = self._parse_baseline(argv[i+1:])
chart["baselines"].append(baseline)
i += 1 + new_i
continue
else:
return (chart, i)
except IndexError:
print("Parameter '%s' requires a value!" % argv[i])
return ({}, 0)
return (chart, i)
def _report_add_chart(self, report, chart):
report.add_chart(chart["name"], chart["test"])
for baseline in chart["baselines"]:
try:
report.add_baseline(None, baseline["name"],
baseline["execid"],
baseline["metric"])
except KeyError as e:
print("Parameter '%s' is required for a baseline!" %\
e.args[0])
return EC_SYNTAX
for series in chart["series"]:
try:
report.add_series(None, series["name"],
series["metric"],
series["tags"])
except KeyError as e:
print("Parameter '%s' is required for a series!" %\
e.args[0])
return EC_SYNTAX
return 0
def _do_create(self, argv):
charts = []
i = 1
series = None
baseline = None
report = perfrepo.PerfRepoReport()
report.set_type("Metric")
try:
while i < len(argv):
if argv[i] == "name":
if report.get_name() is None:
report.set_name(argv[i+1])
i += 2
continue
else:
print("Report name already specified!",
file=sys.stderr)
return EC_SYNTAX
elif argv[i] == "type":
report.set_type(argv[i+1])
i += 2
continue
elif argv[i] == "chart":
chart, new_i = self._parse_chart_add(argv[i+1:])
charts.append(chart)
i += 1 + new_i
continue
else:
print("Parameter '%s' not defined/implemented!" %\
argv[i], file=sys.stderr)
return EC_SYNTAX
except IndexError:
print("Parameter '%s' requires a value!" % argv[i])
return EC_SYNTAX
if report.get_name() is None:
print("Report name not specified!", file=sys.stderr)
return EC_SYNTAX
for chart in charts:
self._report_add_chart(report, chart)
report = self._perf_api.report_create(report)
print("Created report with url: %s" % self._perf_api.get_obj_url(report))
return 0
def _do_update(self, argv):
report_id = None
try:
if argv[1] != "id":
print("Parameter 'id' is required!", file=sys.stderr)
return EC_SYNTAX
report_id = str(int(argv[2]))
except IndexError:
print("Parameter 'id' is required!", file=sys.stderr)
return EC_SYNTAX
except ValueError:
print("Value of parameter 'id' must be a number!", file=sys.stderr)
return EC_SYNTAX
report = self._perf_api.report_get_by_id(report_id)
if report is None:
print("Invalid ID specified!", file=sys.stderr)
return EC_SYNTAX
i = 3
while i < len(argv):
if argv[i] == "name":
report.set_name(argv[i+1])
i += 2
continue
op = "edit"
if argv[i] in ["add", "del", "edit"]:
op = argv[i]
i += 1
if argv[i] == "chart":
if op == "add":
chart, new_i = self._parse_chart_add(argv[i+1:])
i += 1 + new_i
self._report_add_chart(report, chart)
elif op == "edit":
chart_num = int(argv[i+1])
i += 2
while i < len(argv):
if argv[i] == "name":
report.set_chart_name(chart_num, argv[i+1])
i += 2
continue
elif argv[i] == "testid":
report.set_chart_test_id(chart_num, argv[i+1])
i += 2
continue
elif argv[i] == "testuid":
test = self._perf_api.test_get_by_uid(argv[i+1])
report.set_chart_test_id(chart_num, test.get_id())
i += 2
continue
op2 = "edit"
if argv[i] in ["add", "del", "edit"]:
op = argv[i]
i += 1
if argv[i] == "series":
if op == "add":
series, new_i = self._parse_series(argv[i+1:])
i += 1 + new_i
try:
report.add_series(chart_num,
series["name"],
series["metric"],
series["tags"])
except KeyError as e:
print("Parameter '%s' is required for a series!"\
% e.args[0])
return EC_SYNTAX
elif op == "edit":
series_num = int(argv[i+1])
i += 2
while i < len(argv):
if argv[i] == "name":
report.set_series_name(chart_num,
series_num,
argv[i+1])
i += 2
continue
elif argv[i] == "metric":
report.set_series_metric(chart_num,
series_num,
argv[i+1])
i += 2
continue
elif argv[i] == "+tags":
tags = argv[i+1].split(',')
report.add_series_tags(chart_num,
series_num,
tags)
i += 2
continue
elif argv[i] == "-tags":
tags = argv[i+1].split(',')
report.remove_series_tags(chart_num,
series_num,
tags)
i += 2
continue
else:
break
elif op == "del":
series_num = int(argv[i+1])
report.del_series(chart_num, series_num)
i += 2
continue
elif argv[i] == "baseline":
if op == "add":
baseline, new_i = self._parse_baseline(argv[i+1:])
i += 1 + new_i
try:
report.add_baseline(None, baseline["name"],
baseline["metric"],
baseline["execid"])
except KeyError as e:
print("Parameter '%s' is required for a baseline!"\
% e.args[0])
return EC_SYNTAX
elif op == "edit":
baseline_num = int(argv[i+1])
i += 2
while i < len(argv):
if argv[i] == "name":
report.set_baseline_name(chart_num,
baseline_num,
argv[i+1])
i += 2
continue
elif argv[i] == "metric":
report.set_baseline_metric(chart_num,
baseline_num,
argv[i+1])
i += 2
continue
elif argv[i] == "execid":
report.set_baseline_execid(chart_num,
baseline_num,
argv[i+1])
i += 2
continue
else:
break
elif op == "del":
baseline_num = int(argv[i+1])
report.del_baseline(chart_num, baseline_num)
i += 2
continue
else:
break
elif op == "del":
chart_num = int(argv[i+1])
report.del_chart(chart_num)
i += 2
continue
else:
print("Unknown parameter '%s'!" % argv[i])
return EC_SYNTAX
self._perf_api.report_update(report)
return 0
def run(self):
argv = self._argv
if len(argv) == 0:
return EC_SYNTAX
elif argv[0] == "help":
self.usage(sys.stdout)
return 0
elif argv[0] in ["get", "show"]:
try:
report_id = int(argv[1])
report = self._perf_api.report_get_by_id(report_id)
if report is None:
print("Report not found.")
return EC_NOTFOUND
else:
print(report)
except IndexError:
print("No ID specified!", file=sys.stderr)
return EC_SYNTAX
except ValueError:
print("ID needs to be an integer!", file=sys.stderr)
return EC_SYNTAX
elif argv[0] in ["create"]:
return self._do_create(argv)
elif argv[0] in ["update"]:
return self._do_update(argv)
elif argv[0] in ["delete"]:
try:
report_id = int(argv[1])
result = self._perf_api.report_delete_by_id(report_id)
if result:
print("Report deleted.")
else:
print("Report delete failed.")
return EC_DELETEFAILED
except IndexError:
print("No ID specified!", file=sys.stderr)
return EC_SYNTAX
except ValueError:
print("ID needs to be an integer!", file=sys.stderr)
return EC_SYNTAX
else:
print("Command '%s' not implemented for Reports." % argv[0], file=sys.stderr)
return EC_NOTIMPLEMENTED
return 0
def main():
"""
Main function
"""
cli_classes = {"report": ReportCLI,
"testexec": TestExecCLI,
"test": TestCLI}
obj = None
conf_file = None
url = None
username = None
password = None
i = 1
while obj is None and i < len(sys.argv):
if sys.argv[i] in cli_classes:
obj = sys.argv[i]
i += 1
elif sys.argv[i] in ["-u", "--url"]:
url = sys.argv[i+1]
i += 2
elif sys.argv[i] in ["-n", "--username"]:
username = sys.argv[i+1]
i += 2
elif sys.argv[i] in ["-p", "--password"]:
password = sys.argv[i+1]
i += 2
elif sys.argv[i] in ["-c", "--config"]:
conf_file = sys.argv[i+1]
i += 2
elif sys.argv[i] in ["-h", "--help", "help"]:
usage(0, sys.stdout)
else:
usage(EC_SYNTAX)
if obj is None:
usage(0, f=sys.stdout)
else:
config.opts_init()
usr_cfg = os.path.expanduser('~/.perfrepocli/perfrepo-cli.conf')
if os.path.isfile(usr_cfg):
config.load_config(usr_cfg)
if conf_file is not None and os.path.isfile(conf_file):
config.load_config(conf_file)
cli = cli_classes[obj](url, username, password, sys.argv[i:])
ret_val = cli.run()
if ret_val in [ EC_SYNTAX, EC_NOTIMPLEMENTED ]:
cli.usage()
return ret_val
return 0
if __name__ == "__main__":
sys.exit(main())