[Asterisk-code-review] app_mixmonitor: test for MixMonitorMute by MixMonitor ID (testsuite[master])
Friendly Automation
asteriskteam at digium.com
Mon Mar 20 09:53:29 CDT 2023
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/testsuite/+/20000 )
Change subject: app_mixmonitor: test for MixMonitorMute by MixMonitor ID
......................................................................
app_mixmonitor: test for MixMonitorMute by MixMonitor ID
Test the ability to retrieve the mixmonitor ID from dialplan
then use it to mute and stop individual mixmonitor instances
Also test that sending a mute action without specifying
the mixmonitor ID results in the action happening on
all instances.
Requires coresponding Asterisk change to pass.
ASTERISK-30464
Change-Id: I05cf277d2905a9024020aedf0ab389b528237fa3
---
R tests/manager/mixmonitor/mixmonitor_basic/configs/ast1/extensions.conf
R tests/manager/mixmonitor/mixmonitor_basic/test-config.yaml
A tests/manager/mixmonitor/mixmonitor_id/configs/ast1/extensions.conf
A tests/manager/mixmonitor/mixmonitor_id/run-test
A tests/manager/mixmonitor/mixmonitor_id/test-config.yaml
A tests/manager/mixmonitor/tests.yaml
M tests/manager/tests.yaml
7 files changed, 222 insertions(+), 2 deletions(-)
Approvals:
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/tests/manager/mixmonitor/configs/ast1/extensions.conf b/tests/manager/mixmonitor/mixmonitor_basic/configs/ast1/extensions.conf
similarity index 100%
rename from tests/manager/mixmonitor/configs/ast1/extensions.conf
rename to tests/manager/mixmonitor/mixmonitor_basic/configs/ast1/extensions.conf
diff --git a/tests/manager/mixmonitor/test-config.yaml b/tests/manager/mixmonitor/mixmonitor_basic/test-config.yaml
similarity index 98%
rename from tests/manager/mixmonitor/test-config.yaml
rename to tests/manager/mixmonitor/mixmonitor_basic/test-config.yaml
index 2ee5b6c..03b986c 100644
--- a/tests/manager/mixmonitor/test-config.yaml
+++ b/tests/manager/mixmonitor/mixmonitor_basic/test-config.yaml
@@ -49,7 +49,7 @@
Action: 'MixMonitor'
Channel: '{channel}'
File: 'theRecording.wav'
- Options: 'r'
+ Options: 'ri(monty)'
-
ami-events:
conditions:
diff --git a/tests/manager/mixmonitor/mixmonitor_id/configs/ast1/extensions.conf b/tests/manager/mixmonitor/mixmonitor_id/configs/ast1/extensions.conf
new file mode 100644
index 0000000..abd0555
--- /dev/null
+++ b/tests/manager/mixmonitor/mixmonitor_id/configs/ast1/extensions.conf
@@ -0,0 +1,21 @@
+[default]
+exten => talk,1,Answer()
+ same => n,UserEvent(startone)
+ same => n,Wait(1)
+ same => n,UserEvent(starttwo)
+ same => n,Wait(1)
+ same => n,UserEvent(muteone)
+ same => n,Wait(1)
+ same => n,UserEvent(mutetwo)
+ same => n,Wait(1)
+ same => n,UserEvent(unmute)
+ same => n,Wait(1)
+ same => n,UserEvent(stopone)
+ same => n,Wait(1)
+ same => n,UserEvent(stoptwo)
+ same => n,Wait(5)
+ same => n,Hangup()
+
+exten => echo,1,Answer()
+ same => n,Echo()
+ same => n,Hangup()
\ No newline at end of file
diff --git a/tests/manager/mixmonitor/mixmonitor_id/run-test b/tests/manager/mixmonitor/mixmonitor_id/run-test
new file mode 100755
index 0000000..ef8a01e
--- /dev/null
+++ b/tests/manager/mixmonitor/mixmonitor_id/run-test
@@ -0,0 +1,159 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2023, Sangoma Technologies.
+Michael Bradeen <mbradeen at sangoma.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import sys
+import logging
+from twisted.internet import reactor
+from asterisk.test_case import TestCase
+
+LOGGER = logging.getLogger(__name__)
+
+class MixMonitorTest(TestCase):
+ def __init__(self):
+ super(MixMonitorTest, self).__init__()
+
+ self.passed = False
+ self.startCount = 0
+ self.passedStart = False
+ self.muteCount = 0
+ self.passedMute = False
+ self.passedUnMute = False
+ self.stopCount = 0
+ self.passedStop = False
+ self.mixmonid1 = ""
+ self.mixmonid2 = ""
+ self.create_asterisk()
+
+
+ def __checkPass(self):
+ self.passed = self.passedStart and self.passedMute and self.passedUnMute and self.passedStop
+
+ LOGGER.info("Checking Test Pass/Fail")
+ LOGGER.info("Passed Start: " + str(self.passedStart))
+ LOGGER.info("Passed Mute: " + str(self.passedMute))
+ LOGGER.info("Passed UnMute: " + str(self.passedUnMute))
+ LOGGER.info("Passed Stop: " + str(self.passedStop))
+ LOGGER.info("Passed All: " + str(self.passed))
+
+ def launch_test(self):
+ LOGGER.info("Placing call to local talking extension")
+ self.ami.originate(channel="Local/talk at default",
+ context="default",
+ exten="echo",
+ priority="1")
+
+ def check_teststate(self, ami, event):
+
+ def switchState(teststate, channel):
+ message = {'Action': 'None', }
+ if teststate == "startone":
+ message = {'Action': 'MixMonitor', 'Channel': channel,
+ 'File': 'oneRecording.wav', 'Options': 'ri(idone)'}
+ elif teststate == "starttwo":
+ message = {'Action': 'MixMonitor', 'Channel': channel,
+ 'File': 'twoRecording.wav', 'Options': 'ri(idtwo)'}
+ elif teststate == "muteone":
+ message = {'Action': 'MixMonitorMute', 'Channel': channel,
+ 'Direction': 'both', 'State': '1', 'MixMonitorID': self.mixmonid1}
+ elif teststate == "mutetwo":
+ message = {'Action': 'MixMonitorMute', 'Channel': channel,
+ 'Direction': 'both', 'State': '1', 'MixMonitorID': self.mixmonid2}
+ elif teststate == "unmute":
+ message = {'Action': 'MixMonitorMute', 'Channel': channel,
+ 'Direction': 'both', 'State': '0'}
+ elif teststate == "stopone":
+ message = {'Action': 'StopMixMonitor', 'Channel': channel,
+ 'MixMonitorID': self.mixmonid1}
+ elif teststate == "stoptwo":
+ message = {'Action': 'StopMixMonitor', 'Channel': channel,
+ 'MixMonitorID': self.mixmonid2}
+ return message
+
+ LOGGER.info("Checking UserEvent")
+ self.ami.sendMessage(switchState(event.get("userevent").lower(), event.get("channel")))
+ return
+
+ def check_start_mixmonitor(self, ami, event):
+
+ self.startCount+=1
+ LOGGER.info("Checking MixMonitorStart " + str(self.startCount))
+ if self.startCount == 2 :
+ self.passedStart = True
+ return
+
+ def check_chanvar(self, ami, event):
+
+ def switchState(event):
+ VarName = event.get("variable").lower()
+ VarVal = event.get("value")
+ if VarName == "idone":
+ LOGGER.info("Setting idone:" + VarVal)
+ self.mixmonid1 = VarVal
+ elif VarName == "idtwo":
+ LOGGER.info("Setting idtwo:" + VarVal)
+ self.mixmonid2 = VarVal
+
+ LOGGER.info("Checking VarSet")
+ switchState(event)
+ return
+
+ def check_mute_mixmonitor(self, ami, event):
+ self.muteCount+=1
+ LOGGER.info("Checking MixMonitorMute " + str(self.muteCount))
+ if self.muteCount == 2 :
+ self.passedMute = True
+ return
+
+ def check_testevent(self, ami, event):
+ LOGGER.info("Checking TestEvent")
+
+ # only look for source and count for a mute toggle
+ if event.get("state") == "AUDIOHOOK_GROUP_MUTE_TOGGLE":
+ if event.get("source") == "MixMonitor" and event.get("count") == "2" :
+ self.passedUnMute = True
+ return
+
+ def check_stop_mixmonitor(self, ami, event):
+ self.stopCount+=1
+ LOGGER.info("Checking MixMonitorStop " + str(self.stopCount))
+ if self.stopCount == 2 :
+ self.passedStop = True
+ self.__checkPass()
+ # stop reactor at final MixMonitorStop
+ reactor.stop()
+ return
+
+ def ami_connect(self, ami):
+ self.ami = ami
+ self.ami.registerEvent("UserEvent", self.check_teststate)
+ self.ami.registerEvent("TestEvent", self.check_testevent)
+ self.ami.registerEvent("MixMonitorStart", self.check_start_mixmonitor)
+ self.ami.registerEvent("MixMonitorMute", self.check_mute_mixmonitor)
+ self.ami.registerEvent("MixMonitorStop", self.check_stop_mixmonitor)
+ self.ami.registerEvent("VarSet", self.check_chanvar)
+
+ self.launch_test()
+
+ def run(self):
+ self.create_ami_factory()
+
+
+def main():
+ test = MixMonitorTest()
+ reactor.run()
+ if test.passed:
+ return 0
+ return 1
+
+
+if __name__ == "__main__":
+ sys.exit(main() or 0)
+
+
+# vim:sw=4:ts=4:expandtab:textwidth=79
diff --git a/tests/manager/mixmonitor/mixmonitor_id/test-config.yaml b/tests/manager/mixmonitor/mixmonitor_id/test-config.yaml
new file mode 100644
index 0000000..5a903d2
--- /dev/null
+++ b/tests/manager/mixmonitor/mixmonitor_id/test-config.yaml
@@ -0,0 +1,15 @@
+testinfo:
+ summary: 'Tests that the MixMonitor id channel variable'
+ description: |
+ 'This test verifies that the MixMonitor id channel variable can be used to
+ stop and mute individually running MixMonitor instances.'
+
+properties:
+ dependencies:
+ - python : 'twisted'
+ - python : 'starpy'
+ - asterisk : 'app_echo'
+ - asterisk : 'app_mixmonitor'
+ - asterisk : 'app_userevent'
+ tags:
+ - mixmonitor
diff --git a/tests/manager/mixmonitor/tests.yaml b/tests/manager/mixmonitor/tests.yaml
new file mode 100644
index 0000000..18d4900
--- /dev/null
+++ b/tests/manager/mixmonitor/tests.yaml
@@ -0,0 +1,5 @@
+# Enter tests here in the order they should be considered for execution:
+tests:
+ - test: 'mixmonitor_basic'
+ - test: 'mixmonitor_id'
+
diff --git a/tests/manager/tests.yaml b/tests/manager/tests.yaml
index 1f0dccf..993b966 100644
--- a/tests/manager/tests.yaml
+++ b/tests/manager/tests.yaml
@@ -14,7 +14,7 @@
- test: 'exten_state_list'
- test: 'presence_state_changed'
- test: 'presence_state_list'
- - test: 'mixmonitor'
+ - dir: 'mixmonitor'
- test: 'manager_vars'
- test: 'status'
- test: 'status_all_vars'
--
To view, visit https://gerrit.asterisk.org/c/testsuite/+/20000
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Change-Id: I05cf277d2905a9024020aedf0ab389b528237fa3
Gerrit-Change-Number: 20000
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Bradeen <mbradeen at sangoma.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230320/b7df8dab/attachment-0001.html>
More information about the asterisk-code-review
mailing list