Browse Source

Merge "Update WinRM config options"

tags/0.1.0
Jenkins 1 year ago
parent
commit
f83c7e2ea1

+ 34
- 5
oswin_tempest_plugin/clients/wsman.py View File

@@ -13,24 +13,39 @@
13 13
 #    License for the specific language governing permissions and limitations
14 14
 #    under the License.
15 15
 
16
+import os
17
+
16 18
 from oslo_log import log as logging
17 19
 from winrm import protocol
18 20
 
21
+from oswin_tempest_plugin import config
19 22
 from oswin_tempest_plugin import exceptions
20 23
 
21 24
 LOG = logging.getLogger(__name__)
25
+CONF = config.CONF
22 26
 
23 27
 protocol.Protocol.DEFAULT_TIMEOUT = "PT3600S"
24 28
 
25 29
 
26
-def run_wsman_cmd(host, username, password, cmd, fail_on_error=False):
30
+def 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 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 41
     LOG.debug('Connecting to: %s', host)
29 42
     p = protocol.Protocol(endpoint=url,
30
-                          transport='plaintext',
43
+                          transport=transport_method,
31 44
                           server_cert_validation='ignore',
32 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 50
     shell_id = p.open_shell()
36 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 69
     return (std_out, std_err, return_code)
55 70
 
56 71
 
57
-def run_wsman_ps(host, username, password, cmd, fail_on_error=False):
72
+def 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 76
     cmd = ("powershell -NonInteractive -ExecutionPolicy RemoteSigned "
59 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
+
82
+def 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)

+ 24
- 5
oswin_tempest_plugin/config.py View File

@@ -45,11 +45,6 @@ HyperVGroup = [
45 45
     cfg.BoolOpt('cluster_enabled',
46 46
                 default=False,
47 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 48
     cfg.IntOpt('failover_timeout',
54 49
                default=120,
55 50
                help='The maximum amount of time to wait for a failover to '
@@ -68,9 +63,33 @@ HyperVGroup = [
68 63
                     "vNUMA will be skipped."),
69 64
 ]
70 65
 
66
+hyperv_host_auth_group = cfg.OptGroup(name='hyperv_host_auth',
67
+                                      title='Hyper-V host '
68
+                                            'authentication options')
69
+
70
+hyperv_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 90
 _opts = [
73 91
     (hyperv_group, HyperVGroup),
92
+    (hyperv_host_auth_group, hyperv_host_auth_opts),
74 93
 ]
75 94
 
76 95
 

+ 10
- 10
oswin_tempest_plugin/tests/scenario/test_cluster.py View File

@@ -64,12 +64,14 @@ class HyperVClusterTest(test_base.TestBase,
64 64
         super(HyperVClusterTest, cls).skip_checks()
65 65
 
66 66
         # check if the cluster Tests can be run.
67
-        conf_opts = ['cluster_enabled', 'username', 'password']
68
-        for conf_opt in conf_opts:
69
-            if not getattr(CONF.hyperv, conf_opt):
70
-                msg = ('The config option "hyperv.%s" has not been set. '
71
-                       'Skipping.' % conf_opt)
72
-                raise cls.skipException(msg)
67
+        if not CONF.hyperv.cluster_enabled:
68
+            msg = 'Hyper-V cluster tests are disabled.'
69
+            raise cls.skipException(msg)
70
+
71
+        if not CONF.hyperv_host_auth.username:
72
+            msg = ('No Hyper-V host username has been provided. '
73
+                   'Skipping cluster tests.')
74
+            raise cls.skipException(msg)
73 75
 
74 76
         if not CONF.compute.min_compute_nodes >= 2:
75 77
             msg = 'Expected at least 2 compute nodes.'
@@ -86,11 +88,9 @@ class HyperVClusterTest(test_base.TestBase,
86 88
         # succeed. On the 2nd failure, the VM will failover to another
87 89
         # node. Also, there needs to be a delay between commands, so the
88 90
         # original failover has time to finish.
89
-        wsman.run_wsman_ps(host_ip, CONF.hyperv.username,
90
-                           CONF.hyperv.password, cmd, True)
91
+        wsman.run_hv_host_wsman_ps(host_ip, cmd)
91 92
         time.sleep(CONF.hyperv.failover_sleep_interval)
92
-        wsman.run_wsman_ps(host_ip, CONF.hyperv.username,
93
-                           CONF.hyperv.password, cmd, True)
93
+        wsman.run_hv_host_wsman_ps(host_ip, cmd)
94 94
 
95 95
     def _wait_for_failover(self, server, original_host):
96 96
         """Waits for the given server to failover to another host.

Loading…
Cancel
Save