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 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: %s \ with Instance: %s' % (data['floating_ip'], data['instance_id'])) except novaclient_exceptions.ClientException, e: LOG.error("ClientException in FloatingIpAssociate", exc_info=True) messages.error(request, 'Error associating Floating IP: %s' % e.message)
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.message)
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: %s \ with Instance: %s' % (data['floating_ip'], data['instance_id'])) except novaclient_exceptions.ClientException, e: LOG.error("ClientException in FloatingIpAssociate", exc_info=True) messages.error(request, 'Error associating Floating IP: %s' % e.message)
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, '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(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_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.assertRaises(novaclient_exceptions.ClientException) self.assertRedirects( res, reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.mox.VerifyAll()
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, '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('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.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_server_add_floating_ip(self): novaclient = self.stub_novaclient() novaclient.floating_ips = self.mox.CreateMockAnything() novaclient.servers = self.mox.CreateMockAnything() novaclient.servers.get(IsA(int)).AndReturn(self.server) novaclient.floating_ips.get(IsA(int)).AndReturn(self.floating_ip) novaclient.servers.add_floating_ip(IsA(self.server.__class__), IsA(self.floating_ip.__class__)).AndReturn( self.server ) self.mox.ReplayAll() server = api.server_add_floating_ip(self.request, 1, 1) self.assertIsInstance(server, api.Server) self.mox.VerifyAll()