diff options
Diffstat (limited to 'yardstick/tests/unit/common/test_openstack_utils.py')
-rw-r--r-- | yardstick/tests/unit/common/test_openstack_utils.py | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/yardstick/tests/unit/common/test_openstack_utils.py b/yardstick/tests/unit/common/test_openstack_utils.py index 640d2d2c9..eb96aef84 100644 --- a/yardstick/tests/unit/common/test_openstack_utils.py +++ b/yardstick/tests/unit/common/test_openstack_utils.py @@ -35,28 +35,6 @@ class GetHeatApiVersionTestCase(unittest.TestCase): self.assertEqual(api_version, expected_result) -class GetNetworkIdTestCase(unittest.TestCase): - - def test_get_network_id(self): - _uuid = uuidutils.generate_uuid() - mock_shade_client = mock.Mock() - mock_shade_client.list_networks = mock.Mock() - mock_shade_client.list_networks.return_value = [{'id': _uuid}] - - output = openstack_utils.get_network_id(mock_shade_client, - 'network_name') - self.assertEqual(_uuid, output) - - def test_get_network_id_no_network(self): - mock_shade_client = mock.Mock() - mock_shade_client.list_networks = mock.Mock() - mock_shade_client.list_networks.return_value = None - - output = openstack_utils.get_network_id(mock_shade_client, - 'network_name') - self.assertIsNone(output) - - class DeleteNeutronNetTestCase(unittest.TestCase): def setUp(self): @@ -208,3 +186,27 @@ class RemoveRouterInterfaceTestCase(unittest.TestCase): self.mock_shade_client, self.router) mock_logger.error.assert_called_once() self.assertFalse(output) + + +class CreateFloatingIpTestCase(unittest.TestCase): + + def setUp(self): + self.mock_shade_client = mock.Mock() + self.network_name_or_id = 'name' + self.mock_shade_client.create_floating_ip = mock.Mock() + + def test_create_floating_ip(self): + self.mock_shade_client.create_floating_ip.return_value = \ + {'floating_ip_address': 'value1', 'id': 'value2'} + output = openstack_utils.create_floating_ip(self.mock_shade_client, + self.network_name_or_id) + self.assertEqual({'fip_addr': 'value1', 'fip_id': 'value2'}, output) + + @mock.patch.object(openstack_utils, 'log') + def test_create_floating_ip_exception(self, mock_logger): + self.mock_shade_client.create_floating_ip.side_effect = ( + exc.OpenStackCloudException('error message')) + output = openstack_utils.create_floating_ip( + self.mock_shade_client, self.network_name_or_id) + mock_logger.error.assert_called_once() + self.assertIsNone(output) |