From a937c4633d0258aecce76f560ca4342be1d52b03 Mon Sep 17 00:00:00 2001 From: crouzet Date: Wed, 6 Feb 2019 08:49:25 +0100 Subject: [PATCH] sat #8523 : protection d'appels ssh inutiles sur plateforme windows --- commands/application.py | 53 ++++++++++++++++------------- commands/compile.py | 1 - commands/launcher.py | 75 ++++++++++++++++++++++------------------- commands/test.py | 2 +- 4 files changed, 70 insertions(+), 61 deletions(-) diff --git a/commands/application.py b/commands/application.py index 9067b0a..f700feb 100644 --- a/commands/application.py +++ b/commands/application.py @@ -342,36 +342,41 @@ def generate_catalog(machines, config, logger): catalog = file(catfile, "w") catalog.write("\n\n") for k in machines: - logger.write(" ssh %s " % (k + " ").ljust(20, '.'), 4) - logger.flush() - - ssh_cmd = 'ssh -o "StrictHostKeyChecking no" %s %s' % (k, cmd) - p = subprocess.Popen(ssh_cmd, shell=True, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - p.wait() - - if p.returncode != 0: - logger.write(src.printcolors.printc(src.KO_STATUS) + "\n", 4) - logger.write(" " + src.printcolors.printcWarning(p.stderr.read()), - 2) - else: - logger.write(src.printcolors.printc(src.OK_STATUS) + "\n", 4) - lines = p.stdout.readlines() - freq = lines[0][:-1].split(':')[-1].split('.')[0].strip() - nb_proc = len(lines) -1 - memory = lines[-1].split(':')[-1].split()[0].strip() - memory = int(memory) / 1000 + if not src.architecture.is_windows(): + logger.write(" ssh %s " % (k + " ").ljust(20, '.'), 4) + logger.flush() + + ssh_cmd = 'ssh -o "StrictHostKeyChecking no" %s %s' % (k, cmd) + p = subprocess.Popen(ssh_cmd, shell=True, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + p.wait() + + machine_access = (p.returncode == 0) + if not machine_access: + logger.write(src.printcolors.printc(src.KO_STATUS) + "\n", 4) + logger.write(" " + src.printcolors.printcWarning(p.stderr.read()), + 2) + else: + logger.write(src.printcolors.printc(src.OK_STATUS) + "\n", 4) + lines = p.stdout.readlines() + freq = lines[0][:-1].split(':')[-1].split('.')[0].strip() + nb_proc = len(lines) -1 + memory = lines[-1].split(':')[-1].split()[0].strip() + memory = int(memory) / 1000 catalog.write(" \n\n") for k in machines: - logger.write(" ssh %s " % (k + " ").ljust(20, '.'), 4) - logger.flush() - - # Verify that the machine is accessible - ssh_cmd = 'ssh -o "StrictHostKeyChecking no" %s %s' % (k, cmd) - p = subprocess.Popen(ssh_cmd, shell=True, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - p.wait() - - if p.returncode != 0: # The machine is not accessible - logger.write(src.printcolors.printc(src.KO_STATUS) + "\n", 4) - logger.write(" " + - src.printcolors.printcWarning(p.stderr.read()), 2) - else: - # The machine is accessible, write the corresponding section on - # the xml file - logger.write(src.printcolors.printc(src.OK_STATUS) + "\n", 4) - lines = p.stdout.readlines() - freq = lines[0][:-1].split(':')[-1].split('.')[0].strip() - nb_proc = len(lines) -1 - memory = lines[-1].split(':')[-1].split()[0].strip() - memory = int(memory) / 1000 - - catalog.write(" \n") - catalog.write(" \n") + + catalog.write(" userName=\"%s\"\n" % user) + catalog.write(" name=\"%s\"\n" % k) + catalog.write(" hostname=\"%s\"\n" % k) + catalog.write(" >\n") + catalog.write(" \n") catalog.write("\n") catalog.close() diff --git a/commands/test.py b/commands/test.py index 0d39d25..62fd7fe 100644 --- a/commands/test.py +++ b/commands/test.py @@ -636,7 +636,7 @@ def run(args, runner, logger): show_desktop = (options.display and options.display.upper() == "NO") if options.display and options.display != "NO": remote_name = options.display.split(':')[0] - if remote_name != "": + if remote_name != "" and (not src.architecture.is_windows()): check_remote_machine(remote_name, logger) # if explicitly set use user choice os.environ['DISPLAY'] = options.display -- 2.39.2