/
analytics_tests.py
4770 lines (4366 loc) · 211 KB
/
analytics_tests.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
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
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Need to import path to test/fixtures and test/scripts/
# Ex : export PYTHONPATH='$PATH:/root/test/fixtures/:/root/test/scripts/'
#
# To run tests, you can do 'python -m testtools.run tests'. To run specific tests,
# You can do 'python -m testtools.run -l tests'
# Set the env variable PARAMS_FILE to point to your ini file. Else it will try to pick params.ini in PWD
#
import fixtures
from tcutils.util import *
import logging as LOG
import re
import json
import urllib2
import requests
import time
import datetime
import threading
import Queue
from subprocess import Popen, PIPE
import shlex
import pprint
from netaddr import *
import random
from tcutils.collector.opserver_introspect_utils import VerificationOpsSrvIntrospect
from physical_router_fixture import PhysicalRouterFixture
from tcutils.contrail_status_check import ContrailStatusChecker
from tcutils.collector.opserver_util import OpServerUtils
months = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun':
6, 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}
months_number_to_name = {
'01': 'JAN', '02': 'FEB', '03': 'MAR', '04': 'APR', '05': 'MAY',
'06': 'JUN', '07': 'JUL', '08': 'AUG', '09': 'SEP', '10': 'OCT', '11': 'NOV', '12': 'DEC'}
uve_dict = {
'xmpp-peer/': ['state_info', 'peer_stats_info', 'event_info',
'send_state', 'identifier'],
'config-node/': ['module_cpu_info', 'module_id', 'cpu_info',
'build_info', 'config_node_ip', 'process_info'],
'control-node/': ['uptime', 'build_info', 'cpu_info', 'ifmap_info', 'process_info'],
'analytics-node/': ['cpu_info', 'ModuleCpuState', 'module_cpu_info',
'process_info', 'contrail-collector', 'contrail-query-engine',
'contrail-analytics-nodemgr', 'contrail-analytics-api', 'build_info',
'generator_infos'],
'generator/': ['client_info', 'ModuleServerState', 'session_stats', 'generator_info'],
'bgp-peer/': ['state_info', 'peer_stats_info', 'families', 'peer_type', 'local_asn',
'configured_families', 'event_info', 'peer_address', 'peer_asn', 'send_state'],
'vrouter/': ['exception_packets', 'cpu_info', 'uptime',
'total_flows', 'drop_stats', 'xmpp_stats_list',
'vhost_stats', 'process_info',
'control_ip', 'dns_servers',
'build_info', 'vhost_cfg',
'tunnel_type', 'xmpp_peer_list',
'self_ip_list','process_status',
'exception_packets','drop_stats',
'phy_if_stats_list',
'vhost_stats'],
'dns-node/': ['start_time', 'build_info', 'self_ip_list'],
'virtual-machine/': [
'interface_list',
'vm_name',
'uuid']}
uve_list = ['xmpp-peer/', 'config-node/', 'control-node/','virtual-machine/',
'analytics-node/', 'generator/', 'bgp-peer/', 'dns-node/', 'vrouter/']
exceptions={'device_manager':'contrail-device-manager',
'schema':'contrail-schema',
'svc-monitor':'contrail-svc-monitor'
}
exceptions_flags = {'device_manager':False,
'schema' : False,
'svc-monitor':False
}
http_introspect_ports = {'HttpPortConfigNodemgr' : 8100,
'HttpPortControlNodemgr' : 8101,
'HttpPortVRouterNodemgr' : 8102,
'HttpPortDatabaseNodemgr' : 8103,
'HttpPortAnalyticsNodemgr' : 8104,
'HttpPortStorageStatsmgr' : 8105,
'HttpPortControl' : 8083,
'HttpPortApiServer' : 8084,
'HttpPortAgent' : 8085,
'HttpPortSchemaTransformer' : 8087,
'HttpPortSvcMonitor' : 8088,
'HttpPortCollector' : 8089,
'HttpPortOpserver' : 8090,
'HttpPortQueryEngine' : 8091,
'HttpPortDns' : 8092}
GENERATORS = {'Compute' : ['contrail-vrouter-agent',
'contrail-vrouter-nodemgr'
],
'Analytics' : [
'contrail-query-engine',
'contrail-analytics-nodemgr',
'contrail-collector',
'contrail-analytics-api'
],
'Database' : ['contrail-database-nodemgr'],
'Config' : ['contrail-api',
'contrail-svc-monitor',
'contrail-config-nodemgr',
'contrail-schema',
'contrail-device-manager'],
'Control' : ['contrail-control',
'contrail-control-nodemgr',
'contrail-dns'
]
}
class AnalyticsVerification(fixtures.Fixture):
def __init__(self, inputs, cn_inspect, agent_inspect, ops_inspect, logger=LOG):
self.inputs = inputs
self.ops_inspect = ops_inspect
self.agent_inspect = agent_inspect
self.cn_inspect = cn_inspect
self.logger = logger
self.get_all_generators()
self.uve_verification_flags = []
def get_all_generators(self):
self.generator_hosts = []
self.bgp_hosts = []
self.compute_hosts = []
self.collector_hosts = []
for collector_ip in self.inputs.collector_ips:
c_host = self.inputs.host_data[collector_ip]['name']
self.collector_hosts.append(c_host)
if (c_host not in self.generator_hosts):
self.generator_hosts.append(c_host)
for ip in self.inputs.bgp_ips:
bgp_host = self.inputs.host_data[ip]['name']
self.bgp_hosts.append(bgp_host)
if (bgp_host not in self.generator_hosts):
self.generator_hosts.append(bgp_host)
for ip in self.inputs.compute_ips:
compute_host = self.inputs.host_data[ip]['name']
self.compute_hosts.append(compute_host)
if (compute_host not in self.generator_hosts):
self.generator_hosts.append(compute_host)
def get_connection_status(self, collector, generator, moduleid, node_type, instanceid='0'):
'''Getting connection status with generator:node_type:moduleid:instanceid with collector
'''
connobj = self.get_connection_dict(
collector, generator, moduleid, node_type, instanceid)
if connobj:
return connobj['status']
else:
return None
def get_primary_collector(self, opserver, generator, moduleid, node_type, instanceid='0'):
'''Get primary collector for a generator'''
connobj = self.get_connection_dict(
opserver, generator, moduleid, node_type, instanceid)
if connobj:
return connobj['primary']
else:
return None
def get_secondary_collector(self, opserver, generator, moduleid, node_type, instanceid='0'):
'''Get secondary collector for a generator'''
connobj = self.get_connection_dict(
opserver, generator, moduleid, node_type, instanceid)
if connobj:
return connobj['secondary']
else:
return None
@retry_for_value(delay=2, tries=5)
def get_ops_generator_from_ops_introspect(self, collector, generator, moduleid, node_type, instanceid):
obj = self.ops_inspect[collector].get_ops_generator(
generator=generator, moduleid=moduleid, node_type=node_type, instanceid=instanceid)
if not obj:
self.logger.warn("ops generator uve analytics/uves/generator/%s:%s:%s?flat not returned" %
(generator, node_type, moduleid))
return obj
def get_connection_dict(self, collector, generator, moduleid, node_type, instanceid):
'''Getting connection dict with generator:moduleid with collector
'''
self.opsobj = self.get_ops_generator_from_ops_introspect(collector, generator, moduleid, node_type, instanceid)
if not self.opsobj:
self.logger.error("query returned none")
return None
self.conoutput = self.opsobj.get_attr('Client', 'client_info')
if not self.conoutput:
self.logger.debug("query returned none")
return None
return self.conoutput
def verify_generator_connection_to_collector(self):
'''Verify the collector connection with different modules'''
for k,v in GENERATORS.items():
if (k == 'Compute'):
for name in self.inputs.compute_names:
for elem in v:
assert self.verify_connection_status(
name,elem,k)
if (k == 'Analytics'):
for name in self.inputs.collector_names:
for elem in v:
assert self.verify_connection_status(
name,elem,k)
if (k == 'Database'):
for name in self.inputs.database_names:
for elem in v:
assert self.verify_connection_status(
name,elem,k)
if (k == 'Config'):
for name in self.inputs.cfgm_names:
result = False
for elem in v:
result = result or self.verify_connection_status(
name,elem,k)
assert result
if (k == 'Control'):
for name in self.inputs.bgp_names:
for elem in v:
assert self.verify_connection_status(
name,elem,k)
@retry(delay=5, tries=4)
def verify_connection_status(self, generator, moduleid, node_type, instanceid='0'):
'''Verify if connection status with collector and generator:node_type:moduleid:instance
is established
'''
self.g = generator
self.m = moduleid
result = True
for collector_ip in self.inputs.collector_ips:
self.logger.debug("Verifying through opserver in %s" %
(collector_ip))
status = self.get_connection_status(
collector_ip, self.g, self.m, node_type, instanceid)
if (status == 'Established'):
self.logger.info("Validated that %s:%s:%s:%s is connected to \
collector %s" %(self.g, node_type, self.m, instanceid,
collector_ip))
result = result & True
else:
self.logger.warn(
"%s:%s:%s:%s is NOT connected to collector %s" %
(self.g, node_type, self.m, instanceid, collector_ip))
result = result & False
return result
def get_collector_of_gen(self, collector, gen, module, node_type, instance='0'):
'''Gets the collector node of a generator
'''
connobj = self.get_connection_dict(
collector, gen, module, node_type, instance)
return connobj['collector_name']
def get_all_generator_links(self, module=None):
'''Get all links for a particular generator'''
ret = []
try:
links = self.ops_inspect[self.inputs.collector_ips[
0]].get_hrefs_to_all_UVEs_of_a_given_UVE_type(uveType='generators')
if links:
pattern = '%s(.*)' % module
compiled = re.compile(pattern)
for elem in links:
if compiled.search(str(elem)):
ret.append(elem)
except Exception as e:
self.logger.warn("Got exception as %s" % (e))
finally:
return ret
def get_module_instances(self, module):
'''Return the module instances from analytics/genarators url'''
ret = []
try:
links = self.get_all_generator_links(module=module)
if links:
for elem in links:
inst = str(elem['name']).split(":")[-1]
ret.append(inst)
except Exception as e:
self.logger.warn("Got exception as %s" % (e))
finally:
return ret
def get_uve_key(self, uve=None):
'''{
href: "http://10.204.216.14:8081/analytics/uves/virtual-machine/292c7779-c085-4079-91f6-440272bd2922?flat",
name: "292c7779-c085-4079-91f6-440272bd2922"
}'''
ret = []
try:
links = self.ops_inspect[self.inputs.collector_ips[0]
].get_hrefs_to_all_UVEs_of_a_given_UVE_type(uveType=uve)
if links:
for elem in links:
ret.append(elem['name'])
except Exception as e:
self.logger.warn("Got exception as %s" % (e))
finally:
return ret
# Collector uve functions#
# ------------------------#
# @retry(delay=5, tries=1)
def verify_collector_uve(self):
'''Verify that all generators are connected to collector'''
result = True
# Verify module-ids correctly shown in the collector uve for respective generators
# verify module-id for bgp node in collector uve - should be
# 'Contrail-Control'
for ip in self.inputs.bgp_ips:
assert self.verify_collector_connection_introspect(ip,http_introspect_ports['HttpPortControl'])
for ip in self.inputs.cfgm_ips:
assert self.verify_collector_connection_introspect(ip,http_introspect_ports['HttpPortApiServer'])
result = False
for ip in self.inputs.cfgm_ips:
if not self.verify_collector_connection_introspect(ip,http_introspect_ports['HttpPortSchemaTransformer']):
continue
else:
result = result or self.verify_collector_connection_introspect(ip,http_introspect_ports['HttpPortSchemaTransformer'])
assert result
for ip in self.inputs.cfgm_ips:
result = result or self.verify_collector_connection_introspect(ip,http_introspect_ports['HttpPortSvcMonitor'])
assert result
for ip in self.inputs.collector_ips:
assert self.verify_collector_connection_introspect(ip,http_introspect_ports['HttpPortOpserver'])
for ip in self.inputs.collector_ips:
assert self.verify_collector_connection_introspect(ip,http_introspect_ports['HttpPortQueryEngine'])
for ip in self.inputs.collector_ips:
self.logger.debug("Verifying through opserver in %s" % (ip))
expected_module_id = ['contrail-control', 'contrail-dns']
expected_node_type = 'Control'
expected_instance_id = '0'
for bgp_host in self.bgp_hosts:
for module in expected_module_id:
is_established = self.verify_connection_status(
bgp_host, module, expected_node_type, expected_instance_id)
# collector=self.output['collector_name']
if is_established:
#self.logger.info("%s:%s connected to collector %s"%(bgp_host,module,collector))
result = result and True
else:
result = result and False
expected_module_id = 'contrail-vrouter-agent'
expected_node_type = 'Compute'
expected_instance_id = '0'
for compute_host in self.compute_hosts:
is_established = self.verify_connection_status(
compute_host, expected_module_id, expected_node_type, expected_instance_id)
# collector=self.output['collector_name']
if is_established:
result = result and True
else:
result = result and False
# Verifying module_id from ApiServer
expected_cfgm_modules = 'contrail-schema'
expected_node_type = 'Config'
expected_instance_id = '0'
for cfgm_node in self.inputs.cfgm_names:
result1 = True
is_established = self.verify_connection_status(
cfgm_node, expected_cfgm_modules, expected_node_type, expected_instance_id)
if is_established:
# collector=self.output['collector_name']
result1 = result1 and True
break
else:
result1 = result1 and False
result = result and result1
#Verifying for ServiceMonitor
expected_cfgm_modules = 'contrail-svc-monitor'
expected_node_type = 'Config'
expected_instance_id = '0'
for cfgm_node in self.inputs.cfgm_names:
result1 = True
is_established = self.verify_connection_status(
cfgm_node, expected_cfgm_modules, expected_node_type, expected_instance_id)
if is_established:
# collector=self.output['collector_name']
resulti1 = result1 and True
break
else:
result1 = result1 and False
result = result and result1
# Verifying module_id ApiServer
expected_apiserver_module = 'Contrail-Api'
expected_apiserver_instances = self.get_module_instances(
expected_apiserver_module)
expected_node_type = 'Config'
# expected_cfgm_modules=['Contrail-Schema','contrail-svc-monitor']
for cfgm_node in self.inputs.cfgm_names:
for inst in expected_apiserver_instances:
result1 = True
is_established = self.verify_connection_status(
cfgm_node, expected_apiserver_module, expected_node_type, inst)
if is_established:
result1 = result1 and True
break
else:
result = result and False
result = result1 and result
# Verifying module_id Contrail-Analytics-Api
expected_opserver_module = 'Contrail-Analytics-Api'
expected_opserver_instances = self.get_module_instances(
expected_opserver_module)
expected_node_type = 'Analytics'
for c_host in self.collector_hosts:
for inst in expected_opserver_instances:
is_established = self.verify_connection_status(
c_host, expected_opserver_module, expected_node_type, inst)
if is_established:
# collector=self.output['collector_name']
result = result and True
else:
result = result and False
# Verifying collector:moduleid
expected_collector_module = ['contrail-collector', 'contrail-query-engine']
expected_node_type = 'Analytics'
expected_instance_id = '0'
for c_host in self.collector_hosts:
for module in expected_collector_module:
is_established = self.verify_connection_status(
c_host, module, expected_node_type, expected_instance_id)
# collector=self.output['collector_name']
if is_established:
result = result and True
else:
result = result and False
return result
@retry(delay=3, tries=15)
def verify_hrefs_to_all_uves_of_a_given_uve_type(self):
'''Verify all analytics links
'''
result = True
for ip in self.inputs.collector_ips:
self.logger.debug(
"Verifying the bgp-routers links through opserver %s" % (ip))
self.links = self.ops_inspect[
ip].get_hrefs_to_all_UVEs_of_a_given_UVE_type(uveType='control-nodes')
gen_list = []
for elem in self.links:
name = elem.get_attr('Name')
gen_list.append(name)
missing_nodes = set(gen_list) ^ set(self.inputs.bgp_names)
if not missing_nodes:
self.logger.info("%s is present in the link" %
(self.inputs.bgp_names))
result = result and True
else:
self.logger.info(
"%s is not present in the in the bgp-routers" %
(missing_nodes))
result = result and False
self.logger.info(
"Verifying the vrouters links through opserver %s" % (ip))
self.links = self.ops_inspect[
ip].get_hrefs_to_all_UVEs_of_a_given_UVE_type(uveType='vrouters')
gen_list = []
for elem in self.links:
name = elem.get_attr('Name')
gen_list.append(name)
for name in self.inputs.compute_names:
if (name in gen_list):
self.logger.info("%s is present in the link" % (name))
result = result and True
else:
self.logger.info(
"%s is not present in the in the vrouters" % (name))
result = result and False
self.logger.info(
"Verifying the collector links through opserver %s" % (ip))
self.links = self.ops_inspect[
ip].get_hrefs_to_all_UVEs_of_a_given_UVE_type(uveType='analytics-nodes')
gen_list = []
for elem in self.links:
name = elem.get_attr('Name')
gen_list.append(name)
missing_nodes = set(gen_list) ^ set(self.inputs.collector_names)
if not missing_nodes:
self.logger.info("%s is present in the link" %
(self.inputs.collector_names))
result = result and True
else:
self.logger.info(
"%s is not present in the in the bgp-routers" %
(missing_nodes))
result = result and False
self.logger.info(
"Verifying the collector links through opserver %s" % (ip))
self.links = self.ops_inspect[
ip].get_hrefs_to_all_UVEs_of_a_given_UVE_type(uveType='config-nodes')
gen_list = []
for elem in self.links:
name = elem.get_attr('Name')
gen_list.append(name)
missing_nodes = set(gen_list) ^ set(self.inputs.cfgm_names)
if not missing_nodes:
self.logger.info("%s is present in the link" %
(self.inputs.cfgm_names))
result = result and True
else:
self.logger.info(
"%s is not present in the in the bgp-routers" %
(missing_nodes))
result = result and False
return result
# end collector uve functions
# vrouter uve functions
# ------------------------#
# Vrouter xmpp connection verification
@retry(delay=3, tries=15)
def verify_vrouter_xmpp_connections(self):
'''Verify that vrouter is connected to the bgp router'''
result = False
for compute_host in self.compute_hosts:
peers = []
collector = self.get_collector_of_gen(
self.inputs.collector_ips[0], compute_host, 'contrail-vrouter-agent', 'Compute')
collector_ip = self.inputs.host_data[collector]['host_ip']
self.ops_compute_obj = self.ops_inspect[
collector_ip].get_ops_vrouter(vrouter=compute_host)
xmpp_peer_list = self.ops_compute_obj.get_attr(
'Agent', 'xmpp_peer_list')
for elem in xmpp_peer_list:
ip = elem['ip']
peers.append(ip)
factor = 1
if len(self.inputs.bgp_control_ips)>1:
factor = 2 # Xmpp client connects to 2 servers at most when more are available
missing_peers = set(self.inputs.bgp_control_ips) - set(peers)
if not len(missing_peers) > len(self.inputs.bgp_control_ips) - factor:
self.logger.info(
"Vrouter %s connected to %s xmpp peers out of %s" %
(compute_host, set(peers), set(self.inputs.bgp_control_ips)))
self.logger.info(
"xmpp peer correctly displayed as %s for vrouter %s " %
(peers, compute_host))
result = True
else:
self.logger.error("vrouter %s not connected to 2 xmpp peers, should connect to at least one more from %s" %
(compute_host, missing_peers))
return False
return result
@retry(delay=3, tries=15)
def verify_vm_list_not_in_vrouter_uve(self, vm_uuid=None, vrouter='localhost', tap=None):
'''Verifies that vm not in the vrouter uve if the vm is deleted'''
result = True
result1 = True
result2 = True
if not vm_uuid:
self.logger.warn("vm_uuid not resceived")
return False
collector = self.get_collector_of_gen(
self.inputs.collector_ips[0], vrouter, 'contrail-vrouter-agent', 'Compute')
collector_ip=self.inputs.get_host_ip(name=collector)
self.vrouter_ops_obj = self.ops_inspect[
collector_ip].get_ops_vrouter(vrouter=vrouter)
# Verifying vm in vrouter uve
vrouter_ops_vms = self.vrouter_ops_obj.get_attr(
'Agent', 'virtual_machine_list', match=vm_uuid)
if not vrouter_ops_vms:
result = result and True
self.logger.debug("VM %s is not present in vrouter %s uve " %
(vm_uuid, vrouter))
else:
result = result and False
self.logger.debug("VM %s is still present in vrouter %s uve " %
(vm_uuid, vrouter))
self.logger.debug(
"Verifying if the vm interface deleted from vroter uve...")
vm_interface_list = self.vrouter_ops_obj.get_attr(
'Agent', 'interface_list')
if vm_interface_list:
for elem in vm_interface_list:
if re.search(vm_uuid, elem):
self.logger.warn(
"%s interface NOT yet deleted from vrouter uve ..." % (elem))
result1 = result1 and False
else:
result1 = result1 and True
else:
self.logger.debug(
"interface for vm %s deleted from vrouter uve ..." %
(vm_uuid))
result1 = result1 and True
if result1:
self.logger.debug(
"interface for vm %s deleted from vrouter uve ..." %
(vm_uuid))
result = result and True
# Verify that deleted interface not in error interface list
error_interface_list = self.vrouter_ops_obj.get_attr(
'Agent', 'error_intf_list')
if error_interface_list:
for elem in error_interface_list:
if (re.search(vm_uuid, elem)):
self.logger.warn(
"%s deleted interface in error interface list ..." % (elem))
result2 = result2 and False
else:
self.logger.debug(
"Deleted interface not in error interface list ...")
result2 = result2 and True
return result and result1 and result2
@retry(delay=3, tries=15)
def verify_vm_list_in_vrouter_uve(self, vm_uuid=None, vn_fq_name=None, vrouter='localhost', tap=None):
'''Verify that vm exists in the vrouter
,also verifies that network, in which vm is connected , gets downloaded in vrouter and tap interface of the vm is created'''
result = False
result1 = False
if not vm_uuid:
self.logger.debug("vm_uuid not resceived")
return False
collector = self.get_collector_of_gen(
self.inputs.collector_ips[0], vrouter, 'contrail-vrouter-agent', 'Compute')
collector_ip=self.inputs.get_host_ip(name=collector)
self.vrouter_ops_obj = self.ops_inspect[
collector_ip].get_ops_vrouter(vrouter=vrouter)
# Verifying vm in vrouter uve
vrouter_ops_vms = self.vrouter_ops_obj.get_attr(
'Agent', 'virtual_machine_list', match=vm_uuid)
if not vrouter_ops_vms:
result = False
self.logger.error("VM %s is not present in vrouter %s uve " %
(vm_uuid, vrouter))
else:
result = True
self.logger.debug("VM %s is present in vrouter %s uve " %
(vm_uuid, vrouter))
# Verifying tap interfaces in vrouter uve
if tap:
# disabling for the time beeing.Vrouter tap interface name is
# chenaged..
result = True
vm_tap_intf = self.vrouter_ops_obj.get_attr(
'Agent', 'interface_list', match=tap)
if not vm_tap_intf:
result1 = False
self.logger.debug(
"Tap interface %s of vm %s is not present in vrouter %s uve " %
(tap, vm_uuid, vrouter))
else:
result1 = True
self.logger.info(
"tap interface %s of vm %s is present in vrouter %s uve " %
(tap, vm_uuid, vrouter))
else:
result1 = True
# Verify if network created
if vn_fq_name:
result2 = False
uve_vn = self.vrouter_ops_obj.get_attr(
'Agent', 'connected_networks', match=vn_fq_name)
if not uve_vn:
result2 = False
self.logger.error(
"Connected network %s of vm %s is not present in vrouter %s uve " %
(vn_fq_name, vm_uuid, vrouter))
else:
result2 = True
self.logger.debug(
"Connected network %s of vm %s is present in vrouter %s uve " %
(vn_fq_name, vm_uuid, vrouter))
else:
result2 = True
return (result and result1 and result2)
# return (result and result2)
def get_flows_vrouter_uve(self, vrouter='localhost', flowType='active_flows'):
'''flowType=active_flows,aged_flows,total_flows'''
collector = self.get_collector_of_gen(
self.inputs.collector_ips[0], vrouter, 'contrail-vrouter-agent', 'Compute')
collector_ip = self.inputs.host_data[collector]['host_ip']
self.vrouter_ops_obj = self.ops_inspect[
collector_ip].get_ops_vrouter(vrouter=vrouter)
return self.vrouter_ops_obj.get_attr('Stats', 'flow_rate')['active_flows']
def get_vrouter_mem_stats(self):
'''compute uve o/p: {u'nodef1': {u'sys_mem_info':
{u'total': 197934164, u'used': 4815188, u'free': 193118976,
u'buffers': 155812}, u'num_cpu': 32, u'cpu_share': 0.171875,
u'meminfo': {u'virt': 2462240, u'peakvirt': 2525360,
u'res': 109032},
u'cpuload': {u'fifteen_min_avg': 0.05, u'five_min_avg': 0.03,
u'one_min_avg': 0.06}}}
return u'virt' as dict with node_name as key
'''
all_vr_mem_stats = {}
for compute_host in self.compute_hosts:
collector = self.get_collector_of_gen(
self.inputs.collector_ips[0], compute_host, 'contrail-vrouter-agent', 'Compute')
collector_ip = self.inputs.host_data[collector]['host_ip']
self.vrouter_ops_obj = self.ops_inspect[
collector_ip].get_ops_vrouter(vrouter=compute_host)
if self.vrouter_ops_obj:
out = self.vrouter_ops_obj.get_attr('Stats', 'cpu_info')
else:
return all_vr_mem_stats
all_vr_mem_stats[compute_host] = out['meminfo']['virt']
return all_vr_mem_stats
def get_vrouter_drop_stats(self):
'''Get data from vrouter uve drop_stats data..
sample: drop_stats: {ds_flow_no_memory: 0,ds_flow_queue_limit_exceeded: 55426,...}
'''
all_vr_drop_stats = {}
for compute_host in self.compute_hosts:
collector = self.get_collector_of_gen(
self.inputs.collector_ips[0], compute_host, 'contrail-vrouter-agent', 'Compute')
collector_ip = self.inputs.host_data[collector]['host_ip']
self.vrouter_ops_obj = self.ops_inspect[
collector_ip].get_ops_vrouter(vrouter=compute_host)
out = self.vrouter_ops_obj.get_attr('Stats', 'drop_stats')
all_vr_drop_stats[compute_host] = out
return all_vr_drop_stats
def get_agent_introspect_agentstatsreq(self, agent_ip=None):
inspect_h = self.agent_inspect[agent_ip]
return inspect_h.get_vna_pkt_agentstatsreq()
def get_agent_introspect_fetchallflowrecords(self, agent_ip=None):
inspect_h = self.agent_inspect[agent_ip]
return inspect_h.get_vna_fetchallflowrecords()
# self.records=inspect_h.get_vna_fetchallflowrecords()
def get_agent_introspect_fetchflowrecords(self, agent_ip=None, vrf=None, sip=None, dip=None, sport=None, dport=None, protocol=None):
inspect_h = self.agent_inspect[agent_ip]
return inspect_h.get_vna_fetchflowrecord(vrf=vrf, sip=sip, dip=dip, sport=sport, dport=dport, protocol=protocol)
def get_agent_introspect_Kflowrecords(self, agent_ip=None):
#self.agent_inspect= self.connections.agent_inspect
inspect_h = self.agent_inspect[agent_ip]
return inspect_h.get_vna_kflowresp()
def get_vrouter_active_xmpp_peer(self, vrouter=None):
'''Gets the the active xmpp connection from vrouter uve
[{u'status': u'true', u'ip': u'10.204.216.14', u'setup_time':
u'2013-Jun-25 08:43:46.726649'}, {u'status': u'true',
u'ip': u'10.204.216.25', u'primary': u'true',
u'setup_time': u'2013-Jun-25 08:43:46.725917'}]
'''
collector = self.get_collector_of_gen(
self.inputs.collector_ips[0], vrouter, 'contrail-vrouter-agent', 'Compute')
collector_ip = self.inputs.host_data[collector]['host_ip']
self.vrouter_ops_obj = self.ops_inspect[
collector_ip].get_ops_vrouter(vrouter=vrouter)
# self.vrouter_ops_obj=self.ops_inspect.get_ops_vrouter(vrouter=vrouter)
if not self.vrouter_ops_obj:
self.logger.critical("%s vrouter uve returned none" % (vrouter))
return None
xmpp_peer_list = self.vrouter_ops_obj.get_attr(
'Agent', 'xmpp_peer_list', match=('primary', True))
if xmpp_peer_list:
return xmpp_peer_list[0]['ip']
else:
return None
@retry(delay=5, tries=12)
def verify_active_xmpp_peer_in_vrouter_uve(self):
'''Verify active vrouter uve for active xmpp connections
'''
result = True
for agent in self.inputs.compute_names:
# getting active xmpp peer from vrouter uve
act_xmpp_uve = self.get_vrouter_active_xmpp_peer(vrouter=agent)
self.logger.info("Active xmpp peer in %s vrouter uve is %s" %
(agent, act_xmpp_uve))
# self.inputs.host_data['nodea19']['host_ip']
agent_ip = self.inputs.host_data[agent]['host_ip']
inspect_h = self.agent_inspect[agent_ip]
xmpp_peer_from_agent_inspect = inspect_h.get_vna_xmpp_connection_status(
)
for elem in xmpp_peer_from_agent_inspect:
if (elem['cfg_controller'] == 'Yes'):
active_xmpp = elem['controller_ip']
self.logger.info(
"Active xmpp peer in %s agent introspect is %s" %
(agent, active_xmpp))
if (act_xmpp_uve == active_xmpp):
result = result & True
else:
return False
return result
def get_vrouter_interface_list(self, collector, vrouter):
'''Return the interface list from vrouter uve'''
self.vrouter_ops_obj = self.ops_inspect[
collector].get_ops_vrouter(vrouter=vrouter)
return self.vrouter_ops_obj.get_attr('Agent', 'interface_list')
# end vrouter uve functions
# virtual-network uve functions
# ------------------------#
def get_vn_uve(self, vn_fq_name):
'''This function returns entire vn uve.Need this to verify that vn uve does not exists if the vn is deleted'''
for ip in self.inputs.collector_ips:
self.opsobj = self.ops_inspect[ip]
ops_vn = self.opsobj.get_ops_vn(vn_fq_name=vn_fq_name)
if ops_vn:
return ops_vn
return None
def verify_vn_uve_tiers(self, vn_fq_name=None):
'''Verify that when vn is created , vn uve should show info from UveVirtualNetworkConfig and UveVirtualNetworkAgent'''
result = False
if not vn_fq_name:
vn_fq_name='default-domain:%s:default-virtual-network'%self.inputs.stack_tenant
for ip in self.inputs.collector_ips:
self.logger.debug("Verifying through opserver in %s" % (ip))
self.opsobj = self.ops_inspect[ip]
self.ops_vnoutput = self.opsobj.get_ops_vn(vn_fq_name=vn_fq_name)
if not self.ops_vnoutput:
self.logger.error("%s uve did not return any output " %
vn_fq_name)
return False
expected_tiers = ['UveVirtualNetworkAgent',
'UveVirtualNetworkConfig']
tiers = self.ops_vnoutput.keys()
missing_tier = set(expected_tiers) - set(tiers)
if not missing_tier:
self.logger.info(
"Tiers correctly shown in vn vue for %s in collector %s" % (vn_fq_name, ip))
result = True
else:
self.logger.error(
"uve message did not come from %s for %s in collector %s" %
(missing_tier, vn_fq_name, ip))
return False
return result
@retry(delay=5, tries=6)
def verify_vn_uve_ri(self, vn_fq_name=None, ri_name=None):
'''Verify routing instance element when vn is created by apiserver'''
result = True
if not vn_fq_name:
vn_fq_name='default-domain:%s:default-virtual-network'%self.inputs.stack_tenant
for ip in self.inputs.collector_ips:
self.logger.info("Verifying through opserver in %s" % (ip))
self.opsobj = self.ops_inspect[ip]
self.ops_vnoutput = self.opsobj.get_ops_vn(vn_fq_name=vn_fq_name)
if not self.ops_vnoutput:
self.logger.error("%s uve did not return any output" %
vn_fq_name)
return False
ri_list = self.ops_vnoutput.get_attr(
'Config', 'routing_instance_list')
if (ri_list == None):
self.logger.error(
"%s uve did not return any routing instance" % vn_fq_name)
return False
if not ri_name:
domain, use, vn_name = vn_fq_name.split(':')
else:
vn_name = ri_name
for elem in ri_list:
if vn_name in elem:
self.logger.info(
"routing instance %s correctly showed in vue for %s" % (vn_fq_name, vn_name))
return True
else:
self.logger.error("Routing instance not shown in %s uve" %
(vn_fq_name))
result = result and False
return result
@retry(delay=5, tries=6)
def verify_ri_not_in_vn_uve(self, vn_fq_name=None, ri_name=None):
'''Verify routing instance element when vn is created by apiserver'''
result = True
if not vn_fq_name:
vn_fq_name='default-domain:%s:default-virtual-network'%self.inputs.stack_tenant
for ip in self.inputs.collector_ips:
self.logger.info("Verifying through opserver in %s" % (ip))
self.opsobj = self.ops_inspect[ip]
self.ops_vnoutput = self.opsobj.get_ops_vn(vn_fq_name=vn_fq_name)
if not self.ops_vnoutput:
self.logger.error("%s uve did not return any output" %
vn_fq_name)
return False
ri_list = self.ops_vnoutput.get_attr(
'Config', 'routing_instance_list')
if (ri_list == None):
self.logger.info("%s uve did not return any routing instance" %
vn_fq_name)
return True
if not ri_name:
domain, use, vn_name = vn_fq_name.split(':')
else:
vn_name = ri_name
for elem in ri_list:
if vn_name in elem:
self.logger.error(
"routing instance %s correctly showed in vue for %s" % (vn_fq_name, vn_name))
return False
else:
self.logger.info("Routing instance not shown in %s uve" %
(vn_fq_name))
result = result and True
return result
@retry(delay=2, tries=30)
def verify_vn_uve_for_vm_not_in_vn(self, vn_fq_name=None, vm=None):
'''Verify vm not in vn uve'''
result = False
vm_intf_lst = []
if not vn_fq_name:
self.logger.debug("vn name not passed")
return False
if not vm:
self.logger.debug("vm list name passed")
return False
for ip in self.inputs.collector_ips:
self.logger.debug("Verifying through opserver in %s" % (ip))
self.opsobj = self.ops_inspect[ip]
self.ops_vnoutput = self.opsobj.get_ops_vn(vn_fq_name=vn_fq_name)
if not self.ops_vnoutput:
self.logger.warn("%s uve did not return any output" %
vn_fq_name)
return False
# Verifying vm list
vm_uuid_list = self.ops_vnoutput.get_attr(
'Agent', 'virtualmachine_list', match=vm)
if not vm_uuid_list:
self.logger.debug("%s BM not in %s uve " % (vm, vn_fq_name))
return True
else:
self.logger.warn("%s still in %s uve" %
(vm_uuid_list, vn_fq_name))
self.logger.error("%s vm still in %s uve" % (vm, vn_fq_name))
return False
# Verifying the vm interface deleted in the vn uve
vm_interface_list = self.ops_vnoutput.get_attr(
'Agent', 'interface_list')
if vm_interface_list:
for elem in vm_interface_list:
if (re.search(vm, elem)):
self.logger.info("%s vm interface not in %s uve " %
(vm, vn_fq_name))
result = result and True
else:
self.logger.error("%s interface still in %s uve" %
(elem, vn_fq_name))
result = result and False
else:
self.logger.info("%s vm interface not in %s uve " %
(vm, vn_fq_name))
result = result and True
return result
@retry(delay=5, tries=10)
def verify_vn_uve_for_vm(self, vn_fq_name=None, vm=None):
'''Verify vm in vn uve'''
result = False
vm_intf_lst = []
if not vn_fq_name:
self.logger.debug("vn name not passed")
return False
if not vm:
self.logger.info("vm list name passed")
return False
for ip in self.inputs.collector_ips:
self.logger.info("Verifying through opserver in %s" % (ip))
self.opsobj = self.ops_inspect[ip]
self.ops_vnoutput = self.opsobj.get_ops_vn(vn_fq_name=vn_fq_name)
if not self.ops_vnoutput:
self.logger.error("%s uve did not return any output" %
vn_fq_name)