Adding list_virtual_interfaces method to the servers_client
In addition, adding tests for that method.
Change-Id: Id7b1101b6490a714981b70d6e8e1ccb079e8a01c
diff --git a/tempest/services/compute/json/servers_client.py b/tempest/services/compute/json/servers_client.py
index 02cf970..ecff7be 100644
--- a/tempest/services/compute/json/servers_client.py
+++ b/tempest/services/compute/json/servers_client.py
@@ -498,3 +498,11 @@
resp, body = self.post(url, post_body, self.headers)
body = json.loads(body)
return resp, body['output']
+
+ def list_virtual_interfaces(self, server_id):
+ """
+ List the virtual interfaces used in an instance.
+ """
+ resp, body = self.get('/'.join(['servers', server_id,
+ 'os-virtual-interfaces']))
+ return resp, json.loads(body)
diff --git a/tempest/services/compute/xml/servers_client.py b/tempest/services/compute/xml/servers_client.py
index 8be342d..8df5f8e 100644
--- a/tempest/services/compute/xml/servers_client.py
+++ b/tempest/services/compute/xml/servers_client.py
@@ -393,3 +393,12 @@
body=str(Document(post_body)))
body = xml_to_json(etree.fromstring(body))
return resp, body
+
+ def list_virtual_interfaces(self, server_id):
+ """
+ List the virtual interfaces used in an instance.
+ """
+ resp, body = self.get('/'.join(['servers', server_id,
+ 'os-virtual-interfaces']), self.headers)
+ server = self._parse_server(etree.fromstring(body))
+ return resp, server
diff --git a/tempest/tests/compute/servers/test_virtual_interfaces.py b/tempest/tests/compute/servers/test_virtual_interfaces.py
new file mode 100644
index 0000000..6198526
--- /dev/null
+++ b/tempest/tests/compute/servers/test_virtual_interfaces.py
@@ -0,0 +1,87 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2013 OpenStack Foundation
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from tempest.common.utils.data_utils import rand_name
+from tempest import exceptions
+from tempest.test import attr
+from tempest.tests.compute import base
+
+
+class VirtualInterfacesTest(object):
+
+ @classmethod
+ def setUpClass(self, cls):
+ cls.name = rand_name('server')
+ cls.client = cls.servers_client
+ resp, server = cls.servers_client.create_server(cls.name,
+ cls.image_ref,
+ cls.flavor_ref)
+ cls.server_id = server['id']
+
+ cls.servers_client.wait_for_server_status(cls.server_id, 'ACTIVE')
+
+ @classmethod
+ def tearDownClass(self, cls):
+ cls.servers_client.delete_server(cls.server_id)
+
+ @attr(type='positive')
+ def test_list_virtual_interfaces(self):
+ # Positive test:Should be able to GET the virtual interfaces list
+ # for a given server_id
+ resp, output = self.client.list_virtual_interfaces(self.server_id)
+ self.assertEqual(200, resp.status)
+ self.assertNotEqual(output, None)
+ virtual_interfaces = output
+ self.assertNotEqual(0, len(virtual_interfaces),
+ 'Expected virtual interfaces, got zero.')
+
+ @attr(type='negative')
+ def test_list_virtual_interfaces_invalid_server_id(self):
+ # Negative test: Should not be able to GET virtual interfaces
+ # for an invalid server_id
+ try:
+ resp, output = self.client.list_virtual_interfaces('!@#$%^&*()')
+ except exceptions.NotFound:
+ pass
+
+
+@attr(type='smoke')
+class VirtualInterfacesTestJSON(base.BaseComputeTestJSON,
+ VirtualInterfacesTest):
+ @classmethod
+ def setUpClass(cls):
+ super(VirtualInterfacesTestJSON, cls).setUpClass()
+ VirtualInterfacesTest.setUpClass(cls)
+
+ @classmethod
+ def tearDownClass(cls):
+ VirtualInterfacesTest.tearDownClass(cls)
+ super(VirtualInterfacesTestJSON, cls).tearDownClass()
+
+
+@attr(type='smoke')
+class VirtualInterfacesTestXML(base.BaseComputeTestXML,
+ VirtualInterfacesTest):
+ @classmethod
+ def setUpClass(cls):
+ super(VirtualInterfacesTestXML, cls).setUpClass()
+ VirtualInterfacesTest.setUpClass(cls)
+
+ @classmethod
+ def tearDownClass(cls):
+ VirtualInterfacesTest.tearDownClass(cls)
+ super(VirtualInterfacesTestXML, cls).tearDownClass()