Esempio n. 1
0
    def test_play_output_file(self):
        """
        Ensure tlog-play will redirect output to file
        """

        outputfile = mklogfile(self.tempdir)
        recordedtext = 'output_test'
        shell = ssh_pexpect(self.user1, 'Secret123', 'localhost')
        shell.sendline(f'tlog-rec -w journal echo {recordedtext}')
        time.sleep(5)

        entry = journal_find_last()
        message = entry['MESSAGE']
        rec = ast.literal_eval(message)['rec']
        tlog_rec = 'TLOG_REC={}'.format(rec)

        playcmd = f'tlog-play -r journal -M {tlog_rec} > {outputfile}'
        shell2 = ssh_pexpect(self.user1, 'Secret123', 'localhost')
        shell2.sendline(playcmd)
        time.sleep(5)

        with open(outputfile) as f:
            read_data = f.read()
            assert recordedtext in read_data
        f.closed
Esempio n. 2
0
    def test_record_from_different_hostnames(self):
        """
        Check tlog-rec reflects hostname changes in recordings

        This is to simulate receiving remote journal sessions
        """
        oldname = socket.gethostname()
        shell = pexpect.spawn('/bin/bash')
        for num in range(0, 3):
            newname = 'test{}-{}'.format(num, oldname)
            socket.sethostname(newname)
            open('/etc/hostname', 'w').write(newname)
            shell.sendline('hostname')
            shell.expect(newname)
            time.sleep(1)
            shell.sendline('tlog-rec -w journal whoami')
            time.sleep(1)
            shell.sendline('hostnamectl status')
            time.sleep(1)
            entry = journal_find_last()
            message = entry['MESSAGE']
            mhostname = ast.literal_eval(message)['host']
            assert mhostname == newname
            time.sleep(1)
        socket.sethostname(oldname)
        open('/etc/hostname', 'w').write(oldname)
Esempio n. 3
0
    def test_record_from_different_hostnames(self):
        """
        Check tlog-rec reflects hostname changes in recordings

        This is to simulate receiving remote journal sessions
        """
        oldname = socket.gethostname()
        shell = pexpect.spawn('/bin/bash')
        for num in range(0, 3):
            newname = 'test{}-{}'.format(num, oldname)
            socket.sethostname(newname)
            open('/etc/hostname', 'w').write(newname)
            shell.sendline('hostname')
            shell.expect(newname)
            time.sleep(1)
            shell.sendline('tlog-rec -w journal whoami')
            time.sleep(1)
            shell.sendline('hostnamectl status')
            time.sleep(1)
            entry = journal_find_last()
            message = entry['MESSAGE']
            mhostname = ast.literal_eval(message)['host']
            assert mhostname == newname
            time.sleep(1)
        socket.sethostname(oldname)
        open('/etc/hostname', 'w').write(oldname)
Esempio n. 4
0
    def test_play_from_journal(self):
        """
        Check tlog-play can playback session from journal
        """
        shell = ssh_pexpect(self.user1, 'Secret123', 'localhost')
        mkrecording(shell, sleep=4)
        shell.close()

        entry = journal_find_last()
        message = entry['MESSAGE']
        rec = ast.literal_eval(message)['rec']
        tlog_rec = 'TLOG_REC={}'.format(rec)
        cmd = 'tlog-play -r journal -M {}'.format(tlog_rec)
        shell2 = ssh_pexpect(self.user1, 'Secret123', 'localhost')
        shell2.sendline(cmd)
        out = shell2.expect([pexpect.TIMEOUT, 'KNOWN BUGS'], timeout=10)
        assert out == 1
Esempio n. 5
0
    def test_play_from_journal(self):
        """
        Check tlog-play can playback session from journal
        """
        shell = ssh_pexpect(self.user1, 'Secret123', 'localhost')
        mkrecording(shell, sleep=4)
        shell.close()

        entry = journal_find_last()
        message = entry['MESSAGE']
        rec = ast.literal_eval(message)['rec']
        tlog_rec = 'TLOG_REC={}'.format(rec)
        cmd = 'tlog-play -r journal -M {}'.format(tlog_rec)
        shell2 = ssh_pexpect(self.user1, 'Secret123', 'localhost')
        shell2.sendline(cmd)
        out = shell2.expect([pexpect.TIMEOUT, 'localhost'], timeout=10)
        assert out == 1