Skip to content
This repository was archived by the owner on Oct 22, 2019. It is now read-only.

Commit 2bf36b3

Browse files
authored
Merge pull request #174 from projectcalico/fix-host-config
Move per-host config out of global config
2 parents 96a0e62 + 593d399 commit 2bf36b3

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

calico_containers/pycalico/datastore.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,8 @@ def ensure_global_config(self):
268268

269269
# Configure IPAM directory structures (to ensure confd is able to
270270
# watch appropriate directory trees).
271-
host = get_hostname()
272271
for version in (4, 6):
273-
affinity_path = IPAM_HOST_AFFINITY_PATH % {"host": host,
274-
"version": version}
275272
pool_path = IP_POOLS_PATH % {"version": version}
276-
self._write_global_dir(affinity_path)
277273
self._write_global_dir(pool_path)
278274

279275
# create directories for custom filters
@@ -373,6 +369,12 @@ def create_host(self, hostname, ipv4, ipv6, as_num):
373369
bgp_ipv6 = BGP_HOST_IPV6_PATH % {"hostname": hostname}
374370
bgp_as = BGP_HOST_AS_PATH % {"hostname": hostname}
375371

372+
# Create the per-host affinity paths.
373+
for version in (4, 6):
374+
affinity_path = IPAM_HOST_AFFINITY_PATH % {"host": hostname,
375+
"version": version}
376+
self._write_global_dir(affinity_path)
377+
376378
# Set up the host
377379
self.etcd_client.write(host_ipv4, ipv4)
378380
self.etcd_client.write(bgp_ipv4, ipv4)

calico_containers/tests/unit/test_datastore.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
BGP_CUSTOM_FILTERS_IPV4_PATH = BGP_CUSTOM_FILTERS_PATH + "v4/"
7575
BGP_CUSTOM_FILTERS_IPV6_PATH = BGP_CUSTOM_FILTERS_PATH + "v6/"
7676

77-
IPAM_V4_PATH = "/calico/ipam/v2/host/THIS_HOST/ipv4/block/"
78-
IPAM_V6_PATH = "/calico/ipam/v2/host/THIS_HOST/ipv6/block/"
77+
IPAM_V4_PATH = "/calico/ipam/v2/host/TEST_HOST/ipv4/block/"
78+
IPAM_V6_PATH = "/calico/ipam/v2/host/TEST_HOST/ipv6/block/"
7979

8080
# 4 endpoints, with 2 TEST profile and 2 UNIT profile.
8181
EP_56 = Endpoint(TEST_HOST, "docker", TEST_CONT_ID, "567890abcdef",
@@ -590,9 +590,7 @@ def test_ensure_global_config(self, m_gethostname):
590590
self.etcd_client.read.assert_has_calls(expected_reads)
591591

592592
expected_writes = [call(int_prefix_path, "cali"),
593-
call(IPAM_V4_PATH, None, dir=True),
594593
call(IPV4_POOLS_PATH, None, dir=True),
595-
call(IPAM_V6_PATH, None, dir=True),
596594
call(IPV6_POOLS_PATH, None, dir=True),
597595
call(BGP_CUSTOM_FILTERS_IPV4_PATH, None, dir=True),
598596
call(BGP_CUSTOM_FILTERS_IPV6_PATH, None, dir=True),
@@ -633,9 +631,7 @@ def explode(path, value, **kwargs):
633631
self.datastore.ensure_global_config()
634632

635633
expected_writes = [call(int_prefix_path, "cali"),
636-
call(IPAM_V4_PATH, None, dir=True),
637634
call(IPV4_POOLS_PATH, None, dir=True),
638-
call(IPAM_V6_PATH, None, dir=True),
639635
call(IPV6_POOLS_PATH, None, dir=True),
640636
call(BGP_CUSTOM_FILTERS_IPV4_PATH, None, dir=True),
641637
call(BGP_CUSTOM_FILTERS_IPV6_PATH, None, dir=True),
@@ -969,11 +965,13 @@ def mock_read_success(path):
969965
call(TEST_BGP_HOST_IPV4_PATH, ipv4),
970966
call(TEST_BGP_HOST_IPV6_PATH, ipv6),
971967
call(TEST_BGP_HOST_AS_PATH, bgp_as),
968+
call(IPAM_V4_PATH, None, dir=True),
969+
call(IPAM_V6_PATH, None, dir=True),
972970
call(TEST_HOST_PATH + "/config/marker",
973971
"created")]
974972
self.etcd_client.write.assert_has_calls(expected_writes,
975973
any_order=True)
976-
assert_equal(self.etcd_client.write.call_count, 5)
974+
assert_equal(self.etcd_client.write.call_count, 7)
977975

978976
def test_create_host_mainline(self):
979977
"""
@@ -999,6 +997,8 @@ def mock_read(path):
999997
expected_writes = [call(TEST_HOST_IPV4_PATH, ipv4),
1000998
call(TEST_BGP_HOST_IPV4_PATH, ipv4),
1001999
call(TEST_BGP_HOST_IPV6_PATH, ipv6),
1000+
call(IPAM_V4_PATH, None, dir=True),
1001+
call(IPAM_V6_PATH, None, dir=True),
10021002
call(TEST_HOST_PATH +
10031003
"/config/DefaultEndpointToHostAction",
10041004
"RETURN"),
@@ -1008,7 +1008,7 @@ def mock_read(path):
10081008
None, dir=True)]
10091009
self.etcd_client.write.assert_has_calls(expected_writes,
10101010
any_order=True)
1011-
assert_equal(self.etcd_client.write.call_count, 6)
1011+
assert_equal(self.etcd_client.write.call_count, 8)
10121012

10131013
def test_get_per_host_config_mainline(self):
10141014
value = self.datastore.get_per_host_config("hostname", "SomeConfig")

0 commit comments

Comments
 (0)