summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Muresan <amuresan@cloudbasesolutions.com>2017-08-03 14:14:07 +0300
committerAlexandru Muresan <amuresan@cloudbasesolutions.com>2017-09-05 10:30:59 +0300
commitef51813201b1f1362cdf0d1c0b134253d36a1a50 (patch)
tree3176e9bb76bf5d348d643babec7838cdaf58cbd1
parent3cc5f94ac9a4bfb4c3f2a2c3cf1d1fe05ddfc688 (diff)
Update WinRM config options
A new config group is being added, allowing specifying WinRM credentials to be used when accessing Hyper-V hosts. This will also allow setting a transport type other than 'plaintext'. At the same time, this change adds a new helper method that may be used in order to run commands on the Hyper-V hosts. Change-Id: I5852154d8275ebd36785bcf56899da3257f1a5a8
Notes
Notes (review): Code-Review+2: Lucian Petrut <lpetrut@cloudbasesolutions.com> Workflow+1: Lucian Petrut <lpetrut@cloudbasesolutions.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 06 Sep 2017 10:37:30 +0000 Reviewed-on: https://review.openstack.org/490433 Project: openstack/oswin-tempest-plugin Branch: refs/heads/master
-rw-r--r--oswin_tempest_plugin/clients/wsman.py39
-rw-r--r--oswin_tempest_plugin/config.py29
-rw-r--r--oswin_tempest_plugin/tests/scenario/test_cluster.py20
3 files changed, 68 insertions, 20 deletions
diff --git a/oswin_tempest_plugin/clients/wsman.py b/oswin_tempest_plugin/clients/wsman.py
index 3ccb55d..3a0806d 100644
--- a/oswin_tempest_plugin/clients/wsman.py
+++ b/oswin_tempest_plugin/clients/wsman.py
@@ -13,24 +13,39 @@
13# License for the specific language governing permissions and limitations 13# License for the specific language governing permissions and limitations
14# under the License. 14# under the License.
15 15
16import os
17
16from oslo_log import log as logging 18from oslo_log import log as logging
17from winrm import protocol 19from winrm import protocol
18 20
21from oswin_tempest_plugin import config
19from oswin_tempest_plugin import exceptions 22from oswin_tempest_plugin import exceptions
20 23
21LOG = logging.getLogger(__name__) 24LOG = logging.getLogger(__name__)
25CONF = config.CONF
22 26
23protocol.Protocol.DEFAULT_TIMEOUT = "PT3600S" 27protocol.Protocol.DEFAULT_TIMEOUT = "PT3600S"
24 28
25 29
26def run_wsman_cmd(host, username, password, cmd, fail_on_error=False): 30def run_wsman_cmd(host, cmd, username, password=None,
31 cert_pem_path=None, cert_key_pem_path=None,
32 transport_method='plaintext', fail_on_error=True):
27 url = 'https://%s:5986/wsman' % host 33 url = 'https://%s:5986/wsman' % host
34
35 if transport_method == 'ssl':
36 if not (os.path.exists(cert_pem_path) and
37 os.path.exists(cert_key_pem_path)):
38 raise exceptions.WSManException('Could not find certificate path '
39 'or certificate key path.')
40
28 LOG.debug('Connecting to: %s', host) 41 LOG.debug('Connecting to: %s', host)
29 p = protocol.Protocol(endpoint=url, 42 p = protocol.Protocol(endpoint=url,
30 transport='plaintext', 43 transport=transport_method,
31 server_cert_validation='ignore', 44 server_cert_validation='ignore',
32 username=username, 45 username=username,
33 password=password) 46 password=password,
47 cert_pem=cert_pem_path,
48 cert_key_pem=cert_key_pem_path)
34 49
35 shell_id = p.open_shell() 50 shell_id = p.open_shell()
36 LOG.debug('Running command on host %(host)s: %(cmd)s', 51 LOG.debug('Running command on host %(host)s: %(cmd)s',
@@ -54,7 +69,21 @@ def run_wsman_cmd(host, username, password, cmd, fail_on_error=False):
54 return (std_out, std_err, return_code) 69 return (std_out, std_err, return_code)
55 70
56 71
57def run_wsman_ps(host, username, password, cmd, fail_on_error=False): 72def run_wsman_ps(host, cmd, username, password, cert_pem_path=None,
73 cert_key_pem_path=None, transport='plaintext',
74 fail_on_error=True):
75
58 cmd = ("powershell -NonInteractive -ExecutionPolicy RemoteSigned " 76 cmd = ("powershell -NonInteractive -ExecutionPolicy RemoteSigned "
59 "-Command \"%s\"" % cmd) 77 "-Command \"%s\"" % cmd)
60 return run_wsman_cmd(host, username, password, cmd, fail_on_error) 78 return run_wsman_cmd(host, cmd, username, password, cert_pem_path,
79 cert_key_pem_path, fail_on_error)
80
81
82def run_hv_host_wsman_ps(host, cmd, fail_on_error=True):
83 return run_wsman_ps(
84 host, cmd,
85 username=CONF.hyperv_host_auth.username,
86 password=CONF.hyperv_host_auth.password,
87 cert_pem_path=CONF.hyperv_host_auth.cert_pem_path,
88 cert_key_pem_path=CONF.hyperv_host_auth.cert_key_pem_path,
89 transport='plaintext', fail_on_error=fail_on_error)
diff --git a/oswin_tempest_plugin/config.py b/oswin_tempest_plugin/config.py
index 8870636..a4488d1 100644
--- a/oswin_tempest_plugin/config.py
+++ b/oswin_tempest_plugin/config.py
@@ -40,11 +40,6 @@ HyperVGroup = [
40 cfg.BoolOpt('cluster_enabled', 40 cfg.BoolOpt('cluster_enabled',
41 default=False, 41 default=False,
42 help="The compute nodes are joined into a Hyper-V Cluster."), 42 help="The compute nodes are joined into a Hyper-V Cluster."),
43 cfg.StrOpt('username',
44 help="The username of the Hyper-V hosts."),
45 cfg.StrOpt('password',
46 secret=True,
47 help='The password of the Hyper-V hosts.'),
48 cfg.IntOpt('failover_timeout', 43 cfg.IntOpt('failover_timeout',
49 default=120, 44 default=120,
50 help='The maximum amount of time to wait for a failover to ' 45 help='The maximum amount of time to wait for a failover to '
@@ -54,9 +49,33 @@ HyperVGroup = [
54 help='The amount of time to wait between failover checks.'), 49 help='The amount of time to wait between failover checks.'),
55] 50]
56 51
52hyperv_host_auth_group = cfg.OptGroup(name='hyperv_host_auth',
53 title='Hyper-V host '
54 'authentication options')
55
56hyperv_host_auth_opts = [
57 cfg.StrOpt('username',
58 help="The username of the Hyper-V hosts."),
59 cfg.StrOpt('password',
60 secret=True,
61 help='The password of the Hyper-V hosts.'),
62 cfg.StrOpt('cert_pem_path',
63 default=None,
64 help='SSL certificate for WinRM remote PS connection.'),
65 cfg.StrOpt('cert_key_pem_path',
66 default=None,
67 help='SSL key paired with cert_pem_path for WinRM remote PS '
68 'connection.'),
69 cfg.StrOpt('transport_method',
70 default='plaintext',
71 choices=('ssl', 'ntlm', 'plaintext'),
72 help='The method that should be used to establish a connection '
73 'to a Hyper-V host.')
74]
57 75
58_opts = [ 76_opts = [
59 (hyperv_group, HyperVGroup), 77 (hyperv_group, HyperVGroup),
78 (hyperv_host_auth_group, hyperv_host_auth_opts),
60] 79]
61 80
62 81
diff --git a/oswin_tempest_plugin/tests/scenario/test_cluster.py b/oswin_tempest_plugin/tests/scenario/test_cluster.py
index 0a68963..86cba54 100644
--- a/oswin_tempest_plugin/tests/scenario/test_cluster.py
+++ b/oswin_tempest_plugin/tests/scenario/test_cluster.py
@@ -63,12 +63,14 @@ class HyperVClusterTest(test_base.TestBase,
63 super(HyperVClusterTest, cls).skip_checks() 63 super(HyperVClusterTest, cls).skip_checks()
64 64
65 # check if the cluster Tests can be run. 65 # check if the cluster Tests can be run.
66 conf_opts = ['cluster_enabled', 'username', 'password'] 66 if not CONF.hyperv.cluster_enabled:
67 for conf_opt in conf_opts: 67 msg = 'Hyper-V cluster tests are disabled.'
68 if not getattr(CONF.hyperv, conf_opt): 68 raise cls.skipException(msg)
69 msg = ('The config option "hyperv.%s" has not been set. ' 69
70 'Skipping.' % conf_opt) 70 if not CONF.hyperv_host_auth.username:
71 raise cls.skipException(msg) 71 msg = ('No Hyper-V host username has been provided. '
72 'Skipping cluster tests.')
73 raise cls.skipException(msg)
72 74
73 if not CONF.compute.min_compute_nodes >= 2: 75 if not CONF.compute.min_compute_nodes >= 2:
74 msg = 'Expected at least 2 compute nodes.' 76 msg = 'Expected at least 2 compute nodes.'
@@ -85,11 +87,9 @@ class HyperVClusterTest(test_base.TestBase,
85 # succeed. On the 2nd failure, the VM will failover to another 87 # succeed. On the 2nd failure, the VM will failover to another
86 # node. Also, there needs to be a delay between commands, so the 88 # node. Also, there needs to be a delay between commands, so the
87 # original failover has time to finish. 89 # original failover has time to finish.
88 wsman.run_wsman_ps(host_ip, CONF.hyperv.username, 90 wsman.run_hv_host_wsman_ps(host_ip, cmd)
89 CONF.hyperv.password, cmd, True)
90 time.sleep(CONF.hyperv.failover_sleep_interval) 91 time.sleep(CONF.hyperv.failover_sleep_interval)
91 wsman.run_wsman_ps(host_ip, CONF.hyperv.username, 92 wsman.run_hv_host_wsman_ps(host_ip, cmd)
92 CONF.hyperv.password, cmd, True)
93 93
94 def _wait_for_failover(self, server, original_host): 94 def _wait_for_failover(self, server, original_host):
95 """Waits for the given server to failover to another host. 95 """Waits for the given server to failover to another host.