Skip to content

Commit

Permalink
Fix API test for external subnet visibility
Browse files Browse the repository at this point in the history
The test_external_network_visibility test incorrectly
assumes that subnets will never be visible on external
networks. However, this is not true in the case that a
network is both external and shared, in which case its
subnets will be shared and will be visible globally.

This updates the test to only make the subnet visibility
assertion on the configured public external network which
is stable and won't be in flux like networks created by
other tests.

At some point this test should just create its own external
network and make assertions on that rather than depend on
a specific configuration of the public network.

Related-Bug: #1553595
Change-Id: I0219e17d2ec70939039344826d35cb533b3ce065
  • Loading branch information
kevinbenton committed Mar 13, 2016
1 parent 22dd1c9 commit 6919da4
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions tempest/api/network/test_networks.py
Expand Up @@ -12,10 +12,9 @@
# 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 itertools

import netaddr
import six
import testtools

from tempest.api.network import base
from tempest.common import custom_matchers
Expand Down Expand Up @@ -376,6 +375,9 @@ def test_create_delete_subnet_all_attributes(self):

@test.attr(type='smoke')
@test.idempotent_id('af774677-42a9-4e4b-bb58-16fe6a5bc1ec')
@test.requires_ext(extension='external-net', service='network')
@testtools.skipUnless(CONF.network.public_network_id,
'The public_network_id option must be specified.')
def test_external_network_visibility(self):
"""Verifies user can see external networks but not subnets."""
body = self.networks_client.list_networks(**{'router:external': True})
Expand All @@ -387,17 +389,12 @@ def test_external_network_visibility(self):
self.assertEmpty(nonexternal, "Found non-external networks"
" in filtered list (%s)." % nonexternal)
self.assertIn(CONF.network.public_network_id, networks)

subnets_iter = (network['subnets']
for network in body['networks']
if not network['shared'])
# subnets_iter is a list (iterator) of lists. This flattens it to a
# list of UUIDs
public_subnets_iter = itertools.chain(*subnets_iter)
body = self.subnets_client.list_subnets()
subnets = [sub['id'] for sub in body['subnets']
if sub['id'] in public_subnets_iter]
self.assertEmpty(subnets, "Public subnets visible")
# only check the public network ID because the other networks may
# belong to other tests and their state may have changed during this
# test
body = self.subnets_client.list_subnets(
network_id=CONF.network.public_network_id)
self.assertEmpty(body['subnets'], "Public subnets visible")


class BulkNetworkOpsTestJSON(base.BaseNetworkTest):
Expand Down

0 comments on commit 6919da4

Please sign in to comment.