diff --git a/bindep.txt b/bindep.txt new file mode 100644 index 00000000..d85ce7ff --- /dev/null +++ b/bindep.txt @@ -0,0 +1,10 @@ +# This file contains runtime (non-python) dependencies +# More info at: http://docs.openstack.org/infra/bindep/readme.html + +openvswitch [platform:rpm test] +openvswitch-switch [platform:dpkg test] +autoconf [test] +automake [test] +libtool [test] +gcc [test] +make [test] diff --git a/ovn_bgp_agent/tests/functional/base.py b/ovn_bgp_agent/tests/functional/base.py index 6e44af98..81fa1558 100644 --- a/ovn_bgp_agent/tests/functional/base.py +++ b/ovn_bgp_agent/tests/functional/base.py @@ -24,9 +24,11 @@ from oslo_config import cfg from oslo_log import log as logging from oslo_utils import fileutils from oslotest import base +from ovsdbapp.tests.functional import base as ovsdbapp_base import ovn_bgp_agent from ovn_bgp_agent import config +from ovn_bgp_agent.tests.functional import fixtures CONF = cfg.CONF @@ -119,3 +121,11 @@ class BaseFunctionalTestCase(base.BaseTestCase, group = kw.pop('group', None) for k, v in kw.items(): CONF.set_override(k, v, group) + + +class BaseFunctionalNorthboundTestCase(ovsdbapp_base.FunctionalTestCase): + schemas = ['OVN_Northbound'] + + def setUp(self): + super().setUp() + self.api = self.useFixture(fixtures.NbApiFixture(self.connection)).obj diff --git a/ovn_bgp_agent/tests/functional/drivers/__init__.py b/ovn_bgp_agent/tests/functional/drivers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ovn_bgp_agent/tests/functional/drivers/openstack/__init__.py b/ovn_bgp_agent/tests/functional/drivers/openstack/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ovn_bgp_agent/tests/functional/drivers/openstack/utils/__init__.py b/ovn_bgp_agent/tests/functional/drivers/openstack/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ovn_bgp_agent/tests/functional/drivers/openstack/utils/test_ovn.py b/ovn_bgp_agent/tests/functional/drivers/openstack/utils/test_ovn.py new file mode 100644 index 00000000..78afebdc --- /dev/null +++ b/ovn_bgp_agent/tests/functional/drivers/openstack/utils/test_ovn.py @@ -0,0 +1,49 @@ +# Copyright 2024 Red Hat, Inc. +# +# 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. + +from ovn_bgp_agent import constants +from ovn_bgp_agent.tests.functional import base + + +class OvsdbNbOvnIdl(base.BaseFunctionalNorthboundTestCase): + def _lsp_add(self, ls_name, lsp_name, type_, tag): + self.api.lsp_add(ls_name, lsp_name, type=type_).execute( + check_error=True) + # lsp_add requires parent to be specified with the tag, work it + # around with the db_set + self.api.db_set( + 'Logical_Switch_Port', lsp_name, ('tag', tag)).execute( + check_error=True) + + def test_get_network_vlan_tags(self): + # 0 is not a valid tag, let's start with 1 + expected_tags = list(range(1, 4)) + len_tags = len(expected_tags) + + for i, tag in enumerate(expected_tags): + self.api.ls_add('ls%d' % i).execute(check_error=True) + ls_name = 'ls%d' % (i % 2) + lsp_name = 'localnetport%d' % i + self._lsp_add( + ls_name, lsp_name, + constants.OVN_LOCALNET_VIF_PORT_TYPE, tag=tag) + for i, tag in enumerate(expected_tags): + ls_name = 'ls%d' % i + lsp_name = 'port%d' % i + self._lsp_add( + ls_name, lsp_name, + type_=None, tag=i + len_tags) + + tags = self.api.get_network_vlan_tags() + self.assertCountEqual(expected_tags, tags) diff --git a/ovn_bgp_agent/tests/functional/fixtures.py b/ovn_bgp_agent/tests/functional/fixtures.py new file mode 100644 index 00000000..e574bdac --- /dev/null +++ b/ovn_bgp_agent/tests/functional/fixtures.py @@ -0,0 +1,21 @@ +# Copyright 2024 Red Hat, Inc. +# +# 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. + +from ovsdbapp.tests.functional.schema import fixtures + +from ovn_bgp_agent.drivers.openstack.utils import ovn + + +class NbApiFixture(fixtures.ApiImplFixture): + api_cls = ovn.OvsdbNbOvnIdl diff --git a/tools/setup-ovs.sh b/tools/setup-ovs.sh new file mode 100644 index 00000000..b93b447c --- /dev/null +++ b/tools/setup-ovs.sh @@ -0,0 +1,18 @@ +#!/bin/bash -xe + +# This is a copy from the ovsdbapp projects + +OVN_BRANCH=${OVN_BRANCH:-main} + +if [ "$OVN_SRCDIR" -a ! -d "$OVN_SRCDIR" ]; then + echo "Building OVN branch $OVN_BRANCH in $OVN_SRCDIR" + mkdir -p $OVN_SRCDIR + git clone --recurse-submodules https://github.com/ovn-org/ovn.git $OVN_SRCDIR + pushd $OVN_SRCDIR + git checkout $OVN_BRANCH + pushd ovs + ./boot.sh && PYTHON=/usr/bin/python ./configure && make -j$(($(nproc) + 1)) + popd + ./boot.sh && PYTHON=/usr/bin/python ./configure && make -j$(($(nproc) + 1)) + popd +fi diff --git a/tox.ini b/tox.ini index e7c23e08..0a933784 100644 --- a/tox.ini +++ b/tox.ini @@ -25,10 +25,15 @@ commands = flake8 {posargs} commands = {posargs} [testenv:functional] -setenv = - {[testenv]setenv} +setenv = {[testenv]setenv} + OVN_SRCDIR={envdir}/src/ovn + OVS_SRCDIR={envdir}/src/ovn/ovs + VTEP_SRCDIR={envdir}/src/ovn/ovs/vtep + OVN_BRANCH={env:OVN_BRANCH:} commands = + bash {toxinidir}/tools/setup-ovs.sh stestr run --exclude-regex ".tests.unit" {posargs} +allowlist_externals = bash [testenv:cover] setenv =