コード例 #1
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)
コード例 #2
0
ファイル: tests.py プロジェクト: katzj/horizon
    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()
コード例 #3
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)
コード例 #4
0
ファイル: tests.py プロジェクト: OpenStack-Kha/horizon
    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)
コード例 #5
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)
コード例 #6
0
ファイル: tests.py プロジェクト: AsylumCorp/horizon
    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)
コード例 #7
0
ファイル: forms.py プロジェクト: nimbis/horizon
 def handle(self, request, data):
     ip_id = int(data["floating_ip_id"])
     try:
         api.server_add_floating_ip(request, data["instance_id"], ip_id)
         LOG.info('Associating Floating IP "%s" with Instance "%s"' % (data["floating_ip"], data["instance_id"]))
         messages.success(
             request,
             _("Successfully associated Floating IP %(ip)s " "with Instance: %(inst)s")
             % {"ip": data["floating_ip"], "inst": data["instance_id"]},
         )
     except novaclient_exceptions.ClientException, e:
         LOG.exception("ClientException in FloatingIpAssociate")
         messages.error(request, _("Error associating Floating IP: %s") % e)
コード例 #8
0
ファイル: forms.py プロジェクト: OpenStack-Kha/horizon
 def handle(self, request, data):
     try:
         api.server_add_floating_ip(request,
                                    data['instance_id'],
                                    data['floating_ip_id'])
         LOG.info('Associating Floating IP "%s" with Instance "%s"'
                             % (data['floating_ip'], data['instance_id']))
         messages.info(request, _('Successfully associated Floating IP \
                                 %(ip)s with Instance: %(inst)s'
                                 % {"ip": data['floating_ip'],
                                    "inst": data['instance_id']}))
     except novaclient_exceptions.ClientException, e:
         LOG.exception("ClientException in FloatingIpAssociate")
         messages.error(request, _('Error associating Floating IP: %s') % e)
コード例 #9
0
ファイル: forms.py プロジェクト: AsylumCorp/horizon
 def handle(self, request, data):
     ip_id = int(data['floating_ip_id'])
     try:
         api.server_add_floating_ip(request,
                                    data['instance_id'],
                                    ip_id)
         LOG.info('Associating Floating IP "%s" with Instance "%s"'
                             % (data['floating_ip'], data['instance_id']))
         messages.success(request,
                          _('Successfully associated Floating IP %(ip)s '
                            'with Instance: %(inst)s')
                            % {"ip": data['floating_ip'],
                               "inst": data['instance_id']})
     except:
         exceptions.handle(request,
                           _('Unable to associate floating IP.'))
     return shortcuts.redirect('horizon:nova:access_and_security:index')
コード例 #10
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)
コード例 #11
0
ファイル: nova_tests.py プロジェクト: rbumg/horizon
    def test_server_add_floating_ip(self):
        server = api.nova.Server(self.servers.first(), self.request)
        floating_ip = self.floating_ips.first()
        novaclient = self.stub_novaclient()

        novaclient.floating_ips = self.mox.CreateMockAnything()
        novaclient.servers = self.mox.CreateMockAnything()
        novaclient.servers.get(server.id).AndReturn(server)
        novaclient.floating_ips.get(floating_ip.id).AndReturn(floating_ip)
        novaclient.servers.add_floating_ip(server.id, floating_ip.ip).AndReturn(server)
        self.mox.ReplayAll()

        server = api.server_add_floating_ip(self.request, server.id, floating_ip.id)
        self.assertIsInstance(server, api.nova.Server)
コード例 #12
0
    def test_server_add_floating_ip(self):
        server = api.nova.Server(self.servers.first(), self.request)
        floating_ip = self.floating_ips.first()
        novaclient = self.stub_novaclient()

        novaclient.floating_ips = self.mox.CreateMockAnything()
        novaclient.servers = self.mox.CreateMockAnything()
        novaclient.servers.get(server.id).AndReturn(server)
        novaclient.floating_ips.get(floating_ip.id).AndReturn(floating_ip)
        novaclient.servers.add_floating_ip(server.id, floating_ip.ip) \
                          .AndReturn(server)
        self.mox.ReplayAll()

        server = api.server_add_floating_ip(self.request, server.id,
                                            floating_ip.id)
        self.assertIsInstance(server, api.nova.Server)