[PY3] Add unicode_literals to docker state/execution modules

This commit is contained in:
Erik Johnson 2017-12-13 22:49:23 -06:00
parent b6725536f8
commit 5e1f75aab0
No known key found for this signature in database
GPG Key ID: 5E5583C437808F3F
19 changed files with 58 additions and 53 deletions

View File

@ -100,7 +100,7 @@ Detailed Function Documentation
-------------------------------
'''
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import inspect
import logging
@ -108,6 +108,9 @@ import os
import re
import salt.utils.files
import salt.utils.stringutils
from salt.ext import six
from operator import attrgetter
try:
@ -136,7 +139,7 @@ DEFAULT_DC_FILENAMES = ('docker-compose.yml', 'docker-compose.yaml')
def __virtual__():
if HAS_DOCKERCOMPOSE:
match = re.match(VERSION_RE, str(compose.__version__))
match = re.match(VERSION_RE, six.text_type(compose.__version__))
if match:
version = tuple([int(x) for x in match.group(1).split('.')])
if version >= MIN_DOCKERCOMPOSE:
@ -201,7 +204,7 @@ def __read_docker_compose_file(file_path):
file_name = os.path.basename(file_path)
result = {file_name: ''}
for line in fl:
result[file_name] += line
result[file_name] += salt.utils.stringutils.to_unicode(line)
except EnvironmentError:
return __standardize_result(False,
'Could not read {0}'.format(file_path),
@ -233,7 +236,7 @@ def __write_docker_compose(path, docker_compose):
os.mkdir(dir_name)
try:
with salt.utils.files.fopen(file_path, 'w') as fl:
fl.write(docker_compose)
fl.write(salt.utils.stringutils.to_str(docker_compose))
except EnvironmentError:
return __standardize_result(False,
'Could not write {0}'.format(file_path),

View File

@ -2350,13 +2350,13 @@ def version():
ret = _client_wrapper('version')
version_re = re.compile(VERSION_RE)
if 'Version' in ret:
match = version_re.match(str(ret['Version']))
match = version_re.match(six.text_type(ret['Version']))
if match:
ret['VersionInfo'] = tuple(
[int(x) for x in match.group(1).split('.')]
)
if 'ApiVersion' in ret:
match = version_re.match(str(ret['ApiVersion']))
match = version_re.match(six.text_type(ret['ApiVersion']))
if match:
ret['ApiVersionInfo'] = tuple(
[int(x) for x in match.group(1).split('.')]
@ -3935,9 +3935,9 @@ def build(path=None,
)
else:
if not isinstance(repository, six.string_types):
repository = str(repository)
repository = six.text_type(repository)
if not isinstance(tag, six.string_types):
tag = str(tag)
tag = six.text_type(tag)
# For the build function in the low-level API, the "tag" refers to the full
# tag (e.g. myuser/myimage:mytag). This is different than in other
@ -4075,9 +4075,9 @@ def commit(name,
respository = image
if not isinstance(repository, six.string_types):
repository = str(repository)
repository = six.text_type(repository)
if not isinstance(tag, six.string_types):
tag = str(tag)
tag = six.text_type(tag)
time_started = time.time()
response = _client_wrapper(
@ -4226,9 +4226,9 @@ def import_(source,
respository = image
if not isinstance(repository, six.string_types):
repository = str(repository)
repository = six.text_type(repository)
if not isinstance(tag, six.string_types):
tag = str(tag)
tag = six.text_type(tag)
path = __salt__['container_resource.cache_file'](source)
@ -4575,7 +4575,7 @@ def push(image,
salt myminion docker.push myuser/mycontainer:mytag
'''
if not isinstance(image, six.string_types):
image = str(image)
image = six.text_type(image)
kwargs = {'stream': True,
'client_timeout': client_timeout}
@ -4846,6 +4846,8 @@ def save(name,
try:
with __utils__['files.fopen'](saved_path, 'rb') as uncompressed:
# No need to decode on read and encode on on write, since we're
# reading and immediately writing out bytes.
if compression != 'gzip':
# gzip doesn't use a Compressor object, it uses a .open()
# method to open the filehandle. If not using gzip, we need
@ -4940,9 +4942,9 @@ def tag_(name, repository, tag='latest', force=False, image=None):
respository = image
if not isinstance(repository, six.string_types):
repository = str(repository)
repository = six.text_type(repository)
if not isinstance(tag, six.string_types):
tag = str(tag)
tag = six.text_type(tag)
image_id = inspect_image(name)['Id']
response = _client_wrapper('tag',
@ -5952,7 +5954,7 @@ def _script(name,
ret = run_all(
name,
path + ' ' + str(args) if args else path,
path + ' ' + six.text_type(args) if args else path,
exec_driver=exec_driver,
stdin=stdin,
python_shell=python_shell,

View File

@ -55,7 +55,7 @@ States to manage Docker containers, images, volumes, and networks
The old syntax will continue to work until the **Fluorine** release of
Salt.
'''
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import copy
import logging

View File

@ -45,7 +45,7 @@ configuration remains unchanged.
:ref:`here <docker-authentication>` for more information on how to
configure access to docker registries in :ref:`Pillar <pillar>` data.
'''
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import copy
import logging
import os
@ -1669,7 +1669,7 @@ def running(name,
ret['comment'] = 'The \'image\' argument is required'
return ret
elif not isinstance(image, six.string_types):
image = str(image)
image = six.text_type(image)
try:
networks = _parse_networks(networks)
@ -2175,7 +2175,7 @@ def run(name,
ret['comment'] = 'The \'image\' argument is required'
return ret
elif not isinstance(image, six.string_types):
image = str(image)
image = six.text_type(image)
cret = mod_run_check(onlyif, unless, creates)
if isinstance(cret, dict):
@ -2351,11 +2351,11 @@ def stopped(name=None,
targets = []
for target in containers:
if not isinstance(target, six.string_types):
target = str(target)
target = six.text_type(target)
targets.append(target)
elif name:
if not isinstance(name, six.string_types):
targets = [str(name)]
targets = [six.text_type(name)]
else:
targets = [name]

View File

@ -35,7 +35,7 @@ module (formerly called **dockerng**) in the 2017.7.0 release.
:ref:`here <docker-authentication>` for more information on how to
configure access to docker registries in :ref:`Pillar <pillar>` data.
'''
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import logging
# Import salt libs
@ -192,7 +192,7 @@ def present(name,
'comment': ''}
if not isinstance(name, six.string_types):
name = str(name)
name = six.string_types(name)
# At most one of the args that result in an image being built can be used
num_build_args = len([x for x in (build, load, sls) if x is not None])
@ -209,7 +209,7 @@ def present(name,
)
return ret
if not isinstance(tag, six.string_types):
tag = str(tag)
tag = six.string_types(tag)
full_image = ':'.join((name, tag))
else:
if tag:

View File

@ -30,7 +30,7 @@ Management of Docker networks
These states were moved from the :mod:`docker <salt.states.docker>` state
module (formerly called **dockerng**) in the 2017.7.0 release.
'''
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import copy
import logging
import random

View File

@ -30,7 +30,7 @@ Management of Docker volumes
These states were moved from the :mod:`docker <salt.states.docker>` state
module (formerly called **dockerng**) in the 2017.7.0 release.
'''
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import logging
# Import salt libs

View File

@ -7,7 +7,7 @@ input as formatted by states.
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import logging
import os

View File

@ -3,7 +3,7 @@
Functions to translate input for container creation
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import os
# Import Salt libs
@ -375,14 +375,14 @@ def port_bindings(val, **kwargs):
try:
val = helpers.split(val)
except AttributeError:
val = helpers.split(str(val))
val = helpers.split(six.text_type(val))
for idx in range(len(val)):
if not isinstance(val[idx], six.string_types):
val[idx] = str(val[idx])
val[idx] = six.text_type(val[idx])
def _format_port(port_num, proto):
return str(port_num) + '/udp' if proto.lower() == 'udp' else port_num
return six.text_type(port_num) + '/udp' if proto.lower() == 'udp' else port_num
bindings = {}
for binding in val:
@ -391,7 +391,7 @@ def port_bindings(val, **kwargs):
if num_bind_parts == 1:
# Single port or port range being passed through (no
# special mapping)
container_port = str(bind_parts[0])
container_port = six.text_type(bind_parts[0])
if container_port == '':
raise SaltInvocationError(
'Empty port binding definition found'

View File

@ -4,7 +4,7 @@ Functions to translate input in the docker CLI format to the format desired by
by the API.
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import os
# Import Salt libs
@ -148,7 +148,7 @@ def validate_subnet(val):
def translate_str(val):
return str(val) if not isinstance(val, six.string_types) else val
return six.text_type(val) if not isinstance(val, six.string_types) else val
def translate_int(val):
@ -183,10 +183,10 @@ def translate_command(val):
elif isinstance(val, list):
for idx in range(len(val)):
if not isinstance(val[idx], six.string_types):
val[idx] = str(val[idx])
val[idx] = six.text_type(val[idx])
else:
# Make sure we have a string
val = str(val)
val = six.text_type(val)
return val
@ -199,7 +199,7 @@ def translate_bytes(val):
val = int(val)
except (TypeError, ValueError):
if not isinstance(val, six.string_types):
val = str(val)
val = six.text_type(val)
return val
@ -215,10 +215,10 @@ def translate_stringlist(val):
try:
val = split(val)
except AttributeError:
val = split(str(val))
val = split(six.text_type(val))
for idx in range(len(val)):
if not isinstance(val[idx], six.string_types):
val[idx] = str(val[idx])
val[idx] = six.text_type(val[idx])
return val
@ -300,9 +300,9 @@ def translate_labels(val):
key = item
val = ''
if not isinstance(key, six.string_types):
key = str(key)
key = six.text_type(key)
if not isinstance(val, six.string_types):
val = str(val)
val = six.text_type(val)
new_val[key] = val
val = new_val
return val

View File

@ -3,7 +3,7 @@
Functions to translate input for network creation
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
# Import Salt libs
from salt.exceptions import SaltInvocationError

View File

@ -4,7 +4,7 @@ Integration tests for the docker_container states
'''
# Import Python Libs
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import functools
import random
import string

View File

@ -3,7 +3,7 @@
Integration tests for the docker_container states
'''
# Import Python Libs
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import errno
import functools
import logging

View File

@ -3,7 +3,7 @@
Integration tests for the docker_network states
'''
# Import Python Libs
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import errno
import functools
import logging

View File

@ -3,7 +3,7 @@
Common code used in Docker integration tests
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import functools
import random
import string

View File

@ -4,7 +4,7 @@ Unit tests for the docker module
'''
# Import Python Libs
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
@ -751,7 +751,7 @@ class DockerTestCase(TestCase, LoaderModuleMockMixin):
with patch.object(docker_mod, 'inspect_container', inspect_container_mock):
with patch.object(docker_mod, 'inspect_image', inspect_image_mock):
ret = docker_mod.compare_container('container1', 'container2')
ret = docker_mod.compare_containers('container1', 'container2')
self.assertEqual(ret, {})
def test_resolve_tag(self):

View File

@ -4,7 +4,7 @@ Unit tests for the docker state
'''
# Import Python Libs
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin

View File

@ -4,7 +4,7 @@ Unit tests for the docker state
'''
# Import Python Libs
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin

View File

@ -6,7 +6,7 @@ tests.unit.utils.test_docker
Test the funcs in salt.utils.docker and salt.utils.docker.translate
'''
# Import Python Libs
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import copy
import functools
import logging
@ -1985,7 +1985,7 @@ class TranslateNetworkInputTestCase(TranslateBase):
),
self.apply_defaults(
{'gateway': val if isinstance(val, six.string_types)
else str(val)}
else six.text_type(val)}
)
)