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_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('dash_floating_ips_associate', args=[self.TEST_TENANT, 1]), {'instance_id': 1, 'floating_ip_id': self.floating_ip.id, 'floating_ip': self.floating_ip.ip, 'method': 'FloatingIpAssociate'}) 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(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_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('dash_floating_ips_associate', args=[self.TEST_TENANT, 1])) self.assertTemplateUsed(res, 'django_openstack/dash/floating_ips/associate.html') self.mox.VerifyAll()
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('dash_floating_ips_associate', args=[self.TEST_TENANT, 1])) self.assertTemplateUsed( res, 'django_openstack/dash/floating_ips/associate.html') self.mox.VerifyAll()
def test_tenant_floating_ip_get(self): novaclient = self.stub_novaclient() novaclient.floating_ips = self.mox.CreateMockAnything() novaclient.floating_ips.get(IsA(int)).AndReturn(self.floating_ip) self.mox.ReplayAll() floating_ip = api.tenant_floating_ip_get(self.request, 1) self.assertIsInstance(floating_ip, api.FloatingIp) 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 associate(request, tenant_id, 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_to_response( 'django_openstack/dash/floating_ips/associate.html', { 'associate_form': form, }, context_instance=template.RequestContext(request))
def associate(request, tenant_id, 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_to_response( "django_openstack/dash/floating_ips/associate.html", {"associate_form": form}, context_instance=template.RequestContext(request), )