Handle XML body of server's virtual interfaces correctly.
In addition, fix the test to check the json in a right way, and
add test that validates the virtual interfaces' mac address
Change-Id: I0cb6c0479041d06f504f8c00f4042b48063cec15
diff --git a/tempest/services/compute/xml/servers_client.py b/tempest/services/compute/xml/servers_client.py
index 3abf0c3..072f510 100644
--- a/tempest/services/compute/xml/servers_client.py
+++ b/tempest/services/compute/xml/servers_client.py
@@ -131,6 +131,17 @@
self._parse_links(body, json[sub])
return json
+ def _parse_xml_virtual_interfaces(self, xml_dom):
+ """
+ Return server's virtual interfaces XML as JSON.
+ """
+ data = {"virtual_interfaces": []}
+ for iface in xml_dom.getchildren():
+ data["virtual_interfaces"].append(
+ {"id": iface.get("id"),
+ "mac_address": iface.get("mac_address")})
+ return data
+
def get_server(self, server_id):
"""Returns the details of an existing server."""
resp, body = self.get("servers/%s" % str(server_id), self.headers)
@@ -400,5 +411,5 @@
"""
resp, body = self.get('/'.join(['servers', server_id,
'os-virtual-interfaces']), self.headers)
- server = self._parse_server(etree.fromstring(body))
- return resp, server
+ virt_int = self._parse_xml_virtual_interfaces(etree.fromstring(body))
+ return resp, virt_int
diff --git a/tempest/tests/compute/servers/test_virtual_interfaces.py b/tempest/tests/compute/servers/test_virtual_interfaces.py
index 6198526..0c57485 100644
--- a/tempest/tests/compute/servers/test_virtual_interfaces.py
+++ b/tempest/tests/compute/servers/test_virtual_interfaces.py
@@ -15,6 +15,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import netaddr
+
from tempest.common.utils.data_utils import rand_name
from tempest import exceptions
from tempest.test import attr
@@ -45,18 +47,22 @@
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.')
+ virt_ifaces = output
+ self.assertNotEqual(0, len(virt_ifaces['virtual_interfaces']),
+ 'Expected virtual interfaces, got 0 interfaces.')
+ for virt_iface in virt_ifaces['virtual_interfaces']:
+ mac_address = virt_iface['mac_address']
+ self.assertTrue(netaddr.valid_mac(mac_address),
+ "Invalid mac address detected.")
@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
+ invalid_server_id = rand_name('!@#$%^&*()')
+ self.assertRaises(exceptions.NotFound,
+ self.client.list_virtual_interfaces,
+ invalid_server_id)
@attr(type='smoke')