예제 #1
0
    def runTest(self):
        print("\n############## Running telnet tests ################\n")
        for connection in self.conns:
            test = Test()
            test.set_test_method("Telnet socket connect test")
            ip = connection
            port = self.conns[connection]
            print("\n####### connecting to " + ip + " : " + str(port) +
                  " ########\n")
            try:
                tn = telnetlib.Telnet(ip, port)
                print(tn.read_all())
                test.set_message("Successfully connected to: " + connection +
                                 ":" + conns[connection])
                test.set_result("Success")
                tn.close()

            except TimeoutError as e:
                test.set_message("Failed to connect to: " + connection + ":" +
                                 str(conns[connection]) + " with error \n" +
                                 "Time Out Error error({0}): {1}".format(
                                     e.errno, e.strerror))
                test.set_result("failed")
                print("Time Out Error error({0}): {1}".format(
                    e.errno, e.strerror))
            self.testResults.append(test)
예제 #2
0
    def test(self):
        for x in self.urls:
            test = Test()
            print("calling: " + x)
            try:
                r = requests.get(url=x)

                if r.status_code < 300:
                    test.set_message("Success with status code " +
                                     str(r.status_code))
                    test.set_result("Success")
                elif r.status_code < 400:
                    test.set_message("Redirect with status code " +
                                     str(r.status_code))
                    test.set_result("failed")
                elif r.status_code < 500:
                    test.set_message("Bad request with status code " +
                                     str(r.status_code))
                    test.set_result("failed")
                else:
                    test.set_message(
                        "internal server error with status code " +
                        str(r.status_code))
                    test.set_result("failed")
            except requests.exceptions.ConnectionError as e:
                test.set_message("connection failed")
            self.testResults.append(test)
예제 #3
0
 def runTest(self):
     for connection in self.conns:
         test = Test()
         test.set_test_method("ping")
         resp = ""
         ip = connection
         try:
             op = subprocess.check_output(["ping", ip, "-n", "3"])
             x = str(op)
             y = x.split("\\r\\n")
             for i in y:
                 if not ('b\'' in i) and not ("'" in i):
                     resp += i + "\n"
             test.set_message(resp)
             test.set_result("Success")
             self.testResults.append(test)
         except subprocess.CalledProcessError as e:
             print(e)
             test.set_message("Request failed")
             test.set_result("failed")
             self.testResults.append(test)