Skip to content

Commit

Permalink
[Caracal] Update github workflow & Fix unit tests
Browse files Browse the repository at this point in the history
Update python version to 3.10 and set the base branch in the github
workflowto Caracal(2024.1-m3).

Fix Unit Tests:

With later versions of pecan, WebTest is not a dependency of it anymore,
so in order to continue using this, an additional import in
test-requirements is required.

Remove autoconfig loading, which breaks stestr test execution.
Cli options can be loaded only once (without
clearing them), which causes our tests to fail as required default
configuration cli options can not be registered, as an default configuration
has already been loaded.

As part of the secure RBAC community goal, the "enforce_new_defaults" and
"enforce_scope" setting is True by default. Avoiding PolicyNotAuthorized erros
during test execution certain actions simply need to be executed as admin.
  • Loading branch information
sven-rosenzweig committed Nov 15, 2024
1 parent 9035ee7 commit 7b3376f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ name: run-tox
on:
push:
branches:
- stable/yoga-m3
- stable/2024.1-m3
pull_request:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.8]
python: ['3.10']
steps:
- uses: actions/checkout@v2
- name: Setup python
Expand Down
1 change: 1 addition & 0 deletions networking_aci/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def get_additional_service_plugins(self):
return dict(service_plugins='tag')

def setUp(self):
config.register_common_config_options()
self._mechanism_drivers.append(constants.ACI_DRIVER_NAME)
cfg.CONF.set_override('debug', True)
config.setup_logging()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

from networking_aci.tests.unit import utils

cfg.CONF.use_stderr = False
cfg.CONF(args=[])


class AciNeutronAgentTest(base.BaseTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@ def setUp(self):

def test_create_subnet_az_hint_matches(self):
net_kwargs = {'arg_list': (extnet_api.EXTERNAL,), extnet_api.EXTERNAL: True}
with self.network(**net_kwargs) as network:
with self.network(**net_kwargs, as_admin=True) as network:
with self.subnetpool(["1.1.0.0/16", "1.2.0.0/24"], name="foo", tenant_id="foo", admin=True) as snp:
with self.subnet(network=network, cidr="1.1.1.0/24", gateway_ip="1.1.1.1",
subnetpool_id=snp['subnetpool']['id']) as subnet:
subnetpool_id=snp['subnetpool']['id'], as_admin=True) as subnet:
self.assertIsNotNone(subnet)

def test_create_subnet_network_az_snp_no_az_fails(self):
net_kwargs = {'arg_list': (extnet_api.EXTERNAL,), extnet_api.EXTERNAL: True}
with self.network(availability_zone_hints=["qa-de-1a"], **net_kwargs) as network:
with self.network(availability_zone_hints=["qa-de-1a"], **net_kwargs, as_admin=True) as network:
with self.subnetpool(["1.1.0.0/16", "1.2.0.0/24"], address_scope_id=self._address_scope['id'], name="foo",
tenant_id="foo", admin=True) as snp:
resp = self._create_subnet(self.fmt, cidr="1.1.1.0/24", gateway_ip="1.1.1.1",
name="foo",
net_id=network['network']['id'], tenant_id=network['network']['tenant_id'],
subnetpool_id=snp['subnetpool']['id'])
subnetpool_id=snp['subnetpool']['id'],
as_admin=True)
self.assertEqual(400, resp.status_code)
self.assertEqual("SubnetSubnetPoolAZAffinityError", resp.json['NeutronError']['type'])
self.assertIsNotNone(re.search(f"network {network['network']['id']} has AZ hint qa-de-1a,.*"
Expand All @@ -52,7 +53,7 @@ def test_create_subnet_network_az_snp_no_az_fails(self):

def test_create_subnet_network_no_az_snp_az_fails(self):
net_kwargs = {'arg_list': (extnet_api.EXTERNAL,), extnet_api.EXTERNAL: True}
with self.network(**net_kwargs) as network:
with self.network(**net_kwargs, as_admin=True) as network:
with self.subnetpool(["1.1.0.0/16", "1.2.0.0/24"], address_scope_id=self._address_scope['id'], name="foo",
tenant_id="foo", admin=True) as snp:
ctx = context.get_admin_context()
Expand All @@ -63,7 +64,7 @@ def test_create_subnet_network_no_az_snp_az_fails(self):
resp = self._create_subnet(self.fmt, cidr="1.1.1.0/24", gateway_ip="1.1.1.1",
name="foo",
net_id=network['network']['id'], tenant_id=network['network']['tenant_id'],
subnetpool_id=snp['subnetpool']['id'])
subnetpool_id=snp['subnetpool']['id'], as_admin=True)
self.assertEqual(400, resp.status_code)
self.assertEqual("SubnetSubnetPoolAZAffinityError", resp.json['NeutronError']['type'])
self.assertIsNotNone(re.search(f"network {network['network']['id']} has AZ hint None,.*"
Expand All @@ -73,9 +74,9 @@ def test_create_subnet_network_no_az_snp_az_fails(self):
def test_create_subnet_network_snp_az_hint_works_when_turned_off(self):
cfg.CONF.set_override('subnet_subnetpool_az_check_enabled', False, group='ml2_aci')
net_kwargs = {'arg_list': (extnet_api.EXTERNAL,), extnet_api.EXTERNAL: True}
with self.network(availability_zone_hints=["qa-de-1a"], **net_kwargs) as network:
with self.network(availability_zone_hints=["qa-de-1a"], **net_kwargs, as_admin=True) as network:
with self.subnetpool(["1.1.0.0/16", "1.2.0.0/24"], address_scope_id=self._address_scope['id'], name="foo",
tenant_id="foo", admin=True) as snp:
with self.subnet(network=network, cidr="1.1.1.0/24", gateway_ip="1.1.1.1",
subnetpool_id=snp['subnetpool']['id']) as subnet:
subnetpool_id=snp['subnetpool']['id'], as_admin=True) as subnet:
self.assertIsNotNone(subnet)
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ testtools>=1.4.0
testresources>=0.2.4
requests
stestr>=1.0.0 # Apache-2.0
WebTest>=2.0.27 # MIT
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[tox]
envlist = py38
envlist = py310
minversion = 3.18.0
skipsdist = True
requires = virtualenv >= 20

[testenv]
usedevelop = True
install_command = pip install -c {env:UPPER_CONSTRAINTS_FILE:https://raw.githubusercontent.com/sapcc/requirements/stable/yoga-m3/upper-constraints.txt} -r requirements.txt -r test-requirements.txt -U {opts} {packages}
install_command = pip install -c {env:UPPER_CONSTRAINTS_FILE:https://raw.githubusercontent.com/sapcc/requirements/stable/2024.1-m3/upper-constraints.txt} -r requirements.txt -r test-requirements.txt -U {opts} {packages}
setenv = VIRTUAL_ENV={envdir}
PYTHONWARNINGS=default::DeprecationWarning
deps = -r{toxinidir}/test-requirements.txt
-e{env:NEUTRON_SOURCE:git+https://github.com/sapcc/neutron.git@stable/yoga-m3#egg=neutron}
-e{env:NEUTRON_SOURCE:git+https://github.com/sapcc/neutron.git@stable/2024.1-m3#egg=neutron}
whitelist_externals = sh
commands = stestr run {posargs}
download = True
Expand Down

0 comments on commit 7b3376f

Please sign in to comment.