Пример #1
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()
Пример #2
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)
    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
    def test_index(self):
        keypairs = self.keypairs.list()
        sec_groups = self.security_groups.list()
        floating_ips = self.floating_ips.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.nova, 'server_list')

        api.nova.server_list(IsA(http.HttpRequest),
                             all_tenants=True).AndReturn(self.servers.list())
        api.nova.keypair_list(IsA(http.HttpRequest)).AndReturn(keypairs)
        api.tenant_floating_ip_list(IsA(http.HttpRequest)) \
                                    .AndReturn(floating_ips)
        api.security_group_list(IsA(http.HttpRequest)).AndReturn(sec_groups)

        self.mox.ReplayAll()

        url = reverse('horizon:project:access_and_security:index')
        res = self.client.get(url)

        self.assertTemplateUsed(res, 'project/access_and_security/index.html')
        self.assertItemsEqual(res.context['keypairs_table'].data, keypairs)
        self.assertItemsEqual(res.context['security_groups_table'].data,
                              sec_groups)
        self.assertItemsEqual(res.context['floating_ips_table'].data,
                              floating_ips)
Пример #5
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()
Пример #6
0
    def test_edit_rules_get_exception(self):
        sec_group = self.security_groups.first()
        sec_group_list = self.security_groups.list()

        self.mox.StubOutWithMock(api, 'security_group_get')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        self.mox.StubOutWithMock(api.nova, 'keypair_list')
        self.mox.StubOutWithMock(api.nova, 'server_list')

        api.nova.server_list(IsA(http.HttpRequest),
                             all_tenants=True).AndReturn(self.servers.list())
        api.nova.keypair_list(IsA(http.HttpRequest)) \
                .AndReturn(self.keypairs.list())
        api.tenant_floating_ip_list(IsA(http.HttpRequest)) \
                                    .AndReturn(self.floating_ips.list())
        api.security_group_get(IsA(http.HttpRequest),
                               sec_group.id).AndRaise(self.exceptions.nova)
        api.security_group_list(
                        IsA(http.HttpRequest)).AndReturn(sec_group_list)
        api.security_group_list(
                        IsA(http.HttpRequest)).AndReturn(sec_group_list)
        self.mox.ReplayAll()

        res = self.client.get(self.edit_url)
        self.assertRedirects(res, INDEX_URL)
Пример #7
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)
Пример #8
0
    def test_disassociate_post_with_exception(self):
        floating_ip = self.floating_ips.first()
        server = self.servers.first()
        self.mox.StubOutWithMock(api.nova, 'keypair_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        self.mox.StubOutWithMock(api, 'server_remove_floating_ip')
        self.mox.StubOutWithMock(api.nova, 'server_list')

        api.nova.server_list(IsA(http.HttpRequest),
                             all_tenants=True).AndReturn(self.servers.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.tenant_floating_ip_list(IsA(http.HttpRequest)) \
                                    .AndReturn(self.floating_ips.list())

        api.server_remove_floating_ip(IsA(http.HttpRequest),
                                      server.id,
                                      floating_ip.id) \
                                .AndRaise(self.exceptions.nova)
        self.mox.ReplayAll()

        action = "floating_ips__disassociate__%s" % floating_ip.id
        res = self.client.post(INDEX_URL, {"action": action})
        self.assertRedirectsNoFollow(res, INDEX_URL)
Пример #9
0
    def test_index(self):
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        api.tenant_floating_ip_list(IsA(http.HttpRequest)).\
                                    AndReturn(self.floating_ips)
        self.mox.ReplayAll()

        res = self.client.get(FLOATING_IPS_INDEX)
        self.assertTemplateUsed(res, 'nova/floating_ips/index.html')
        self.assertItemsEqual(res.context['floating_ips'], self.floating_ips)
Пример #10
0
 def get_floating_ips_data(self):
     try:
         floating_ips = api.tenant_floating_ip_list(self.request)
     except novaclient_exceptions.ClientException, e:
         floating_ips = []
         LOG.exception("ClientException in floating ip index")
         messages.error(self.request, _("Error fetching floating ips: %s") % e)
Пример #11
0
    def test_index(self):
        self.mox.StubOutWithMock(api, "tenant_floating_ip_list")
        self.mox.StubOutWithMock(api, "security_group_list")
        self.mox.StubOutWithMock(api.nova, "keypair_list")

        api.nova.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)
        api.tenant_floating_ip_list(IsA(http.HttpRequest)).AndReturn(self.floating_ips)
        api.security_group_list(IsA(http.HttpRequest)).AndReturn(self.security_groups)

        self.mox.ReplayAll()

        res = self.client.get(reverse("horizon:nova:access_and_security:index"))

        self.assertTemplateUsed(res, "nova/access_and_security/index.html")
        self.assertItemsEqual(res.context["keypairs_table"].data, self.keypairs)
        self.assertItemsEqual(res.context["security_groups_table"].data, self.security_groups)
        self.assertItemsEqual(res.context["floating_ips_table"].data, self.floating_ips)
Пример #12
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)
Пример #13
0
    def test_index(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.ReplayAll()

        res = self.client.get(
                             reverse('horizon:nova:access_and_security:index'))

        self.assertTemplateUsed(res, 'nova/access_and_security/index.html')
        self.assertItemsEqual(res.context['keypairs'], self.keypairs)
        self.assertItemsEqual(res.context['security_groups'],
                              self.security_groups)
        self.assertItemsEqual(res.context['floating_ips'], self.floating_ips)
Пример #14
0
def index(request):
    for f in (ReleaseFloatingIp, FloatingIpDisassociate, FloatingIpAllocate):
        _unused, handled = f.maybe_handle(request)
        if handled:
            return handled
    try:
        floating_ips = api.tenant_floating_ip_list(request)
    except novaclient_exceptions.ClientException, e:
        floating_ips = []
        LOG.exception("ClientException in floating ip index")
        messages.error(request,
                       _('Error fetching floating ips: %s') % e.message)
Пример #15
0
    def test_disassociate_post(self):
        self.mox.StubOutWithMock(api.nova, 'keypair_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_get')
        self.mox.StubOutWithMock(api, 'server_remove_floating_ip')

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

        api.server_remove_floating_ip(IsA(http.HttpRequest), IsA(int),
                                                             IsA(int)).\
                                                             AndReturn(None)
        self.mox.ReplayAll()

        action = "floating_ips__disassociate__%s" % self.floating_ip.id
        res = self.client.post(INDEX_URL, {"action": action})
        self.assertRedirectsNoFollow(res, INDEX_URL)
Пример #16
0
    def test_disassociate_post(self):
        floating_ip = self.floating_ips.first()
        server = self.servers.first()
        self.mox.StubOutWithMock(api.nova, "keypair_list")
        self.mox.StubOutWithMock(api, "security_group_list")
        self.mox.StubOutWithMock(api, "tenant_floating_ip_list")
        self.mox.StubOutWithMock(api, "tenant_floating_ip_get")
        self.mox.StubOutWithMock(api, "server_remove_floating_ip")
        self.mox.StubOutWithMock(api.nova, "server_list")

        api.nova.server_list(IsA(http.HttpRequest), all_tenants=True).AndReturn(self.servers.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.tenant_floating_ip_list(IsA(http.HttpRequest)).AndReturn(self.floating_ips.list())
        api.server_remove_floating_ip(IsA(http.HttpRequest), server.id, floating_ip.id)
        self.mox.ReplayAll()

        action = "floating_ips__disassociate__%s" % floating_ip.id
        res = self.client.post(INDEX_URL, {"action": action})
        self.assertMessageCount(success=1)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Пример #17
0
    def test_delete_keypair_exception(self):
        keypair = self.keypairs.first()
        self.mox.StubOutWithMock(api.nova, 'keypair_list')
        self.mox.StubOutWithMock(api.nova, 'keypair_delete')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        self.mox.StubOutWithMock(api.nova, 'server_list')

        api.nova.server_list(IsA(http.HttpRequest),
                             all_tenants=True).AndReturn(self.servers.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        api.tenant_floating_ip_list(IsA(http.HttpRequest)) \
                                   .AndReturn(self.floating_ips.list())
        api.nova.keypair_list(IsA(http.HttpRequest)) \
                .AndReturn(self.keypairs.list())
        api.nova.keypair_delete(IsA(http.HttpRequest), keypair.name) \
                .AndRaise(self.exceptions.nova)
        self.mox.ReplayAll()

        formData = {'action': 'keypairs__delete__%s' % keypair.name}
        res = self.client.post(INDEX_VIEW_URL, formData)
        self.assertRedirectsNoFollow(res, INDEX_VIEW_URL)
Пример #18
0
    def get_floating_ips_data(self):
        try:
            floating_ips = api.tenant_floating_ip_list(self.request)
        except:
            floating_ips = []
            exceptions.handle(self.request,
                              _('Unable to retrieve floating IP addresses.'))

        instances = []
        try:
            instances = api.nova.server_list(self.request, all_tenants=True)
        except:
            exceptions.handle(self.request,
                        _('Unable to retrieve instance list.'))

        instances_dict = dict([(obj.id, obj) for obj in instances])

        for ip in floating_ips:
            ip.instance_name = instances_dict[ip.instance_id].name \
                if ip.instance_id in instances_dict else None

        return floating_ips
Пример #19
0
    tenant_id = request.user.tenant_id
    for f in (CreateGroup, DeleteGroup, DeleteKeypair, ReleaseFloatingIp,
              FloatingIpDisassociate, FloatingIpAllocate):
        _unused, handled = f.maybe_handle(request)
        if handled:
            return handled

    try:
        security_groups = api.security_group_list(request)
    except novaclient_exceptions.ClientException, e:
        security_groups = []
        LOG.exception("ClientException in security_groups index")
        messages.error(request, _('Error fetching security_groups: %s')
                                 % e.message)
    try:
        floating_ips = api.tenant_floating_ip_list(request)
    except novaclient_exceptions.ClientException, e:
        floating_ips = []
        LOG.exception("ClientException in floating ip index")
        messages.error(request,
                    _('Error fetching floating ips: %s') % e.message)
    try:
        keypairs = api.keypair_list(request)
    except novaclient_exceptions.ClientException, e:
        keypairs = []
        LOG.exception("ClientException in keypair index")
        messages.error(request, _('Error fetching keypairs: %s') % e.message)

    context = {'keypairs': keypairs,
               'floating_ips': floating_ips,
               'security_groups': security_groups,