Beispiel #1
0
def then_the_user_has_funckey_hint_disabled(context, firstname, lastname,
                                            position):
    confd_user = context.helpers.confd_user.get_by(firstname=firstname,
                                                   lastname=lastname)
    funckey = context.confd_client.users(confd_user).get_funckey(int(position))
    prefix_exten = _get_funckey_prefix_exten(confd_user['id'], funckey)
    until.true(_assert_idle_hints_state, context, prefix_exten, tries=10)
Beispiel #2
0
def then_the_user_has_all_forwards_hints_enabled(context, firstname, lastname):
    confd_user = context.helpers.confd_user.get_by(firstname=firstname,
                                                   lastname=lastname)
    funckeys = context.confd_client.users(confd_user).list_funckeys()['keys']
    for funckey in funckeys.values():
        prefix_exten = _get_funckey_prefix_exten(confd_user['id'], funckey)
        until.true(_assert_inuse_hints_state, context, prefix_exten, tries=10)
Beispiel #3
0
    def test_restrict_when_auth_service_is_down(self):
        self.stop_service('dird')
        self.stop_service('auth')
        self.start_service('dird')
        dird = self.make_dird(VALID_TOKEN_MAIN_TENANT)

        def _returns_503():
            assert_that(
                calling(dird.config.get).with_args(MAIN_TENANT),
                raises(DirdError).matching(
                    has_properties(
                        status_code=503,
                        error_id='matser-tenant-not-initiated',
                    )),
            )

        until.assert_(_returns_503, tries=10)

        self.start_service('auth')
        auth = self.make_mock_auth()
        until.true(auth.is_up, timeout=START_TIMEOUT)
        self.configure_wazo_auth()

        def _not_return_503():
            try:
                response = dird.config.get(MAIN_TENANT)
                assert_that(response, has_key('debug'))
            except Exception as e:
                raise AssertionError(e)

        until.assert_(_not_return_503, tries=10)
Beispiel #4
0
def test_restrict_on_with_slow_wazo_auth():
    BaseIntegrationTest.stop_service('confd')
    BaseIntegrationTest.stop_service('auth')
    BaseIntegrationTest.start_service('confd')
    BaseIntegrationTest.setup_helpers()
    helper_confd._reset()
    helper_new_client._reset()
    confd._reset()
    confd_csv._reset()

    def _returns_503():
        try:
            response = confd.extensions.features.get()
            response.assert_status(503)
        except ConnectionError:
            raise AssertionError

    until.assert_(_returns_503, tries=10)

    BaseIntegrationTest.start_service('auth')
    auth._reset()
    until.true(auth.is_up, tries=5)
    BaseIntegrationTest.setup_token()

    def _not_return_503():
        response = confd.extensions.features.get()
        response.assert_status(200)

    until.assert_(_not_return_503, tries=10)
Beispiel #5
0
 def setUp(self):
     super().setUp()
     until.true(self.bus_is_up, tries=10)
     bus_port = self.service_port(5672, 'rabbitmq')
     self.bus = BusClient.from_connection_fields(host='127.0.0.1',
                                                 port=bus_port)
     self.bus.downstream_exchange_declare('wazo-headers', 'headers')
Beispiel #6
0
def then_monit_monitors_the_service_process_name(context, process_name):
    until.true(
        context.helpers.monit.process_monitored,
        process_name,
        timeout=10,
        message='Monit did not monitor process {}'.format(process_name),
    )
def step_user_is_talking_to_other_party_with_contact(context, tracking_id,
                                                     other_party_id,
                                                     contact_number):
    phone = context.phone_register.get_phone(tracking_id,
                                             int(contact_number) - 1)
    until.true(phone.is_talking, tries=3)
    assert_that(phone.is_talking_to(other_party_id))
Beispiel #8
0
def given_there_is_an_outcall_using_extension(context, exten, exten_context):
    outcall_name = f'outcall-{exten}'
    body = {
        'name': outcall_name,
        'enabled': True,
    }
    outcall = context.helpers.outcall.create(body)

    body = {'context': exten_context}
    trunk = context.helpers.trunk.create(body)
    context.helpers.outcall.add_trunk(outcall, trunk)

    template = context.helpers.endpoint_sip.get_template_by(label='global')
    body = {
        'name': outcall_name,
        'auth_section_options': [
            ['username', outcall_name],
            ['password', outcall_name],
        ],
        'endpoint_section_options': [],
        'templates': [template],
    }
    sip = context.helpers.endpoint_sip.create(body)

    context.helpers.trunk.add_endpoint_sip(trunk, sip)
    body = {'exten': exten, 'context': exten_context}
    extension = context.helpers.extension.create(body)

    context.helpers.outcall.add_extension(outcall, extension)

    phone = context.helpers.sip_phone.register_and_track_phone(outcall_name, sip)
    until.true(phone.is_registered, tries=3)
def when_incoming_call_received_from_name_to_exten(context,
                                                   incall_name,
                                                   exten,
                                                   exten_context,
                                                   callerid=None):
    body = {'context': exten_context}
    trunk = context.helpers.trunk.create(body)
    template = context.helpers.endpoint_sip.get_template_by(label='global')
    body = {
        'name':
        incall_name,
        'auth_section_options': [
            ['username', incall_name],
            ['password', incall_name],
        ],
        'endpoint_section_options': [],
        'templates': [template],
    }
    if callerid:
        body['endpoint_section_options'].append(['callerid', callerid])
    sip = context.helpers.endpoint_sip.create(body)

    # NOTE(fblackburn): We do not wait on pjsip reload inside this step
    # to be able to listen events before this step in the scenario
    context.confd_client.trunks(trunk).add_endpoint_sip(sip)
    time.sleep(1)

    phone = context.helpers.sip_phone.register_and_track_phone(
        incall_name, sip)
    until.true(phone.is_registered, tries=3)
    phone.call(exten)
Beispiel #10
0
 def auth_stopped(cls):
     cls.stop_service('auth')
     yield
     cls.start_service('auth')
     auth = cls.make_mock_auth()
     until.true(auth.is_up, timeout=START_TIMEOUT)
     cls.configure_wazo_auth()
    def given_bridged_call_stasis(self, caller_uuid=None, callee_uuid=None):
        bridge = self.ari.bridges.create(type='mixing')

        caller = self.stasis_channel()
        caller_uuid = caller_uuid or make_user_uuid()
        caller.setChannelVar(variable='XIVO_USERUUID', value=caller_uuid)
        caller.setChannelVar(variable='WAZO_TENANT_UUID', value=VALID_TENANT)
        bridge.addChannel(channel=caller.id)

        callee = self.stasis_channel()
        callee_uuid = callee_uuid or make_user_uuid()
        callee.setChannelVar(variable='XIVO_USERUUID', value=callee_uuid)
        callee.setChannelVar(variable='WAZO_TENANT_UUID', value=VALID_TENANT)
        bridge.addChannel(channel=callee.id)

        self.calld_client.set_token(VALID_TOKEN)

        def channels_have_been_created_in_calld(caller_id, callee_id):
            calls = self.calld_client.calls.list_calls(
                application=SOME_STASIS_APP,
                application_instance=SOME_STASIS_APP_INSTANCE)
            channel_ids = [call['call_id'] for call in calls['items']]
            return (caller_id in channel_ids and callee_id in channel_ids)

        until.true(channels_have_been_created_in_calld,
                   callee.id,
                   caller.id,
                   tries=3)

        return caller.id, callee.id
Beispiel #12
0
    def _get_last_call_log_generated(self):
        with self.database.queries() as queries:

            def call_log_generated():
                return queries.find_last_call_log() is not None

            until.true(call_log_generated, tries=5)
            return queries.find_last_call_log().id
Beispiel #13
0
 def auth_stopped(self):
     self.stop_service('auth')
     yield
     self.start_service('auth')
     self.reset_clients()
     until.true(self.auth.is_up,
                tries=5,
                message='wazo-auth did not come back up')
Beispiel #14
0
 def confd_stopped(cls):
     cls.stop_service('confd')
     try:
         yield
     finally:
         cls.start_service('confd')
         cls.reset_clients()
         until.true(cls.confd.is_up, tries=5)
Beispiel #15
0
 def restart_postgres(cls):
     cls.restart_service('db', signal='SIGINT')  # fast shutdown
     cls.engine.dispose()
     cls.setup_db_session()
     database = DBUserClient(cls.db_uri)
     until.true(database.is_up,
                timeout=5,
                message='Postgres did not come back up')
Beispiel #16
0
 def ari_stopped(cls):
     cls.stop_service('ari')
     try:
         yield
     finally:
         cls.start_service('ari')
         cls.reset_clients()
         until.true(cls.ari.is_up, tries=5)
Beispiel #17
0
    def test_when_asterisk_sends_non_json_events_then_calld_reconnects(self):
        self.stasis.non_json_message()

        until.false(self._calld_is_not_connected,
                    tries=3,
                    message='wazo-calld did not disconnect from ARI')
        until.true(self._calld_is_connected,
                   tries=3,
                   message='wazo-calld did not reconnect to ARI')
Beispiel #18
0
    def local_messages(cls, event_name, expected=None, timeout=3.0):
        def test():
            return cls._local_messages.count(event_name) == expected

        try:
            until.true(test, timeout=timeout, interval=0.1)
        except until.NoMoreTries:
            pass
        return cls._local_messages.pop(event_name)
Beispiel #19
0
    def remote_messages(cls, event_name, expected=None, timeout=3.0):
        def test():
            return cls.remote_bus.get_messages_count == expected

        try:
            until.true(test, timeout=timeout, interval=0.1)
        except until.NoMoreTries:
            pass
        return cls.remote_bus.get_messages(event_name)
Beispiel #20
0
 def process_monitored(self, process_name):
     until.true(self.is_monit_started,
                timeout=60,
                interval=10,
                message='Monit is unreachable')
     result = self.get_monit_status()
     for line in result:
         if line == "Process '{}'".format(process_name):
             return True
     return False
Beispiel #21
0
    def test_when_asterisk_restart_then_calld_reconnects(self):
        until.true(self._calld_is_connected, tries=3)

        self.restart_service('ari')
        self.reset_clients()

        assert_that(self.service_logs(),
                    contains_string("ARI connection error"))

        until.true(self._calld_is_connected, tries=3)
Beispiel #22
0
 def reset_clients(cls):
     cls.bus = cls.make_bus()
     cls.call_logd = cls.make_call_logd()
     cls.database = cls.make_database()
     cls.cel_database = cls.make_cel_database()
     cls.filesystem = cls.make_filesystem()
     cls.email = cls.make_email()
     cls.auth = cls.make_auth()
     if not isinstance(cls.auth, WrongClient):
         until.true(cls.auth.is_up, tries=5)
         cls.configure_wazo_auth_for_multitenants()
Beispiel #23
0
    def restart_database(self, container_name):
        self.restart_service(container_name, signal='SIGINT')  # fast shutdown
        self.reset_clients()

        db_helper = self.database
        if container_name == 'cel-postgres':
            db_helper = self.cel_database

        until.true(
            db_helper.is_up,
            timeout=5,
            message=f'{container_name} did not come back up',
        )
Beispiel #24
0
def wait_for_rabbitmq(integration_test):
    def try_connect(connection):
        try:
            connection.connect()
        except Exception:
            return False
        else:
            connection.release()
            return True

    port = integration_test.service_port(5672, 'rabbitmq')
    with Connection(f'amqp://*****:*****@127.0.0.1:{port}//') as connection:
        until.true(try_connect, connection, timeout=30)
    def given_bridged_call_not_stasis(self,
                                      caller_uuid=None,
                                      callee_uuid=None,
                                      caller_variables=None):
        caller_uuid = caller_uuid or make_user_uuid()
        callee_uuid = callee_uuid or make_user_uuid()
        variables = {
            'XIVO_USERUUID': caller_uuid,
            '__CALLEE_XIVO_USERUUID': callee_uuid,
            '__WAZO_TENANT_UUID': VALID_TENANT,
        }
        variables.update(caller_variables or {})
        caller = self.ari.channels.originate(
            endpoint=ENDPOINT_AUTOANSWER,
            context='local',
            extension='dial-autoanswer',
            variables={'variables': variables})

        def bridged_channel(caller):
            try:
                bridge = next(bridge for bridge in self.ari.bridges.list()
                              if caller.id in bridge.json['channels'])
                callee_channel_id = next(
                    iter(set(bridge.json['channels']) - {caller.id}))
                return callee_channel_id
            except StopIteration:
                return False

        callee_channel_id = until.true(bridged_channel, caller, timeout=3)
        return caller.id, callee_channel_id
Beispiel #26
0
    def _command_was_called(self, bus_events, command):
        def poll():
            return any(message for message in bus_events.accumulate()
                       if message['name'] == 'sysconfd_sentinel'
                       and message['data']['command'] == command)

        return until.true(poll, timeout=5)
    def stasis_channel(self):
        def channel_is_in_stasis(channel_id):
            try:
                self.ari.channels.setChannelVar(channelId=channel_id,
                                                variable='TEST_STASIS',
                                                value='')
                return True
            except ARINotInStasis:
                return False

        new_channel = self.ari.channels.originate(
            endpoint=ENDPOINT_AUTOANSWER,
            app=SOME_STASIS_APP,
            appArgs=[SOME_STASIS_APP_INSTANCE])
        until.true(channel_is_in_stasis, new_channel.id, tries=2)

        return new_channel
Beispiel #28
0
    def test_when_create_twice_with_authorize_then_does_not_raise(self):
        result = self.client.external.create(MICROSOFT, self.admin_user_uuid,
                                             {})
        self._simulate_user_authentication(result['state'])
        old_result = self.client.external.get(MICROSOFT, self.admin_user_uuid)
        result = self.client.external.create(MICROSOFT, self.admin_user_uuid,
                                             {})
        self._simulate_user_authentication(result['state'])

        def _token_is_updated():
            try:
                result = self.client.external.get(MICROSOFT,
                                                  self.admin_user_uuid)
            except requests.HTTPError:
                return False
            return result['token_expiration'] != old_result['token_expiration']

        until.true(_token_is_updated, timeout=15, interval=1)
Beispiel #29
0
    def test_publish_timeout_when_rabbitmq_is_down_then_up(self):
        event = MockEvent('some_event', value='some_value')

        self.stop_rabbitmq()

        with self.local_event(event.name):
            assert_that(
                calling(self.local_bus.publish).with_args(event),
                raises(OperationalError),
            )

            self.start_rabbitmq()
            until.true(self.check_is_running, timeout=30)

            self.local_bus.publish(event)
            assert_that(
                self.local_messages(event.name, 1),
                has_item(has_entry('value', 'some_value')),
            )
Beispiel #30
0
    def test_that_adding_favorite_produces_bus_event(self):
        bus_port = self.service_port(5672, 'rabbitmq')
        bus = BusClient.from_connection_fields(host='127.0.0.1', port=bus_port)
        until.true(bus.is_up, tries=5)
        bus.downstream_exchange_declare('wazo-headers', 'headers')
        bus_events = bus.accumulator('directory.*.favorite.*')

        def favorite_bus_event_received(name):
            assert_that(
                bus_events.accumulate(with_headers=True),
                has_item(
                    has_entries(
                        message=has_entry('name', name),
                        headers=has_entry('tenant_uuid', MAIN_TENANT),
                    )),
            )

        with self.personal({'firstname': 'Alice'}) as alice:
            with self.favorite('personal', alice['id']):
                until.assert_(favorite_bus_event_received,
                              'favorite_added',
                              tries=2)

        until.assert_(favorite_bus_event_received, 'favorite_deleted', tries=2)