Greetings, For https://fedorahosted.org/python-pytest-multihost/ticket/6 , i have proposed a patch, I think this patch is more of a workaround , than a solution. I would like to get more inputs on how to use pytest-multihost to execute commands on Windows. The method i am using requires cygwin with openssh/bash to be installed.
Request to review the patch. Regards Niranjan
From 5944e86f881516209fcb030ec3da7ad1b58ab4cc Mon Sep 17 00:00:00 2001 From: Niranjan MR <[email protected]> Date: Wed, 6 Apr 2016 14:08:13 +0530 Subject: [PATCH] Add new parameter "type" for hosts to have Expand class WinHost to add function run_win_command which executes commands on Windows. Signed-off-by: Niranjan MR <[email protected]> --- pytest_multihost/config.py | 4 ++++ pytest_multihost/host.py | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/pytest_multihost/config.py b/pytest_multihost/config.py index 31045c21e8ee67c1793f154f841375f8df7b365f..e42b2743dd7b4cf17b935c961248803a8e1dd46e 100644 --- a/pytest_multihost/config.py +++ b/pytest_multihost/config.py @@ -182,6 +182,10 @@ class Domain(object): from pytest_multihost.host import Host return Host + def get_winhost_class(self, host_dict): + from pytest_multihost.host import WinHost + return WinHost + @property def roles(self): """All the roles of the hosts in this domain""" diff --git a/pytest_multihost/host.py b/pytest_multihost/host.py index e6c0db50799b2042e699d66ed9ec5f04f6592d31..113035753b216fcc7053706d9855e85399dd5e53 100644 --- a/pytest_multihost/host.py +++ b/pytest_multihost/host.py @@ -27,9 +27,10 @@ class BaseHost(object): transport_class = None def __init__(self, domain, hostname, role, ip=None, - external_hostname=None, username=None, password=None): + external_hostname=None, username=None, password=None, host_type=None): self.domain = domain self.role = str(role) + self.host_type = str(host_type) if username is None: self.ssh_username = self.config.ssh_username else: @@ -118,11 +119,12 @@ class BaseHost(object): username = dct.pop('username', None) password = dct.pop('password', None) + host_type = dct.pop('host_type', None) check_config_dict_empty(dct, 'host %s' % hostname) return cls(domain, hostname, role, ip, external_hostname, - username, password) + username, password, host_type) def to_dict(self): """Export info about this Host to a dict""" @@ -250,8 +252,40 @@ class Host(BaseHost): class WinHost(BaseHost): """ Representation of a remote Windows host. - - This is a stub; Windows hosts can't currently be interacted with. """ + transport_class = transport.SSHTransport + def run_win_command(self, argv, set_env=True, stdin_text=None, + log_stdout=True, raiseonerr=True, + cwd=None): + command = self.transport.start_shell(argv, log_stdout=log_stdout) + #self.config.test_dir = '%s/%s' % ('/home',self.config.username) + print("self.config",dir(self.config)) + + # Set working directory + if cwd is None: + cwd = self.config.test_dir + command.stdin.write('cd %s\n' % shell_quote(cwd)) + + # Set the environment + if set_env: + command.stdin.write('. %s\n' % shell_quote(self.env_sh_path)) + + if isinstance(argv, basestring): + # Run a shell command given as a string + command.stdin.write('(') + command.stdin.write(argv) + command.stdin.write(')') + else: + # Run a command given as a popen-style list (no shell expansion) + for arg in argv: + command.stdin.write(shell_quote(arg)) + command.stdin.write(' ') + + command.stdin.write(';exit\n') + if stdin_text: + command.stdin.write(stdin_text) + command.stdin.flush() + + command.wait(raiseonerr=raiseonerr) + return command - pass -- 1.9.3
pgpx6NIWDSlsD.pgp
Description: PGP signature
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code
