Example #1
0
def _generate_call_logs():
    parser = argparse.ArgumentParser(description='Call logs generator')
    options = parse_args(parser)
    key_config = load_key_file(DEFAULT_CONFIG)
    config = ChainMap(key_config, DEFAULT_CONFIG)

    auth_client = AuthClient(**config['auth'])
    confd_client = ConfdClient(**config['confd'])
    token_renewer = TokenRenewer(auth_client)
    token_renewer.subscribe_to_token_change(confd_client.set_token)

    cel_fetcher = CELFetcher()
    generator = CallLogsGenerator([
        LocalOriginateCELInterpretor(confd_client),
        DispatchCELInterpretor(CallerCELInterpretor(confd_client),
                               CalleeCELInterpretor(confd_client))
    ])
    writer = CallLogsWriter()
    publisher = BusPublisher(config)
    manager = CallLogsManager(cel_fetcher, generator, writer, publisher)

    options = vars(options)
    with token_renewer:
        if options.get('action') == 'delete':
            if options.get('all'):
                manager.delete_all()
            elif options.get('days'):
                manager.delete_from_days(options['days'])
        else:
            if options.get('days'):
                manager.generate_from_days(days=options['days'])
            else:
                manager.generate_from_count(cel_count=options['cel_count'])
def _generate_call_logs():
    parser = argparse.ArgumentParser(description='Call logs generator')
    options = parse_args(parser)

    file_config = {
        key: value
        for key, value in read_config_file_hierarchy(DEFAULT_CONFIG).items()
        if key in ('confd', 'bus', 'auth', 'db_uri', 'cel_db_uri')
    }
    key_config = {}
    auth_username = file_config['auth'].get('username')
    auth_password = file_config['auth'].get('password')
    if not (auth_username and auth_password):
        key_config = load_key_file(ChainMap(file_config, DEFAULT_CONFIG))
    config = ChainMap(key_config, file_config, DEFAULT_CONFIG)
    set_xivo_uuid(config, logger)
    init_db_from_config({'db_uri': config['cel_db_uri']})
    DBSession = new_db_session(config['db_uri'])
    CELDBSession = new_db_session(config['cel_db_uri'])
    dao = DAO(DBSession, CELDBSession)

    auth_client = AuthClient(**config['auth'])
    confd_client = ConfdClient(**config['confd'])
    token_renewer = TokenRenewer(auth_client)
    token_renewer.subscribe_to_token_change(confd_client.set_token)

    generator = CallLogsGenerator(
        confd_client,
        [
            LocalOriginateCELInterpretor(),
            DispatchCELInterpretor(CallerCELInterpretor(),
                                   CalleeCELInterpretor()),
        ],
    )
    token_renewer.subscribe_to_next_token_details_change(
        generator.set_default_tenant_uuid)
    writer = CallLogsWriter(dao)
    publisher = BusPublisher(service_uuid=config['uuid'], **config['bus'])
    manager = CallLogsManager(dao, generator, writer, publisher)

    options = vars(options)
    with token_renewer:
        if options.get('action') == 'delete':
            if options.get('all'):
                manager.delete_all()
            elif options.get('days'):
                manager.delete_from_days(options['days'])
        else:
            if options.get('days'):
                manager.generate_from_days(days=options['days'])
            else:
                manager.generate_from_count(cel_count=options['cel_count'])
Example #3
0
def _generate_call_logs():
    parser = argparse.ArgumentParser(description='Call logs generator')
    options = parse_args(parser)

    file_config = {
        key: value
        for key, value in read_config_file_hierarchy(DEFAULT_CONFIG).items()
        if key in ('confd', 'bus', 'auth', 'db_uri')
    }
    key_config = load_key_file(ChainMap(file_config, DEFAULT_CONFIG))
    config = ChainMap(key_config, file_config, DEFAULT_CONFIG)
    init_db_from_config(config)

    auth_client = AuthClient(**config['auth'])
    confd_client = ConfdClient(**config['confd'])
    token_renewer = TokenRenewer(auth_client)
    token_renewer.subscribe_to_token_change(confd_client.set_token)

    cel_fetcher = CELFetcher()
    generator = CallLogsGenerator(
        confd_client,
        [
            LocalOriginateCELInterpretor(confd_client),
            DispatchCELInterpretor(
                CallerCELInterpretor(confd_client), CalleeCELInterpretor(confd_client)
            ),
        ],
    )
    token_renewer.subscribe_to_next_token_details_change(
        generator.set_default_tenant_uuid
    )
    writer = CallLogsWriter()
    publisher = BusPublisher(config)
    manager = CallLogsManager(cel_fetcher, generator, writer, publisher)

    options = vars(options)
    with token_renewer:
        if options.get('action') == 'delete':
            if options.get('all'):
                manager.delete_all()
            elif options.get('days'):
                manager.delete_from_days(options['days'])
        else:
            if options.get('days'):
                manager.generate_from_days(days=options['days'])
            else:
                manager.generate_from_count(cel_count=options['cel_count'])
Example #4
0
 def __init__(self, config):
     auth_config = dict(config['auth'])
     auth_config.pop('key_file', None)
     auth_client = AuthClient(**auth_config)
     cel_fetcher = CELFetcher()
     confd_client = ConfdClient(**config['confd'])
     generator = CallLogsGenerator([
         LocalOriginateCELInterpretor(confd_client),
         DispatchCELInterpretor(CallerCELInterpretor(confd_client),
                                CalleeCELInterpretor(confd_client))
     ])
     writer = CallLogsWriter()
     self._publisher = BusPublisher(config)
     self.manager = CallLogsManager(cel_fetcher, generator, writer,
                                    self._publisher)
     self.bus_client = BusClient(config)
     self.rest_api = CoreRestApi(config)
     self.token_renewer = TokenRenewer(auth_client)
     self.token_renewer.subscribe_to_token_change(confd_client.set_token)
     self._load_plugins(config)
Example #5
0
 def __init__(self, config):
     auth_client = AuthClient(**config['auth'])
     cel_fetcher = CELFetcher()
     confd_client = ConfdClient(**config['confd'])
     generator = CallLogsGenerator(
         confd_client,
         [
             LocalOriginateCELInterpretor(confd_client),
             DispatchCELInterpretor(
                 CallerCELInterpretor(confd_client),
                 CalleeCELInterpretor(confd_client),
             ),
         ],
     )
     writer = CallLogsWriter()
     self.token_renewer = TokenRenewer(auth_client)
     self.token_renewer.subscribe_to_token_change(confd_client.set_token)
     self.token_renewer.subscribe_to_next_token_details_change(
         generator.set_default_tenant_uuid)
     self._publisher = BusPublisher(config)
     self.manager = CallLogsManager(cel_fetcher, generator, writer,
                                    self._publisher)
     self.bus_client = BusClient(config)
     self.rest_api = CoreRestApi(config)
     self.status_aggregator = StatusAggregator()
     self.token_status = TokenStatus()
     plugin_helpers.load(
         namespace='wazo_call_logd.plugins',
         names=config['enabled_plugins'],
         dependencies={
             'api': api,
             'config': config,
             'token_renewer': self.token_renewer,
             'status_aggregator': self.status_aggregator,
         },
     )
    def __init__(self, config):
        self.config = config
        DBSession = new_db_session(config['db_uri'])
        CELDBSession = new_db_session(config['cel_db_uri'])
        self.dao = DAO(DBSession, CELDBSession)
        writer = CallLogsWriter(self.dao)

        # NOTE(afournier): it is important to load the tasks before configuring the Celery app
        self.celery_task_manager = plugin_helpers.load(
            namespace='wazo_call_logd.celery_tasks',
            names=config['enabled_celery_tasks'],
            dependencies={
                'config': self.config,
                'dao': self.dao,
                'app': celery.app,
            },
        )
        celery.configure(config)
        self._celery_process = celery.spawn_workers(config)

        auth_client = AuthClient(**config['auth'])
        confd_client = ConfdClient(**config['confd'])
        generator = CallLogsGenerator(
            confd_client,
            [
                LocalOriginateCELInterpretor(),
                DispatchCELInterpretor(
                    CallerCELInterpretor(),
                    CalleeCELInterpretor(),
                ),
            ],
        )
        self.token_renewer = TokenRenewer(auth_client)
        self.token_renewer.subscribe_to_token_change(confd_client.set_token)
        self.token_renewer.subscribe_to_next_token_details_change(
            generator.set_default_tenant_uuid)

        self.bus_publisher = BusPublisher(service_uuid=config['uuid'],
                                          **config['bus'])
        self.bus_consumer = BusConsumer(**config['bus'])
        self.manager = CallLogsManager(self.dao, generator, writer,
                                       self.bus_publisher)

        self._bus_subscribe()

        self.http_server = HTTPServer(config)
        if not app.config['auth'].get('master_tenant_uuid'):
            self.token_renewer.subscribe_to_next_token_details_change(
                init_master_tenant)

        self.status_aggregator = StatusAggregator()
        self.token_status = TokenStatus()
        plugin_helpers.load(
            namespace='wazo_call_logd.plugins',
            names=config['enabled_plugins'],
            dependencies={
                'api': api,
                'config': config,
                'dao': self.dao,
                'token_renewer': self.token_renewer,
                'status_aggregator': self.status_aggregator,
                'bus_publisher': self.bus_publisher,
            },
        )
 def setUp(self):
     self.caller_cel_interpretor = CallerCELInterpretor(confd_mock())
class TestCallerCELInterpretor(TestCase):

    def setUp(self):
        self.caller_cel_interpretor = CallerCELInterpretor(confd_mock())

    def test_interpret_cel_unknown_or_ignored_event(self):
        cel = Mock(eventtype='unknown_or_ignored_eventtype')
        call = Mock(RawCallLog)

        result = self.caller_cel_interpretor.interpret_cel(cel, call)

        assert_that(result, equal_to(call))

    def test_interpret_chan_start(self):
        cel = Mock()
        cel_date = cel.eventtime = datetime.datetime(year=2013, month=1, day=1)
        cel_source_name, cel_source_exten = cel.cid_name, cel.cid_num = 'source_name', 'source_exten'
        cel_destination_exten = cel.exten = 'destination_exten'
        line_identity = 'sip/asldfj'
        cel.channame = line_identity + '-0000001'
        call = Mock(RawCallLog)

        result = self.caller_cel_interpretor.interpret_chan_start(cel, call)

        assert_that(result, all_of(
            has_property('date', cel_date),
            has_property('source_name', cel_source_name),
            has_property('source_exten', cel_source_exten),
            has_property('destination_exten', cel_destination_exten),
            has_property('source_line_identity', line_identity),
        ))

    def test_interpret_chan_start_with_destination_s(self):
        cel = Mock()
        cel_date = cel.eventtime = datetime.datetime(year=2013, month=1, day=1)
        cel_source_name, cel_source_exten = cel.cid_name, cel.cid_num = 'source_name', 'source_exten'
        cel.exten = 's'
        line_identity = 'sip/asldfj'
        cel.channame = line_identity + '-0000001'
        call = Mock(RawCallLog)

        result = self.caller_cel_interpretor.interpret_chan_start(cel, call)

        assert_that(result, all_of(
            has_property('date', cel_date),
            has_property('source_name', cel_source_name),
            has_property('source_exten', cel_source_exten),
            has_property('destination_exten', ''),
            has_property('source_line_identity', line_identity),
        ))

    def test_interpret_xivo_incall(self):
        cel = Mock()
        call = Mock(RawCallLog)

        result = self.caller_cel_interpretor.interpret_xivo_incall(cel, call)

        assert_that(result, has_property('direction', 'inbound'))

    def test_interpret_xivo_outcall(self):
        cel = Mock()
        call = Mock(RawCallLog)

        result = self.caller_cel_interpretor.interpret_xivo_outcall(cel, call)

        assert_that(result, has_property('direction', 'outbound'))

    def test_interpret_app_start_when_cid_name_num_are_empty_then_do_not_change_source_name_exten(self):
        cel = Mock()
        cel_userfield = cel.userfield = 'userfield'
        cel.cid_name = ''
        cel.cid_num = ''
        call = Mock(RawCallLog, source_name=sentinel.original_name)

        result = self.caller_cel_interpretor.interpret_app_start(cel, call)

        assert_that(result, all_of(
            has_property('user_field', cel_userfield),
            has_property('source_name', sentinel.original_name)
        ))

    def test_interpret_app_start_when_cid_name_then_replace_source_name(self):
        cel = Mock()
        cel_userfield = cel.userfield = 'userfield'
        cel_cid_name = cel.cid_name = 'Reversed'
        cel_cid_num = cel.cid_num = 'Reversed'
        call = Mock(RawCallLog, source_name='Original Name')

        result = self.caller_cel_interpretor.interpret_app_start(cel, call)

        assert_that(result, all_of(
            has_property('user_field', cel_userfield),
            has_property('source_name', cel_cid_name),
            has_property('source_exten', cel_cid_num)
        ))

    def test_interpret_answer_no_destination_yet(self):
        cel = Mock(cid_name=sentinel.destination_exten)
        call = Mock(RawCallLog, destination_exten=None)

        result = self.caller_cel_interpretor.interpret_answer(cel, call)

        assert_that(result, all_of(
            has_property('destination_exten', sentinel.destination_exten),
        ))

    def test_interpret_answer_with_destination_already_set(self):
        cel = Mock(cid_name=sentinel.other_destination)
        call = Mock(RawCallLog, destination_exten=sentinel.original_destination)

        result = self.caller_cel_interpretor.interpret_answer(cel, call)

        assert_that(result, all_of(
            has_property('destination_exten', sentinel.original_destination),
        ))

    def test_interpret_bridge_start_or_enter_with_no_source_set(self):
        cel = Mock(
            cid_name=sentinel.source_name,
            cid_num=sentinel.source_exten,
        )
        call = Mock(RawCallLog, source_name=None, source_exten=None)

        result = self.caller_cel_interpretor.interpret_bridge_start_or_enter(cel, call)

        assert_that(result, all_of(
            has_property('source_name', sentinel.source_name),
            has_property('source_exten', sentinel.source_exten),
        ))

    def test_interpret_bridge_start_or_enter_sets_date_answer(self):
        cel = Mock(
            eventtime=sentinel.eventtime,
            cid_name=sentinel.name,
            cid_num=sentinel.exten,
        )
        call = Mock(RawCallLog, source_name=None, source_exten=None)

        result = self.caller_cel_interpretor.interpret_bridge_start_or_enter(cel, call)

        assert_that(result, all_of(
            has_property('date_answer', sentinel.eventtime),
        ))

    def test_interpret_bridge_start_or_enter_with_source_already_set(self):
        cel = Mock(cid_name=sentinel.other_source_name,
                   cid_num=sentinel.other_source_exten)
        call = Mock(RawCallLog,
                    source_name=sentinel.first_source_name,
                    source_exten=sentinel.first_source_exten)

        result = self.caller_cel_interpretor.interpret_bridge_start_or_enter(cel, call)

        assert_that(result, all_of(
            has_property('source_name', sentinel.first_source_name),
            has_property('source_exten', sentinel.first_source_exten),
        ))

    def test_interpret_xivo_from_s(self):
        exten = '1002'
        cel = Mock(exten=exten)
        call = Mock(CallLog)

        result = self.caller_cel_interpretor.interpret_xivo_from_s(cel, call)

        assert_that(result, all_of(
            has_property('destination_exten', '1002'),
        ))