Skip to content

Commit b22095f

Browse files
author
Ulysses Souza
authored
Merge pull request #2580 from ulyssessouza/4.2.1-release
Bump 4.2.1
2 parents 1d1532f + 9923746 commit b22095f

10 files changed

+64
-42
lines changed

Jenkinsfile

+2-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def buildImages = { ->
3131
}
3232

3333
def getDockerVersions = { ->
34-
def dockerVersions = ["17.06.2-ce"]
34+
def dockerVersions = ["19.03.5"]
3535
wrappedNode(label: "ubuntu && !zfs && amd64") {
3636
def result = sh(script: """docker run --rm \\
3737
--entrypoint=python \\
@@ -46,8 +46,6 @@ def getDockerVersions = { ->
4646

4747
def getAPIVersion = { engineVersion ->
4848
def versionMap = [
49-
'17.06': '1.30',
50-
'18.03': '1.37',
5149
'18.09': '1.39',
5250
'19.03': '1.40'
5351
]
@@ -84,7 +82,7 @@ def runTests = { Map settings ->
8482
try {
8583
sh """docker network create ${testNetwork}"""
8684
sh """docker run -d --name ${dindContainerName} -v /tmp --privileged --network ${testNetwork} \\
87-
dockerswarm/dind:${dockerVersion} dockerd -H tcp://0.0.0.0:2375
85+
docker:${dockerVersion}-dind dockerd -H tcp://0.0.0.0:2375
8886
"""
8987
sh """docker run \\
9088
--name ${testContainerName} \\

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ integration-test-py3: build-py3
4242
docker run -t --rm -v /var/run/docker.sock:/var/run/docker.sock docker-sdk-python3 py.test -v tests/integration/${file}
4343

4444
TEST_API_VERSION ?= 1.35
45-
TEST_ENGINE_VERSION ?= 18.09.5
45+
TEST_ENGINE_VERSION ?= 19.03.5
4646

4747
.PHONY: setup-network
4848
setup-network:
@@ -55,7 +55,7 @@ integration-dind: integration-dind-py2 integration-dind-py3
5555
integration-dind-py2: build setup-network
5656
docker rm -vf dpy-dind-py2 || :
5757
docker run -d --network dpy-tests --name dpy-dind-py2 --privileged\
58-
dockerswarm/dind:${TEST_ENGINE_VERSION} dockerd -H tcp://0.0.0.0:2375 --experimental
58+
docker:${TEST_ENGINE_VERSION}-dind dockerd -H tcp://0.0.0.0:2375 --experimental
5959
docker run -t --rm --env="DOCKER_HOST=tcp://dpy-dind-py2:2375" --env="DOCKER_TEST_API_VERSION=${TEST_API_VERSION}"\
6060
--network dpy-tests docker-sdk-python py.test tests/integration
6161
docker rm -vf dpy-dind-py2
@@ -64,7 +64,7 @@ integration-dind-py2: build setup-network
6464
integration-dind-py3: build-py3 setup-network
6565
docker rm -vf dpy-dind-py3 || :
6666
docker run -d --network dpy-tests --name dpy-dind-py3 --privileged\
67-
dockerswarm/dind:${TEST_ENGINE_VERSION} dockerd -H tcp://0.0.0.0:2375 --experimental
67+
docker:${TEST_ENGINE_VERSION}-dind dockerd -H tcp://0.0.0.0:2375 --experimental
6868
docker run -t --rm --env="DOCKER_HOST=tcp://dpy-dind-py3:2375" --env="DOCKER_TEST_API_VERSION=${TEST_API_VERSION}"\
6969
--network dpy-tests docker-sdk-python3 py.test tests/integration
7070
docker rm -vf dpy-dind-py3
@@ -76,7 +76,7 @@ integration-dind-ssl: build-dind-certs build build-py3
7676
docker run -d --env="DOCKER_HOST=tcp://localhost:2375" --env="DOCKER_TLS_VERIFY=1"\
7777
--env="DOCKER_CERT_PATH=/certs" --volumes-from dpy-dind-certs --name dpy-dind-ssl\
7878
--network dpy-tests --network-alias docker -v /tmp --privileged\
79-
dockerswarm/dind:${TEST_ENGINE_VERSION}\
79+
docker:${TEST_ENGINE_VERSION}-dind\
8080
dockerd --tlsverify --tlscacert=/certs/ca.pem --tlscert=/certs/server-cert.pem\
8181
--tlskey=/certs/server-key.pem -H tcp://0.0.0.0:2375 --experimental
8282
docker run -t --rm --volumes-from dpy-dind-ssl --env="DOCKER_HOST=tcp://docker:2375"\

docker/context/api.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ class ContextAPI(object):
1414
Contains methods for context management:
1515
create, list, remove, get, inspect.
1616
"""
17-
DEFAULT_CONTEXT = Context("default")
17+
DEFAULT_CONTEXT = Context("default", "swarm")
1818

1919
@classmethod
2020
def create_context(
21-
cls, name, orchestrator="swarm", host=None, tls_cfg=None,
21+
cls, name, orchestrator=None, host=None, tls_cfg=None,
2222
default_namespace=None, skip_tls_verify=False):
2323
"""Creates a new context.
2424
Returns:
@@ -38,9 +38,7 @@ def create_context(
3838
>>> print(ctx.Metadata)
3939
{
4040
"Name": "test",
41-
"Metadata": {
42-
"StackOrchestrator": "swarm"
43-
},
41+
"Metadata": {},
4442
"Endpoints": {
4543
"docker": {
4644
"Host": "unix:///var/run/docker.sock",
@@ -57,7 +55,9 @@ def create_context(
5755
ctx = Context.load_context(name)
5856
if ctx:
5957
raise errors.ContextAlreadyExists(name)
60-
endpoint = "docker" if orchestrator == "swarm" else orchestrator
58+
endpoint = "docker"
59+
if orchestrator and orchestrator != "swarm":
60+
endpoint = orchestrator
6161
ctx = Context(name, orchestrator)
6262
ctx.set_endpoint(
6363
endpoint, host, tls_cfg,
@@ -79,9 +79,7 @@ def get_context(cls, name=None):
7979
>>> print(ctx.Metadata)
8080
{
8181
"Name": "test",
82-
"Metadata": {
83-
"StackOrchestrator": "swarm"
84-
},
82+
"Metadata": {},
8583
"Endpoints": {
8684
"docker": {
8785
"Host": "unix:///var/run/docker.sock",

docker/context/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def get_tls_dir(name=None, endpoint=""):
7373
return os.path.join(context_dir, "tls")
7474

7575

76-
def get_context_host(path=None):
77-
host = utils.parse_host(path, IS_WINDOWS_PLATFORM)
76+
def get_context_host(path=None, tls=False):
77+
host = utils.parse_host(path, IS_WINDOWS_PLATFORM, tls)
7878
if host == DEFAULT_UNIX_SOCKET:
7979
# remove http+ from default docker socket url
8080
return host.strip("http+")

docker/context/context.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@
1111

1212
class Context:
1313
"""A context."""
14-
def __init__(self, name, orchestrator="swarm", host=None, endpoints=None):
14+
def __init__(self, name, orchestrator=None, host=None, endpoints=None,
15+
tls=False):
1516
if not name:
1617
raise Exception("Name not provided")
1718
self.name = name
1819
self.orchestrator = orchestrator
1920
if not endpoints:
2021
default_endpoint = "docker" if (
21-
orchestrator == "swarm"
22+
not orchestrator or orchestrator == "swarm"
2223
) else orchestrator
2324
self.endpoints = {
2425
default_endpoint: {
25-
"Host": get_context_host(host),
26-
"SkipTLSVerify": False
26+
"Host": get_context_host(host, tls),
27+
"SkipTLSVerify": not tls
2728
}
2829
}
2930
else:
@@ -44,7 +45,7 @@ def set_endpoint(
4445
self, name="docker", host=None, tls_cfg=None,
4546
skip_tls_verify=False, def_namespace=None):
4647
self.endpoints[name] = {
47-
"Host": get_context_host(host),
48+
"Host": get_context_host(host, not skip_tls_verify),
4849
"SkipTLSVerify": skip_tls_verify
4950
}
5051
if def_namespace:
@@ -84,7 +85,8 @@ def _load_meta(cls, name):
8485
context {} : {}""".format(name, e))
8586

8687
return (
87-
metadata["Name"], metadata["Metadata"]["StackOrchestrator"],
88+
metadata["Name"],
89+
metadata["Metadata"].get("StackOrchestrator", None),
8890
metadata["Endpoints"])
8991
return None, None, None
9092

@@ -161,7 +163,7 @@ def Name(self):
161163

162164
@property
163165
def Host(self):
164-
if self.orchestrator == "swarm":
166+
if not self.orchestrator or self.orchestrator == "swarm":
165167
return self.endpoints["docker"]["Host"]
166168
return self.endpoints[self.orchestrator]["Host"]
167169

@@ -171,18 +173,19 @@ def Orchestrator(self):
171173

172174
@property
173175
def Metadata(self):
176+
meta = {}
177+
if self.orchestrator:
178+
meta = {"StackOrchestrator": self.orchestrator}
174179
return {
175180
"Name": self.name,
176-
"Metadata": {
177-
"StackOrchestrator": self.orchestrator
178-
},
181+
"Metadata": meta,
179182
"Endpoints": self.endpoints
180183
}
181184

182185
@property
183186
def TLSConfig(self):
184187
key = self.orchestrator
185-
if key == "swarm":
188+
if not key or key == "swarm":
186189
key = "docker"
187190
if key in self.tls_cfg.keys():
188191
return self.tls_cfg[key]

docker/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version = "4.2.0"
1+
version = "4.2.1"
22
version_info = tuple([int(d) for d in version.split("-")[0].split(".")])

docs/change-log.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
Change log
22
==========
33

4+
4.2.1
5+
-----
6+
7+
[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/65?closed=1)
8+
9+
### Features
10+
11+
- Add option on when to use `tls` on Context constructor
12+
- Make context orchestrator field optional
13+
414
4.2.0
515
-----
616

tests/integration/api_container_test.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,14 @@ def test_valid_log_driver_and_log_opt(self):
273273

274274
def test_invalid_log_driver_raises_exception(self):
275275
log_config = docker.types.LogConfig(
276-
type='asdf-nope',
276+
type='asdf',
277277
config={}
278278
)
279279

280-
expected_msg = "logger: no log driver named 'asdf-nope' is registered"
280+
expected_msgs = [
281+
"logger: no log driver named 'asdf' is registered",
282+
"looking up logging plugin asdf: plugin \"asdf\" not found",
283+
]
281284
with pytest.raises(docker.errors.APIError) as excinfo:
282285
# raises an internal server error 500
283286
container = self.client.create_container(
@@ -287,7 +290,7 @@ def test_invalid_log_driver_raises_exception(self):
287290
)
288291
self.client.start(container)
289292

290-
assert excinfo.value.explanation == expected_msg
293+
assert excinfo.value.explanation in expected_msgs
291294

292295
def test_valid_no_log_driver_specified(self):
293296
log_config = docker.types.LogConfig(
@@ -1102,6 +1105,8 @@ def test_port(self):
11021105

11031106

11041107
class ContainerTopTest(BaseAPIIntegrationTest):
1108+
@pytest.mark.xfail(reason='Output of docker top depends on host distro, '
1109+
'and is not formalized.')
11051110
def test_top(self):
11061111
container = self.client.create_container(
11071112
TEST_IMG, ['sleep', '60']
@@ -1112,28 +1117,25 @@ def test_top(self):
11121117
self.client.start(container)
11131118
res = self.client.top(container)
11141119
if not IS_WINDOWS_PLATFORM:
1115-
assert res['Titles'] == [
1116-
'UID', 'PID', 'PPID', 'C', 'STIME', 'TTY', 'TIME', 'CMD'
1117-
]
1120+
assert res['Titles'] == [u'PID', u'USER', u'TIME', u'COMMAND']
11181121
assert len(res['Processes']) == 1
11191122
assert res['Processes'][0][-1] == 'sleep 60'
11201123
self.client.kill(container)
11211124

11221125
@pytest.mark.skipif(
11231126
IS_WINDOWS_PLATFORM, reason='No psargs support on windows'
11241127
)
1128+
@pytest.mark.xfail(reason='Output of docker top depends on host distro, '
1129+
'and is not formalized.')
11251130
def test_top_with_psargs(self):
11261131
container = self.client.create_container(
11271132
TEST_IMG, ['sleep', '60'])
11281133

11291134
self.tmp_containers.append(container)
11301135

11311136
self.client.start(container)
1132-
res = self.client.top(container, 'waux')
1133-
assert res['Titles'] == [
1134-
'USER', 'PID', '%CPU', '%MEM', 'VSZ', 'RSS',
1135-
'TTY', 'STAT', 'START', 'TIME', 'COMMAND'
1136-
]
1137+
res = self.client.top(container, '-eopid,user')
1138+
assert res['Titles'] == [u'PID', u'USER']
11371139
assert len(res['Processes']) == 1
11381140
assert res['Processes'][0][10] == 'sleep 60'
11391141

tests/integration/context_api_test.py

+7
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ def test_context_remove(self):
5050
ContextAPI.remove_context("test")
5151
with pytest.raises(errors.ContextNotFound):
5252
ContextAPI.inspect_context("test")
53+
54+
def test_load_context_without_orchestrator(self):
55+
ContextAPI.create_context("test")
56+
ctx = ContextAPI.get_context("test")
57+
assert ctx
58+
assert ctx.Name == "test"
59+
assert ctx.Orchestrator is None

tests/unit/context_test.py

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def test_default_in_context_list(self):
3737
def test_get_current_context(self):
3838
assert ContextAPI.get_current_context().Name == "default"
3939

40+
def test_https_host(self):
41+
c = Context("test", host="tcp://testdomain:8080", tls=True)
42+
assert c.Host == "https://testdomain:8080"
43+
4044
def test_context_inspect_without_params(self):
4145
ctx = ContextAPI.inspect_context()
4246
assert ctx["Name"] == "default"

0 commit comments

Comments
 (0)