psdk-test fix for session close and proxy issue.
psdk-test case for etc was failing as session was not getting closed. psdk-test case for sysroot was failing as proxy setting step was not done properly.
Fix: paramiko library will be used, which have option of closing the session after running particular command. psdk-test for sysroot steps has been modified for setting up proxy and then running the ade sysroot commands.
Apertis: T7237, T7238
Signed-off-by: Tarun Baghmar tarun.baghmar@in.bosch.com
Merge request reports
Activity
Please can you split these changes into more atomic changes as per the guidelines.
1 Acquire::http::Proxy "http://10.168.128.45:3128"; 2 Acquire::https::Proxy "http://10.168.128.45:3128"; 1 Acquire::http::Proxy "http://10.47.96.180:3128"; 8 8 from subprocess import check_call, check_output, CalledProcessError 9 9 import os 10 10 import time 11 import paramiko 11 12 12 13 13 14 class PsdkCommands(object): 14 15 15 16 def __init__(self, old_sdk, new_sdk, user_test_file, debug): 16 self.vbox_manage = "/usr/bin/vboxmanage" 17 #vbox_manage path will change in case of Linux it is /usr/bin/vboxmanage 18 self.vbox_manage = "C:\Program Files (x86)\Sun xVM VirtualBox\VBoxManage.exe" 59 62 return [ "scp", "-i", self.ssh_id_file, 60 63 "-P", self.local_port ] + ssh_opts + lst 61 64 else: 62 return [ "ssh", self.local_host, "-i", self.ssh_id_file, "-p", 63 self.local_port ] + ssh_opts + lst 65 return [ "ssh", self.local_host, "-i", self.ssh_id_file,"-p", 82 print ("executing ssh command") 83 ssh_client = None 84 ssh_client = paramiko.SSHClient() 85 ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy) 86 ssh_client.connect(self.hostname, self.local_port, 'user', 'user') 87 88 stdin, stdout, stderr = ssh_client.exec_command(command) 89 while not stdout.channel.exit_status_ready() and not stdout.channel.recv_ready(): 90 time.sleep(1) 91 for line in stdout.read().splitlines(): 92 print(line) 93 for line in stderr.read().splitlines(): 94 print(line) 95 if ssh_client is not None: 96 print("Connection closed successfully") 97 ssh_client.close() - Comment on lines +81 to +97
Creating and killing a connection for each command seems inefficient and may cause issues in the future if others not familiar with this behaviour look at the test.
Most people looking at the test would expect running
execute_ssh_command("cd <foo>")
followed byexecute_ssh_command("touch bar.txt")
to createbar.txt
in thefoo
directory, as the connection is closed each time, this won't be the case.We should have a
connect
(returning a instance),send_command
andclose
command, much like paramiko its self.Edited by Martyn Welch
90 111 "--type", "hdd", "--medium", vdi_path ]) 91 112 92 113 def create_persistent_disk(self, pdisk_path): 93 print("Creating persistent disk: %s" % pdisk_path) 114 print("Creating persistent disk: %s \n" % pdisk_path) 90 111 "--type", "hdd", "--medium", vdi_path ]) 91 112 92 113 def create_persistent_disk(self, pdisk_path): 93 print("Creating persistent disk: %s" % pdisk_path) 114 print("Creating persistent disk: %s \n" % pdisk_path) 94 115 self._run([ self.vbox_manage, "createhd", "--size", "40000", "--variant", 95 116 "Standard", "--filename", pdisk_path ]) 96 117 97 118 def attach_persistent_disk(self, vm, pdisk_path): 119 print("\n Attaching persistent disk: %s" % pdisk_path) 105 127 print("Waiting 5 secs ...") 106 128 time.sleep(5) 107 129 108 def run_ade_sysroot(self, release, op='update'): 109 self._run(self._ssh([ "ade", "sysroot", op, "--release", release ]), 110 ssh=True) 130 def run_ade_sysroot(self, release, proxy_ip='10.47.96.180', op='update'): 105 127 print("Waiting 5 secs ...") 106 128 time.sleep(5) 107 129 108 def run_ade_sysroot(self, release, op='update'): 109 self._run(self._ssh([ "ade", "sysroot", op, "--release", release ]), 110 ssh=True) 130 def run_ade_sysroot(self, release, proxy_ip='10.47.96.180', op='update'): 131 print("proxy ip value is", proxy_ip) 132 self.execute_ssh_command("export http_proxy="+ proxy_ip + ":3128 ;" 107 129 108 def run_ade_sysroot(self, release, op='update'): 109 self._run(self._ssh([ "ade", "sysroot", op, "--release", release ]), 110 ssh=True) 130 def run_ade_sysroot(self, release, proxy_ip='10.47.96.180', op='update'): 131 print("proxy ip value is", proxy_ip) 132 self.execute_ssh_command("export http_proxy="+ proxy_ip + ":3128 ;" 133 + "export https_proxy="+ proxy_ip + ":3128 ;" 134 + "ade sysroot " + op + " --release " + release + ";") 111 135 112 136 def copy_file(self, cfile): 113 137 self._run(self._ssh([cfile, (self.local_host + ":/home/user/") ], 114 138 copy_file=True), ssh=True) 139 140 def copy_proxy_file(self, cfile): 141 self._run(self._ssh([cfile, (self.local_host + ":/home/user/etc/apt/apt.conf.d/") ], 140 def copy_proxy_file(self, cfile): 141 self._run(self._ssh([cfile, (self.local_host + ":/home/user/etc/apt/apt.conf.d/") ], 142 copy_file=True), ssh=True) 115 143 116 144 def move_proxy_file(self, proxy_test_file, apt_conf_dir): 117 self._run(self._ssh(["sudo", "mv", 118 os.path.join("/home/user/", proxy_test_file), 119 apt_conf_dir]), ssh=True) 145 proxy_file_move = os.path.join("/home/user/", proxy_test_file) 146 self.execute_ssh_command("sudo mv " + proxy_file_move + " " + apt_conf_dir) 120 147 121 148 def check_file(self, file_path): 122 149 print(f"\nChecking file contents for {file_path}:\n" \ 123 150 "===========================================================") 124 self._run(self._ssh([ "cat", file_path ]), ssh=True) 151 self.execute_ssh_command("cat " + file_path) This has been replaced by !228 (merged)