コード例 #1
0
ファイル: __init__.py プロジェクト: periscope-ps/periscope
 def test_register_metadata(self):
     # TODO more testing is needed
     results = open(self.PATH + 'hls_snmp.xml').read()
     results_set = ResultSet.parse_result(results)
     services = parse_lookup_service_result(results_set)
     
     self.assertEqual(len(services), 2)
     self.assertEqual(len(services[0]['data']), 8)
     self.assertEqual(len(services[1]['data']), 5)
     
     for psservice in services:
         serviceType = psservice['service'].serviceType
         serviceName = psservice['service'].serviceName
         accessPoint = psservice['service'].accessPoint
         serviceDescription = psservice['service'].serviceDescription
         
         service = create_psservice(serviceName,
                 accessPoint,
                 serviceType,
                 serviceDescription,
                 psservice['event_types'])
         
         for data in psservice['data']:
             obj = register_metadata(service, data.data)
             # check if all data elements were registered
             watch = psServiceWatchList.objects.filter(service=service, network_object=obj)
             self.assertTrue(watch.count() > 0)
コード例 #2
0
ファイル: __init__.py プロジェクト: periscope-ps/periscope
 def test_register_snmp_meta(self):
     # Create SNMP Metadata objects
     util_params = {'supportedEventType': [events.NET_UTILIZATION, events.SNMP]}
     err_params = {'supportedEventType': [events.NET_ERROR, events.SNMP]}
     disc_params = {'supportedEventType': [events.NET_DISCARD, events.SNMP]}
     
     # Create interfaces
     interfaces = []
     for i in range(4):
         interface = Interface(hostName='testhostname',
             ifName='testinterface%d' % i,
             capacity=1000000,
             direction='in')
         interfaces.append(interface)
     
     interfaces[1].direction = 'out'
     
     # Different SNMP subject types
     netutil_subject1 = NetUtilSubject(interface=interfaces[0])
     netutil_subject2 = NetUtilSubject(interface=interfaces[1])
     neterr_subject = NetErrorSubject(interface=interfaces[2])
     netdisc_subject = NetDiscardSubject(interface=interfaces[3])
     
     util_meta1 = Metadata(subject=netutil_subject1,
                     event_types=[events.NET_UTILIZATION, events.SNMP],
                     parameters=util_params)
     
     util_meta2 = Metadata(subject=netutil_subject2,
                     event_types=[events.NET_UTILIZATION, events.SNMP],
                     parameters=util_params)
     
     err_meta = Metadata(subject=neterr_subject,
                     event_types=[events.NET_ERROR, events.SNMP],
                     parameters=err_params)
     
     disc_meta = Metadata(subject=netdisc_subject,
                     event_types=[events.NET_DISCARD, events.SNMP],
                     parameters=disc_params)
     
     serviceType = 'MA'
     serviceName = 'testservice'
     accessPoint = 'http://example.com:9999/services/snmp'
     serviceDescription = 'test description'
             
     service = create_psservice(serviceName,
             accessPoint,
             serviceType,
             serviceDescription,
             [events.SNMP, events.NET_UTILIZATION, events.NET_ERROR, events.NET_DISCARD])
     
     # register the meta data
     util_port1 = register_snmp_meta(service, util_meta1)
     util_port2 = register_snmp_meta(service, util_meta2)
     err_port = register_snmp_meta(service, err_meta)
     disc_port = register_snmp_meta(service, disc_meta)
     
     # Assert all ports belong to the same Node
     self.assertEqual(util_port1.parent, util_port2.parent)
     self.assertEqual(util_port1.parent, err_port.parent)
     self.assertEqual(util_port1.parent, disc_port.parent)
     
     
     # Assert correct SNMP event types have been added
     self.assertIsNotNone(psServiceWatchList.objects.get(
                 service=service,
                 network_object=util_port1,
                 event_type__value=events.NET_UTILIZATION_RECV
     ))
     
     self.assertIsNotNone(psServiceWatchList.objects.get(
                 service=service,
                 network_object=util_port2,
                 event_type__value=events.NET_UTILIZATION_SENT
     ))