Exemple #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'])
class TestCalleeCELInterpretor(TestCase):

    def setUp(self):
        self.callee_cel_interpretor = CalleeCELInterpretor(confd_mock())

    def test_interpret_chan_start(self):
        line_identity = 'sip/asldfj'
        cel = Mock(channame=line_identity + '-0000001')
        call = Mock(RawCallLog)

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

        assert_that(result, has_property('destination_line_identity', line_identity))
Exemple #4
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'])
Exemple #5
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)
 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.callee_cel_interpretor = CalleeCELInterpretor(confd_mock())