From 28a08cf77a1dfc20e0169527d4dac714d4e869a4 Mon Sep 17 00:00:00 2001 From: Frode Nordahl Date: Thu, 5 Sep 2019 16:39:04 +0200 Subject: [PATCH] Add quagga tests --- zaza/openstack/charm_tests/quagga/__init__.py | 15 +++++ zaza/openstack/charm_tests/quagga/tests.py | 63 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 zaza/openstack/charm_tests/quagga/__init__.py create mode 100644 zaza/openstack/charm_tests/quagga/tests.py diff --git a/zaza/openstack/charm_tests/quagga/__init__.py b/zaza/openstack/charm_tests/quagga/__init__.py new file mode 100644 index 0000000..e67cd6a --- /dev/null +++ b/zaza/openstack/charm_tests/quagga/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2018 Canonical Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +"""Collection of code for testing quagga charm.""" diff --git a/zaza/openstack/charm_tests/quagga/tests.py b/zaza/openstack/charm_tests/quagga/tests.py new file mode 100644 index 0000000..67a49d6 --- /dev/null +++ b/zaza/openstack/charm_tests/quagga/tests.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 + +# Copyright 2018 Canonical Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +"""Encapsulating `quagga` testing.""" + +import logging +import re +import unittest + +import zaza + + +class QuaggaTest(unittest.TestCase): + """Class for `quagga` tests.""" + + @classmethod + def setUpClass(cls): + """Run class setup for `quagga` tests.""" + super(QuaggaTest, cls).setUpClass() + + def test_bgp_peer_datapath(self): + """Get peers from BGP neighbour list and ping them.""" + status = zaza.model.get_status() + applications = (app for app in ['spine0', 'spine1', 'tor0', 'tor1', + 'tor2', 'peer0', 'peer1'] + if app in status.applications.keys()) + for application in applications: + for unit in zaza.model.get_units(application): + bgp_sum = zaza.model.run_on_unit( + unit.entity_id, + 'echo "sh bgp ipv4 unicast summary" | vtysh')['Stdout'] + r = re.compile('^(\d+\.\d+\.\d+\.\d+)') + ip_list = [] + for line in bgp_sum.splitlines(): + m = r.match(line) + if m: + ip_list.append(m.group(1)) + logging.info('unit {} neighbours {}' + .format(unit.entity_id, ip_list)) + + if not ip_list: + raise Exception('FAILED: Unit {} has no BGP peers.' + .format(unit.entity_id)) + for ip in ip_list: + result = zaza.model.run_on_unit( + unit.entity_id, + 'ping -c 3 {}'.format(ip)) + logging.info(result['Stdout']) + if result['Code'] == '1': + raise Exception('FAILED')