Add namespaces to xml in Network client

If tag contains ":" it can't be just added to xml. We should set
namespaces to use it correctly.

Change-Id: Ib533a8d876599840c043e4cf6254031da8e7f790
diff --git a/tempest/services/compute/xml/common.py b/tempest/services/compute/xml/common.py
index 4def19f..b29b932 100644
--- a/tempest/services/compute/xml/common.py
+++ b/tempest/services/compute/xml/common.py
@@ -18,6 +18,11 @@
 XMLNS_11 = "http://docs.openstack.org/compute/api/v1.1"
 XMLNS_V3 = "http://docs.openstack.org/compute/api/v1.1"
 
+NEUTRON_NAMESPACES = {
+    'router': "http://docs.openstack.org/ext/neutron/router/api/v1.0",
+    'provider': 'http://docs.openstack.org/ext/provider/api/v1.0',
+}
+
 
 # NOTE(danms): This is just a silly implementation to help make generating
 # XML faster for prototyping. Could be replaced with proper etree gorp
@@ -137,6 +142,9 @@
         tag = child.tag
         if tag.startswith("{"):
             ns, tag = tag.split("}", 1)
+            for key, uri in NEUTRON_NAMESPACES.iteritems():
+                if uri == ns[1:]:
+                    tag = key + ":" + tag
         if plurals is not None and tag in plurals:
                 json[tag] = parse_array(child, plurals)
         else:
diff --git a/tempest/services/network/xml/network_client.py b/tempest/services/network/xml/network_client.py
index 97d514f..4a73c34 100644
--- a/tempest/services/network/xml/network_client.py
+++ b/tempest/services/network/xml/network_client.py
@@ -49,9 +49,14 @@
         post_body = common.Element(root)
         post_body.add_attr('xmlns:xsi',
                            'http://www.w3.org/2001/XMLSchema-instance')
+        elements = set()
         for name, attr in body[root].items():
             elt = self._get_element(name, attr)
             post_body.append(elt)
+            if ":" in name:
+                elements.add(name.split(":")[0])
+        if elements:
+            self._add_namespaces(post_body, elements)
         return str(common.Document(post_body))
 
     def serialize_list(self, body, root_name=None, item_name=None):
@@ -88,6 +93,11 @@
         else:
             return common.Element(name, value)
 
+    def _add_namespaces(self, root, elements):
+        for element in elements:
+            root.add_attr('xmlns:%s' % element,
+                          common.NEUTRON_NAMESPACES[element])
+
     def create_member(self, address, protocol_port, pool_id):
         uri = '%s/lb/members' % (self.uri_prefix)
         post_body = common.Element("member")