Commit 5cab3200 authored by Laurent Meiller's avatar Laurent Meiller

Merge branch '2361-generate-sip-registration-locally' into 'master'

2361 generate sip registration locally

See merge request !41
parents a28f2f3b cdd4cd57
......@@ -7,6 +7,7 @@ xivo-dao (2019.03.00) xivo-callisto; urgency=medium
[ Vojtech Sodoma ]
* 2359 Be able to set mds0 only for SIP Trunk configuration
* 2361 Generate SIP registration only for local trunks of the MDS
-- Laurent Meiller <lmeiller@avencall.com> Mon, 25 Feb 2019 14:44:06 +0100
......
......@@ -406,8 +406,24 @@ def find_voicemail_general_settings(session):
@daosession
def find_sip_general_settings(session):
rows = session.query(StaticSIP).filter(StaticSIP.commented == 0).all()
def find_sip_general_settings(session, current_mds_name):
rows = session.query(
StaticSIP
).outerjoin(
TrunkFeatures, StaticSIP.id == TrunkFeatures.registerid
).outerjoin(
MediaServer, TrunkFeatures.mediaserverid == MediaServer.id
).filter(
and_(
StaticSIP.id != None, # noqa
StaticSIP.commented == 0,
or_(
MediaServer.name == None,
MediaServer.name == 'all_mds',
MediaServer.name == current_mds_name
)
)
).all()
res = []
for row in rows:
......
......@@ -787,18 +787,36 @@ class TestAsteriskConfDAO(DAOTestCase, PickupHelperMixin):
assert_that(voicemail_settings, contains_inanyorder(*expected_result))
def test_find_sip_general_settings(self):
self.add_netiface(networktype='voip', address='1.1.1.1')
local_mds = self.add_mediaserver(name='mds1', display_name='MDS1', voip_ip='10.10.0.1')
remote_mds = self.add_mediaserver(name='mds2', display_name='MDS2', voip_ip='10.10.0.2')
global_mds = self.add_mediaserver(name='all_mds', display_name='All MDS', voip_ip='10.10.0.3')
local_trunk = self.add_usersip(category='trunk', name='trunk1')
local_register = self.add_sip_general_settings(var_name='register', var_val='udp://mds1-register:passwd:mds1@192.168.56.201')
self.add_sip_trunk(protocol='sip', protocolid=local_trunk.id, mediaserverid=local_mds.id, registerid=local_register.id)
remote_trunk = self.add_usersip(category='trunk', name='trunk2')
remote_register = self.add_sip_general_settings(var_name='register', var_val='udp://mds2-register:passwd:mds2@192.168.56.202')
self.add_sip_trunk(protocol='sip', protocolid=remote_trunk.id, mediaserverid=remote_mds.id, registerid=remote_register.id)
global_trunk = self.add_usersip(category='trunk', name='trunk3')
global_register = self.add_sip_general_settings(var_name='register', var_val='udp://mds3-register:passwd:mds3@192.168.56.203')
self.add_sip_trunk(protocol='sip', protocolid=global_trunk.id, mediaserverid=global_mds.id, registerid=global_register.id)
sip1 = self.add_sip_general_settings()
sip2 = self.add_sip_general_settings()
self.add_sip_general_settings(commented=1)
expected_result = [
{'var_name': local_register.var_name,
'var_val': local_register.var_val},
{'var_name': global_register.var_name,
'var_val': global_register.var_val},
{'var_name': sip1.var_name,
'var_val': sip1.var_val},
{'var_name': sip2.var_name,
'var_val': sip2.var_val},
]
sip_settings = asterisk_conf_dao.find_sip_general_settings()
sip_settings = asterisk_conf_dao.find_sip_general_settings(local_mds.name)
assert_that(sip_settings, contains_inanyorder(*expected_result))
......
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