blob: 738e4a834f6399f1ed476f16dda36e284dd04d19 [file] [log] [blame]
Dan Smith8ad1c472013-02-26 13:03:16 -05001# Copyright 2013 IBM Corp.
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
Sean Dague1937d092013-05-17 16:36:38 -040016from tempest.api.compute import base
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040017from tempest.test import attr
Dan Smith8ad1c472013-02-26 13:03:16 -050018
19import time
20
21
ivan-zhuf2b00502013-10-18 10:06:52 +080022class AttachInterfacesTestJSON(base.BaseV2ComputeTest):
Dan Smith8ad1c472013-02-26 13:03:16 -050023 _interface = 'json'
24
25 @classmethod
26 def setUpClass(cls):
Matthew Treinishfaa340d2013-07-19 16:26:21 -040027 if not cls.config.service_available.neutron:
Mark McClainf2982e82013-07-06 17:48:03 -040028 raise cls.skipException("Neutron is required")
Salvatore Orlando5a337242014-01-15 22:49:22 +000029 # This test class requires network and subnet
30 cls.set_network_resources(network=True, subnet=True)
David Kranzb9017e72013-05-07 11:16:29 -040031 super(AttachInterfacesTestJSON, cls).setUpClass()
32 cls.client = cls.os.interfaces_client
Dan Smith8ad1c472013-02-26 13:03:16 -050033
34 def _check_interface(self, iface, port_id=None, network_id=None,
35 fixed_ip=None):
36 self.assertIn('port_state', iface)
37 if port_id:
38 self.assertEqual(iface['port_id'], port_id)
39 if network_id:
40 self.assertEqual(iface['net_id'], network_id)
41 if fixed_ip:
42 self.assertEqual(iface['fixed_ips'][0]['ip_address'], fixed_ip)
43
44 def _create_server_get_interfaces(self):
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090045 resp, server = self.create_test_server(wait_until='ACTIVE')
Dan Smith8ad1c472013-02-26 13:03:16 -050046 resp, ifs = self.client.list_interfaces(server['id'])
Leo Toyodaba9e9092013-04-08 09:02:11 +090047 resp, body = self.client.wait_for_interface_status(
48 server['id'], ifs[0]['port_id'], 'ACTIVE')
49 ifs[0]['port_state'] = body['port_state']
Dan Smith8ad1c472013-02-26 13:03:16 -050050 return server, ifs
51
52 def _test_create_interface(self, server):
53 resp, iface = self.client.create_interface(server['id'])
Leo Toyodaba9e9092013-04-08 09:02:11 +090054 resp, iface = self.client.wait_for_interface_status(
55 server['id'], iface['port_id'], 'ACTIVE')
Dan Smith8ad1c472013-02-26 13:03:16 -050056 self._check_interface(iface)
57 return iface
58
59 def _test_create_interface_by_network_id(self, server, ifs):
60 network_id = ifs[0]['net_id']
61 resp, iface = self.client.create_interface(server['id'],
62 network_id=network_id)
Leo Toyodaba9e9092013-04-08 09:02:11 +090063 resp, iface = self.client.wait_for_interface_status(
64 server['id'], iface['port_id'], 'ACTIVE')
Dan Smith8ad1c472013-02-26 13:03:16 -050065 self._check_interface(iface, network_id=network_id)
66 return iface
67
68 def _test_show_interface(self, server, ifs):
69 iface = ifs[0]
70 resp, _iface = self.client.show_interface(server['id'],
71 iface['port_id'])
72 self.assertEqual(iface, _iface)
73
74 def _test_delete_interface(self, server, ifs):
75 # NOTE(danms): delete not the first or last, but one in the middle
76 iface = ifs[1]
77 self.client.delete_interface(server['id'], iface['port_id'])
78 for i in range(0, 5):
79 _r, _ifs = self.client.list_interfaces(server['id'])
80 if len(ifs) != len(_ifs):
81 break
82 time.sleep(1)
83
84 self.assertEqual(len(_ifs), len(ifs) - 1)
85 for _iface in _ifs:
86 self.assertNotEqual(iface['port_id'], _iface['port_id'])
87 return _ifs
88
89 def _compare_iface_list(self, list1, list2):
90 # NOTE(danms): port_state will likely have changed, so just
91 # confirm the port_ids are the same at least
92 list1 = [x['port_id'] for x in list1]
93 list2 = [x['port_id'] for x in list2]
94
95 self.assertEqual(sorted(list1), sorted(list2))
96
Attila Fazekasf15c4eb2013-12-17 11:34:48 +010097 @attr(type='smoke')
Dan Smith8ad1c472013-02-26 13:03:16 -050098 def test_create_list_show_delete_interfaces(self):
99 server, ifs = self._create_server_get_interfaces()
100 interface_count = len(ifs)
101 self.assertTrue(interface_count > 0)
102 self._check_interface(ifs[0])
103
104 iface = self._test_create_interface(server)
105 ifs.append(iface)
106
107 iface = self._test_create_interface_by_network_id(server, ifs)
108 ifs.append(iface)
109
110 resp, _ifs = self.client.list_interfaces(server['id'])
111 self._compare_iface_list(ifs, _ifs)
112
113 self._test_show_interface(server, ifs)
114
115 _ifs = self._test_delete_interface(server, ifs)
116 self.assertEqual(len(ifs) - 1, len(_ifs))
117
118
119class AttachInterfacesTestXML(AttachInterfacesTestJSON):
120 _interface = 'xml'