blob: e620e03b6a6ce3a5cc33fb9a9779cab96e65e0b3 [file] [log] [blame]
Rami Vaknin76bc8bd2013-02-17 16:18:27 +02001# Copyright 2013 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Rami Vaknin7b9f36b2013-02-20 00:09:07 +020016import netaddr
Matt Riedemann858e7202016-03-05 21:41:52 -050017import testtools
Rami Vaknin7b9f36b2013-02-20 00:09:07 +020018
Sean Dague1937d092013-05-17 16:36:38 -040019from tempest.api.compute import base
JordanP68c3f032013-06-25 18:50:49 +020020from tempest import config
Matt Riedemann858e7202016-03-05 21:41:52 -050021from tempest.lib import exceptions
Hoisaleshwara Madan V Sf009df42013-12-04 12:48:02 +053022from tempest import test
Rami Vaknin76bc8bd2013-02-17 16:18:27 +020023
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000024CONF = config.CONF
25
Rami Vaknin76bc8bd2013-02-17 16:18:27 +020026
ivan-zhuf2b00502013-10-18 10:06:52 +080027class VirtualInterfacesTestJSON(base.BaseV2ComputeTest):
Rami Vaknin76bc8bd2013-02-17 16:18:27 +020028
29 @classmethod
Emily Hugenbruche7991d92014-12-12 16:53:36 +000030 def setup_credentials(cls):
Salvatore Orlando5a337242014-01-15 22:49:22 +000031 # This test needs a network and a subnet
32 cls.set_network_resources(network=True, subnet=True)
Emily Hugenbruche7991d92014-12-12 16:53:36 +000033 super(VirtualInterfacesTestJSON, cls).setup_credentials()
34
35 @classmethod
36 def setup_clients(cls):
37 super(VirtualInterfacesTestJSON, cls).setup_clients()
Rami Vaknin76bc8bd2013-02-17 16:18:27 +020038 cls.client = cls.servers_client
Emily Hugenbruche7991d92014-12-12 16:53:36 +000039
40 @classmethod
41 def resource_setup(cls):
42 super(VirtualInterfacesTestJSON, cls).resource_setup()
David Kranz0fb14292015-02-11 15:55:20 -050043 server = cls.create_test_server(wait_until='ACTIVE')
Rami Vaknin76bc8bd2013-02-17 16:18:27 +020044 cls.server_id = server['id']
45
Chris Hoge7579c1a2015-02-26 14:12:15 -080046 @test.idempotent_id('96c4e2ef-5e4d-4d7f-87f5-fed6dca18016')
Matthew Treinish2df97482014-06-13 15:02:26 -040047 @test.services('network')
Rami Vaknin76bc8bd2013-02-17 16:18:27 +020048 def test_list_virtual_interfaces(self):
49 # Positive test:Should be able to GET the virtual interfaces list
50 # for a given server_id
Matt Riedemann858e7202016-03-05 21:41:52 -050051
52 if CONF.service_available.neutron:
53 # TODO(mriedem): After a microversion implements the API for
54 # neutron, a 400 should be a failure for nova-network and neutron.
55 with testtools.ExpectedException(exceptions.BadRequest):
56 self.client.list_virtual_interfaces(self.server_id)
57 else:
58 output = self.client.list_virtual_interfaces(self.server_id)
59 self.assertIsNotNone(output)
60 virt_ifaces = output
61 self.assertNotEqual(0, len(virt_ifaces['virtual_interfaces']),
62 'Expected virtual interfaces, got 0 '
63 'interfaces.')
64 for virt_iface in virt_ifaces['virtual_interfaces']:
65 mac_address = virt_iface['mac_address']
66 self.assertTrue(netaddr.valid_mac(mac_address),
67 "Invalid mac address detected. mac address: %s"
68 % mac_address)