def test_get_free_floating_ip(self, mock_find_floating_ip, mock_shuffle):
"""Get free floating ip successfully."""
floating_network = {"floating_ip": "308b73-t9cc-1a6a-a270-12cc4811bd4a"}
- created_items = {}
floating_ips = [
{
"port_id": "608b73-r9cc-5a6a-a270-82cc4811bd4a",
mock_find_floating_ip.return_value = "508b73-o9cc-5a6a-a270-72cc4811bd8"
expected_result = "508b73-o9cc-5a6a-a270-72cc4811bd8"
- result = self.vimconn._get_free_floating_ip(
- self.server, floating_network, created_items
- )
+ result = self.vimconn._get_free_floating_ip(self.server, floating_network)
self.assertEqual(result, expected_result)
mock_shuffle.assert_called_once_with(floating_ips)
mock_find_floating_ip.assert_called_once_with(
- self.server, floating_ips, floating_network, created_items
+ self.server, floating_ips, floating_network
)
@patch("random.shuffle")
):
"""Neutron list floating IPs raises exception."""
floating_network = {"floating_ip": "308b73-t9cc-1a6a-a270-12cc4811bd4a"}
- created_items = {}
self.vimconn.neutron = CopyingMock()
self.vimconn.neutron.list_floatingips.side_effect = Exception(
"Floating ips could not be listed."
)
with self.assertRaises(Exception) as err:
- result = self.vimconn._get_free_floating_ip(
- self.server, floating_network, created_items
- )
+ result = self.vimconn._get_free_floating_ip(self.server, floating_network)
self.assertEqual(result, None)
self.assertEqual(str(err.exception), "Floating ips could not be listed.")
mock_shuffle.assert_not_called()
):
"""_find_floating_ip method raises exception."""
floating_network = {"floating_ip": "308b73-t9cc-1a6a-a270-12cc4811bd4a"}
- created_items = {}
floating_ips = [
{
"port_id": "608b73-r9cc-5a6a-a270-82cc4811bd4a",
)
with self.assertRaises(Exception) as err:
- result = self.vimconn._get_free_floating_ip(
- self.server, floating_network, created_items
- )
+ result = self.vimconn._get_free_floating_ip(self.server, floating_network)
self.assertEqual(result, None)
self.assertEqual(str(err.exception), "Free floating ip could not be found.")
mock_shuffle.assert_called_once_with(floating_ips)
mock_find_floating_ip.assert_called_once_with(
- self.server, floating_ips, floating_network, created_items
+ self.server, floating_ips, floating_network
)
@patch.object(vimconnector, "_create_floating_ip")
"floating_ip": "y08b73-o9cc-1a6a-a270-12cc4811bd4u",
"vim_id": "608b73-r9cc-5a6a-a270-82cc4811bd4a",
},
- created_items,
)
self.vimconn.neutron.show_floatingip.assert_called_once_with(
"y08b73-o9cc-1a6a-a270-12cc4811bd4u"
"floating_ip": "y08b73-o9cc-1a6a-a270-12cc4811bd4u",
"vim_id": "608b73-r9cc-5a6a-a270-82cc4811bd4a",
},
- created_items,
)
self.vimconn.neutron.show_floatingip.assert_called_with(None)
mock_sleep.assert_not_called()
"vim_id": "608b73-r9cc-5a6a-a270-82cc4811bd4a",
"exit_on_floating_ip_error": False,
},
- created_items,
)
self.vimconn.neutron.show_floatingip.assert_not_called()
mock_sleep.assert_not_called()
"vim_id": "608b73-r9cc-5a6a-a270-82cc4811bd4a",
"exit_on_floating_ip_error": True,
},
- created_items,
)
self.vimconn.neutron.show_floatingip.assert_not_called()
mock_sleep.assert_not_called()
(
self.server,
floating_network,
- created_items,
),
)
self.assertEqual(
(
self.server,
floating_network,
- created_items,
),
)
self.assertEqual(
(
self.server,
floating_network,
- created_items,
),
)
self.assertEqual(self.vimconn.neutron.show_floatingip.call_count, 3)
(
self.server,
floating_network,
- created_items,
),
)
self.assertEqual(
(
self.server,
floating_network,
- created_items,
),
)
self.assertEqual(
(
self.server,
floating_network,
- created_items,
),
)
self.assertEqual(
(
self.server,
floating_network,
- created_items,
),
)
(
self.server,
floating_network,
- created_items,
),
)
self.assertEqual(
(
self.server,
floating_network,
- created_items,
),
)
self.assertEqual(
(
self.server,
floating_network,
- created_items,
),
)
self.assertEqual(
(
self.server,
floating_network,
- created_items,
),
)
(
self.server,
floating_network,
- created_items,
),
)
self.assertEqual(
(
self.server,
floating_network,
- created_items,
),
)
self.assertEqual(
(
self.server,
floating_network,
- created_items,
),
)
(
self.server,
floating_network,
- created_items,
),
)
self.assertEqual(
(
self.server,
floating_network,
- created_items,
),
)
self.assertEqual(
(
self.server,
floating_network,
- created_items,
),
)
return self.neutron.show_floatingip(free_floating_ip)
def _get_free_floating_ip(
- self, server: object, floating_network: dict, created_items: dict
+ self, server: object, floating_network: dict
) -> Optional[str]:
"""Get the free floating IP address.
Args:
server (object): Server Object
floating_network (dict): Floating network details
- created_items (dict): All created items belongs to new VM instance
Returns:
free_floating_ip (str): Free floating ip addr
# Randomize
random.shuffle(floating_ips)
- return self._find_floating_ip(
- server, floating_ips, floating_network, created_items
- )
+ return self._find_floating_ip(server, floating_ips, floating_network)
def _prepare_external_network_for_vminstance(
self,
# several times
while not assigned:
free_floating_ip = self._get_free_floating_ip(
- server, floating_network, created_items
+ server, floating_network
)
if not free_floating_ip:
--- /dev/null
+#######################################################################################
+# Copyright ETSI Contributors and Others.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#######################################################################################
+---
+fixes:
+ - |
+ Fixing the signature of method _get_free_floating_ip in vimconn_openstack.py.
+