Ejemplo n.º 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(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('steer:engine: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)
Ejemplo n.º 2
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(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("steer:engine: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)
Ejemplo n.º 3
0
    def test_disassociate_post(self):
        self.mox.StubOutWithMock(api.engine, "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.engine.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)
Ejemplo n.º 4
0
 def get_floating_ips_data(self):
     try:
         floating_ips = api.tenant_floating_ip_list(self.request)
     except engineclient_exceptions.ClientException, e:
         floating_ips = []
         LOG.exception("ClientException in floating ip index")
         messages.error(self.request,
                     _('Error fetching floating ips: %s') % e)
Ejemplo n.º 5
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.engine, 'keypair_list')
        api.engine.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 = engineclient_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('steer:engine: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(engineclient_exceptions.ClientException)

        self.assertRedirects(res, INDEX_URL)
Ejemplo n.º 6
0
    def test_disassociate_post(self):
        self.mox.StubOutWithMock(api.engine, '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.engine.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)
Ejemplo n.º 7
0
    def test_index(self):
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api.engine, 'keypair_list')

        api.engine.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('steer:engine:access_and_security:index'))

        self.assertTemplateUsed(res, 'engine/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)
Ejemplo n.º 8
0
    def test_index(self):
        self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api.engine, 'keypair_list')

        api.engine.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('steer:engine:access_and_security:index'))

        self.assertTemplateUsed(res, 'engine/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)
Ejemplo n.º 9
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.engine, "keypair_list")
        api.engine.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 = engineclient_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("steer:engine: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(engineclient_exceptions.ClientException)

        self.assertRedirects(res, INDEX_URL)