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

Commit

Permalink
Merge pull request #174 from projectcalico/fix-host-config
Browse files Browse the repository at this point in the history
Move per-host config out of global config
  • Loading branch information
djosborne authored Dec 6, 2016
2 parents 96a0e62 + 593d399 commit 2bf36b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
10 changes: 6 additions & 4 deletions calico_containers/pycalico/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,8 @@ def ensure_global_config(self):

# Configure IPAM directory structures (to ensure confd is able to
# watch appropriate directory trees).
host = get_hostname()
for version in (4, 6):
affinity_path = IPAM_HOST_AFFINITY_PATH % {"host": host,
"version": version}
pool_path = IP_POOLS_PATH % {"version": version}
self._write_global_dir(affinity_path)
self._write_global_dir(pool_path)

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

# Create the per-host affinity paths.
for version in (4, 6):
affinity_path = IPAM_HOST_AFFINITY_PATH % {"host": hostname,
"version": version}
self._write_global_dir(affinity_path)

# Set up the host
self.etcd_client.write(host_ipv4, ipv4)
self.etcd_client.write(bgp_ipv4, ipv4)
Expand Down
16 changes: 8 additions & 8 deletions calico_containers/tests/unit/test_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
BGP_CUSTOM_FILTERS_IPV4_PATH = BGP_CUSTOM_FILTERS_PATH + "v4/"
BGP_CUSTOM_FILTERS_IPV6_PATH = BGP_CUSTOM_FILTERS_PATH + "v6/"

IPAM_V4_PATH = "/calico/ipam/v2/host/THIS_HOST/ipv4/block/"
IPAM_V6_PATH = "/calico/ipam/v2/host/THIS_HOST/ipv6/block/"
IPAM_V4_PATH = "/calico/ipam/v2/host/TEST_HOST/ipv4/block/"
IPAM_V6_PATH = "/calico/ipam/v2/host/TEST_HOST/ipv6/block/"

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

expected_writes = [call(int_prefix_path, "cali"),
call(IPAM_V4_PATH, None, dir=True),
call(IPV4_POOLS_PATH, None, dir=True),
call(IPAM_V6_PATH, None, dir=True),
call(IPV6_POOLS_PATH, None, dir=True),
call(BGP_CUSTOM_FILTERS_IPV4_PATH, None, dir=True),
call(BGP_CUSTOM_FILTERS_IPV6_PATH, None, dir=True),
Expand Down Expand Up @@ -633,9 +631,7 @@ def explode(path, value, **kwargs):
self.datastore.ensure_global_config()

expected_writes = [call(int_prefix_path, "cali"),
call(IPAM_V4_PATH, None, dir=True),
call(IPV4_POOLS_PATH, None, dir=True),
call(IPAM_V6_PATH, None, dir=True),
call(IPV6_POOLS_PATH, None, dir=True),
call(BGP_CUSTOM_FILTERS_IPV4_PATH, None, dir=True),
call(BGP_CUSTOM_FILTERS_IPV6_PATH, None, dir=True),
Expand Down Expand Up @@ -969,11 +965,13 @@ def mock_read_success(path):
call(TEST_BGP_HOST_IPV4_PATH, ipv4),
call(TEST_BGP_HOST_IPV6_PATH, ipv6),
call(TEST_BGP_HOST_AS_PATH, bgp_as),
call(IPAM_V4_PATH, None, dir=True),
call(IPAM_V6_PATH, None, dir=True),
call(TEST_HOST_PATH + "/config/marker",
"created")]
self.etcd_client.write.assert_has_calls(expected_writes,
any_order=True)
assert_equal(self.etcd_client.write.call_count, 5)
assert_equal(self.etcd_client.write.call_count, 7)

def test_create_host_mainline(self):
"""
Expand All @@ -999,6 +997,8 @@ def mock_read(path):
expected_writes = [call(TEST_HOST_IPV4_PATH, ipv4),
call(TEST_BGP_HOST_IPV4_PATH, ipv4),
call(TEST_BGP_HOST_IPV6_PATH, ipv6),
call(IPAM_V4_PATH, None, dir=True),
call(IPAM_V6_PATH, None, dir=True),
call(TEST_HOST_PATH +
"/config/DefaultEndpointToHostAction",
"RETURN"),
Expand All @@ -1008,7 +1008,7 @@ def mock_read(path):
None, dir=True)]
self.etcd_client.write.assert_has_calls(expected_writes,
any_order=True)
assert_equal(self.etcd_client.write.call_count, 6)
assert_equal(self.etcd_client.write.call_count, 8)

def test_get_per_host_config_mainline(self):
value = self.datastore.get_per_host_config("hostname", "SomeConfig")
Expand Down

0 comments on commit 2bf36b3

Please sign in to comment.