summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-09-06 10:37:30 +0000
committerGerrit Code Review <review@openstack.org>2017-09-06 10:37:30 +0000
commitf83c7e2ea158c853f597259f3fd78f8e3ee2f4e5 (patch)
tree391d4f89b5de693adf9da0cff82f53b7d88ebbea
parentccf4693683db2b9e6b82b433bc71d0aa19915dbd (diff)
parentef51813201b1f1362cdf0d1c0b134253d36a1a50 (diff)
Merge "Update WinRM config options"
-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 c76981f..082147f 100644
--- a/oswin_tempest_plugin/config.py
+++ b/oswin_tempest_plugin/config.py
@@ -45,11 +45,6 @@ HyperVGroup = [
45 cfg.BoolOpt('cluster_enabled', 45 cfg.BoolOpt('cluster_enabled',
46 default=False, 46 default=False,
47 help="The compute nodes are joined into a Hyper-V Cluster."), 47 help="The compute nodes are joined into a Hyper-V Cluster."),
48 cfg.StrOpt('username',
49 help="The username of the Hyper-V hosts."),
50 cfg.StrOpt('password',
51 secret=True,
52 help='The password of the Hyper-V hosts.'),
53 cfg.IntOpt('failover_timeout', 48 cfg.IntOpt('failover_timeout',
54 default=120, 49 default=120,
55 help='The maximum amount of time to wait for a failover to ' 50 help='The maximum amount of time to wait for a failover to '
@@ -68,9 +63,33 @@ HyperVGroup = [
68 "vNUMA will be skipped."), 63 "vNUMA will be skipped."),
69] 64]
70 65
66hyperv_host_auth_group = cfg.OptGroup(name='hyperv_host_auth',
67 title='Hyper-V host '
68 'authentication options')
69
70hyperv_host_auth_opts = [
71 cfg.StrOpt('username',
72 help="The username of the Hyper-V hosts."),
73 cfg.StrOpt('password',
74 secret=True,
75 help='The password of the Hyper-V hosts.'),
76 cfg.StrOpt('cert_pem_path',
77 default=None,
78 help='SSL certificate for WinRM remote PS connection.'),
79 cfg.StrOpt('cert_key_pem_path',
80 default=None,
81 help='SSL key paired with cert_pem_path for WinRM remote PS '
82 'connection.'),
83 cfg.StrOpt('transport_method',
84 default='plaintext',
85 choices=('ssl', 'ntlm', 'plaintext'),
86 help='The method that should be used to establish a connection '
87 'to a Hyper-V host.')
88]
71 89
72_opts = [ 90_opts = [
73 (hyperv_group, HyperVGroup), 91 (hyperv_group, HyperVGroup),
92 (hyperv_host_auth_group, hyperv_host_auth_opts),
74] 93]
75 94
76 95
diff --git a/oswin_tempest_plugin/tests/scenario/test_cluster.py b/oswin_tempest_plugin/tests/scenario/test_cluster.py
index 5dec3d4..b9a1485 100644
--- a/oswin_tempest_plugin/tests/scenario/test_cluster.py
+++ b/oswin_tempest_plugin/tests/scenario/test_cluster.py
@@ -64,12 +64,14 @@ class HyperVClusterTest(test_base.TestBase,
64 super(HyperVClusterTest, cls).skip_checks() 64 super(HyperVClusterTest, cls).skip_checks()
65 65
66 # check if the cluster Tests can be run. 66 # check if the cluster Tests can be run.
67 conf_opts = ['cluster_enabled', 'username', 'password'] 67 if not CONF.hyperv.cluster_enabled:
68 for conf_opt in conf_opts: 68 msg = 'Hyper-V cluster tests are disabled.'
69 if not getattr(CONF.hyperv, conf_opt): 69 raise cls.skipException(msg)
70 msg = ('The config option "hyperv.%s" has not been set. ' 70
71 'Skipping.' % conf_opt) 71 if not CONF.hyperv_host_auth.username:
72 raise cls.skipException(msg) 72 msg = ('No Hyper-V host username has been provided. '
73 'Skipping cluster tests.')
74 raise cls.skipException(msg)
73 75
74 if not CONF.compute.min_compute_nodes >= 2: 76 if not CONF.compute.min_compute_nodes >= 2:
75 msg = 'Expected at least 2 compute nodes.' 77 msg = 'Expected at least 2 compute nodes.'
@@ -86,11 +88,9 @@ class HyperVClusterTest(test_base.TestBase,
86 # succeed. On the 2nd failure, the VM will failover to another 88 # succeed. On the 2nd failure, the VM will failover to another
87 # node. Also, there needs to be a delay between commands, so the 89 # node. Also, there needs to be a delay between commands, so the
88 # original failover has time to finish. 90 # original failover has time to finish.
89 wsman.run_wsman_ps(host_ip, CONF.hyperv.username, 91 wsman.run_hv_host_wsman_ps(host_ip, cmd)
90 CONF.hyperv.password, cmd, True)
91 time.sleep(CONF.hyperv.failover_sleep_interval) 92 time.sleep(CONF.hyperv.failover_sleep_interval)
92 wsman.run_wsman_ps(host_ip, CONF.hyperv.username, 93 wsman.run_hv_host_wsman_ps(host_ip, cmd)
93 CONF.hyperv.password, cmd, True)
94 94
95 def _wait_for_failover(self, server, original_host): 95 def _wait_for_failover(self, server, original_host):
96 """Waits for the given server to failover to another host. 96 """Waits for the given server to failover to another host.