Rami Vaknin | 76bc8bd | 2013-02-17 16:18:27 +0200 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 OpenStack Foundation |
| 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 | |
Rami Vaknin | 7b9f36b | 2013-02-20 00:09:07 +0200 | [diff] [blame] | 18 | import netaddr |
JordanP | 68c3f03 | 2013-06-25 18:50:49 +0200 | [diff] [blame] | 19 | import testtools |
Rami Vaknin | 7b9f36b | 2013-02-20 00:09:07 +0200 | [diff] [blame] | 20 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 21 | from tempest.api.compute import base |
Rami Vaknin | 76bc8bd | 2013-02-17 16:18:27 +0200 | [diff] [blame] | 22 | from tempest.common.utils.data_utils import rand_name |
JordanP | 68c3f03 | 2013-06-25 18:50:49 +0200 | [diff] [blame] | 23 | from tempest import config |
Rami Vaknin | 76bc8bd | 2013-02-17 16:18:27 +0200 | [diff] [blame] | 24 | from tempest import exceptions |
| 25 | from tempest.test import attr |
Rami Vaknin | 76bc8bd | 2013-02-17 16:18:27 +0200 | [diff] [blame] | 26 | |
| 27 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 28 | class VirtualInterfacesTestJSON(base.BaseComputeTest): |
| 29 | _interface = 'json' |
Rami Vaknin | 76bc8bd | 2013-02-17 16:18:27 +0200 | [diff] [blame] | 30 | |
JordanP | 68c3f03 | 2013-06-25 18:50:49 +0200 | [diff] [blame] | 31 | CONF = config.TempestConfig() |
| 32 | |
Rami Vaknin | 76bc8bd | 2013-02-17 16:18:27 +0200 | [diff] [blame] | 33 | @classmethod |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 34 | def setUpClass(cls): |
| 35 | super(VirtualInterfacesTestJSON, cls).setUpClass() |
Rami Vaknin | 76bc8bd | 2013-02-17 16:18:27 +0200 | [diff] [blame] | 36 | cls.client = cls.servers_client |
Mauro S. M. Rodrigues | 0a1bdff | 2013-03-11 11:41:18 -0400 | [diff] [blame] | 37 | resp, server = cls.create_server(wait_until='ACTIVE') |
Rami Vaknin | 76bc8bd | 2013-02-17 16:18:27 +0200 | [diff] [blame] | 38 | cls.server_id = server['id'] |
| 39 | |
Mark McClain | f2982e8 | 2013-07-06 17:48:03 -0400 | [diff] [blame^] | 40 | @testtools.skipIf(CONF.network.neutron_available, "This feature is not " + |
| 41 | "implemented by Neutron. See bug: #1183436") |
Giulio Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame] | 42 | @attr(type='gate') |
Rami Vaknin | 76bc8bd | 2013-02-17 16:18:27 +0200 | [diff] [blame] | 43 | def test_list_virtual_interfaces(self): |
| 44 | # Positive test:Should be able to GET the virtual interfaces list |
| 45 | # for a given server_id |
| 46 | resp, output = self.client.list_virtual_interfaces(self.server_id) |
| 47 | self.assertEqual(200, resp.status) |
| 48 | self.assertNotEqual(output, None) |
Rami Vaknin | 7b9f36b | 2013-02-20 00:09:07 +0200 | [diff] [blame] | 49 | virt_ifaces = output |
| 50 | self.assertNotEqual(0, len(virt_ifaces['virtual_interfaces']), |
| 51 | 'Expected virtual interfaces, got 0 interfaces.') |
| 52 | for virt_iface in virt_ifaces['virtual_interfaces']: |
| 53 | mac_address = virt_iface['mac_address'] |
| 54 | self.assertTrue(netaddr.valid_mac(mac_address), |
| 55 | "Invalid mac address detected.") |
Rami Vaknin | 76bc8bd | 2013-02-17 16:18:27 +0200 | [diff] [blame] | 56 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 57 | @attr(type=['negative', 'gate']) |
Rami Vaknin | 76bc8bd | 2013-02-17 16:18:27 +0200 | [diff] [blame] | 58 | def test_list_virtual_interfaces_invalid_server_id(self): |
| 59 | # Negative test: Should not be able to GET virtual interfaces |
| 60 | # for an invalid server_id |
Rami Vaknin | 7b9f36b | 2013-02-20 00:09:07 +0200 | [diff] [blame] | 61 | invalid_server_id = rand_name('!@#$%^&*()') |
| 62 | self.assertRaises(exceptions.NotFound, |
| 63 | self.client.list_virtual_interfaces, |
| 64 | invalid_server_id) |
Rami Vaknin | 76bc8bd | 2013-02-17 16:18:27 +0200 | [diff] [blame] | 65 | |
| 66 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 67 | class VirtualInterfacesTestXML(VirtualInterfacesTestJSON): |
| 68 | _interface = 'xml' |