Browse Source

Fix StringIO import and patch paramiko in Python 3

This fixes ModuleNotFoundError: No module named 'StringIO',
raised in Python 3 functional tests. We also patch paramiko
on Python 3, since we use it in functional tests.

Change-Id: I357dd9c3ec7c0a76d31b7f94ec0e844d9bdcb5c5
Grzegorz Grasza 4 months ago
parent
commit
ff9ed8461e

+ 3
- 3
novajoin/tests/functional/test_enrollment.py View File

@@ -19,9 +19,9 @@ The test uses the default demo project and credentials and assumes there is a
19 19
 centos-image present in Glance.
20 20
 """
21 21
 
22
+import io
22 23
 import json
23 24
 import os
24
-import StringIO
25 25
 import testtools
26 26
 import time
27 27
 import uuid
@@ -147,7 +147,7 @@ class TestEnrollment(testtools.TestCase):
147 147
         # we wouldn't be able to connect to keystone from the same namespace.
148 148
 
149 149
         pkey = paramiko.RSAKey.from_private_key(
150
-            StringIO.StringIO(self._key.private_key))
150
+            io.StringIO(self._key.private_key))
151 151
         client = paramiko.SSHClient()
152 152
         client.load_system_host_keys()
153 153
         client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
@@ -170,7 +170,7 @@ class TestEnrollment(testtools.TestCase):
170 170
         stdin, stdout, stderr = ssh.exec_command('id admin')
171 171
         self.assertRegex(
172 172
             'uid=\d+\(admin\) gid=\d+\(admins\) groups=\d+\(admins\)',
173
-            stdout.read())
173
+            stdout.read().decode())
174 174
 
175 175
     @loopingcall.RetryDecorator(200, 5, 5, (AssertionError,))
176 176
     def _check_ipa_client_created(self):

+ 28
- 0
roles/configure-freeipa/tasks/main.yaml View File

@@ -16,6 +16,34 @@
16 16
     replace: 'GSS_AUTH_AVAILABLE = False'
17 17
   become: true
18 18
 
19
+- name: Install paramiko to patch it (Python3)
20
+  pip:
21
+    name: paramiko
22
+    executable: pip{{ python_version }}
23
+  become: true
24
+  when: python_version is defined
25
+
26
+- name: Find Paramiko ssh_gss.py (Python3)
27
+  command: python{{ python_version }} -c "from paramiko import ssh_gss; print(ssh_gss.__file__.rstrip('c'))"
28
+  register: ssh_gss_file
29
+  when: python_version is defined
30
+
31
+- name: Patch Paramiko (https://github.com/paramiko/paramiko/pull/1311)
32
+  replace:
33
+    path: '{{ ssh_gss_file.stdout }}'
34
+    regexp: 'GSS_EXCEPTIONS = \(gssapi.GSSException,\)'
35
+    replace: 'GSS_EXCEPTIONS = ()'
36
+  become: true
37
+  when: python_version is defined
38
+
39
+- name: Patch Paramiko (https://github.com/paramiko/paramiko/pull/1311)
40
+  replace:
41
+    path: '{{ ssh_gss_file.stdout }}'
42
+    regexp: 'GSS_AUTH_AVAILABLE = True'
43
+    replace: 'GSS_AUTH_AVAILABLE = False'
44
+  become: true
45
+  when: python_version is defined
46
+
19 47
 - name: Uninstall urllib3 to fix later conflict with python-urllib3 system package
20 48
   pip:
21 49
     name: urllib3

Loading…
Cancel
Save