Ver código fonte

Fixes. Related to ftth#40

Guillermo Espinoza 6 anos atrás
pai
commit
1e8b72c902
3 arquivos alterados com 41 adições e 16 exclusões
  1. 3 0
      Huawei.py
  2. 11 6
      ObjectSsh.py
  3. 27 10
      ObjectTelnet.py

+ 3 - 0
Huawei.py

@@ -19,3 +19,6 @@ class Huawei(OLTBase):
 
     def run_enable_password(self):
         return False
+
+    def get_expected_cardinal(self):
+        return ["#","}:"]

+ 11 - 6
ObjectSsh.py

@@ -97,7 +97,12 @@ class ObjectSsh(ObjectConnection):
                     print "Send: "
                     print self.olt.get_write_exit()
                 self.stdin.write(self.olt.get_write_exit() + self.NEW_LINE_UNIX)
-                position = self.read_data([self.olt.get_expected_cardinal(), self.olt.get_expected_exit()])
+                cardinal = self.olt.get_expected_cardinal()
+                if isinstance(cardinal, list):
+                    read_data_list = cardinal + [self.olt.get_expected_exit()]
+                else:    
+                    read_data_list = [cardinal, self.olt.get_expected_exit()]
+                position = self.read_data(read_data_list)
                 if position == 2:
                     # quit terminal
                     if self.debug:
@@ -122,7 +127,7 @@ class ObjectSsh(ObjectConnection):
         self.command_print(command)
         command = command.strip()
         if "\\n" in command and (len(command) == 4 or len(command) == 2):
-            print "Sendig ENTER \\r\\n"
+            print "Sending ENTER \\r\\n"
             command = '\r\n'
         else:
             command = command.rstrip(self.NEW_LINE_WINDOWS).rstrip(self.NEW_LINE_UNIX)
@@ -149,15 +154,15 @@ class ObjectSsh(ObjectConnection):
         if self.debug:
             print "Expected: "
             print character
-            print "Recived:"
+            print "Received: "
         while not self.stdout.channel.exit_status_ready() and not stop:
             all_data += self.stdout.channel.recv(buffer_size)
             if self.debug:
-                print all_data
+                print "Debug: " + all_data
             while self.stdout.channel.recv_ready():
                 all_data += self.stdout.channel.recv(buffer_size)
                 if self.debug:
-                    print all_data
+                    print "Debug: " +  all_data
             nc = 1
             for ch in character:
                 if ch is not None and ch in all_data:
@@ -165,7 +170,7 @@ class ObjectSsh(ObjectConnection):
                     position = nc
                     break
                 nc += 1
-        print(str(all_data))
+        print str(all_data)
         self.all_data = self.all_data + str(all_data)
         return position
 

+ 27 - 10
ObjectTelnet.py

@@ -47,9 +47,14 @@ class ObjectTelnet(ObjectConnection):
             error = self.read_data([self.olt.get_expected_password()])
             if error != -1:
                 self.tn.write(self.password + self.NEW_LINE_UNIX)
-                print("Loged in...\n")
+                print("Logged in...\n")
                 print self.tn.read_very_lazy()
-                error = self.read_data([self.olt.get_expected_initial()])
+                cardinal = self.olt.get_expected_cardinal()
+                if isinstance(cardinal, list):
+                    read_data_list = cardinal
+                else:    
+                    read_data_list = [cardinal]
+                error = self.read_data(read_data_list)
                 if error != -1:
                     if self.file_name is not None:
                         self.connection_file()
@@ -57,14 +62,14 @@ class ObjectTelnet(ObjectConnection):
                         self.connection_data()
                     else:
                         self.connection_old()
-                    print("fin-----")
+                    print("-----FIN-----")
                     nc = 0
                     while self.QUIT:
                         if nc == 20:
                             self.QUIT = False
                         # send quit to terminal until exit confirmation
                         self.command_quit(self.olt.get_write_exit())
-                        contador += 1
+                        nc += 1
                     self.tn.close()
                     self.save_log()
                     exit(self.RUN_OK)
@@ -111,7 +116,12 @@ class ObjectTelnet(ObjectConnection):
                 if self.olt.run_enable_password():
                     self.read_data([self.olt.get_expected_enable_password()])
                     self.tn.write(self.password_enable + self.NEW_LINE_UNIX)
-                self.read_data([self.olt.get_expected_cardinal()])
+                cardinal = self.olt.get_expected_cardinal()
+                if isinstance(cardinal, list):
+                    read_data_list = cardinal
+                else:    
+                    read_data_list = [cardinal]
+                self.read_data(read_data_list)
             return True
         return False
 
@@ -127,10 +137,18 @@ class ObjectTelnet(ObjectConnection):
                 read_data = None
                 with_confirmation = False
                 if self.olt.get_expected_exit() is not None:
-                    read_data = [self.olt.get_expected_cardinal(), self.olt.get_expected_exit()]
+                    cardinal = self.olt.get_expected_cardinal()
+                    if isinstance(cardinal, list):
+                        read_data = cardinal + [self.olt.get_expected_exit()]
+                    else:    
+                        read_data = [cardinal, self.olt.get_expected_exit()]
                     with_confirmation = True
                 if self.olt.get_expected_exit_with_confirmation() is not None:
-                    read_data = [self.olt.get_expected_cardinal(), self.olt.get_expected_exit_with_confirmation()]
+                    cardinal = self.olt.get_expected_cardinal()
+                    if isinstance(cardinal, list):
+                        read_data = cardinal + [self.olt.get_expected_exit_with_confirmation()]
+                    else:    
+                        read_data = [cardinal, self.olt.get_expected_exit_with_confirmation()]
                     with_confirmation = False
                 if read_data is not None:
                     position = self.read_data(read_data)
@@ -155,7 +173,7 @@ class ObjectTelnet(ObjectConnection):
         self.command_print(command)
         command = command.strip()
         if "\\n" in command and (len(command) == 4 or len(command) == 2):
-            print "Sendig ENTER \\r\\n"
+            print "Sending ENTER \\r\\n"
             command = '\r\n'
         else:
             command = command.rstrip(self.NEW_LINE_WINDOWS).rstrip(self.NEW_LINE_UNIX)
@@ -164,8 +182,7 @@ class ObjectTelnet(ObjectConnection):
                 if self.debug:
                     print "Send: "
                     print command
-                self.stdin.write(command + self.NEW_LINE_UNIX)
-                self.stdin.flush()
+                self.tn.write(command + self.NEW_LINE_UNIX)
                 self.read_data(expected)
 
     def read_data(self, expected):