def setUpClass(cls):
        if (os.getenv('LD_LIBRARY_PATH', '').find('build/lib') < 0):
            if (os.getenv('DYLD_LIBRARY_PATH', '').find('build/lib') < 0):
                assert(False)

        cls.cassandra_port = AnalyticsFixture.get_free_port()
        mockcassandra.start_cassandra(cls.cassandra_port)
        cls.redis_port = AnalyticsFixture.get_free_port()
        mockredis.start_redis(cls.redis_port)
Example #2
0
    def test_07_table_source_module_list(self):
        '''
        This test verifies /analytics/table/<table>/column-values/Source
        and /analytics/table/<table>/column-values/ModuleId
        '''
        logging.info('%%% test_07_table_source_module_list %%%')
        if AnalyticsTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir, -1,
                             self.__class__.cassandra_port, 
                             collector_ha_test=True))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_collector_obj_count()
        exp_genlist1 = ['contrail-collector', 'contrail-analytics-api',
                        'contrail-query-engine']
        assert vizd_obj.verify_generator_list(vizd_obj.collectors[0], 
                                              exp_genlist1)
        exp_genlist2 = ['contrail-collector'] 
        assert vizd_obj.verify_generator_list(vizd_obj.collectors[1], 
                                              exp_genlist2)
        exp_src_list = [col.hostname for col in vizd_obj.collectors]
        exp_mod_list = exp_genlist1 
        assert vizd_obj.verify_table_source_module_list(exp_src_list, 
                                                        exp_mod_list)
        # stop the second redis_uve instance and verify the src/module list
        vizd_obj.redis_uves[1].stop()
        exp_src_list = [vizd_obj.collectors[0].hostname]
        exp_mod_list = exp_genlist1
        assert vizd_obj.verify_table_source_module_list(exp_src_list, 
                                                        exp_mod_list)
Example #3
0
 def test_05_fieldname_query(self):
     '''
     This test starts redis,vizd,opserver and qed
     It uses the test class' cassandra instance
     It then queries the stats table for messagetypes
     and objecttypes
     '''
     logging.info("%%% test_05_fieldname_query %%%")
     start_time = UTCTimestampUsec() - 3600 * 1000 * 1000
     self._update_analytics_start_time(start_time)
     vizd_obj = self.useFixture(
         AnalyticsFixture(logging, builddir,
                          self.__class__.redis_port,
                          self.__class__.cassandra_port))
     assert vizd_obj.verify_on_setup()
     assert vizd_obj.verify_collector_obj_count()
     collectors = [vizd_obj.get_collector()]
     generator_obj = self.useFixture(
         GeneratorFixture("VRouterAgent", collectors,
                          logging, vizd_obj.get_opserver_port()))
     assert generator_obj.verify_on_setup()
     # Sends 2 different vn uves in 1 sec spacing
     generator_obj.generate_intervn()
     assert vizd_obj.verify_fieldname_messagetype()
     assert vizd_obj.verify_fieldname_table()
     return True
 def test_04_session_query(self):
     '''
     This test starts redis, vizd, opserver and qed
     It uses the test class' cassandra instance
     Then it sends session stats to the collector
     and checks if session stats can be accessed from QE
     '''
     logging.info("%%% test_04_session_query  %%%")
     if AnalyticsTest._check_skip_test() is True:
         return True
     vizd_obj = self.useFixture(
         AnalyticsFixture(logging, builddir, self.__class__.cassandra_port))
     assert vizd_obj.verify_on_setup()
     assert vizd_obj.verify_collector_obj_count()
     # set the start time in analytics db 1 hour earlier than
     # the current time. For flow series test, we need to create
     # flow samples older than the current time.
     start_time = UTCTimestampUsec() - 3600 * 1000 * 1000
     self._update_analytics_start_time(start_time)
     collectors = [vizd_obj.get_collector()]
     generator_obj = self.useFixture(
         GeneratorFixture("contrail-vrouter-agent", collectors, logging,
                          vizd_obj.get_opserver_port(), start_time))
     assert generator_obj.verify_on_setup()
     generator_obj.generate_session_samples()
     assert vizd_obj.verify_session_samples(generator_obj)
     assert vizd_obj.verify_session_table(generator_obj)
     assert vizd_obj.verify_session_series_aggregation_binning(
         generator_obj)
     return True
    def test_08_verify_database_purge_support_deltatime_format_with_redis_password(
            self):
        '''
        This test starts redis,vizd,opserver and qed
        It uses the test class' cassandra instance
        and checks if database purge functonality is
        is working properly
        '''
        logging.info("%%% test_08_database_purge_query %%%")
        if AnalyticsDbTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging,
                             builddir,
                             self.__class__.cassandra_port,
                             cassandra_user='******',
                             cassandra_password='******',
                             redis_password='******'))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_collector_obj_count()
        assert vizd_obj.verify_generator_collector_connection(
            vizd_obj.opserver.http_port)
        assert vizd_obj.verify_database_purge_support_deltatime_format()
        return True
    def test_06_alarmgen_basic(self):
        '''
        This test starts the analytics processes.
        It enables partition 0 on alarmgen, and confirms
        that it got enabled
        '''
        logging.info("*** test_06_alarmgen_basic ***")
        if AnalyticsUveTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging,
                             builddir,
                             self.__class__.redis_port,
                             0,
                             kafka_zk=self.__class__.zk_port))
        assert vizd_obj.verify_on_setup()

        assert (vizd_obj.set_alarmgen_partition(0, 1) == 'true')
        assert (vizd_obj.verify_alarmgen_partition(0, 'true'))
        assert (vizd_obj.set_alarmgen_partition(1, 1) == 'true')
        assert (vizd_obj.set_alarmgen_partition(2, 1) == 'true')
        assert (vizd_obj.set_alarmgen_partition(3, 1) == 'true')
        assert (vizd_obj.verify_uvetable_alarm(
            "ObjectCollectorInfo",
            "ObjectCollectorInfo:" + socket.gethostname(), "ProcessStatus"))
        return True
Example #7
0
    def test_ipfix(self):
        '''
        This test starts redis, vizd, opserver and qed
        It uses the test class' cassandra instance
        Then it feeds IPFIX packets to the collector
        and queries for them
        '''

        logging.info('%%% test_ipfix %%%')
        vizd_obj = self.useFixture(
            AnalyticsFixture(logging,
                             builddir,
                             self.__class__.cassandra_port,
                             ipfix_port=True))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_collector_obj_count()

        ipfix_ip = '127.0.0.1'
        ipfix_port = vizd_obj.collectors[0].get_ipfix_port()
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        f1 = open(builddir + '/opserver/test/data/ipfix_t.data')
        sock.sendto(f1.read(), (ipfix_ip, ipfix_port))
        f2 = open(builddir + '/opserver/test/data/ipfix_d.data')
        sock.sendto(f2.read(), (ipfix_ip, ipfix_port))
        sock.close()

        uexp = [{
            'name': '127.0.0.1',
            'flow.sport': 49152,
            'flow.sip': '10.84.45.254',
            'flow.flowtype': 'IPFIX'
        }]
        assert (self.verify_uflow(vizd_obj, 'IPFIX', uexp))
    def test_02_vm_uve_with_password(self):
        '''
        This test starts redis, vizd, opserver, qed, and a python generator
        that simulates vrouter and sends UveVirtualMachineAgentTrace messages.
        Then it checks that the VM UVE (via redis) can be accessed from
        opserver.
        '''
        logging.info("*** test_02_vm_uve_with_password ***")
        if AnalyticsUveTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging,
                             builddir,
                             -1,
                             0,
                             redis_password='******'))
        assert vizd_obj.verify_on_setup()
        collectors = [vizd_obj.get_collector()]
        generator_obj = self.useFixture(
            GeneratorFixture("contrail-vrouter-agent", collectors, logging,
                             vizd_obj.get_opserver_port()))
        assert generator_obj.verify_on_setup()
        generator_obj.send_vm_uve(vm_id='abcd', num_vm_ifs=5, msg_count=5)
        assert generator_obj.verify_vm_uve(vm_id='abcd',
                                           num_vm_ifs=5,
                                           msg_count=5)
        return True
Example #9
0
    def setUpClass(cls):
        if (os.getenv('LD_LIBRARY_PATH', '').find('build/lib') < 0):
            if (os.getenv('DYLD_LIBRARY_PATH', '').find('build/lib') < 0):
                assert (False)

        cls.cassandra_port = AnalyticsFixture.get_free_port()
        mockcassandra.start_cassandra(cls.cassandra_port)
    def test_19_query_with_redis_ssl(self):
        '''
        This test starts redis,vizd,opserver and qed in
        redis ssl enabled environment.
        It then posts query to opserver to get syslog from
        query-engine.
        '''
        logging.info("%%% test_19_query_with_redis_ssl %%%")
        if AnalyticsTest._check_skip_test() is True:
            return True

        redis_ssl_params = {
            'keyfile': builddir + '/opserver/test/data/ssl/server-privkey.pem',
            'certfile': builddir + '/opserver/test/data/ssl/server.pem',
            'ca_cert': builddir + '/opserver/test/data/ssl/ca-cert.pem',
            'ssl_enable': True
        }

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging,
                             builddir,
                             self.__class__.cassandra_port,
                             redis_ssl_params=redis_ssl_params,
                             opserver_redis_ssl=False))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_message_table_moduleid()
        return True
Example #11
0
    def test_10_redis_uve_restart(self):
        logging.info('*** test_10_redis_uve_restart ***')
        if AnalyticsTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir, self.__class__.cassandra_port))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_collector_redis_uve_connection(
            vizd_obj.collectors[0])
        assert vizd_obj.verify_opserver_redis_uve_connection(vizd_obj.opserver)
        # verify redis-uve list
        host = socket.gethostname()
        gen_list = [
            host + ':Analytics:Collector:0', host + ':Analytics:QueryEngine:0',
            host + ':Analytics:OpServer:0'
        ]
        assert vizd_obj.verify_generator_uve_list(gen_list)
        # stop redis-uve
        vizd_obj.redis_uves[0].stop()
        assert vizd_obj.verify_collector_redis_uve_connection(
            vizd_obj.collectors[0], False)
        assert vizd_obj.verify_opserver_redis_uve_connection(
            vizd_obj.opserver, False)
        # start redis-uve and verify that Collector and Opserver are
        # connected to the redis-uve
        vizd_obj.redis_uves[0].start()
        assert vizd_obj.verify_collector_redis_uve_connection(
            vizd_obj.collectors[0])
        assert vizd_obj.verify_opserver_redis_uve_connection(vizd_obj.opserver)
        # verify that UVEs are resynced with redis-uve
        assert vizd_obj.verify_generator_uve_list(gen_list)
    def test_16_rbac(self, mock_is_role_cloud_admin,
                     mock_get_resource_list_from_uve_type):
        logging.info("%%% test_16_rbac %%%")
        if AnalyticsTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir, self.__class__.cassandra_port))
        assert vizd_obj.verify_on_setup()
        collectors = [vizd_obj.get_collector()]
        start_time = UTCTimestampUsec() - 3600 * 1000 * 1000
        generator_obj = self.useFixture(
            GeneratorFixture("contrail-vrouter-agent", collectors, logging,
                             vizd_obj.get_opserver_port(), start_time))
        assert generator_obj.verify_on_setup()
        logging.info("Starting intervn gen " + str(UTCTimestampUsec()))
        # send 2 vn UVEs
        generator_obj.generate_intervn()
        token = 'user:admin'
        mock_is_role_cloud_admin.return_value = True
        mock_get_resource_list_from_uve_type.return_value = None
        # for admin role, there should be 2 vn uves
        uves = vizd_obj.get_opserver_vns(token)
        assert (len(uves) == 2)
        mock_is_role_cloud_admin.return_value = False
        mock_get_resource_list_from_uve_type.return_value = set(
            ["default-domain:vn0"])
        token = 'user:default-domain:vn0'
        # for non-admin role, there should be 1 vn uve
        uves = vizd_obj.get_opserver_vns(token)
        assert (len(uves) == 1)
        return True
Example #13
0
    def test_02_message_table_query(self):
        '''
        This test starts redis,vizd,opserver and qed
        It uses the test class' cassandra instance
        Then it checks that the collector UVE (via redis)
        and syslog (via cassandra) can be accessed from
        opserver.
        '''
        logging.info("%%% test_02_message_table_query %%%")
        if AnalyticsTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir, self.__class__.cassandra_port))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_collector_obj_count()
        assert vizd_obj.verify_message_table_moduleid()
        assert vizd_obj.verify_message_table_select_uint_type()
        assert vizd_obj.verify_message_table_messagetype()
        assert vizd_obj.verify_message_table_where_or()
        assert vizd_obj.verify_message_table_where_and()
        assert vizd_obj.verify_message_table_where_prefix()
        assert vizd_obj.verify_message_table_filter()
        assert vizd_obj.verify_message_table_filter2()
        assert vizd_obj.verify_message_table_sort()
        assert vizd_obj.verify_message_table_limit()
        return True
Example #14
0
    def test_15_verify_introspect_ssl(self):
        '''
        This test enables introspect ssl and starts all the analytics
        generators in the AnalyticsFixture and verifies that the introspect
        port is accessible with https.
        '''
        logging.info('%%% test_15_verify_introspect_ssl %%%')
        sandesh_cfg = {
            'sandesh_keyfile': builddir+'/opserver/test/data/ssl/server-privkey.pem',
            'sandesh_certfile': builddir+'/opserver/test/data/ssl/server.pem',
            'sandesh_ca_cert': builddir+'/opserver/test/data/ssl/ca-cert.pem',
            'introspect_ssl_enable': 'True'
        }
        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir,
                             self.__class__.cassandra_port,
                             sandesh_config=sandesh_cfg))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_collector_obj_count()

        # remove the config from vizd so that it tries to access introspect
        # with http, it should fail
        vizd_obj.set_sandesh_config(None)
        assert not vizd_obj.verify_collector_gen(vizd_obj.collectors[0])

        # start a python generator with introspect_ssl_enable = True
        # and verify that its introspect page is accessible.
        vizd_obj.set_sandesh_config(sandesh_cfg)
        test_gen = self.useFixture(
            GeneratorFixture("contrail-test-generator",
                vizd_obj.get_collectors(), logging,
                vizd_obj.get_opserver_port(), sandesh_config=sandesh_cfg))
        assert test_gen.verify_on_setup()
    def test_04_intervn_query(self):
        '''
        This test starts redis,vizd,opserver and qed
        It uses the test class' cassandra instance
        Then it sends intervn stats to the collector
        and checks if intervn stats can be accessed from
        QE.
        '''
        logging.info("*** test_04_intervn_query ***")
        if AnalyticsTest._check_skip_test() is True:
            return True

        # set the start time in analytics db 1 hour earlier than
        # the current time. For flow series test, we need to create
        # flow samples older than the current time.
        start_time = UTCTimestampUsec() - 3600 * 1000 * 1000
        self._update_analytics_start_time(start_time)
        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir, self.__class__.redis_port,
                             self.__class__.cassandra_port))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_collector_obj_count()
        collectors = [vizd_obj.get_collector()]
        generator_obj = self.useFixture(
            GeneratorFixture("contrail-vrouter-agent", collectors, logging,
                             vizd_obj.get_opserver_port(), start_time))
        assert generator_obj.verify_on_setup()
        logging.info("Starting intervn gen " + str(UTCTimestampUsec()))
        generator_obj.generate_intervn()
        logging.info("Ending intervn gen " + str(UTCTimestampUsec()))
        assert vizd_obj.verify_intervn_all(generator_obj)
        assert vizd_obj.verify_intervn_sum(generator_obj)
        return True
Example #16
0
    def test_10_verify_object_value_table_query(self):
        '''
        This test verifies the ObjectValueTable query.
        '''
        logging.info('%%% test_10_verify_object_value_table_query %%%')

        if AnalyticsTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir, self.__class__.cassandra_port))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_collector_obj_count()
        assert vizd_obj.verify_object_value_table_query(
            table='ObjectCollectorInfo',
            exp_object_values=[vizd_obj.collectors[0].hostname])
        # verify that the object table query works for object id containing
        # XML control characters.
        collectors = [vizd_obj.get_collector()]
        generator_obj = self.useFixture(
            GeneratorFixture('contrail-vrouter-agent', collectors, logging,
                             vizd_obj.get_opserver_port()))
        assert generator_obj.verify_on_setup()
        generator_obj.send_vm_uve(vm_id='vm11&>', num_vm_ifs=2, msg_count=1)
        assert vizd_obj.verify_object_value_table_query(
            table='ObjectVMTable', exp_object_values=['vm11&>'])
Example #17
0
    def test_03_vm_uve(self):
        '''
        This test starts redis, vizd, opserver, qed, and a python generator
        that simulates vrouter and sends UveVirtualMachineAgentTrace messages.
        It uses the test class' cassandra instance. Then it checks that the
        VM UVE (via redis) can be accessed from opserver.
        '''
        logging.info("*** test_03_vm_uve ***")
        if AnalyticsTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(AnalyticsFixture(logging, builddir, 0))
        assert vizd_obj.verify_on_setup()
        collectors = [vizd_obj.get_collector()]
        generator_obj = self.useFixture(
            GeneratorFixture("VRouterAgent", collectors, logging,
                             vizd_obj.get_opserver_port()))
        assert generator_obj.verify_on_setup()
        generator_obj.send_vm_uve(vm_id='abcd', num_vm_ifs=5, msg_count=5)
        assert generator_obj.verify_vm_uve(vm_id='abcd',
                                           num_vm_ifs=5,
                                           msg_count=5)
        # Delete the VM UVE and verify that the deleted flag is set
        # in the UVE cache
        generator_obj.delete_vm_uve('abcd')
        assert generator_obj.verify_vm_uve_cache(vm_id='abcd', delete=True)
        # Add the VM UVE with the same vm_id and verify that the deleted flag
        # is cleared in the UVE cache
        generator_obj.send_vm_uve(vm_id='abcd', num_vm_ifs=5, msg_count=5)
        assert generator_obj.verify_vm_uve_cache(vm_id='abcd')
        assert generator_obj.verify_vm_uve(vm_id='abcd',
                                           num_vm_ifs=5,
                                           msg_count=5)
        return True
Example #18
0
    def test_11_verify_syslog_table_query(self):
        '''
        This test verifies the Syslog query.
        '''
        import logging.handlers
        logging.info('%%% test_11_verify_syslog_table_query %%%')

        if AnalyticsTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging,
                             builddir,
                             self.__class__.cassandra_port,
                             syslog_port=True))
        assert vizd_obj.verify_on_setup()
        syslogger = logging.getLogger("SYSLOGER")
        lh = logging.handlers.SysLogHandler(
            address=('127.0.0.1', vizd_obj.collectors[0].get_syslog_port()))
        lh.setFormatter(
            logging.Formatter('%(asctime)s %(name)s:%(message)s',
                              datefmt='%b %d %H:%M:%S'))
        lh.setLevel(logging.INFO)
        syslogger.addHandler(lh)
        line = 'pizza pasta babaghanoush'
        syslogger.critical(line)
        assert vizd_obj.verify_keyword_query(line, ['pasta', 'pizza'])
        assert vizd_obj.verify_keyword_query(line, ['babaghanoush'])
        # SYSTEMLOG
        assert vizd_obj.verify_keyword_query(line, ['PROGRESS', 'QueryExec'])
        # bad charecter (loose?)
        line = 'football ' + chr(201) + chr(203) + chr(70) + ' and baseball'
        syslogger.critical(line)
        assert vizd_obj.verify_keyword_query(line, ['football', 'baseball'])
Example #19
0
 def test_18_verify_object_table_query(self):
     '''
     This test verifies the Object Table query.
     '''
     logging.info('%%% test_18_verify_object_table_query %%%')
     vizd_obj = self.useFixture(
         AnalyticsFixture(logging, builddir, self.__class__.cassandra_port))
     assert vizd_obj.verify_on_setup()
     collectors = [vizd_obj.get_collector()]
     generator_obj = self.useFixture(
         GeneratorFixture('contrail-control',
                          collectors,
                          logging,
                          None,
                          node_type='Control',
                          sandesh_config={'system_logs_rate_limit': 10}))
     assert generator_obj.verify_on_setup()
     msg_types = generator_obj.send_sandesh_types_object_logs(
         socket.gethostname())
     assert vizd_obj.verify_object_table_sandesh_types(
         'ObjectBgpRouter', socket.gethostname(), msg_types)
     # Check if ObjectId's can be fetched properly for ObjectTable queries
     vm_generator_obj = self.useFixture(
         GeneratorFixture("contrail-vrouter-agent", collectors, logging,
                          vizd_obj.get_opserver_port()))
     assert vm_generator_obj.verify_on_setup()
     assert vizd_obj.verify_object_table_objectid_values(
         'ObjectBgpRouter', [socket.gethostname()])
     vm1_name = 'vm1'
     vm2_name = 'vm2'
     vm_generator_obj.send_vm_uve(vm_id=vm1_name, num_vm_ifs=2, msg_count=2)
     vm_generator_obj.send_vm_uve(vm_id=vm2_name, num_vm_ifs=2, msg_count=2)
     assert vizd_obj.verify_object_table_objectid_values(
         'ObjectVMTable', [vm1_name, vm2_name])
Example #20
0
    def test_08_where_clause_query(self):
        '''
        This test is used to check the working of integer 
        fields in the where query 
        '''
        logging.info("%%% test_08_where_clause_query %%%")

        if AnalyticsTest._check_skip_test() is True:
            return True

        start_time = UTCTimestampUsec() - 3600 * 1000 * 1000
        self._update_analytics_start_time(start_time)
        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir, self.__class__.cassandra_port))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_where_query()
        #Query the flowseriestable with different where options
        assert vizd_obj.verify_collector_obj_count()
        collectors = [vizd_obj.get_collector()]
        generator_obj = self.useFixture(
            GeneratorFixture("contrail-vrouter-agent", collectors, logging,
                             vizd_obj.get_opserver_port(), start_time))
        assert generator_obj.verify_on_setup()
        generator_obj.generate_flow_samples()
        assert vizd_obj.verify_where_query_prefix(generator_obj)
        return True
Example #21
0
 def test_05_fieldname_query(self):
     '''
     This test starts redis,vizd,opserver and qed
     It uses the test class' cassandra instance
     It then queries the stats table for messagetypes
     and objecttypes
     '''
     logging.info("%%% test_05_fieldname_query %%%")
     vizd_obj = self.useFixture(
         AnalyticsFixture(logging, builddir, self.__class__.cassandra_port))
     assert vizd_obj.verify_on_setup()
     assert vizd_obj.verify_collector_obj_count()
     collectors = [vizd_obj.get_collector()]
     generator_obj = self.useFixture(
         GeneratorFixture("VRouterAgent",
                          collectors,
                          logging,
                          vizd_obj.get_opserver_port(),
                          sandesh_config={'system_logs_rate_limit': 10}))
     assert generator_obj.verify_on_setup()
     # Messagetype is stored in the FieldNames.fields table only
     # for objectlog and systemlog. For systemlog it is stored as
     # MessageTable:Messagetype and for objectlog it is stored as
     # <ObjectTableName>:Messagetype. Send only systemlog
     logging.info("Starting sandesh types gen " + str(UTCTimestampUsec()))
     generator_obj.send_sandesh_types_object_logs(
         socket.gethostname(), types=[SandeshType.SYSTEM])
     logging.info("Ending sandesh types gen " + str(UTCTimestampUsec()))
     # Sends 2 different vn uves in 1 sec spacing
     logging.info("Starting intervn gen " + str(UTCTimestampUsec()))
     generator_obj.generate_intervn()
     logging.info("Ending intervn gen " + str(UTCTimestampUsec()))
     assert vizd_obj.verify_fieldname_messagetype()
     assert vizd_obj.verify_fieldname_table()
     return True
    def test_04_statprefix_obj(self):
        '''
        This test starts redis,vizd,opserver and qed
        It uses the test class' cassandra instance
        Then it sends test object stats to the collector
        and checks if they can be accessed from QE, using prefix-suffix indexes
        '''
        logging.info("*** test_04_statprefix_obj ***")
        if StatsTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir, self.__class__.redis_port,
                             self.__class__.cassandra_port))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_collector_obj_count()
        collectors = [vizd_obj.get_collector()]

        generator_obj = self.useFixture(
            StatsFixture("VRouterAgent", collectors, logging,
                         vizd_obj.get_opserver_port()))
        assert generator_obj.verify_on_setup()

        logging.info("Starting stat gen " + str(UTCTimestampUsec()))

        generator_obj.send_test_obj_stat("t010", "lxxx", "samp1", 1, 1)
        generator_obj.send_test_obj_stat("t010", "lyyy", "samp1", 2, 2)
        generator_obj.send_test_obj_stat("t010", "lyyy", "samp3", 2, 2, "", 5)
        generator_obj.send_test_obj_stat("t011", "lyyy", "samp2", 1, 1.1, "",
                                         7)
        generator_obj.send_test_obj_stat("t011", "lxxx", "samp2", 2, 1.2)
        generator_obj.send_test_obj_stat("t011", "lxxx", "samp2", 2, 1.2, "",
                                         9)

        logging.info("Checking Objectlog Stats str-str " +
                     str(UTCTimestampUsec()))

        assert generator_obj.verify_test_stat(
            "StatTable.StatTestObj.st",
            "-2m",
            select_fields=["UUID", "st.s1", "st.i1", "st.d1"],
            where_clause='name|st.s1=t010|samp1',
            num=2,
            check_rows=[{
                "st.s1": "samp1",
                "st.i1": 2,
                "st.d1": 2
            }, {
                "st.s1": "samp1",
                "st.i1": 1,
                "st.d1": 1
            }])

        return True
    def test_04_redis_uve_restart_with_password(self):
        logging.info('*** test_03_redis_uve_restart_with_password ***')

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging,
                             builddir,
                             -1,
                             0,
                             redis_password='******'))
        self.verify_uve_resync(vizd_obj)
        return True
    def test_03_min_max_query(self):
        '''
        This test starts redis,vizd,opserver and qed
        It uses the test class' cassandra instance
        Then it inserts into the stat table rows 
        and queries MAX and MIN on them
        '''
        logging.info("*** test_03_min_max_query ***")
        if StatsTest._check_skip_test() is True:
            return True
        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir, self.__class__.redis_port,
                             self.__class__.cassandra_port))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_collector_obj_count()
        collectors = [vizd_obj.get_collector()]

        generator_obj = self.useFixture(
            StatsFixture("VRouterAgent", collectors, logging,
                         vizd_obj.get_opserver_port()))
        assert generator_obj.verify_on_setup()

        logging.info("Starting stat gen " + str(UTCTimestampUsec()))

        generator_obj.send_test_stat("t04", "lxxx", "samp1", 1, 5)
        generator_obj.send_test_stat("t04", "lyyy", "samp1", 4, 3.4)
        generator_obj.send_test_stat("t04", "lyyy", "samp1", 2, 4, "", 5)

        logging.info("Checking Stats " + str(UTCTimestampUsec()))
        assert generator_obj.verify_test_stat(
            "StatTable.StatTestState.st",
            "-2m",
            select_fields=["MAX(st.i1)", "PERCENTILES(st.i1)", "AVG(st.i1)"],
            where_clause='name|st.s1=t04|samp1',
            num=1,
            check_rows=[{
                u'MAX(st.i1)': 4,
                u'PERCENTILES(st.i1)': None,
                u'AVG(st.i1)': 2.33333
            }])

        assert generator_obj.verify_test_stat(
            "StatTable.StatTestState.st",
            "-2m",
            select_fields=["MIN(st.d1)", "AVG(st.d1)"],
            where_clause='name|st.s1=t04|samp1',
            num=1,
            check_rows=[{
                u'MIN(st.d1)': 3.4,
                u'AVG(st.d1)': 4.13333
            }])

        return True
Example #25
0
    def test_00_basicsamples(self):
        '''
        This test starts redis,vizd,opserver and qed
        It uses the test class' cassandra instance
        Then it sends test stats to the collector
        and checks if they can be accessed from QE.
        '''
        logging.info("%%% test_00_basicsamples %%%")
        if StatsTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir,
                             self.__class__.redis_port,
                             self.__class__.cassandra_port))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_collector_obj_count()
        collectors = [vizd_obj.get_collector()]

        generator_obj = self.useFixture(
            StatsFixture("VRouterAgent", collectors,
                             logging, vizd_obj.get_opserver_port()))
        assert generator_obj.verify_on_setup()

        logging.info("Starting stat gen " + str(UTCTimestampUsec()))

        generator_obj.send_test_stat_dynamic("t00","samp1",1,1);
        generator_obj.send_test_stat_dynamic("t00","samp2",2,1.1);
        generator_obj.send_test_stat_dynamic("t00","samp3",1,-5062);
        generator_obj.send_test_stat_dynamic("t00&t01","samp1&samp2",2,1.1);
        generator_obj.send_test_stat_dynamic("t00>t01>","samp1&samp2",2,1.1,
                                             "&test_s2>");

        logging.info("Checking Stats " + str(UTCTimestampUsec()))

        assert generator_obj.verify_test_stat("StatTable.TestStateDynamic.ts",
            "-2m", select_fields = [ "UUID", "ts.s1", "ts.i1", "ts.d1" ],
            where_clause = 'name="t00"', num = 3, check_rows =
            [{ "ts.s1":"samp2", "ts.i1":2, "ts.d1":1.1},
             { "ts.s1":"samp1", "ts.i1":1, "ts.d1":1},
             { "ts.s1":"samp3", "ts.i1":1, "ts.d1":-5062}]);
        assert generator_obj.verify_test_stat("StatTable.TestStateDynamic.ts",
            "-2m", select_fields = [ "UUID", "ts.s1", "ts.s2" ],
            where_clause = 'name="t00&t01"', num = 1, check_rows =
            [{ "ts.s1":"samp1&samp2", "ts.s2": "" }])
        assert generator_obj.verify_test_stat("StatTable.TestStateDynamic.ts",
            "-2m", select_fields = [ "UUID", "name", "ts.s2" ],
            where_clause = 'ts.s1="samp1&samp2"', num = 2, check_rows =
            [{ "name":"t00&t01", "ts.s2": "" },
             { "name":"t00>t01>", "ts.s2":"&test_s2>" }])
            
        return True
Example #26
0
    def test_12_verify_object_table_query(self):
        '''
        This test verifies the ObjectTable query.
        '''
        logging.info('*** test_12_verify_object_table_query ***')

        if AnalyticsTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir, self.__class__.cassandra_port))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_collector_obj_count()
        assert vizd_obj.verify_object_table_query()
    def test_05_statprefix_double(self):
        '''
        This test starts redis,vizd,opserver and qed
        It uses the test class' cassandra instance
        Then it sends test 2nd-level stats to the collector
        and checks if they can be accessed from QE, using prefix-suffix indexes
        '''
        logging.info("%%% test_05_statprefix_double %%%")
        if StatsTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir, self.__class__.cassandra_port))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_collector_obj_count()
        collectors = [vizd_obj.get_collector()]

        generator_obj = self.useFixture(
            StatsFixture("VRouterAgent", collectors, logging,
                         vizd_obj.get_opserver_port()))
        assert generator_obj.verify_on_setup()

        logging.info("Starting stat gen " + str(UTCTimestampUsec()))

        generator_obj.send_test_stat_double("t010", "lxxx", "samp1", 1, 1)
        generator_obj.send_test_stat_double("t010", "lyyy", "samp1", 2, 3)
        generator_obj.send_test_stat_double("t010", "lyyy", "samp3", 2, 3,
                                            "misc2", 5)
        generator_obj.send_test_stat_double("t011", "lyyy", "samp2", 1, 1.1,
                                            "misc1", 7)
        generator_obj.send_test_stat_double("t011", "lxxx", "samp2", 2, 1.2)
        generator_obj.send_test_stat_double("t011", "lxxx", "samp2", 2, 1.2,
                                            "", 9)

        logging.info("Checking 2nd-level Stats str-double" +
                     str(UTCTimestampUsec()))

        assert generator_obj.verify_test_stat(
            "StatTable.StatTestStateDouble.dst.st",
            "-2m",
            select_fields=["UUID", "dst.st.s1", "dst.st.i1", "dst.l1"],
            where_clause='dst.l1|dst.st.s2=lyyy|misc1',
            num=1,
            check_rows=[{
                "dst.st.s1": "samp2",
                "dst.st.i1": 1,
                "dst.l1": "lyyy"
            }])

        return True
Example #28
0
    def test_00_nocassandra(self):
        '''
        This test starts redis,vizd,opserver and qed
        Then it checks that the collector UVE (via redis)
        can be accessed from opserver.
        '''
        logging.info("*** test_00_nocassandra ***")
        if AnalyticsTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(AnalyticsFixture(logging, builddir, 0))
        assert vizd_obj.verify_on_setup()

        return True
Example #29
0
    def test_00_database_purge_query(self):
        '''
        This test starts redis,vizd,opserver and qed
        It uses the test class' cassandra instance
        and checks if database purge functonality is
        is working properly
        '''
        logging.info("*** test_00_database_purge_query ***")
        if AnalyticsDbTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir, self.__class__.redis_port,
                             self.__class__.cassandra_port))
        self.verify_database_purge(vizd_obj)
        return True
Example #30
0
 def test_06_send_tracebuffer(self):
     '''
     This test verifies /analytics/send-tracebuffer/ REST API.
     Opserver publishes the request to send trace buffer to all
     the redis-uve instances. Collector forwards the request to
     the appropriate generator(s). Generator sends the tracebuffer
     to the Collector which then dumps the trace messages in the
     analytics db. Verify that the trace messages are written in
     the analytics db.
     '''
     logging.info('%%% test_06_send_tracebuffer %%%')
     if AnalyticsTest._check_skip_test() is True:
         return True
     
     vizd_obj = self.useFixture(
         AnalyticsFixture(logging, builddir,
                          self.__class__.cassandra_port, 
                          collector_ha_test=True))
     assert vizd_obj.verify_on_setup()
     assert vizd_obj.verify_collector_obj_count()
     # Make sure the contrail-collector is connected to the redis-uve before 
     # sending the trace buffer request
     assert vizd_obj.verify_collector_redis_uve_connection(
                                 vizd_obj.collectors[0])
     # Send trace buffer request for only the first collector
     vizd_obj.opserver.send_tracebuffer_request(
                 vizd_obj.collectors[0].hostname,
                 ModuleNames[Module.COLLECTOR], '0',
                 'UveTrace')
     assert vizd_obj.verify_tracebuffer_in_analytics_db(
                 vizd_obj.collectors[0].hostname,
                 ModuleNames[Module.COLLECTOR], 'UveTrace')
     # There should be no trace buffer from the second collector
     assert not vizd_obj.verify_tracebuffer_in_analytics_db(
                     vizd_obj.collectors[1].hostname,
                     ModuleNames[Module.COLLECTOR], 'UveTrace')
     # Make sure the contrail-collector is connected to the redis-uve before 
     # sending the trace buffer request
     assert vizd_obj.verify_collector_redis_uve_connection(
                                 vizd_obj.collectors[1])
     # Send trace buffer request for all collectors
     vizd_obj.opserver.send_tracebuffer_request(
                 '*', ModuleNames[Module.COLLECTOR], '0',
                 'UveTrace')
     assert vizd_obj.verify_tracebuffer_in_analytics_db(
                 vizd_obj.collectors[1].hostname,
                 ModuleNames[Module.COLLECTOR], 'UveTrace')
Example #31
0
    def test_01_startup(self):
        '''
        This test starts redis,vizd,opserver and qed
        It uses the test class' cassandra instance
        Then it checks that the collector UVE (via redis)
        and syslog (via cassandra) can be accessed from
        opserver.
        '''
        logging.info("*** test_01_startup ***")
        if AnalyticsTest._check_skip_test() is True:
            return True

        vizd_obj = self.useFixture(
            AnalyticsFixture(logging, builddir, self.__class__.cassandra_port))
        assert vizd_obj.verify_on_setup()
        assert vizd_obj.verify_collector_obj_count()
        return True