Python 3 fixes for CloudStack modules and tests. (#24400)

pull/19530/merge
Matt Clay 8 years ago committed by René Moser
parent 6aa32d3e9d
commit d999d613cb

@ -28,7 +28,11 @@
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
import sys
import time
from ansible.module_utils._text import to_text
try:
from cs import CloudStack, CloudStackException, read_config
HAS_LIB_CS = True
@ -47,6 +51,9 @@ CS_HYPERVISORS = [
'Simulator', 'simulator',
]
if sys.version_info > (3,):
long = int
def cs_argument_spec():
return dict(
@ -184,20 +191,23 @@ class AnsibleCloudStack(object):
self.result['diff']['after'][key] = value
result = True
else:
before_value = to_text(current_dict[key])
after_value = to_text(value)
if self.case_sensitive_keys and key in self.case_sensitive_keys:
if value != current_dict[key].encode('utf-8'):
self.result['diff']['before'][key] = current_dict[key].encode('utf-8')
self.result['diff']['after'][key] = value
if before_value != after_value:
self.result['diff']['before'][key] = before_value
self.result['diff']['after'][key] = after_value
result = True
# Test for diff in case insensitive way
elif value.lower() != current_dict[key].encode('utf-8').lower():
self.result['diff']['before'][key] = current_dict[key].encode('utf-8')
self.result['diff']['after'][key] = value
elif before_value.lower() != after_value.lower():
self.result['diff']['before'][key] = before_value
self.result['diff']['after'][key] = after_value
result = True
else:
self.result['diff']['before'][key] = None
self.result['diff']['after'][key] = value
self.result['diff']['after'][key] = to_text(value)
result = True
return result

@ -120,6 +120,7 @@ except ImportError:
HAS_LIB_SSHPUBKEYS = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
from ansible.module_utils.cloudstack import (
AnsibleCloudStack,
CloudStackException,
@ -232,6 +233,8 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack):
def _get_ssh_fingerprint(self, public_key):
key = sshpubkeys.SSHKey(public_key)
if hasattr(key, 'hash_md5'):
return key.hash_md5().replace(to_native('MD5:'), to_native(''))
return key.hash()

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -7,7 +7,7 @@
assert:
that:
- config|failed
- "config.msg == 'missing required arguments: value,name'"
- "config.msg.startswith('missing required arguments: ')"
- name: test configuration
cs_configuration:

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -57,7 +57,7 @@
assert:
that:
- lb|failed
- "'ip_address,name' in lb.msg"
- "lb.msg.startswith('missing required arguments: ')"
- name: test create rule
cs_loadbalancer_rule:
@ -143,7 +143,7 @@
assert:
that:
- lb|failed
- "'vms,name' in lb.msg"
- "lb.msg.startswith('missing required arguments: ')"
- name: test add members to rule
cs_loadbalancer_rule_member:

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -59,7 +59,7 @@
assert:
that:
- pf|failed
- 'pf.msg == "missing required arguments: private_port,ip_address,public_port"'
- 'pf.msg.startswith("missing required arguments: ")'
- name: test present port forwarding
cs_portforward:

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -29,7 +29,7 @@
assert:
that:
- snap|failed
- 'snap.msg == "missing required arguments: vm,name"'
- 'snap.msg.startswith("missing required arguments: ")'
- name: test create snapshot
cs_vmsnapshot:

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

@ -1,3 +1,2 @@
cloud/cs
posix/ci/cloud/cs
skip/python3

Loading…
Cancel
Save