Fix #2804: Add ipv4 and ipv6 static addressing
- Added ipv4_network and ipv6_network to the networks section in the service section for each configured network - Added feature documentation - Added unit tests Signed-off-by: Matt Daue <mattdaue@gmail.com>
This commit is contained in:
parent
8a86e204a0
commit
ee136446a2
8 changed files with 178 additions and 9 deletions
|
|
@ -475,6 +475,30 @@ class CLITestCase(DockerClientTestCase):
|
|||
assert 'forward_facing' in front_aliases
|
||||
assert 'ahead' in front_aliases
|
||||
|
||||
@v2_only()
|
||||
def test_up_with_network_static_addresses(self):
|
||||
filename = 'network-static-addresses.yml'
|
||||
ipv4_address = '172.16.100.100'
|
||||
ipv6_address = 'fe80::1001:100'
|
||||
self.base_dir = 'tests/fixtures/networks'
|
||||
self.dispatch(['-f', filename, 'up', '-d'], None)
|
||||
static_net = '{}_static_test'.format(self.project.name)
|
||||
|
||||
networks = [
|
||||
n for n in self.client.networks()
|
||||
if n['Name'].startswith('{}_'.format(self.project.name))
|
||||
]
|
||||
|
||||
# One networks was created: front
|
||||
assert sorted(n['Name'] for n in networks) == [static_net]
|
||||
web_container = self.project.get_service('web').containers()[0]
|
||||
|
||||
ipam_config = web_container.get(
|
||||
'NetworkSettings.Networks.{}.IPAMConfig'.format(static_net)
|
||||
)
|
||||
assert ipv4_address in ipam_config.values()
|
||||
assert ipv6_address in ipam_config.values()
|
||||
|
||||
@v2_only()
|
||||
def test_up_with_networks(self):
|
||||
self.base_dir = 'tests/fixtures/networks'
|
||||
|
|
|
|||
23
tests/fixtures/networks/network-static-addresses.yml
vendored
Executable file
23
tests/fixtures/networks/network-static-addresses.yml
vendored
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
version: "2"
|
||||
|
||||
services:
|
||||
web:
|
||||
image: busybox
|
||||
command: top
|
||||
networks:
|
||||
static_test:
|
||||
ipv4_address: 172.16.100.100
|
||||
ipv6_address: fe80::1001:100
|
||||
|
||||
networks:
|
||||
static_test:
|
||||
driver: bridge
|
||||
driver_opts:
|
||||
com.docker.network.enable_ipv6: "true"
|
||||
ipam:
|
||||
driver: default
|
||||
config:
|
||||
- subnet: 172.16.100.0/24
|
||||
gateway: 172.16.100.1
|
||||
- subnet: fe80::/64
|
||||
gateway: fe80::1001:1
|
||||
|
|
@ -5,6 +5,7 @@ import random
|
|||
|
||||
import py
|
||||
import pytest
|
||||
from docker.errors import APIError
|
||||
from docker.errors import NotFound
|
||||
|
||||
from ..helpers import build_config
|
||||
|
|
@ -650,6 +651,96 @@ class ProjectTest(DockerClientTestCase):
|
|||
}],
|
||||
}
|
||||
|
||||
@v2_only()
|
||||
def test_up_with_network_static_addresses(self):
|
||||
config_data = config.Config(
|
||||
version=V2_0,
|
||||
services=[{
|
||||
'name': 'web',
|
||||
'image': 'busybox:latest',
|
||||
'networks': {
|
||||
'static_test': {
|
||||
'ipv4_address': '172.16.100.100',
|
||||
'ipv6_address': 'fe80::1001:102'
|
||||
}
|
||||
},
|
||||
}],
|
||||
volumes={},
|
||||
networks={
|
||||
'static_test': {
|
||||
'driver': 'bridge',
|
||||
'driver_opts': {
|
||||
"com.docker.network.enable_ipv6": "true",
|
||||
},
|
||||
'ipam': {
|
||||
'driver': 'default',
|
||||
'config': [
|
||||
{"subnet": "172.16.100.0/24",
|
||||
"gateway": "172.16.100.1"},
|
||||
{"subnet": "fe80::/64",
|
||||
"gateway": "fe80::1001:1"}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
project = Project.from_config(
|
||||
client=self.client,
|
||||
name='composetest',
|
||||
config_data=config_data,
|
||||
)
|
||||
project.up()
|
||||
|
||||
network = self.client.networks(names=['static_test'])[0]
|
||||
service_container = project.get_service('web').containers()[0]
|
||||
|
||||
assert network['Options'] == {
|
||||
"com.docker.network.enable_ipv6": "true"
|
||||
}
|
||||
|
||||
IPAMConfig = (service_container.inspect().get('NetworkSettings', {}).
|
||||
get('Networks', {}).get('composetest_static_test', {}).
|
||||
get('IPAMConfig', {}))
|
||||
assert IPAMConfig.get('IPv4Address') == '172.16.100.100'
|
||||
assert IPAMConfig.get('IPv6Address') == 'fe80::1001:102'
|
||||
|
||||
@v2_only()
|
||||
def test_up_with_network_static_addresses_missing_subnet(self):
|
||||
config_data = config.Config(
|
||||
version=V2_0,
|
||||
services=[{
|
||||
'name': 'web',
|
||||
'image': 'busybox:latest',
|
||||
'networks': {
|
||||
'static_test': {
|
||||
'ipv4_address': '172.16.100.100',
|
||||
'ipv6_address': 'fe80::1001:101'
|
||||
}
|
||||
},
|
||||
}],
|
||||
volumes={},
|
||||
networks={
|
||||
'static_test': {
|
||||
'driver': 'bridge',
|
||||
'driver_opts': {
|
||||
"com.docker.network.enable_ipv6": "true",
|
||||
},
|
||||
'ipam': {
|
||||
'driver': 'default',
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
project = Project.from_config(
|
||||
client=self.client,
|
||||
name='composetest',
|
||||
config_data=config_data,
|
||||
)
|
||||
|
||||
with self.assertRaises(APIError):
|
||||
project.up()
|
||||
|
||||
@v2_only()
|
||||
def test_project_up_volumes(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue