def test_create_floating_ip(self, mock_has_service, mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock_nova_client.floating_ips.create.return_value = FakeFloatingIP(
            **self.mock_floating_ip_list_rep[1])

        self.client.create_floating_ip(network='nova')

        mock_nova_client.floating_ips.create.assert_called_with(pool='nova')
    def test_get_floating_ip_not_found(
            self, mock_has_service, mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock_nova_client.floating_ips.list.return_value = [
            FakeFloatingIP(**ip) for ip in self.mock_floating_ip_list_rep
        ]

        floating_ip = self.client.get_floating_ip(id='666')

        self.assertIsNone(floating_ip)
    def test_detach_ip_from_server(self, mock_has_service, mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock_nova_client.floating_ips.list.return_value = [
            FakeFloatingIP(**ip) for ip in self.mock_floating_ip_list_rep
        ]

        self.client.detach_ip_from_server(
            server_id='server-id', floating_ip_id=1)

        mock_nova_client.servers.remove_floating_ip.assert_called_with(
            server='server-id', address='203.0.113.1')
    def test_get_floating_ip(self, mock_has_service, mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock_nova_client.floating_ips.list.return_value = [
            FakeFloatingIP(**ip) for ip in self.mock_floating_ip_list_rep
        ]

        floating_ip = self.client.get_floating_ip(id='29')

        mock_nova_client.floating_ips.list.assert_called_with()
        self.assertIsInstance(floating_ip, dict)
        self.assertEqual('198.51.100.29', floating_ip['floating_ip_address'])
    def test_add_ip_from_pool(self, mock_has_service, mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock_nova_client.floating_ips.list.return_value = [
            FakeFloatingIP(**ip) for ip in self.mock_floating_ip_list_rep
        ]

        ip = self.client.add_ip_from_pool(server_id='server-id',
                                          network='nova',
                                          fixed_address='192.0.2.129')

        self.assertEqual('203.0.113.1', ip['floating_ip_address'])
    def test_list_floating_ips(self, mock_has_service, mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock_nova_client.floating_ips.list.return_value = [
            FakeFloatingIP(**ip) for ip in self.mock_floating_ip_list_rep
        ]

        floating_ips = self.client.list_floating_ips()

        mock_nova_client.floating_ips.list.assert_called_with()
        self.assertIsInstance(floating_ips, list)
        self.assertEqual(3, len(floating_ips))
        self.assertAreInstances(floating_ips, dict)
    def test_available_floating_ip_new(
            self, mock_has_service, mock__nova_list_floating_ips,
            mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock__nova_list_floating_ips.return_value = []
        mock_nova_client.floating_ips.create.return_value = \
            FakeFloatingIP(**self.mock_floating_ip_list_rep[0])

        ip = self.client.available_floating_ip(network='nova')

        self.assertEqual(self.mock_floating_ip_list_rep[0]['ip'],
                         ip['floating_ip_address'])
    def test_attach_ip_to_server(self, mock_has_service, mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock_nova_client.floating_ips.list.return_value = [
            FakeFloatingIP(**ip) for ip in self.mock_floating_ip_list_rep
        ]

        self.client.attach_ip_to_server(
            server_id='server-id', floating_ip_id=1,
            fixed_address='192.0.2.129')

        mock_nova_client.servers.add_floating_ip.assert_called_with(
            server='server-id', address='203.0.113.1',
            fixed_address='192.0.2.129')