More py3.x support

The Stein supported runtimes proposal [1] has chosen py36 over py35
due to the communities move to testing on Ubuntu 18.04, where py36
is the default runtime. We update tox.ini and setup.cfg accordingly.

Python 3.6 handles dict order differently than in previous python
versions, so to get py36 to work this uses a sorted() call to make
the behavior consistent across python versions for our network
bridge cleanup and adjusts the corresponding test accordingly.

We also add a py37 option to the tox.ini to facilitate future-looking
tests per the resolution on keeping up with Python 3 releases [2].

The py35 option will eventually need to be removed from tox.ini, but
this keeps it for now in order to allow time for folks to transition.

As previously commented, automatic tox envs (pyXX) will use the python
version appropriate to that env and ignore basepython inherited from
[testenv], so we no longer specify a basepython explicitly for these.

[1] https://review.openstack.org/611080
[2] https://review.openstack.org/613145

Change-Id: Iebdc9357a79cae1923109fb5e37fefb8021af18d
changes/39/623739/3
Matthew Edmonds 4 years ago
parent e132845bb9
commit 62df1f2fb9

@ -197,7 +197,7 @@ class SharedEthernetNeutronAgent(agent_base.BasePVMNeutronAgent):
# To determine the ones no longer needed, subtract from all the
# VLANs the ones that are no longer needed.
vlans_to_del = existing_vlans - req_vlans
for vlan_to_del in vlans_to_del:
for vlan_to_del in sorted(vlans_to_del):
if cur_delete < 3:
LOG.warning("Cleaning up VLAN %s from the system. It is "
"no longer in use.", vlan_to_del)

@ -159,11 +159,7 @@ class SEAAgentTest(base.BasePVMTestCase):
# Mock a provision request
mock_get_nb_and_vlan.return_value = ('nb2_uuid', 23)
# Mock up network bridges. VLANs 44, 45, and 46 should be deleted
# as they are not required by anything. VLAN 47 should be needed
# as it is in the pending list. VLAN 48 should be deleted, but will
# put over the three delete max count (and therefore would be hit in
# next pass)
# Mock up network bridges.
mock_nb1 = fake_nb('nb_uuid', 20, [], [])
mock_nb2 = fake_nb('nb2_uuid', 40, [41, 42, 43], [44, 45, 46, 47, 48])
mock_list_bridges.return_value = [mock_nb1, mock_nb2]
@ -190,27 +186,44 @@ class SEAAgentTest(base.BasePVMTestCase):
mock_vs_map.return_value) for cna in (cna1, cna2)],
any_order=True)
# One remove call per net bridge.
# One remove call per net bridge, up to a max of 3.
self.assertEqual(3, mock_nbr_remove.call_count)
# VLANs 44, 45, 46, 47, and 48 are not required by anything, so the
# first three of those should be deleted
mock_nbr_remove.assert_has_calls(
[mock.call(
self.agent.adapter, self.agent.host_uuid, 'nb2_uuid', vlan)
for vlan in (44, 45, 48)], any_order=True)
for vlan in (44, 45, 46)], any_order=True)
# Update mocks to show 44, 45, and 46 were removed
mock_nb2 = fake_nb('nb2_uuid', 40, [41, 42, 43], [47, 48])
mock_list_bridges.return_value = [mock_nb1, mock_nb2]
mock_find_nb_for_cna.return_value = mock_nb2
# Validate no remove.
# Validate no removes if we disable cleanup.
mock_nbr_remove.reset_mock()
mock_prov_devs.reset_mock()
# Set that we can't do the clean up
cfg.CONF.set_override('automated_powervm_vlan_cleanup', False,
group='AGENT')
# Invoke
self.agent.heal_and_optimize()
# Verify. One ensure call per net bridge. Zero for the remove as that
# has been flagged to not clean up.
mock_nbr_remove.assert_not_called()
mock_prov_devs.assert_called_with([preq1, preq2, preq3])
# Now change the CONF back and validate we can remove the remainder
cfg.CONF.set_override('automated_powervm_vlan_cleanup', True,
group='AGENT')
# Invoke
self.agent.heal_and_optimize()
# Should only be two left to remove
self.assertEqual(2, mock_nbr_remove.call_count)
# VLANs 47, and 48 should be the ones that are removed
mock_nbr_remove.assert_has_calls(
[mock.call(
self.agent.adapter, self.agent.host_uuid, 'nb2_uuid', vlan)
for vlan in (47, 48)], any_order=True)
def test_get_nb_and_vlan(self):
"""Be sure nb uuid and vlan parsed from dev properly."""
self.assertEqual(('nb_uuid', 100), self.agent._get_nb_and_vlan(

@ -15,7 +15,7 @@ classifier =
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
[entry_points]
console_scripts =

@ -1,5 +1,5 @@
[tox]
envlist = py35,py27,pep8
envlist = py36,py27,pep8
minversion = 3.1.1
skipsdist = True
# Automatic envs (pyXX) will use the python version appropriate to that
@ -31,14 +31,24 @@ commands =
find . -type f -name "*.pyc" -delete
[testenv:py27]
basepython = python2.7
commands =
{[testenv]commands}
stestr run {posargs}
stestr slowest
[testenv:py35]
basepython = python3.5
commands =
{[testenv]commands}
stestr run {posargs}
stestr slowest
[testenv:py36]
commands =
{[testenv]commands}
stestr run {posargs}
stestr slowest
[testenv:py37]
commands =
{[testenv]commands}
stestr run {posargs}

Loading…
Cancel
Save