Fix floatingip allocation

- Use neutron's floating IP provisioning APIs instead of the
  compute APIs that will proxy the request to neutron anyway.
  Another advantage of doing this is because we'll be using the
  external network to create a floating IP upon, and don't need
  to configure yet another "floating_pool_name" config opt to
  get things to work. When used, in most environments, the
  external network is the same as the floating pool.
- Fix usage of the GET /ports API where an incorrect filter
  parameter ("fixed_ip")  was being used (and subsequently ignored
  by older versions of neutron, see bug #1749820 [1])
- Refactor the check for ironic (we don't use baremetal nodes in
  our testing) to match that in tempest's own implementation of the
  port resolution [2]
- replace assertNotEqual(0, len(somelist)) with
  assertNotEmpty(somelist)


[1] https://launchpad.net/bugs/1749820
[2] https://opendev.org/openstack/tempest/src/commit/5c191faae78f52f876edba72484ea644d3df04fd/tempest/scenario/manager.py#L958-L994

Change-Id: I48b0f21fe75fae623e7e513cf2890f2c10a80317
Co-Authored-by: Goutham Pacha Ravi <gouthampravi@gmail.com>
Co-Authored-by: Shi Yan <yanshi.403@gmail.com>
Signed-off-by: Goutham Pacha Ravi <gouthampravi@gmail.com>
diff --git a/manila_tempest_tests/tests/scenario/manager.py b/manila_tempest_tests/tests/scenario/manager.py
index 6e8a2f6..dede47a 100644
--- a/manila_tempest_tests/tests/scenario/manager.py
+++ b/manila_tempest_tests/tests/scenario/manager.py
@@ -681,28 +681,36 @@
         return subnet
 
     def _get_server_port_id_and_ip4(self, server, ip_addr=None):
-        ports = self.os_admin.ports_client.list_ports(
-            device_id=server['id'], fixed_ip=ip_addr)['ports']
+        if ip_addr:
+            ports = self.os_admin.ports_client.list_ports(
+                device_id=server['id'],
+                fixed_ips='ip_address=%s' % ip_addr)['ports']
+        else:
+            ports = self.os_admin.ports_client.list_ports(
+                device_id=server['id'])['ports']
         # A port can have more than one IP address in some cases.
         # If the network is dual-stack (IPv4 + IPv6), this port is associated
         # with 2 subnets
-        p_status = ['ACTIVE']
-        # NOTE(vsaienko) With Ironic, instances live on separate hardware
-        # servers. Neutron does not bind ports for Ironic instances, as a
-        # result the port remains in the DOWN state.
-        # TODO(vsaienko) remove once bug: #1599836 is resolved.
-        if getattr(CONF.service_available, 'ironic', False):
-            p_status.append('DOWN')
+
+        def _is_active(port):
+            # NOTE(vsaienko) With Ironic, instances live on separate hardware
+            # servers. Neutron does not bind ports for Ironic instances, as a
+            # result the port remains in the DOWN state. This has been fixed
+            # with the introduction of the networking-baremetal plugin but
+            # it's not mandatory (and is not used on all stable branches).
+            return (port['status'] == 'ACTIVE' or
+                    port.get('binding:vnic_type') == 'baremetal')
+
         port_map = [(p["id"], fxip["ip_address"])
                     for p in ports
                     for fxip in p["fixed_ips"]
-                    if netutils.is_valid_ipv4(fxip["ip_address"])
-                    and p['status'] in p_status]
+                    if (netutils.is_valid_ipv4(fxip["ip_address"]) and
+                        _is_active(p))]
         inactive = [p for p in ports if p['status'] != 'ACTIVE']
         if inactive:
             LOG.warning("Instance has ports that are not ACTIVE: %s", inactive)
 
-        self.assertNotEqual(0, len(port_map),
+        self.assertNotEmpty(port_map,
                             "No IPv4 addresses found in: %s" % ports)
         self.assertEqual(len(port_map), 1,
                          "Found multiple IPv4 addresses: %s. "