Commit b777c647 authored by Laurent Meiller's avatar Laurent Meiller

2506 dispatch hints to proper mds where user belongs

parent 2d9ded6f
......@@ -87,7 +87,8 @@ def user_hints(session, context):
(LineFeatures.protocol == 'sip', literal_column("'SIP/'") + UserSIP.name),
(LineFeatures.protocol == 'sccp', literal_column("'SCCP/'") + SCCPLine.name),
(LineFeatures.protocol == 'custom', UserCustom.interface)
]).label('argument'))
]).label('argument'),
LineFeatures.configregistrar.label('mediaserver'))
.join(UserLine.userfeatures)
.join(UserLine.linefeatures)
.outerjoin(UserSIP,
......@@ -113,7 +114,8 @@ def user_hints(session, context):
return tuple(Hint(user_id=row.user_id,
extension=row.extension,
argument=row.argument)
argument=row.argument,
mediaserver=row.mediaserver)
for row in query)
......@@ -131,14 +133,16 @@ def conference_hints(session, context):
return tuple(Hint(user_id=None,
extension=row.extension,
argument=None)
argument=None,
mediaserver='default')
for row in query)
@daosession
def service_hints(session, context):
query = (session.query(Extension.exten.label('extension'),
UserFeatures.id.label('user_id'))
UserFeatures.id.label('user_id'),
LineFeatures.configregistrar.label('mediaserver'))
.join(FuncKeyDestService,
FuncKeyDestService.extension_id == Extension.id)
.join(FuncKeyMapping,
......@@ -148,7 +152,8 @@ def service_hints(session, context):
return tuple(Hint(user_id=row.user_id,
extension=row.extension,
argument=None)
argument=None,
mediaserver=row.mediaserver)
for row in query)
......@@ -156,7 +161,8 @@ def service_hints(session, context):
def forward_hints(session, context):
query = (session.query(Extension.exten.label('extension'),
UserFeatures.id.label('user_id'),
FuncKeyDestForward.number.label('argument'))
FuncKeyDestForward.number.label('argument'),
LineFeatures.configregistrar.label('mediaserver'))
.join(FuncKeyDestForward,
FuncKeyDestForward.extension_id == Extension.id)
.join(FuncKeyMapping,
......@@ -166,7 +172,8 @@ def forward_hints(session, context):
return tuple(Hint(user_id=row.user_id,
extension=clean_extension(row.extension),
argument=row.argument)
argument=row.argument,
mediaserver=row.mediaserver)
for row in query)
......@@ -184,7 +191,8 @@ def agent_hints(session, context):
return tuple(Hint(user_id=row.user_id,
extension=clean_extension(row.extension),
argument=row.argument)
argument=row.argument,
mediaserver='default')
for row in query)
......@@ -197,7 +205,8 @@ def custom_hints(session, context):
return tuple(Hint(user_id=None,
extension=row.extension,
argument=None)
argument=None,
mediaserver=None)
for row in query)
......@@ -224,5 +233,6 @@ def bsfilter_hints(session, context):
return tuple(Hint(user_id=None,
extension=bsfilter_extension,
argument=row.argument)
argument=row.argument,
mediaserver=None)
for row in query)
......@@ -225,5 +225,5 @@ class ForwardTypeConverter(object):
return self.fwd_types[model_type]
Hint = namedtuple('Hint', ['user_id', 'extension', 'argument'])
Hint = namedtuple('Hint', ['user_id', 'extension', 'argument', 'mediaserver'])
Forward = namedtuple('Forward', ['user_id', 'type', 'number'])
......@@ -59,20 +59,22 @@ class TestHints(DAOTestCase, FuncKeyHelper):
self.setup_funckeys()
self.context = 'mycontext'
def add_user_and_func_key(self, protocol='sip', protocol_id=None, exten='1000', commented=0, enablehint=1):
def add_user_and_func_key(self, protocol='sip', protocol_id=None, exten='1000', commented=0, enablehint=1, configregistrar='default'):
if not protocol_id:
protocol_id = self.add_usersip().id
user_row = self.add_user_line_extension(protocol, protocol_id, exten, commented, enablehint)
user_row = self.add_user_line_extension(protocol, protocol_id, exten, commented, enablehint, configregistrar)
self.add_user_destination(user_row.id)
return user_row
def add_user_line_extension(self, protocol, protocol_id, exten, commented=0, enablehint=1):
def add_user_line_extension(self, protocol, protocol_id, exten, commented=0, enablehint=1, configregistrar='default'):
user_row = self.add_user(enablehint=enablehint)
line_row = self.add_line(context=self.context,
protocol=protocol,
protocolid=protocol_id,
commented=commented)
commented=commented,
configregistrar=configregistrar)
extension_row = self.add_extension(exten=exten, context=self.context)
self.add_user_line(user_id=user_row.id,
......@@ -85,13 +87,26 @@ class TestHints(DAOTestCase, FuncKeyHelper):
class TestUserHints(TestHints):
def test_given_user_with_sip_line_then_returns_user_hint(self):
def test_given_user_with_sip_line_then_returns_user_hint_on_main(self):
usersip_row = self.add_usersip(name='abcdef')
user_row = self.add_user_and_func_key('sip', usersip_row.id)
expected = Hint(user_id=user_row.id,
extension='1000',
argument='SIP/abcdef')
argument='SIP/abcdef',
mediaserver='default')
assert_that(hint_dao.user_hints(self.context), contains(expected))
def test_given_user_with_sip_line_then_returns_user_hint_on_mds(self):
self.add_mediaserver(name='mds1', display_name='MDS1', voip_ip='10.10.0.1')
usersip_row = self.add_usersip(name='abcdef')
user_row = self.add_user_and_func_key('sip', usersip_row.id, 1000, 0, 1, 'mds1')
expected = Hint(user_id=user_row.id,
extension='1000',
argument='SIP/abcdef',
mediaserver='mds1')
assert_that(hint_dao.user_hints(self.context), contains(expected))
......@@ -101,7 +116,8 @@ class TestUserHints(TestHints):
expected = Hint(user_id=user_row.id,
extension='1001',
argument='SCCP/1001')
argument='SCCP/1001',
mediaserver='default')
assert_that(hint_dao.user_hints(self.context), contains(expected))
......@@ -111,7 +127,8 @@ class TestUserHints(TestHints):
expected = Hint(user_id=user_row.id,
extension='1002',
argument='ghijkl')
argument='ghijkl',
mediaserver='default')
assert_that(hint_dao.user_hints(self.context), contains(expected))
......@@ -147,7 +164,8 @@ class TestConferenceHints(TestHints):
expected = Hint(user_id=None,
extension=conf_row.confno,
argument=None)
argument=None,
mediaserver='default')
assert_that(hint_dao.conference_hints(self.context), contains(expected))
......@@ -166,7 +184,7 @@ class TestConferenceHints(TestHints):
class TestServiceHints(TestHints):
def test_given_service_func_key_then_returns_service_hint(self):
def test_given_service_func_key_then_returns_service_hint_on_mzin(self):
destination_row = self.create_service_func_key('*25', 'enablednd')
user_row = self.add_user_and_func_key()
......@@ -174,7 +192,20 @@ class TestServiceHints(TestHints):
expected = Hint(user_id=user_row.id,
extension='*25',
argument=None)
argument=None,
mediaserver='default')
def test_given_service_func_key_then_returns_service_hint_on_mds(self):
self.add_mediaserver(name='mds1', display_name='MDS1', voip_ip='10.10.0.1')
destination_row = self.create_service_func_key('*25', 'enablednd')
user_row = self.add_user_and_func_key('sip', None, '1000', 0, 1, 'mds1')
self.add_func_key_to_user(destination_row, user_row)
expected = Hint(user_id=user_row.id,
extension='*25',
argument=None,
mediaserver='mds1')
assert_that(hint_dao.service_hints(self.context), contains(expected))
......@@ -205,7 +236,7 @@ class TestServiceHints(TestHints):
class TestForwardHints(TestHints):
def test_given_forward_func_key_then_returns_forward_hint(self):
def test_given_forward_func_key_then_returns_forward_hint_on_main(self):
destination_row = self.create_forward_func_key('_*23.', 'fwdbusy', '1234')
user_row = self.add_user_and_func_key()
......@@ -213,7 +244,22 @@ class TestForwardHints(TestHints):
expected = Hint(user_id=user_row.id,
extension='*23',
argument='1234')
argument='1234',
mediaserver='default')
assert_that(hint_dao.forward_hints(self.context), contains(expected))
def test_given_forward_func_key_then_returns_forward_hint_on_mds(self):
self.add_mediaserver(name='mds1', display_name='MDS1', voip_ip='10.10.0.1')
destination_row = self.create_forward_func_key('_*23.', 'fwdbusy', '1234')
user_row = self.add_user_and_func_key('sip', None, '1000', 0, 1, 'mds1')
self.add_func_key_to_user(destination_row, user_row)
expected = Hint(user_id=user_row.id,
extension='*23',
argument='1234',
mediaserver='mds1')
assert_that(hint_dao.forward_hints(self.context), contains(expected))
......@@ -225,7 +271,8 @@ class TestForwardHints(TestHints):
expected = Hint(user_id=user_row.id,
extension='*23',
argument=None)
argument=None,
mediaserver='default')
assert_that(hint_dao.forward_hints(self.context), contains(expected))
......@@ -261,7 +308,8 @@ class TestForwardHints(TestHints):
expected = Hint(user_id=user_row.id,
extension='*23',
argument='1234')
argument='1234',
mediaserver='default')
assert_that(hint_dao.forward_hints(self.context), contains(expected))
......@@ -276,7 +324,8 @@ class TestAgentHints(TestHints):
expected = Hint(user_id=user_row.id,
extension='*31',
argument=str(destination_row.agent_id))
argument=str(destination_row.agent_id),
mediaserver='default')
assert_that(hint_dao.agent_hints(self.context), contains(expected))
......@@ -312,7 +361,8 @@ class TestAgentHints(TestHints):
expected = Hint(user_id=user_row.id,
extension='*31',
argument=str(destination_row.agent_id))
argument=str(destination_row.agent_id),
mediaserver='default')
assert_that(hint_dao.agent_hints(self.context), contains(expected))
......@@ -327,7 +377,8 @@ class TestCustomHints(TestHints):
expected = Hint(user_id=None,
extension='1234',
argument=None)
argument=None,
mediaserver=None)
assert_that(hint_dao.custom_hints(self.context), contains(expected))
......@@ -382,7 +433,8 @@ class TestBSFilterHints(TestHints):
expected = Hint(user_id=None,
extension='*37',
argument=str(filtermember_row.id))
argument=str(filtermember_row.id),
mediaserver=None)
assert_that(hint_dao.bsfilter_hints(self.context), contains(expected))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment