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('dash_floating_ips_disassociate', args=[self.TEST_TENANT, 1]), {'floating_ip_id': self.floating_ip.id, 'method': 'FloatingIpDisassociate'}) self.assertRaises(novaclient_exceptions.ClientException) self.assertRedirects(res, reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.mox.VerifyAll()
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('dash_floating_ips_disassociate', args=[self.TEST_TENANT, 1]), {'floating_ip_id': self.floating_ip.id, 'method': 'FloatingIpDisassociate'}) self.assertRedirects(res, reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.mox.VerifyAll()
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(str)) 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('dash_floating_ips_disassociate', args=[self.TEST_TENANT, 1]), { 'floating_ip_id': self.floating_ip.id, 'method': 'FloatingIpDisassociate' }) self.assertRaises(novaclient_exceptions.ClientException) self.assertRedirects( res, reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.mox.VerifyAll()
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('dash_floating_ips_disassociate', args=[self.TEST_TENANT, 1]), { 'floating_ip_id': self.floating_ip.id, 'method': 'FloatingIpDisassociate' }) self.assertRedirects( res, reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.mox.VerifyAll()
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)
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.error("ClientException in FloatingIpAssociate", exc_info=True) messages.error(request, 'Error disassociating Floating IP: %s' % e.message)
def test_server_remove_floating_ip(self): novaclient = self.stub_novaclient() novaclient.servers = self.mox.CreateMockAnything() novaclient.floating_ips = self.mox.CreateMockAnything() novaclient.servers.get(IsA(int)).AndReturn(self.server) novaclient.floating_ips.get(IsA(int)).AndReturn(self.floating_ip) novaclient.servers.remove_floating_ip(IsA(self.server.__class__), IsA(self.floating_ip.__class__)).AndReturn( self.server ) self.mox.ReplayAll() server = api.server_remove_floating_ip(self.request, 1, 1) self.assertIsInstance(server, api.Server) self.mox.VerifyAll()