Use Neutron API for attaching floating ip address 47/58647/2
authorPeriyasamy Palanisamy <periyasamy.palanisamy@ericsson.com>
Mon, 18 Jun 2018 10:30:55 +0000 (12:30 +0200)
committerPeriyasamy Palanisamy <periyasamy.palanisamy@ericsson.com>
Tue, 19 Jun 2018 07:41:06 +0000 (09:41 +0200)
The Nova API for attaching floating ip address with vm instance is
removed in latest Openstack release. Hence moving to neutron API for
attaching floating ip address with VM.

JIRA: SDNVPN-217

Change-Id: If321191eca0915cfd816eabc8890b28ed79cefc7
Signed-off-by: Periyasamy Palanisamy <periyasamy.palanisamy@ericsson.com>
sdnvpn/lib/openstack_utils.py
sdnvpn/test/functest/testcase_3.py
sdnvpn/test/functest/testcase_7.py
sdnvpn/test/functest/testcase_8.py

index a7ac80b..29843f0 100644 (file)
@@ -539,6 +539,18 @@ def create_floating_ip(neutron_client):
     return {'fip_addr': fip_addr, 'fip_id': fip_id}
 
 
+def attach_floating_ip(neutron_client, port_id):
+    extnet_id = get_external_net_id(neutron_client)
+    props = {'floating_network_id': extnet_id,
+             'port_id': port_id}
+    try:
+        return neutron_client.create_floatingip({'floatingip': props})
+    except Exception as e:
+        logger.error("Error [Attach_floating_ip(neutron_client), %s]: %s"
+                     % (port_id, e))
+        return None
+
+
 def add_floating_ip(nova_client, server_id, floatingip_addr):
     try:
         nova_client.servers.add_floating_ip(server_id, floatingip_addr)
index b7fe642..7f70043 100644 (file)
@@ -234,13 +234,11 @@ def main():
         # this to work.
         # We also create the FIP first because it is used in the
         # cloud-init script.
-        fip = os_utils.create_floating_ip(neutron_client)
         # fake_fip is needed to bypass NAT
         # see below for the reason why.
         fake_fip = os_utils.create_floating_ip(neutron_client)
-
-        floatingip_ids.extend([fip['fip_id'], fake_fip['fip_id']])
         # pin quagga to some compute
+        floatingip_ids.append(fake_fip['fip_id'])
         compute_node = nova_client.hypervisors.list()[0]
         quagga_compute_node = "nova:" + compute_node.hypervisor_hostname
         # Map the hypervisor used above to a compute handle
@@ -267,16 +265,19 @@ def main():
 
         instance_ids.append(quagga_vm)
 
-        fip_added = os_utils.add_floating_ip(nova_client,
-                                             quagga_vm.id,
-                                             fip['fip_addr'])
+        quagga_vm_port = test_utils.get_port(neutron_client,
+                                             quagga_vm.id)
+        fip_added = os_utils.attach_floating_ip(neutron_client,
+                                                quagga_vm_port['id'])
 
         msg = ("Assign a Floating IP to %s " %
                TESTCASE_CONFIG.quagga_instance_name)
         if fip_added:
             results.add_success(msg)
+            floatingip_ids.append(fip_added['floatingip']['id'])
         else:
             results.add_failure(msg)
+
         test_utils.attach_instance_to_ext_br(quagga_vm, compute)
 
         try:
index ada45a5..1ad0538 100644 (file)
@@ -151,17 +151,18 @@ def main():
         results.record_action(msg)
         results.add_to_summary(0, '-')
 
-        fip = os_utils.create_floating_ip(neutron_client)
-        fip_added = os_utils.add_floating_ip(nova_client, vm_2.id,
-                                             fip['fip_addr'])
+        vm2_port = test_utils.get_port(neutron_client,
+                                       vm_2.id)
+        fip_added = os_utils.attach_floating_ip(neutron_client,
+                                                vm2_port['id'])
         if fip_added:
             results.add_success(msg)
         else:
             results.add_failure(msg)
 
-        results.ping_ip_test(fip['fip_addr'])
+        results.ping_ip_test(fip_added['floatingip']['floating_ip_address'])
 
-        floatingip_ids.append(fip['fip_id'])
+        floatingip_ids.append(fip_added['floatingip']['id'])
 
     except Exception as e:
         logger.error("exception occurred while executing testcase_7: %s", e)
index e667dba..6336f46 100644 (file)
@@ -154,21 +154,23 @@ def main():
         msg = "Assign a Floating IP to %s" % vm_1.name
         results.record_action(msg)
 
-        fip = os_utils.create_floating_ip(neutron_client)
+        vm1_port = test_utils.get_port(neutron_client, vm_1.id)
+        fip_added = os_utils.attach_floating_ip(neutron_client,
+                                                vm1_port['id'])
 
-        fip_added = os_utils.add_floating_ip(nova_client,
-                                             vm_1.id, fip['fip_addr'])
         if fip_added:
             results.add_success(msg)
         else:
             results.add_failure(msg)
 
+        fip = fip_added['floatingip']['floating_ip_address']
+
         results.add_to_summary(0, "=")
         results.record_action("Ping %s via Floating IP" % vm_1.name)
         results.add_to_summary(0, "-")
-        results.ping_ip_test(fip['fip_addr'])
+        results.ping_ip_test(fip)
 
-        floatingip_ids.append(fip['fip_id'])
+        floatingip_ids.append(fip_added['floatingip']['id'])
 
     except Exception as e:
         logger.error("exception occurred while executing testcase_8: %s", e)