mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
Enable most unittests on python3 (just some vault unittests and a logging one left) (#17240)
Make some python3 fixes to make the unittests pass: * galaxy imports * dictionary iteration in role requirements * swap_stdout helper for unittests * Normalize to text string in a facts.py function
This commit is contained in:
@@ -39,7 +39,7 @@ from ansible.galaxy.role import GalaxyRole
|
||||
from ansible.galaxy.login import GalaxyLogin
|
||||
from ansible.galaxy.token import GalaxyToken
|
||||
from ansible.playbook.role.requirement import RoleRequirement
|
||||
from ansible.utils.unicode import to_unicode
|
||||
from ansible.utils.unicode import to_bytes, to_unicode
|
||||
|
||||
try:
|
||||
from __main__ import display
|
||||
@@ -193,7 +193,7 @@ class GalaxyCLI(CLI):
|
||||
os.makedirs(role_path)
|
||||
readme_path = os.path.join(role_path, "README.md")
|
||||
f = open(readme_path, "wb")
|
||||
f.write(self.galaxy.default_readme)
|
||||
f.write(to_bytes(self.galaxy.default_readme))
|
||||
f.close()
|
||||
|
||||
# create default .travis.yml
|
||||
|
||||
@@ -25,12 +25,11 @@ from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import urllib
|
||||
|
||||
from urllib2 import quote as urlquote, HTTPError
|
||||
|
||||
import ansible.constants as C
|
||||
from ansible.compat.six import string_types
|
||||
from ansible.compat.six.moves.urllib.parse import quote as urlquote, urlencode
|
||||
from ansible.compat.six.moves.urllib.error import HTTPError
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.galaxy.token import GalaxyToken
|
||||
@@ -134,7 +133,7 @@ class GalaxyAPI(object):
|
||||
Retrieve an authentication token
|
||||
"""
|
||||
url = '%s/tokens/' % self.baseurl
|
||||
args = urllib.urlencode({"github_token": github_token})
|
||||
args = urlencode({"github_token": github_token})
|
||||
resp = open_url(url, data=args, validate_certs=self._validate_certs, method="POST")
|
||||
data = json.load(resp)
|
||||
return data
|
||||
@@ -145,7 +144,7 @@ class GalaxyAPI(object):
|
||||
Post an import request
|
||||
"""
|
||||
url = '%s/imports/' % self.baseurl
|
||||
args = urllib.urlencode({
|
||||
args = urlencode({
|
||||
"github_user": github_user,
|
||||
"github_repo": github_repo,
|
||||
"github_reference": reference if reference else ""
|
||||
@@ -271,7 +270,7 @@ class GalaxyAPI(object):
|
||||
@g_connect
|
||||
def add_secret(self, source, github_user, github_repo, secret):
|
||||
url = "%s/notification_secrets/" % self.baseurl
|
||||
args = urllib.urlencode({
|
||||
args = urlencode({
|
||||
"source": source,
|
||||
"github_user": github_user,
|
||||
"github_repo": github_repo,
|
||||
|
||||
@@ -26,10 +26,9 @@ __metaclass__ = type
|
||||
|
||||
import getpass
|
||||
import json
|
||||
import urllib
|
||||
|
||||
from urllib2 import quote as urlquote, HTTPError
|
||||
from urlparse import urlparse
|
||||
from ansible.compat.six.moves.urllib.parse import quote as urlquote, urlparse
|
||||
from ansible.compat.six.moves.urllib.error import HTTPError
|
||||
|
||||
from ansible.errors import AnsibleError, AnsibleOptionsError
|
||||
from ansible.module_utils.urls import open_url
|
||||
|
||||
@@ -34,6 +34,7 @@ import pwd
|
||||
|
||||
from ansible.module_utils.basic import get_all_subclasses
|
||||
from ansible.module_utils.six import PY3, iteritems
|
||||
from ansible.module_utils._text import to_text
|
||||
|
||||
# py2 vs py3; replace with six via ansiballz
|
||||
try:
|
||||
@@ -357,6 +358,7 @@ class Facts(object):
|
||||
proc_1 = os.path.basename(proc_1)
|
||||
|
||||
if proc_1 is not None:
|
||||
proc_1 = to_text(proc_1)
|
||||
proc_1 = proc_1.strip()
|
||||
|
||||
if proc_1 == 'init' or proc_1.endswith('sh'):
|
||||
|
||||
@@ -169,7 +169,7 @@ class RoleRequirement(RoleDefinition):
|
||||
if 'scm' not in role:
|
||||
role['scm'] = None
|
||||
|
||||
for key in role.keys():
|
||||
for key in list(role.keys()):
|
||||
if key not in VALID_SPEC_KEYS:
|
||||
role.pop(key)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user