예제 #1
0
def test_ls():
    ssh_con = SSHconnection(hostname, username, password, port)
    out, err = ssh_con.execute_command("ls /home/pi")
    print("output from Raspberry Pi: " + out)
    # assert out == ""
    assert out != ""
    ssh_con.close()
예제 #2
0
def test_top():
    ssh_con = SSHconnection(hostname, username, password, port)
    out, err = ssh_con.execute_command_buffer("top")
    print("output from Raspberry Pi: " + out)
    # assert out == ""
    #assert out != ""
    ssh_con.close()
예제 #3
0
def test_ls():
    ssh_con = SSHconnection(hostname, username, password, port)
    cmd1 = "ls -l /usr"
    out, err = ssh_con.execute_command(cmd1)
    print("output from Linux host {}: ".format(hostname, out))
    # assert out == ""
    assert out != ""
    ssh_con.close()
예제 #4
0
def test_dmesg(logger):
    ssh_con = SSHconnection(hostname, username, password, port)
    out, err = ssh_con.execute_command_buffer("dmesg")
    print("output from Raspberry Pi: " + out)
    logger.info("output from Raspberry Pi: " + out)
    # assert out == ""
    #assert out != ""
    ssh_con.close()
예제 #5
0
def test_any_command(cmd):
    err = ""
    ssh_con = SSHconnection(hostname, username, password, port)
    out, err = ssh_con.execute_command(cmd)
    if err != "":
        print(err)

    print("output from '{}': \n {}".format(cmd, out))
    ssh_con.close()
예제 #6
0
def test_ls_negative():
    ssh_con = SSHconnection(hostname, username, password, port)
    out, err = ssh_con.execute_command("ls /not_exists")
    if out != "":
        print("output from Raspberry Pi: " + out)
        raise FileExistsError("Expect error")

    assert err == ""
    ssh_con.close()
예제 #7
0
    def process(self, request):
        ssh_con = SSHconnection(hostname, username, password, port)
        print("request = " + request)

        # Execute test based on test case name
        if request.find("test_ls") != -1:
            result, err = ssh_con.execute_command("ls /home/pi")
            print("output from RP: " + result)
        else:
            result = "Unknown test case"

        ssh_con.close()
        return result
예제 #8
0
def test_ls_update():
    ssh_con = SSHconnection(hostname, username, password, port)
    out, err = ssh_con.execute_command("ls /home/pi")
    print("output from Raspberry Pi: " + out)

    if out == "":
        result = "fail"
    else:
        result = "pass"

    testid = 1234
    testname = "test_ls"
    testtime = str(datetime.now())
    db.execute("UPDATE testrecords SET testtime = ? WHERE (testid = ?)",
               (testtime, testid))
    db.commit()

    ssh_con.close()
    assert out != ""
예제 #9
0
def test_ls():
    ssh_con = SSHconnection(hostname, username, password, port)
    out, err = ssh_con.execute_command("ls /home/pi")
    print("output from Raspberry Pi: " + out)

    if out == "":
        result = "fail"
    else:
        result = "pass"

    testid = 1234
    testname = "test_ls"
    testtime = str(datetime.now())
    db.execute("INSERT INTO testrecords VALUES(?, ?, ?, ?)",
               (testid, testname, result, testtime))
    db.commit()

    ssh_con.close()
    assert out != ""
예제 #10
0
    def process_all(self, request):
        ssh_con = SSHconnection(hostname, username, password, port)
        print("request = " + request)

        test_names = request.split("&")

        result = {}
        print(test_names)
        for test in test_names:
            test = test.replace("testcase=", "")
            print(test)
            if test.find("test_ls") != -1:
                out, err = ssh_con.execute_command("ls /home/pi")
                print("output from 'ls /home/pi': " + out)
                result[test] = out
            elif test.find("test_cd") != -1:
                out = " "
                out, err = ssh_con.execute_command("cd /home")
                #out, err = ssh_con.execute_command("cd /root")
                print("output from 'cd /root': " + out)
                if err != "":
                    result[test] = err
                else:
                    result[test] = out
            else:
                result["result"] = "Unknown test case"

        print(result)

        ssh_con.close()

        return result
예제 #11
0
def test_ls_negative():
    ssh_con = SSHconnection(hostname, username, password, port)
    # Pass test:
    # out, err = ssh_con.execute_command("ls /not_exists")

    # Fail test:
    out, err = ssh_con.execute_command("ls /home/pi")

    if out != "":
        result = "fail"
    else:
        result = "pass"

    testid = 56872
    testname = "test_ls_negative"
    testtime = str(datetime.now())
    print("time = " + testtime)
    db.execute("INSERT INTO testrecords VALUES(?, ?, ?, ?)",
               (testid, testname, result, testtime))

    db.commit()
    ssh_con.close()
예제 #12
0
    def setup_class(cls):  # cls is similar to self
        """
        This code will be run before any test case
        """
        print("setup_class is called for class: {}".format(cls.__name__))

        # Getting a logger instance
        cls.log = logging.getLogger(__name__)
        #cls.log = logging.getLogger()  # get default logger "ROOT"
        cls.log.info("Calling Mytest:setup_class")

        # Add the log message handler to the logger
        handler = logging.handlers.RotatingFileHandler(
            LOG_FILENAME,
            maxBytes=5000,  # max size of log file
            backupCount=3,  # how many log files to keep
        )
        cls.log.addHandler(handler)
        # Create SSH Client connection to test device
        cls.ssh_con = SSHconnection(hostname, username, password, port)