Merge "Add "V2 API- add-fixed-IP and remove-fixed-IP server action" tests"
diff --git a/tempest/api/compute/servers/test_attach_interfaces.py b/tempest/api/compute/servers/test_attach_interfaces.py
index 9cdac55..f02cd93 100644
--- a/tempest/api/compute/servers/test_attach_interfaces.py
+++ b/tempest/api/compute/servers/test_attach_interfaces.py
@@ -123,6 +123,33 @@
         _ifs = self._test_delete_interface(server, ifs)
         self.assertEqual(len(ifs) - 1, len(_ifs))
 
+    @attr(type='gate')
+    def test_add_remove_fixed_ip(self):
+        # Add and Remove the fixed IP to server.
+        server, ifs = self._create_server_get_interfaces()
+        interface_count = len(ifs)
+        self.assertTrue(interface_count > 0)
+        self._check_interface(ifs[0])
+        network_id = ifs[0]['net_id']
+        resp, body = self.client.add_fixed_ip(server['id'],
+                                              network_id)
+        self.assertEqual(202, resp.status)
+        # Remove the fixed IP from server.
+        server_resp, server_detail = self.os.servers_client.get_server(
+            server['id'])
+        # Get the Fixed IP from server.
+        fixed_ip = None
+        for ip_set in server_detail['addresses']:
+            for ip in server_detail['addresses'][ip_set]:
+                if ip['OS-EXT-IPS:type'] == 'fixed':
+                    fixed_ip = ip['addr']
+                    break
+            if fixed_ip is not None:
+                break
+        resp, body = self.client.remove_fixed_ip(server['id'],
+                                                 fixed_ip)
+        self.assertEqual(202, resp.status)
+
 
 class AttachInterfacesTestXML(AttachInterfacesTestJSON):
     _interface = 'xml'
diff --git a/tempest/services/compute/json/interfaces_client.py b/tempest/services/compute/json/interfaces_client.py
index f4c4c64..de3aa19 100644
--- a/tempest/services/compute/json/interfaces_client.py
+++ b/tempest/services/compute/json/interfaces_client.py
@@ -80,3 +80,25 @@
                 raise exceptions.TimeoutException(message)
 
         return resp, body
+
+    def add_fixed_ip(self, server_id, network_id):
+        """Add a fixed IP to input server instance."""
+        post_body = json.dumps({
+            'addFixedIp': {
+                'networkId': network_id
+            }
+        })
+        resp, body = self.post('servers/%s/action' % str(server_id),
+                               post_body)
+        return resp, body
+
+    def remove_fixed_ip(self, server_id, ip_address):
+        """Remove input fixed IP from input server instance."""
+        post_body = json.dumps({
+            'removeFixedIp': {
+                'address': ip_address
+            }
+        })
+        resp, body = self.post('servers/%s/action' % str(server_id),
+                               post_body)
+        return resp, body
diff --git a/tempest/services/compute/xml/interfaces_client.py b/tempest/services/compute/xml/interfaces_client.py
index 5df6187..8d4bfcc 100644
--- a/tempest/services/compute/xml/interfaces_client.py
+++ b/tempest/services/compute/xml/interfaces_client.py
@@ -24,6 +24,7 @@
 from tempest.services.compute.xml.common import Element
 from tempest.services.compute.xml.common import Text
 from tempest.services.compute.xml.common import xml_to_json
+from tempest.services.compute.xml.common import XMLNS_11
 
 CONF = config.CONF
 
@@ -104,3 +105,21 @@
                            (port_id, status, self.build_timeout))
                 raise exceptions.TimeoutException(message)
         return resp, body
+
+    def add_fixed_ip(self, server_id, network_id):
+        """Add a fixed IP to input server instance."""
+        post_body = Element("addFixedIp",
+                            xmlns=XMLNS_11,
+                            networkId=network_id)
+        resp, body = self.post('servers/%s/action' % str(server_id),
+                               str(Document(post_body)))
+        return resp, body
+
+    def remove_fixed_ip(self, server_id, ip_address):
+        """Remove input fixed IP from input server instance."""
+        post_body = Element("removeFixedIp",
+                            xmlns=XMLNS_11,
+                            address=ip_address)
+        resp, body = self.post('servers/%s/action' % str(server_id),
+                               str(Document(post_body)))
+        return resp, body