Skip to content
Snippets Groups Projects

psdk-test fix for session close and proxy issue.

Closed Baghmar Tarun requested to merge wip/tarun/persistent-sdk-test into apertis/v2022dev0
14 unresolved threads

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

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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";
  • This seems like it's going to break running this test in as many places as it helps and raises a few questions/comments:

    • Where does this new IP address point?
    • We seem to have a proxy variable, wouldn't it make more sense to dynamcially update/create this file based on whether that is set?
  • Please register or sign in to reply
  • Martyn Welch
    Martyn Welch @martyn started a thread on commit 54861752
  • 63 63 self.user_test_file = "psdk_test_file"
    64 64 self.proxy_test_file = "90proxy"
    65 65 self.apt_conf_d = "/etc/apt/apt.conf.d/"
    66 self.proxy_ip = ""
  • Martyn Welch
    Martyn Welch @martyn started a thread on commit 54861752
  • 80 81 self.cmd.start_vm(self.old_sdk)
    81 82
    82 83 if self.test_type == 'sysroot':
    83 self.cmd.run_ade_sysroot(self.release, 'install')
    84 self.proxy_ip = input("Enter the proxy ip: ")
  • Martyn Welch
    Martyn Welch @martyn started a thread on commit 54861752
  • 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"
  • Martyn Welch
    Martyn Welch @martyn started a thread on commit 54861752
  • 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",
    • Please put these kind of cleanup changes in their own commit. It makes it easier to quickly scan through such changes to check they haven't fundamentally changed operation in any way and don't distract from the purpose of other commits.

    • Please register or sign in to reply
  • Martyn Welch
    Martyn Welch @martyn started a thread on commit 54861752
  • 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 by execute_ssh_command("touch bar.txt") to create bar.txt in the foo directory, as the connection is closed each time, this won't be the case.

      We should have a connect (returning a instance), send_command and close command, much like paramiko its self.

      Edited by Martyn Welch
    • Please register or sign in to reply
  • Martyn Welch
    Martyn Welch @martyn started a thread on commit 54861752
  • 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)
  • Martyn Welch
    Martyn Welch @martyn started a thread on commit 54861752
  • 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)
  • Martyn Welch
    Martyn Welch @martyn started a thread on commit 54861752
  • 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'):
  • Martyn Welch
    Martyn Welch @martyn started a thread on commit 54861752
  • 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 ;"
  • Martyn Welch
    Martyn Welch @martyn started a thread on commit 54861752
  • 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/") ],
  • Martyn Welch
    Martyn Welch @martyn started a thread on commit 54861752
  • 59 62 return [ "scp", "-i", self.ssh_id_file,
    60 63 "-P", self.local_port ] + ssh_opts + lst
    61 64 else:
  • Martyn Welch
    Martyn Welch @martyn started a thread on commit 54861752
  • 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)

  • Please register or sign in to reply
    Loading