Example #1
0
    def test_disassociate_post_with_exception(self):
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        api.tenant_floating_ip_list(IsA(http.HttpRequest)).\
                                    AndReturn(self.floating_ips)

        self.mox.StubOutWithMock(api, 'server_remove_floating_ip')
        exception = novaclient_exceptions.ClientException('ClientException',
                                                    message='clientException')
        api.server_remove_floating_ip(IsA(http.HttpRequest),
                                      IsA(int),
                                      IsA(int)).AndRaise(exception)
        self.mox.StubOutWithMock(messages, 'error')
        messages.error(IsA(http.HttpRequest), IsA(basestring))

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.tenant_floating_ip_get = self.mox.CreateMockAnything()
        api.tenant_floating_ip_get(IsA(http.HttpRequest), IsA(unicode)).\
                                   AndReturn(self.floating_ip)
        self.mox.ReplayAll()
        res = self.client.post(
                reverse('horizon:nova:floating_ips:disassociate', args=[1]),
                {'floating_ip_id': self.floating_ip.id,
                 'method': 'FloatingIpDisassociate'})
        self.assertRaises(novaclient_exceptions.ClientException)
        self.assertRedirects(res, FLOATING_IPS_INDEX)
        self.mox.VerifyAll()
    def test_associate_post_with_exception(self):
        floating_ip = self.floating_ips.first()
        server = self.servers.first()
        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api.nova, 'keypair_list')
        self.mox.StubOutWithMock(api, 'server_add_floating_ip')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.tenant_floating_ip_list(IsA(http.HttpRequest)) \
                                    .AndReturn(self.floating_ips.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        api.nova.keypair_list(IsA(http.HttpRequest)) \
                              .AndReturn(self.keypairs.list())
        exc = novaclient_exceptions.ClientException('ClientException')
        api.server_add_floating_ip(IsA(http.HttpRequest),
                                   server.id,
                                   floating_ip.id).AndRaise(exc)
        api.tenant_floating_ip_get(IsA(http.HttpRequest),
                                   floating_ip.id).AndReturn(floating_ip)
        self.mox.ReplayAll()

        url = reverse('%s:associate' % NAMESPACE, args=[floating_ip.id])
        res = self.client.post(url,
                {'instance_id': 1,
                 'floating_ip_id': floating_ip.id,
                 'floating_ip': floating_ip.ip,
                 'method': 'FloatingIpAssociate'})
        self.assertRaises(novaclient_exceptions.ClientException)
        self.assertRedirects(res, INDEX_URL)
Example #3
0
    def test_associate_post(self):
        server = self.server

        self.mox.StubOutWithMock(api, 'server_list')
        api.server_list = self.mox.CreateMockAnything()
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers)

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        api.tenant_floating_ip_list(IsA(http.HttpRequest)).\
                                    AndReturn(self.floating_ips)

        self.mox.StubOutWithMock(api, 'server_add_floating_ip')
        api.server_add_floating_ip = self.mox.CreateMockAnything()
        api.server_add_floating_ip(IsA(http.HttpRequest), IsA(unicode),
                                                          IsA(unicode)).\
                                                          AndReturn(None)
        self.mox.StubOutWithMock(messages, 'info')
        messages.info(IsA(http.HttpRequest), IsA(unicode))

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.tenant_floating_ip_get = self.mox.CreateMockAnything()
        api.tenant_floating_ip_get(IsA(http.HttpRequest), str(1)).\
                                   AndReturn(self.floating_ip)
        self.mox.ReplayAll()

        res = self.client.post(reverse('horizon:nova:floating_ips:associate',
                                      args=[1]),
                               {'instance_id': 1,
                                'floating_ip_id': self.floating_ip.id,
                                'floating_ip': self.floating_ip.ip,
                                'method': 'FloatingIpAssociate'})

        self.assertRedirects(res, FLOATING_IPS_INDEX)
        self.mox.VerifyAll()
    def test_association(self):
        floating_ip = self.floating_ips.first()
        servers = self.servers.list()

        # Add duplicate instance name to test instance name with [IP]
        # change id and private IP
        server3 = api.nova.Server(self.servers.first(), self.request)
        server3.id = 101
        server3.addresses = deepcopy(server3.addresses)
        server3.addresses['private'][0]['addr'] = "10.0.0.5"
        self.servers.add(server3)

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        self.mox.StubOutWithMock(api, 'server_list')
        api.tenant_floating_ip_get(IsA(http.HttpRequest),
                                   floating_ip.id).AndReturn(floating_ip)
        api.server_list(IsA(http.HttpRequest)).AndReturn(servers)
        self.mox.ReplayAll()

        res = self.client.get(
            reverse(
                "horizon:nova:access_and_security:"
                "floating_ips:associate",
                args=[floating_ip.id]))
        self.assertTemplateUsed(
            res, 'nova/access_and_security/'
            'floating_ips/associate.html')

        self.assertContains(res, '<option value="1">server_1 [1]' '</option>')
        self.assertContains(res, '<option value="101">server_1 [101]'
                            '</option>')
        self.assertContains(res, '<option value="2">server_2</option>')
Example #5
0
    def test_disassociate_post(self):
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        api.tenant_floating_ip_list(IsA(http.HttpRequest)).\
                                    AndReturn(self.floating_ips)
        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_list(IsA(http.HttpRequest)).\
                                AndReturn(self.security_groups)
        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)

        self.mox.StubOutWithMock(api, 'server_remove_floating_ip')
        api.server_remove_floating_ip = self.mox.CreateMockAnything()
        api.server_remove_floating_ip(IsA(http.HttpRequest), IsA(int),
                                                             IsA(int)).\
                                                             AndReturn(None)
        self.mox.StubOutWithMock(messages, 'info')
        messages.info(IsA(http.HttpRequest), IsA(unicode))

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.tenant_floating_ip_get = self.mox.CreateMockAnything()
        api.tenant_floating_ip_get(IsA(http.HttpRequest), IsA(unicode)).\
                                   AndReturn(self.floating_ip)
        self.mox.ReplayAll()
        res = self.client.post(
         reverse('horizon:nova:access_and_security:floating_ips:disassociate',
                 args=[1]),
                 {'floating_ip_id': self.floating_ip.id,
                  'method': 'FloatingIpDisassociate'})
        self.assertRedirects(res, FLOATING_IPS_INDEX)
Example #6
0
    def test_associate_post_with_exception(self):
        floating_ip = self.floating_ips.first()
        server = self.servers.first()
        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api.nova, 'keypair_list')
        self.mox.StubOutWithMock(api, 'server_add_floating_ip')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.tenant_floating_ip_list(IsA(http.HttpRequest)) \
                                    .AndReturn(self.floating_ips.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        api.nova.keypair_list(IsA(http.HttpRequest)) \
                              .AndReturn(self.keypairs.list())
        exc = novaclient_exceptions.ClientException('ClientException')
        api.server_add_floating_ip(IsA(http.HttpRequest), server.id,
                                   floating_ip.id).AndRaise(exc)
        api.tenant_floating_ip_get(IsA(http.HttpRequest),
                                   floating_ip.id).AndReturn(floating_ip)
        self.mox.ReplayAll()

        url = reverse('%s:associate' % NAMESPACE, args=[floating_ip.id])
        res = self.client.post(
            url, {
                'instance_id': 1,
                'floating_ip_id': floating_ip.id,
                'floating_ip': floating_ip.ip,
                'method': 'FloatingIpAssociate'
            })
        self.assertRaises(novaclient_exceptions.ClientException)
        self.assertRedirects(res, INDEX_URL)
Example #7
0
    def test_association(self):
        floating_ip = self.floating_ips.first()
        servers = self.servers.list()

        # Add duplicate instance name to test instance name with [IP]
        # change id and private IP
        server3 = api.nova.Server(self.servers.first(), self.request)
        server3.id = 101
        server3.addresses = deepcopy(server3.addresses)
        server3.addresses['private'][0]['addr'] = "10.0.0.5"
        self.servers.add(server3)

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        self.mox.StubOutWithMock(api.nova, 'server_list')
        api.tenant_floating_ip_get(IsA(http.HttpRequest),
                                   floating_ip.id).AndReturn(floating_ip)
        api.nova.server_list(IsA(http.HttpRequest)).AndReturn(servers)
        self.mox.ReplayAll()

        res = self.client.get(
                             reverse("horizon:nova:access_and_security:"
                                     "floating_ips:associate",
                                     args=[floating_ip.id]))
        self.assertTemplateUsed(res,
                                'nova/access_and_security/'
                                'floating_ips/associate.html')

        self.assertContains(res, '<option value="1">server_1 [1]'
                            '</option>')
        self.assertContains(res, '<option value="101">server_1 [101]'
                            '</option>')
        self.assertContains(res, '<option value="2">server_2</option>')
Example #8
0
    def test_associate_post(self):
        floating_ip = self.floating_ips.first()
        server = self.servers.first()
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        self.mox.StubOutWithMock(api, 'server_add_floating_ip')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        self.mox.StubOutWithMock(api.nova, 'server_list')
        self.mox.StubOutWithMock(api.nova, 'keypair_list')

        api.nova.keypair_list(IsA(http.HttpRequest)) \
                              .AndReturn(self.keypairs.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        api.nova.server_list(IsA(http.HttpRequest)) \
                .AndReturn(self.servers.list())
        api.tenant_floating_ip_list(IsA(http.HttpRequest)) \
                                    .AndReturn(self.floating_ips.list())
        api.server_add_floating_ip(IsA(http.HttpRequest),
                                   server.id,
                                   floating_ip.id)
        api.tenant_floating_ip_get(IsA(http.HttpRequest),
                                   floating_ip.id).AndReturn(floating_ip)
        api.nova.server_list(IsA(http.HttpRequest),
                             all_tenants=True).AndReturn(self.servers.list())
        self.mox.ReplayAll()

        form_data = {'instance_id': server.id,
                     'floating_ip_id': floating_ip.id,
                     'floating_ip': floating_ip.ip,
                     'method': 'FloatingIpAssociate'}
        url = reverse('%s:associate' % NAMESPACE, args=[floating_ip.id])
        res = self.client.post(url, form_data)
        self.assertRedirects(res, INDEX_URL)
Example #9
0
    def test_associate_post(self):
        floating_ip = self.floating_ips.first()
        server = self.servers.first()
        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        self.mox.StubOutWithMock(api, 'server_add_floating_ip')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.tenant_floating_ip_list(IsA(http.HttpRequest)) \
                                    .AndReturn(self.floating_ips.list())
        api.server_add_floating_ip(IsA(http.HttpRequest), server.id,
                                   floating_ip.id)
        api.tenant_floating_ip_get(IsA(http.HttpRequest),
                                   floating_ip.id).AndReturn(floating_ip)
        self.mox.ReplayAll()

        form_data = {
            'instance_id': server.id,
            'floating_ip_id': floating_ip.id,
            'floating_ip': floating_ip.ip,
            'method': 'FloatingIpAssociate'
        }
        url = reverse('%s:associate' % NAMESPACE, args=[floating_ip.id])
        res = self.client.post(url, form_data)
        self.assertRedirects(res, INDEX_URL)
Example #10
0
    def test_associate_post(self):
        self.mox.StubOutWithMock(api, 'server_list')
        api.server_list = self.mox.CreateMockAnything()
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers)

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        api.tenant_floating_ip_list(IsA(http.HttpRequest)).\
                                    AndReturn(self.floating_ips)

        self.mox.StubOutWithMock(api, 'server_add_floating_ip')
        api.server_add_floating_ip = self.mox.CreateMockAnything()
        api.server_add_floating_ip(IsA(http.HttpRequest), IsA(unicode),
                                                          IsA(unicode)).\
                                                          AndReturn(None)
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.tenant_floating_ip_get = self.mox.CreateMockAnything()
        api.tenant_floating_ip_get(IsA(http.HttpRequest), str(1)).\
                                   AndReturn(self.floating_ip)
        self.mox.ReplayAll()

        res = self.client.post(
            reverse('horizon:nova:access_and_security:floating_ips:associate',
                    args=[1]), {
                        'instance_id': 1,
                        'floating_ip_id': self.floating_ip.id,
                        'floating_ip': self.floating_ip.ip,
                        'method': 'FloatingIpAssociate'
                    })

        self.assertRedirects(res, INDEX_URL)
Example #11
0
    def test_disassociate_post_with_exception(self):
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        api.tenant_floating_ip_list(IsA(http.HttpRequest)).\
                                    AndReturn(self.floating_ips)
        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_list(IsA(http.HttpRequest)).\
                                AndReturn(self.security_groups)
        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)

        self.mox.StubOutWithMock(api, 'server_remove_floating_ip')
        exception = novaclient_exceptions.ClientException('ClientException',
                                                    message='clientException')
        api.server_remove_floating_ip(IsA(http.HttpRequest),
                                      IsA(int),
                                      IsA(int)).AndRaise(exception)
        self.mox.StubOutWithMock(messages, 'error')
        messages.error(IsA(http.HttpRequest), IsA(basestring))

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.tenant_floating_ip_get = self.mox.CreateMockAnything()
        api.tenant_floating_ip_get(IsA(http.HttpRequest), IsA(unicode)).\
                                   AndReturn(self.floating_ip)
        self.mox.ReplayAll()
        res = self.client.post(
        reverse('horizon:nova:access_and_security:floating_ips:disassociate',
                args=[1]),
                {'floating_ip_id': self.floating_ip.id,
                 'method': 'FloatingIpDisassociate'})
        self.assertRaises(novaclient_exceptions.ClientException)
        self.assertRedirects(res, FLOATING_IPS_INDEX)
    def test_associate(self):
        floating_ip = self.floating_ips.first()
        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.tenant_floating_ip_get(IsA(http.HttpRequest),
                                   floating_ip.id).AndReturn(floating_ip)
        self.mox.ReplayAll()

        url = reverse('%s:associate' % NAMESPACE, args=[floating_ip.id])
        res = self.client.get(url)
        self.assertTemplateUsed(res,
                        'nova/access_and_security/floating_ips/associate.html')
Example #13
0
    def test_associate(self):
        floating_ip = self.floating_ips.first()
        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.tenant_floating_ip_get(IsA(http.HttpRequest),
                                   floating_ip.id).AndReturn(floating_ip)
        self.mox.ReplayAll()

        url = reverse('%s:associate' % NAMESPACE, args=[floating_ip.id])
        res = self.client.get(url)
        self.assertTemplateUsed(
            res, 'nova/access_and_security/floating_ips/associate.html')
Example #14
0
    def test_associate(self):
        self.mox.StubOutWithMock(api, 'server_list')
        api.server_list = self.mox.CreateMockAnything()
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers)

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.tenant_floating_ip_get = self.mox.CreateMockAnything()
        api.tenant_floating_ip_get(IsA(http.HttpRequest), str(1)).\
                                    AndReturn(self.floating_ip)
        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:nova:floating_ips:associate',
                                      args=[1]))
        self.assertTemplateUsed(res, 'nova/floating_ips/associate.html')
Example #15
0
    def test_associate(self):
        self.mox.StubOutWithMock(api, 'server_list')
        api.server_list = self.mox.CreateMockAnything()
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers)

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.tenant_floating_ip_get = self.mox.CreateMockAnything()
        api.tenant_floating_ip_get(IsA(http.HttpRequest), str(1)).\
                                    AndReturn(self.floating_ip)
        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:nova:floating_ips:associate',
                                      args=[1]))
        self.assertTemplateUsed(res, 'nova/floating_ips/associate.html')
Example #16
0
 def get_object(self, *args, **kwargs):
     ip_id = int(kwargs['ip_id'])
     try:
         return api.tenant_floating_ip_get(self.request, ip_id)
     except:
         redirect = reverse('horizon:nova:access_and_security:index')
         exceptions.handle(self.request,
                           _('Unable to associate floating IP.'),
                           redirect=redirect)
Example #17
0
 def get_object(self, *args, **kwargs):
     ip_id = kwargs['ip_id']
     try:
         return api.tenant_floating_ip_get(self.request, ip_id)
     except Exception as e:
         LOG.exception('Error fetching floating ip with id "%s".' % ip_id)
         messages.error(self.request,
                        _('Unable to associate floating ip: %s') % e)
         raise http.Http404("Floating IP %s not available." % ip_id)
Example #18
0
 def get_object(self, *args, **kwargs):
     ip_id = kwargs['ip_id']
     try:
         return api.tenant_floating_ip_get(self.request, ip_id)
     except Exception as e:
         LOG.exception('Error fetching floating ip with id "%s".' % ip_id)
         messages.error(self.request,
                        _('Unable to associate floating ip: %s') % e)
         raise http.Http404("Floating IP %s not available." % ip_id)
Example #19
0
 def get_object(self, *args, **kwargs):
     ip_id = int(kwargs['ip_id'])
     try:
         return api.tenant_floating_ip_get(self.request, ip_id)
     except:
         redirect = reverse('horizon:nova:access_and_security:index')
         exceptions.handle(self.request,
                           _('Unable to associate floating IP.'),
                           redirect=redirect)
Example #20
0
    def test_associate_post_with_exception(self):
        server = self.server

        self.mox.StubOutWithMock(api, 'server_list')
        api.server_list = self.mox.CreateMockAnything()
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers)

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        api.tenant_floating_ip_list(IsA(http.HttpRequest)).\
                                    AndReturn(self.floating_ips)
        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_list(IsA(http.HttpRequest)).\
                                AndReturn(self.security_groups)
        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)

        self.mox.StubOutWithMock(api, 'server_add_floating_ip')
        api.server_add_floating_ip = self.mox.CreateMockAnything()
        exception = novaclient_exceptions.ClientException('ClientException',
                                                    message='clientException')
        api.server_add_floating_ip(IsA(http.HttpRequest), IsA(unicode),
                                                          IsA(unicode)).\
                                                          AndRaise(exception)

        self.mox.StubOutWithMock(messages, 'error')
        messages.error(IsA(http.HttpRequest), IsA(basestring))

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.tenant_floating_ip_get = self.mox.CreateMockAnything()
        api.tenant_floating_ip_get(IsA(http.HttpRequest), IsA(unicode)).\
                                   AndReturn(self.floating_ip)
        self.mox.ReplayAll()

        res = self.client.post(reverse(
                'horizon:nova:access_and_security:floating_ips:associate',
                args=[1]),
                {'instance_id': 1,
                 'floating_ip_id': self.floating_ip.id,
                 'floating_ip': self.floating_ip.ip,
                 'method': 'FloatingIpAssociate'})
        self.assertRaises(novaclient_exceptions.ClientException)

        self.assertRedirects(res, FLOATING_IPS_INDEX)
Example #21
0
    def test_associate_post_with_exception(self):
        self.mox.StubOutWithMock(api, 'server_list')
        api.server_list = self.mox.CreateMockAnything()
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers)

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        api.tenant_floating_ip_list(IsA(http.HttpRequest)).\
                                    AndReturn(self.floating_ips)
        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_list(IsA(http.HttpRequest)).\
                                AndReturn(self.security_groups)
        self.mox.StubOutWithMock(api.nova, 'keypair_list')
        api.nova.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)

        self.mox.StubOutWithMock(api, 'server_add_floating_ip')
        api.server_add_floating_ip = self.mox.CreateMockAnything()
        exception = novaclient_exceptions.ClientException(
            'ClientException', message='clientException')
        api.server_add_floating_ip(IsA(http.HttpRequest), IsA(unicode),
                                                          IsA(unicode)).\
                                                          AndRaise(exception)

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.tenant_floating_ip_get = self.mox.CreateMockAnything()
        api.tenant_floating_ip_get(IsA(http.HttpRequest), IsA(unicode)).\
                                   AndReturn(self.floating_ip)
        self.mox.ReplayAll()

        res = self.client.post(
            reverse('horizon:nova:access_and_security:floating_ips:associate',
                    args=[1]), {
                        'instance_id': 1,
                        'floating_ip_id': self.floating_ip.id,
                        'floating_ip': self.floating_ip.ip,
                        'method': 'FloatingIpAssociate'
                    })
        self.assertRaises(novaclient_exceptions.ClientException)

        self.assertRedirects(res, INDEX_URL)
Example #22
0
    def test_disassociate_post(self):
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        api.tenant_floating_ip_list(IsA(http.HttpRequest)).\
                                    AndReturn(self.floating_ips)

        self.mox.StubOutWithMock(api, 'server_remove_floating_ip')
        api.server_remove_floating_ip = self.mox.CreateMockAnything()
        api.server_remove_floating_ip(IsA(http.HttpRequest), IsA(int),
                                                             IsA(int)).\
                                                             AndReturn(None)
        self.mox.StubOutWithMock(messages, 'info')
        messages.info(IsA(http.HttpRequest), IsA(unicode))

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.tenant_floating_ip_get = self.mox.CreateMockAnything()
        api.tenant_floating_ip_get(IsA(http.HttpRequest), IsA(unicode)).\
                                   AndReturn(self.floating_ip)
        self.mox.ReplayAll()
        res = self.client.post(
                 reverse('horizon:nova:floating_ips:disassociate', args=[1]),
                 {'floating_ip_id': self.floating_ip.id,
                  'method': 'FloatingIpDisassociate'})
        self.assertRedirects(res, FLOATING_IPS_INDEX)
Example #23
0
    def test_associate_post_with_exception(self):
        server = self.server

        self.mox.StubOutWithMock(api, 'server_list')
        api.server_list = self.mox.CreateMockAnything()
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers)

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        api.tenant_floating_ip_list(IsA(http.HttpRequest)).\
                                    AndReturn(self.floating_ips)

        self.mox.StubOutWithMock(api, 'server_add_floating_ip')
        api.server_add_floating_ip = self.mox.CreateMockAnything()
        exception = novaclient_exceptions.ClientException('ClientException',
                                                    message='clientException')
        api.server_add_floating_ip(IsA(http.HttpRequest), IsA(unicode),
                                                          IsA(unicode)).\
                                                          AndRaise(exception)

        self.mox.StubOutWithMock(messages, 'error')
        messages.error(IsA(http.HttpRequest), IsA(basestring))

        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        api.tenant_floating_ip_get = self.mox.CreateMockAnything()
        api.tenant_floating_ip_get(IsA(http.HttpRequest), IsA(unicode)).\
                                   AndReturn(self.floating_ip)
        self.mox.ReplayAll()

        res = self.client.post(reverse('horizon:nova:floating_ips:associate',
                                      args=[1]),
                               {'instance_id': 1,
                                'floating_ip_id': self.floating_ip.id,
                                'floating_ip': self.floating_ip.ip,
                                'method': 'FloatingIpAssociate'})
        self.assertRaises(novaclient_exceptions.ClientException)

        self.assertRedirects(res, FLOATING_IPS_INDEX)
Example #24
0
    def handle(self, request, data):
        try:
            fip = api.tenant_floating_ip_get(request, data['floating_ip_id'])
            api.server_remove_floating_ip(request, fip.instance_id, fip.id)

            LOG.info('Disassociating Floating IP "%s"'
                      % data['floating_ip_id'])

            messages.info(request,
                          _('Successfully disassociated Floating IP: %s')
                          % data['floating_ip_id'])
        except novaclient_exceptions.ClientException, e:
            LOG.exception("ClientException in FloatingIpAssociate")
            messages.error(request, _('Error disassociating Floating IP: %s')
                                     % e.message)
Example #25
0
def associate(request, ip_id):
    instancelist = [(server.id, 'id: %s, name: %s' %
            (server.id, server.name))
            for server in api.server_list(request)]

    form, handled = FloatingIpAssociate().maybe_handle(request, initial={
                'floating_ip_id': ip_id,
                'floating_ip': api.tenant_floating_ip_get(request, ip_id).ip,
                'instances': instancelist})
    if handled:
        return handled

    return shortcuts.render(request,
                            'nova/floating_ips/associate.html', {
                                'floating_ip_id': ip_id,
                                'associate_form': form})
Example #26
0
    def handle(self, request, data):
        try:
            fip = api.tenant_floating_ip_get(request, data['floating_ip_id'])
            api.server_remove_floating_ip(request, fip.instance_id, fip.id)

            LOG.info('Disassociating Floating IP "%s"' %
                     data['floating_ip_id'])

            messages.info(
                request,
                _('Successfully disassociated Floating IP: %s') %
                data['floating_ip_id'])
        except novaclient_exceptions.ClientException, e:
            LOG.exception("ClientException in FloatingIpAssociate")
            messages.error(
                request,
                _('Error disassociating Floating IP: %s') % e.message)
Example #27
0
def associate(request, ip_id):
    instancelist = [(server.id, 'id: %s, name: %s' % (server.id, server.name))
                    for server in api.server_list(request)]

    form, handled = FloatingIpAssociate().maybe_handle(
        request,
        initial={
            'floating_ip_id': ip_id,
            'floating_ip': api.tenant_floating_ip_get(request, ip_id).ip,
            'instances': instancelist
        })
    if handled:
        return handled

    return shortcuts.render(request, 'nova/floating_ips/associate.html', {
        'floating_ip_id': ip_id,
        'associate_form': form
    })
Example #28
0
def associate(request, ip_id):
    instancelist = [(server.id, 'id: %s, name: %s' %
            (server.id, server.name))
            for server in api.server_list(request)]

    form, handled = FloatingIpAssociate().maybe_handle(request, initial={
                'floating_ip_id': ip_id,
                'floating_ip': api.tenant_floating_ip_get(request, ip_id).ip,
                'instances': instancelist})
    if handled:
        return handled

    context = {'floating_ip_id': ip_id,
               'form': form}

    if request.is_ajax():
        template = 'nova/access_and_security/floating_ips/_associate.html'
        context['hide'] = True
    else:
        template = 'nova/access_and_security/floating_ips/associate.html'

    return shortcuts.render(request, template, context)
Example #29
0
def associate(request, ip_id):
    instancelist = [(server.id, 'id: %s, name: %s' % (server.id, server.name))
                    for server in api.server_list(request)]

    form, handled = FloatingIpAssociate().maybe_handle(
        request,
        initial={
            'floating_ip_id': ip_id,
            'floating_ip': api.tenant_floating_ip_get(request, ip_id).ip,
            'instances': instancelist
        })
    if handled:
        return handled

    context = {'floating_ip_id': ip_id, 'form': form}

    if request.is_ajax():
        template = 'nova/floating_ips/_associate.html'
        context['hide'] = True
    else:
        template = 'nova/floating_ips/associate.html'

    return shortcuts.render(request, template, context)