Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2012 OpenStack, LLC |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
| 18 | import nose |
| 19 | import unittest2 as unittest |
| 20 | |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 21 | from tempest import clients |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 22 | from tempest.common.utils.data_utils import rand_name |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 23 | from tempest import exceptions |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 24 | |
| 25 | |
| 26 | class BaseNetworkTest(unittest.TestCase): |
| 27 | |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 28 | @classmethod |
| 29 | def setUpClass(cls): |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 30 | os = clients.Manager() |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 31 | client = os.network_client |
| 32 | config = os.config |
| 33 | networks = [] |
| 34 | enabled = True |
| 35 | |
| 36 | # Validate that there is even an endpoint configured |
| 37 | # for networks, and mark the attr for skipping if not |
| 38 | try: |
| 39 | client.list_networks() |
| 40 | except exceptions.EndpointNotFound: |
| 41 | enabled = False |
| 42 | skip_msg = "No OpenStack Network API endpoint" |
| 43 | raise nose.SkipTest(skip_msg) |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 44 | |
| 45 | @classmethod |
| 46 | def tearDownClass(cls): |
| 47 | for network in cls.networks: |
| 48 | cls.client.delete_network(network['id']) |
| 49 | |
| 50 | def create_network(self, network_name=None): |
| 51 | """Wrapper utility that returns a test network""" |
| 52 | network_name = network_name or rand_name('test-network') |
| 53 | |
| 54 | resp, body = self.client.create_network(network_name) |
| 55 | network = body['network'] |
| 56 | self.networks.append(network) |
| 57 | return network |