Skip to content

Commit

Permalink
Get calico/node STs running with etcdv3 and v2 datamodel
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Jerram committed Oct 27, 2017
1 parent a742aa6 commit 03fec6d
Show file tree
Hide file tree
Showing 19 changed files with 434 additions and 255 deletions.
32 changes: 23 additions & 9 deletions calico_node/tests/st/bgp/peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,35 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import yaml

def create_bgp_peer(host, scope, ip, asNum):

def create_bgp_peer(host, scope, ip, asNum, metadata=None):
assert scope in ('node', 'global')
node = host.get_hostname() if scope == 'node' else ""
testdata = {
'apiVersion': 'v1',
'kind': 'bgpPeer',
'apiVersion': 'projectcalico.org/v2',
'kind': 'BGPPeer',
'metadata': {
'scope': scope,
'node': node,
'peerIP': ip,
'name': host.name,
},
'spec': {
'asNumber': asNum
'peerIP': ip,
'asNumber': asNum,
}
}
host.writefile("testfile.yaml", testdata)
# Add optional params
# If node is not specified, scope is global.
if scope == "node":
testdata['spec']['node'] = host.get_hostname()
if metadata is not None:
testdata['metadata'] = metadata

host.writefile("testfile.yaml", yaml.dump(testdata))
host.calicoctl("create -f testfile.yaml")

def clear_bgp_peers(host):
peers = yaml.load(host.calicoctl("get bgpPeer --output=yaml"))
if len(peers['items']) == 0:
return
host.writefile("bgppeers.yaml", yaml.dump(peers))
host.calicoctl("delete -f bgppeers.yaml")
7 changes: 5 additions & 2 deletions calico_node/tests/st/bgp/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
from tests.st.utils.constants import (DEFAULT_IPV4_ADDR_1, DEFAULT_IPV4_ADDR_2,
DEFAULT_IPV4_ADDR_3,
DEFAULT_IPV4_POOL_CIDR, LARGE_AS_NUM)
from tests.st.utils.utils import check_bird_status
from tests.st.utils.utils import check_bird_status, update_bgp_config
from unittest import skip

# TODO: Add back when gobgp is updated to work with libcalico-go v2 api
@skip("Disabled until gobgp is updated with libcalico-go v2")
class TestBGPBackends(TestBase):

@attr('slow')
Expand All @@ -41,7 +44,7 @@ def test_bgp_backends(self):
start_calico=True) as host3:

# Set the default AS number.
host1.calicoctl("config set asNumber %s" % LARGE_AS_NUM)
update_bgp_config(host1, asNum=LARGE_AS_NUM)

# Start host1 using the inherited AS, and host2 using a specified
# AS (same as default). These hosts use the gobgp backend, whereas
Expand Down
40 changes: 28 additions & 12 deletions calico_node/tests/st/bgp/test_global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import yaml
from nose.plugins.attrib import attr

from tests.st.test_base import TestBase
Expand All @@ -19,6 +20,8 @@
DEFAULT_IPV4_POOL_CIDR, LARGE_AS_NUM)
from tests.st.utils.exceptions import CommandExecError
from tests.st.utils.utils import check_bird_status
from tests.st.utils.utils import update_bgp_config
from tests.st.utils.utils import get_bgp_spec

class TestBGP(TestBase):

Expand All @@ -27,21 +30,33 @@ def test_defaults(self):
Test default BGP configuration commands.
"""
with DockerHost('host', start_calico=False, dind=False) as host:
# TODO: Re-enable or remove after decsision is made on the defaults
# Check default AS command
self.assertEquals(host.calicoctl("config get asNumber"), "64512")
host.calicoctl("config set asNumber 12345")
self.assertEquals(host.calicoctl("config get asNumber"), "12345")
#response = host.calicoctl("get BGPConfiguration -o yaml")
#bgpcfg = yaml.safe_load(response)
#self.assertEquals(bgpcfg['items'][0]['spec']['asNumber'], 64512)

# Set the default AS number.
update_bgp_config(host, asNum=12345)

self.assertEquals(get_bgp_spec(host)['asNumber'], 12345)

with self.assertRaises(CommandExecError):
host.calicoctl("config set asNumber 99999999999999999999999")
update_bgp_config(host, asNum=99999999999999999999999)
with self.assertRaises(CommandExecError):
host.calicoctl("config set asNumber abcde")
update_bgp_config(host, asNum='abcde')

# Check BGP mesh command
self.assertEquals(host.calicoctl("config get nodeToNodeMesh"), "on")
host.calicoctl("config set nodeToNodeMesh off")
self.assertEquals(host.calicoctl("config get nodeToNodeMesh"), "off")
host.calicoctl("config set nodeToNodeMesh on")
self.assertEquals(host.calicoctl("config get nodeToNodeMesh"), "on")
if 'nodeToNodeMeshEnabled' in get_bgp_spec(host):
self.assertEquals(get_bgp_spec(host)['nodeToNodeMeshEnabled'], True)

update_bgp_config(host, nodeMesh=False)

self.assertEquals(get_bgp_spec(host)['nodeToNodeMeshEnabled'], False)

update_bgp_config(host, nodeMesh=True)

self.assertEquals(get_bgp_spec(host)['nodeToNodeMeshEnabled'], True)

@attr('slow')
def _test_as_num(self, backend='bird'):
Expand All @@ -58,7 +73,7 @@ def _test_as_num(self, backend='bird'):
start_calico=False) as host2:

# Set the default AS number.
host1.calicoctl("config set asNumber %s" % LARGE_AS_NUM)
update_bgp_config(host1, asNum=LARGE_AS_NUM)

# Start host1 using the inherited AS, and host2 using a specified
# AS (same as default).
Expand Down Expand Up @@ -87,6 +102,7 @@ def _test_as_num(self, backend='bird'):
def test_bird_as_num(self):
self._test_as_num(backend='bird')

# TODO: Add back when gobgp is updated to work with libcalico-go v2 api
@attr('slow')
def test_gobgp_as_num(self):
def _test_gobgp_as_num(self):
self._test_as_num(backend='gobgp')
11 changes: 6 additions & 5 deletions calico_node/tests/st/bgp/test_global_peers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from tests.st.utils.docker_host import DockerHost, CLUSTER_STORE_DOCKER_OPTIONS
from tests.st.utils.constants import (DEFAULT_IPV4_ADDR_1, DEFAULT_IPV4_ADDR_2,
DEFAULT_IPV4_POOL_CIDR, LARGE_AS_NUM)
from tests.st.utils.utils import check_bird_status
from tests.st.utils.utils import check_bird_status, update_bgp_config

from .peer import create_bgp_peer

Expand Down Expand Up @@ -51,7 +51,7 @@ def _test_global_peers(self, backend='bird'):
self.assert_true(workload_host1.check_can_ping(DEFAULT_IPV4_ADDR_2, retries=10))

# Turn the node-to-node mesh off and wait for connectivity to drop.
host1.calicoctl("config set nodeToNodeMesh off")
update_bgp_config(host1, nodeMesh=False)
self.assert_true(workload_host1.check_cant_ping(DEFAULT_IPV4_ADDR_2, retries=10))

# Configure global peers to explicitly set up a mesh. This means
Expand All @@ -70,17 +70,18 @@ def _test_global_peers(self, backend='bird'):

# Check the BGP status on each host. Connections from a node to
# itself will be idle since this is invalid BGP configuration.
check_bird_status(host1, [("global", host1.ip, ["Idle", "Active"]),
check_bird_status(host1, [("global", host1.ip, ["Idle", "Connect", "OpenSent", "OpenConfirm", "Active"]),
("global", host2.ip, "Established")])
check_bird_status(host2, [("global", host1.ip, "Established"),
("global", host2.ip, ["Idle", "Active"])])
("global", host2.ip, ["Idle", "Connect", "OpenSent", "OpenConfirm", "Active"])])

@attr('slow')
def test_bird_node_peers(self):
self._test_global_peers(backend='bird')

# TODO: Add back when gobgp is updated to work with libcalico-go v2 api
@attr('slow')
def test_gobgp_node_peers(self):
def _test_gobgp_node_peers(self):
self._test_global_peers(backend='gobgp')

TestGlobalPeers.batchnumber = 1 # Adds a batch number for parallel testing
Expand Down
Loading

0 comments on commit 03fec6d

Please sign in to comment.