Move to docker python SDK 2.x.x
Since we use docker >= 12.1 we can move to docker python SDK 2.x.x. Docker 2.x.x is backwards compatible with older docker versions using the APIClient instead of the DockerClient [1]. [1] https://docker-py.readthedocs.io/en/stable/api.html Change-Id: I9e50a877de6e0a8c3ba56c2d7ebbbe336972a146 Close-Bug: #1696862
This commit is contained in:
parent
b52f3b296a
commit
1e0785c320
@ -14,8 +14,6 @@
|
||||
import contextlib
|
||||
|
||||
import docker
|
||||
from docker import client
|
||||
from docker import tls
|
||||
from docker.utils import utils
|
||||
|
||||
from magnum.conductor.handlers.common import cert_manager
|
||||
@ -79,7 +77,7 @@ def docker_for_cluster(context, cluster):
|
||||
magnum_cert.close()
|
||||
|
||||
|
||||
class DockerHTTPClient(client.Client):
|
||||
class DockerHTTPClient(docker.APIClient):
|
||||
def __init__(self, url='unix://var/run/docker.sock',
|
||||
ver=CONF.docker.docker_remote_api_version,
|
||||
timeout=CONF.docker.default_timeout,
|
||||
@ -88,7 +86,7 @@ class DockerHTTPClient(client.Client):
|
||||
client_cert=None):
|
||||
|
||||
if ca_cert and client_key and client_cert:
|
||||
ssl_config = tls.TLSConfig(
|
||||
ssl_config = docker.tls.TLSConfig(
|
||||
client_cert=(client_cert, client_key),
|
||||
verify=ca_cert,
|
||||
assert_hostname=False,
|
||||
|
@ -17,7 +17,7 @@ docker_group = cfg.OptGroup(name='docker',
|
||||
|
||||
docker_opts = [
|
||||
cfg.StrOpt('docker_remote_api_version',
|
||||
default='1.20',
|
||||
default='1.21',
|
||||
help='Docker remote api version. Override it according to '
|
||||
'specific docker api version in your environment.'),
|
||||
cfg.IntOpt('default_timeout',
|
||||
|
@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from docker import client as docker_py_client
|
||||
import docker
|
||||
import mock
|
||||
|
||||
from magnum.common import docker_utils
|
||||
@ -30,9 +30,9 @@ class TestDockerUtils(base.BaseTestCase):
|
||||
def fake_version():
|
||||
return {'ApiVersion': '1.18'}
|
||||
|
||||
docker = mock.MagicMock()
|
||||
docker.version.side_effect = fake_version
|
||||
res = docker_utils.is_docker_api_version_atleast(docker, '1.19')
|
||||
docker_client = mock.MagicMock()
|
||||
docker_client.version.side_effect = fake_version
|
||||
res = docker_utils.is_docker_api_version_atleast(docker_client, '1.21')
|
||||
self.assertFalse(res)
|
||||
|
||||
|
||||
@ -73,8 +73,8 @@ class DockerClientTestCase(base.BaseTestCase):
|
||||
self.assertEqual(CONF.docker.default_timeout,
|
||||
client.timeout)
|
||||
|
||||
@mock.patch.object(docker_py_client.Client, 'inspect_container')
|
||||
@mock.patch.object(docker_py_client.Client, 'containers')
|
||||
@mock.patch.object(docker.APIClient, 'inspect_container')
|
||||
@mock.patch.object(docker.APIClient, 'containers')
|
||||
def test_list_instances(self, mock_containers, mock_inspect):
|
||||
client = docker_utils.DockerHTTPClient()
|
||||
|
||||
@ -90,8 +90,8 @@ class DockerClientTestCase(base.BaseTestCase):
|
||||
mock_containers.assert_called_once_with(all=True)
|
||||
mock_inspect.assert_has_calls([mock.call(x) for x in range(0, 3)])
|
||||
|
||||
@mock.patch.object(docker_py_client.Client, 'inspect_container')
|
||||
@mock.patch.object(docker_py_client.Client, 'containers')
|
||||
@mock.patch.object(docker.APIClient, 'inspect_container')
|
||||
@mock.patch.object(docker.APIClient, 'containers')
|
||||
def test_list_instances_inspect(self, mock_containers, mock_inspect):
|
||||
client = docker_utils.DockerHTTPClient()
|
||||
|
||||
|
@ -13,7 +13,7 @@ WebOb>=1.7.1 # MIT
|
||||
alembic>=0.8.10 # MIT
|
||||
cliff>=2.6.0 # Apache-2.0
|
||||
decorator>=3.4.0 # BSD
|
||||
docker-py>=1.8.1 # Apache-2.0
|
||||
docker>=2.0.0 # Apache-2.0
|
||||
enum34;python_version=='2.7' or python_version=='2.6' or python_version=='3.3' # BSD
|
||||
eventlet!=0.18.3,<0.21.0,>=0.18.2 # MIT
|
||||
iso8601>=0.1.11 # MIT
|
||||
|
Loading…
Reference in New Issue
Block a user