blob: 1046cd6287e1ad7b9c283e93a061f3d573466b7d [file] [log] [blame]
Jay Pipesf4dad392012-06-05 16:03:58 -04001# 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
18import nose
19import unittest2 as unittest
20
21from tempest import exceptions
22from tempest import openstack
23from tempest.common.utils.data_utils import rand_name
24
25
26class BaseNetworkTest(unittest.TestCase):
27
28 os = openstack.Manager()
29 client = os.network_client
30 config = os.config
31 networks = []
32 enabled = True
33
34 # Validate that there is even an endpoint configured
35 # for networks, and mark the attr for skipping if not
36 try:
37 client.list_networks()
38 except exceptions.EndpointNotFound:
39 enabled = False
40 skip_msg = "No network endpoint"
41
42 @classmethod
43 def setUpClass(cls):
44 if not cls.enabled:
45 raise nose.SkipTest(cls.skip_msg)
46
47 @classmethod
48 def tearDownClass(cls):
49 for network in cls.networks:
50 cls.client.delete_network(network['id'])
51
52 def create_network(self, network_name=None):
53 """Wrapper utility that returns a test network"""
54 network_name = network_name or rand_name('test-network')
55
56 resp, body = self.client.create_network(network_name)
57 network = body['network']
58 self.networks.append(network)
59 return network