Exemplo n.º 1
0
def CommonSetup():
    if not v.failure_detected:
        try:
            tch_auto.log_h1('Load Testbed file')
            args = get_args()
            v.topo = tch_auto.load_topology(args.topo)
        except:
            v.failure_detected = True
            tch_auto.log_error(traceback.format_exc(6))

    tch_auto.log_info('Connect to devices')
    if not v.failure_detected:
        try:
            v.lnx1 = connect(v.topo.lnx1)
            v.lnx2 = connect(v.topo.lnx2)
            v.linphone1 = connect(v.topo.lnx1)
            v.linphone2 = connect(v.topo.lnx2)
            v.lnxs = [v.lnx1, v.lnx2]
            v.linphones = [v.linphone1, v.linphone2]
            v.linphone1.IP = v.topo.lnx1.interface.onboardEthernet.ip
            v.linphone2.IP = v.topo.lnx2.interface.onboardEthernet.ip

            for linphone in v.linphones:
                linphone.prompt = linphone.conn.get_prompt()
                #changing the prompt
                linphone.conn.set_prompt(re.compile(r'.*[$]|linphonec>'))
        except:
            v.failure_detected = True
            tch_auto.log_error(traceback.format_exc(6))
Exemplo n.º 2
0
    def setUp(self):
        tch_auto.log_h1('Common Setup')
        try:
            log_h1('Load Testbed file')
            args = get_args()
            v.topo = load_topology(args.topo)

        except:
            v.failure_detected = True
            tch_auto.log_error(traceback.format_exc(6))

        tch_auto.log_info('Connect to devices')
        if not v.failure_detected:
            try:
                v.lnx1 = connect(v.topo.lnx1)
                v.lnx2 = connect(v.topo.lnx2)
                v.linphone1 = connect(v.topo.lnx1)
                v.linphone2 = connect(v.topo.lnx2)
                v.lnxs = [v.lnx1, v.lnx2]
                v.linphones = [v.linphone1, v.linphone2]
                v.linphone1.IP = v.topo.lnx1.interface.pciEthernet1.ip
                v.linphone2.IP = v.topo.lnx2.interface.pciEthernet2.ip
            except:
                v.failure_detected = True
                tch_auto.log_error(traceback.format_exc(6))

        tch_auto.log_h1('Check validations in two linux machines')

        if not v.failure_detected:
            voip_test.create_null_sinks(v)
        if not v.failure_detected:
            cmds = []
            cmds.append('pactl load-module module-null-sink sink_name=fakemic')
            cmds.append(
                'pactl load-module module-null-sink sink_name=fakespeaker')

            for cmd in cmds:
                for lnx in v.linphones:
                    lnx.execute(cmd)

            validation = munch.munchify({'present': [], 'absent': []})
            cmd = 'pactl list short sources'
            validation.present.append(r'fakemic.monitor')
            validation.present.append(r'fakespeaker.monitor')
            if not v.lnx1.cmd_check(cmd, validation) or not v.lnx2.cmd_check(
                    cmd, validation):
                v.failure_detected = True

        self.assertEqual(v.failure_detected, False)
Exemplo n.º 3
0
 def tearDown(self):
     tch_auto.log_h1('Common CleanUP - Start')
     if v.failure_detected:
         voip_test.end_calls(v)
     for lnx in v.linphones:
         lnx.execute('killall pulseaudio')
     try:
         tch_auto.log_info('Clear all ssh console sessions')
         for linphone in v.linphones:
             linphone.close()
         for lnx in v.lnxs:
             lnx.close()
     except:
         tch_auto.log_error(traceback.format_exc(6))
     tch_auto.report(v)
     tch_auto.log_h1('Voip_test TestCase End')
Exemplo n.º 4
0
    def testTestRun(self):
        v.failure_detected = False
        tch_auto.log_h1('TestRun - Start')
        v.calls = False
        if not v.failure_detected:
            voip_test.start_linphones(v)

        if not v.failure_detected:
            duration = v.lnx1.execute('sox --i -D %s' % v.topo.lnx1.wavFile)
            voip_test.call_play_recored_wav(v)

        if not v.failure_detected:
            v.duration = float(duration) + time.time() + 60
            cmd = 'ls -l received.wav'
            buffer = []
            while v.duration > time.time():
                out = v.lnx2.execute(cmd)
                match = re.search(r'[-rwx]*\s+\w+\s+\w+\s+(\d+).*received.wav',
                                  out)
                if match:
                    buffer.append(match.group(1))
                if len(buffer) >= 3:
                    if len(set(buffer)) == 1:
                        tch_auto.log_info('Playback and recording completed')
                        v.failure_detected = False
                        voip_test.end_calls(v)
                        break
                    else:
                        buffer.pop(0)
                        tch_auto.log_info('Playback and recording in progress')

                else:
                    v.failure_detected = True
                time.sleep(10)

        if v.failure_detected:
            tch_auto.log_error(
                'Playback and recording was not completed in expected time')
            voip_test.end_calls(v)
        else:
            voip_test.validate_wav_files(v)
Exemplo n.º 5
0
def create_null_sinks(v):
    cmds = []
    cmds.append('killall pulseaudio')
    cmds.append('pulseaudio -D')
    for cmd in cmds:
        for lnx in v.linphones:
            lnx.execute(cmd)

    validation = munch.munchify({'present': [], 'absent': []})
    cmd = 'pactl list sources'
    validation.present.append(r'Name: auto_null.monitor')
    if not v.lnx1.cmd_check(cmd, validation) or not v.lnx2.cmd_check(
            cmd, validation):
        v.failure_detected = True

    cmd = 'pactl list sinks'
    validation = munch.munchify({'present': [], 'absent': []})
    validation.present.append(r'Driver: module-null-sink.c')

    if not v.lnx1.cmd_check(cmd, validation) or not v.lnx2.cmd_check(
            cmd, validation):
        v.failure_detected = True

    tch_auto.log_h1('create virtual mic/speaker on two linux machines')
Exemplo n.º 6
0
class Voip_test(unittest.TestCase):
    tch_auto.log_h1('Voip_test TestCase start')

    def setUp(self):
        tch_auto.log_h1('Common Setup')
        try:
            log_h1('Load Testbed file')
            args = get_args()
            v.topo = load_topology(args.topo)

        except:
            v.failure_detected = True
            tch_auto.log_error(traceback.format_exc(6))

        tch_auto.log_info('Connect to devices')
        if not v.failure_detected:
            try:
                v.lnx1 = connect(v.topo.lnx1)
                v.lnx2 = connect(v.topo.lnx2)
                v.linphone1 = connect(v.topo.lnx1)
                v.linphone2 = connect(v.topo.lnx2)
                v.lnxs = [v.lnx1, v.lnx2]
                v.linphones = [v.linphone1, v.linphone2]
                v.linphone1.IP = v.topo.lnx1.interface.pciEthernet1.ip
                v.linphone2.IP = v.topo.lnx2.interface.pciEthernet2.ip
            except:
                v.failure_detected = True
                tch_auto.log_error(traceback.format_exc(6))

        tch_auto.log_h1('Check validations in two linux machines')

        if not v.failure_detected:
            voip_test.create_null_sinks(v)
        if not v.failure_detected:
            cmds = []
            cmds.append('pactl load-module module-null-sink sink_name=fakemic')
            cmds.append(
                'pactl load-module module-null-sink sink_name=fakespeaker')

            for cmd in cmds:
                for lnx in v.linphones:
                    lnx.execute(cmd)

            validation = munch.munchify({'present': [], 'absent': []})
            cmd = 'pactl list short sources'
            validation.present.append(r'fakemic.monitor')
            validation.present.append(r'fakespeaker.monitor')
            if not v.lnx1.cmd_check(cmd, validation) or not v.lnx2.cmd_check(
                    cmd, validation):
                v.failure_detected = True

        self.assertEqual(v.failure_detected, False)

    def testTestRun(self):
        v.failure_detected = False
        tch_auto.log_h1('TestRun - Start')
        v.calls = False
        if not v.failure_detected:
            voip_test.start_linphones(v)

        if not v.failure_detected:
            duration = v.lnx1.execute('sox --i -D %s' % v.topo.lnx1.wavFile)
            voip_test.call_play_recored_wav(v)

        if not v.failure_detected:
            v.duration = float(duration) + time.time() + 60
            cmd = 'ls -l received.wav'
            buffer = []
            while v.duration > time.time():
                out = v.lnx2.execute(cmd)
                match = re.search(r'[-rwx]*\s+\w+\s+\w+\s+(\d+).*received.wav',
                                  out)
                if match:
                    buffer.append(match.group(1))
                if len(buffer) >= 3:
                    if len(set(buffer)) == 1:
                        tch_auto.log_info('Playback and recording completed')
                        v.failure_detected = False
                        voip_test.end_calls(v)
                        break
                    else:
                        buffer.pop(0)
                        tch_auto.log_info('Playback and recording in progress')

                else:
                    v.failure_detected = True
                time.sleep(10)

        if v.failure_detected:
            tch_auto.log_error(
                'Playback and recording was not completed in expected time')
            voip_test.end_calls(v)
        else:
            voip_test.validate_wav_files(v)

    def tearDown(self):
        tch_auto.log_h1('Common CleanUP - Start')
        if v.failure_detected:
            voip_test.end_calls(v)
        for lnx in v.linphones:
            lnx.execute('killall pulseaudio')
        try:
            tch_auto.log_info('Clear all ssh console sessions')
            for linphone in v.linphones:
                linphone.close()
            for lnx in v.lnxs:
                lnx.close()
        except:
            tch_auto.log_error(traceback.format_exc(6))
        tch_auto.report(v)
        tch_auto.log_h1('Voip_test TestCase End')
Exemplo n.º 7
0
def TestSetup():

    tch_auto.log_h1('TestSetup - Start')
    tch_auto.log_h1('Check validations in two linux machines')

    if not v.failure_detected:
        cmds = []
        cmds.append('killall pulseaudio')
        cmds.append('pulseaudio -D')
        for cmd in cmds:
            for lnx in v.linphones:
                lnx.execute(cmd)

        validation = munch.munchify({'present': [], 'absent': []})
        cmd = 'pactl list sources'
        validation.present.append(r'Name: auto_null.monitor')
        if not v.lnx1.cmd_check(cmd, validation) or not v.lnx2.cmd_check(
                cmd, validation):
            v.failure_detected = True

        cmd = 'pactl list sinks'
        validation = munch.munchify({'present': [], 'absent': []})
        validation.present.append(r'Driver: module-null-sink.c')

        if not v.lnx1.cmd_check(cmd, validation) or not v.lnx2.cmd_check(
                cmd, validation):
            v.failure_detected = True

    tch_auto.log_h1('create virtual mic/speaker on two linux machines')
    if not v.failure_detected:
        cmds = []
        cmds.append('pactl load-module module-null-sink sink_name=fakemic')
        cmds.append('pactl load-module module-null-sink sink_name=fakespeaker')

        for cmd in cmds:
            for lnx in v.linphones:
                lnx.execute(cmd)

        validation = munch.munchify({'present': [], 'absent': []})
        cmd = 'pactl list short sources'
        validation.present.append(r'fakemic.monitor')
        validation.present.append(r'fakespeaker.monitor')
        if not v.lnx1.cmd_check(cmd, validation) or not v.lnx2.cmd_check(
                cmd, validation):
            v.failure_detected = True

        cmds = []
        cmds.append('pactl set-default-sink fakespeaker')
        cmds.append('pactl set-default-source fakemic.monitor')

        for cmd in cmds:
            for lnx in v.linphones:
                lnx.execute(cmd)

        validation = munch.munchify({'present': [], 'absent': []})
        cmd = 'cat ~/.linphonerc'
        validation.present.append(r'[sound]')
        validation.present.append(r'playback_dev_id=PulseAudio: default')
        validation.present.append(r'ringer_dev_id=PulseAudio: default')
        validation.present.append(r'capture_dev_id=PulseAudio: default')

        if not v.linphone1.cmd_check(
                cmd, validation) or not v.linphone2.cmd_check(cmd, validation):
            v.failure_detected = True
Exemplo n.º 8
0
def TestRun():
    tch_auto.log_h1('TestRun - Start')
    if not v.failure_detected:
        for linphone in v.linphones:
            linphone.execute('killall linphone linphonec parecord paplay')
            # linphone.execute('killall linphonec')
            out = linphone.execute('linphonec')
            if 'Could not start udp' not in out:
                tch_auto.log_info('Linphone started successfully in %s' %
                                  linphone.Hostname)
            else:
                tch_auto.log_error('Linphone failed to start in %s' %
                                   linphone.Hostname)
                v.failure_detected = True

    if not v.failure_detected:
        if 'Auto answer enabled.' in v.linphone1.execute('autoanswer enable'):
            tch_auto.log_info('Auto answer enabled successfully in %s' %
                              v.linphone1.Hostname)

        pattern = 'Establishing call id to <sip:%s>, assigned id \d+.' % v.linphone1.IP
        cmd = 'call sip:%s' % v.linphone1.IP
        out = v.linphone2.execute(cmd)
        if pattern in out:
            tch_auto.log_info('Call getting established for %s' %
                              v.linphone1.Hostname)

        cmd = 'calls'
        validation = munch.munchify({'present': [], 'absent': []})
        validation.present.append(r'.*<sip:%s>.*StreamsRunning' %
                                  v.linphone1.IP)
        # validation.present.append(r'9  __PIPE__ <sip:10.78.192.120>                 __PIPE__ StreamsRunning  __PIPE__')
        if v.linphone2.cmd_check(cmd, validation, 6):
            cmds = []
            cmds.append('killall parecord paplay')
            cmds.append(
                'parecord --device=fakespeaker.monitor --file-format=wav received1.wav &'
            )
            cmds.append('paplay --device=fakemic Thendral.wav &')
            pid = {}
            for cmd in cmds:
                for lnx in v.lnxs:
                    if 'paplay' in cmd:
                        key = 'paplay'
                    else:
                        key = 'parecord'
                    out = lnx.execute(cmd)
                    m = re.search(r'\[\d\]+\s+(\d+)', out)
                    if m:
                        if lnx.Hostname in pid.keys():
                            pid[lnx.Hostname].update({key: m.group(1)})
                        else:
                            pid.update({lnx.Hostname: {key: m.group(1)}})
            cmd = 'pgrep paplay'
            while True:
                for lnx in v.lnxs:
                    tch_auto.log_info(lnx.Hostname)
                    out = lnx.execute(cmd)
                    if pid[lnx.Hostname]['paplay'] not in out:
                        lnx.execute('killall parecord')
                        pid[lnx.Hostname].update({'paplay': 'Done'})
                if pid[v.lnx1.Hostname]['paplay'] and pid[
                        v.lnx1.Hostname]['paplay'] != 'Done':
                    time.sleep(30)
                if pid[v.lnx1.Hostname]['paplay'] and pid[
                        v.lnx1.Hostname]['paplay'] == 'Done':
                    break
                if not v.failure_detected:
                    for linphone in v.linphones:
                        linphone.execute('terminate')
                        linphone.execute('quit')
Exemplo n.º 9
0

def get_args():
    """ Get arguments from CLI """

    parser.add_argument('-t',
                        '--topo',
                        required=False,
                        default='/auto/WiFi_automation/topo/topo.yaml',
                        help='Provide testbed file')

    args = parser.parse_args()
    return args


tch_auto.log_h1('Common Setup')


def CommonSetup():
    if not v.failure_detected:
        try:
            tch_auto.log_h1('Load Testbed file')
            args = get_args()
            v.topo = tch_auto.load_topology(args.topo)
        except:
            v.failure_detected = True
            tch_auto.log_error(traceback.format_exc(6))

    tch_auto.log_info('Connect to devices')
    if not v.failure_detected:
        try: