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 contextlib
|
||||||
|
|
||||||
import docker
|
import docker
|
||||||
from docker import client
|
|
||||||
from docker import tls
|
|
||||||
from docker.utils import utils
|
from docker.utils import utils
|
||||||
|
|
||||||
from magnum.conductor.handlers.common import cert_manager
|
from magnum.conductor.handlers.common import cert_manager
|
||||||
|
@ -79,7 +77,7 @@ def docker_for_cluster(context, cluster):
|
||||||
magnum_cert.close()
|
magnum_cert.close()
|
||||||
|
|
||||||
|
|
||||||
class DockerHTTPClient(client.Client):
|
class DockerHTTPClient(docker.APIClient):
|
||||||
def __init__(self, url='unix://var/run/docker.sock',
|
def __init__(self, url='unix://var/run/docker.sock',
|
||||||
ver=CONF.docker.docker_remote_api_version,
|
ver=CONF.docker.docker_remote_api_version,
|
||||||
timeout=CONF.docker.default_timeout,
|
timeout=CONF.docker.default_timeout,
|
||||||
|
@ -88,7 +86,7 @@ class DockerHTTPClient(client.Client):
|
||||||
client_cert=None):
|
client_cert=None):
|
||||||
|
|
||||||
if ca_cert and client_key and client_cert:
|
if ca_cert and client_key and client_cert:
|
||||||
ssl_config = tls.TLSConfig(
|
ssl_config = docker.tls.TLSConfig(
|
||||||
client_cert=(client_cert, client_key),
|
client_cert=(client_cert, client_key),
|
||||||
verify=ca_cert,
|
verify=ca_cert,
|
||||||
assert_hostname=False,
|
assert_hostname=False,
|
||||||
|
|
|
@ -17,7 +17,7 @@ docker_group = cfg.OptGroup(name='docker',
|
||||||
|
|
||||||
docker_opts = [
|
docker_opts = [
|
||||||
cfg.StrOpt('docker_remote_api_version',
|
cfg.StrOpt('docker_remote_api_version',
|
||||||
default='1.20',
|
default='1.21',
|
||||||
help='Docker remote api version. Override it according to '
|
help='Docker remote api version. Override it according to '
|
||||||
'specific docker api version in your environment.'),
|
'specific docker api version in your environment.'),
|
||||||
cfg.IntOpt('default_timeout',
|
cfg.IntOpt('default_timeout',
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from docker import client as docker_py_client
|
import docker
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from magnum.common import docker_utils
|
from magnum.common import docker_utils
|
||||||
|
@ -30,9 +30,9 @@ class TestDockerUtils(base.BaseTestCase):
|
||||||
def fake_version():
|
def fake_version():
|
||||||
return {'ApiVersion': '1.18'}
|
return {'ApiVersion': '1.18'}
|
||||||
|
|
||||||
docker = mock.MagicMock()
|
docker_client = mock.MagicMock()
|
||||||
docker.version.side_effect = fake_version
|
docker_client.version.side_effect = fake_version
|
||||||
res = docker_utils.is_docker_api_version_atleast(docker, '1.19')
|
res = docker_utils.is_docker_api_version_atleast(docker_client, '1.21')
|
||||||
self.assertFalse(res)
|
self.assertFalse(res)
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@ class DockerClientTestCase(base.BaseTestCase):
|
||||||
self.assertEqual(CONF.docker.default_timeout,
|
self.assertEqual(CONF.docker.default_timeout,
|
||||||
client.timeout)
|
client.timeout)
|
||||||
|
|
||||||
@mock.patch.object(docker_py_client.Client, 'inspect_container')
|
@mock.patch.object(docker.APIClient, 'inspect_container')
|
||||||
@mock.patch.object(docker_py_client.Client, 'containers')
|
@mock.patch.object(docker.APIClient, 'containers')
|
||||||
def test_list_instances(self, mock_containers, mock_inspect):
|
def test_list_instances(self, mock_containers, mock_inspect):
|
||||||
client = docker_utils.DockerHTTPClient()
|
client = docker_utils.DockerHTTPClient()
|
||||||
|
|
||||||
|
@ -90,8 +90,8 @@ class DockerClientTestCase(base.BaseTestCase):
|
||||||
mock_containers.assert_called_once_with(all=True)
|
mock_containers.assert_called_once_with(all=True)
|
||||||
mock_inspect.assert_has_calls([mock.call(x) for x in range(0, 3)])
|
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.APIClient, 'inspect_container')
|
||||||
@mock.patch.object(docker_py_client.Client, 'containers')
|
@mock.patch.object(docker.APIClient, 'containers')
|
||||||
def test_list_instances_inspect(self, mock_containers, mock_inspect):
|
def test_list_instances_inspect(self, mock_containers, mock_inspect):
|
||||||
client = docker_utils.DockerHTTPClient()
|
client = docker_utils.DockerHTTPClient()
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ WebOb>=1.7.1 # MIT
|
||||||
alembic>=0.8.10 # MIT
|
alembic>=0.8.10 # MIT
|
||||||
cliff>=2.6.0 # Apache-2.0
|
cliff>=2.6.0 # Apache-2.0
|
||||||
decorator>=3.4.0 # BSD
|
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
|
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
|
eventlet!=0.18.3,<0.21.0,>=0.18.2 # MIT
|
||||||
iso8601>=0.1.11 # MIT
|
iso8601>=0.1.11 # MIT
|
||||||
|
|
Loading…
Reference in New Issue