def test_network_delete(self): self.mox.StubOutWithMock(api, "quantum_delete_network") api.quantum_delete_network(IsA(http.HttpRequest), 'n1').AndReturn(True) self.mox.StubOutWithMock(api, 'quantum_list_networks') api.quantum_list_networks(IsA(http.HttpRequest)).\ AndReturn(self.network) self.mox.StubOutWithMock(api, 'quantum_network_details') api.quantum_network_details(IsA(http.HttpRequest), 'n1').AndReturn(self.network_details) self.mox.StubOutWithMock(api, 'quantum_list_ports') api.quantum_list_ports(IsA(http.HttpRequest), 'n1').AndReturn(self.ports) self.mox.StubOutWithMock(api, 'quantum_port_attachment') api.quantum_port_attachment(IsA(http.HttpRequest), 'n1', 'p1').AndReturn(self.port_attachment) self.mox.ReplayAll() formData = {'id': 'n1', 'method': 'DeleteNetwork'} res = self.client.post( reverse('dash_networks', args=[self.request.user.tenant_id]), formData)
def test_network_details(self): self.mox.StubOutWithMock(api, 'quantum_network_details') api.quantum_network_details(IsA(http.HttpRequest), 'n1').AndReturn(self.network_details) self.mox.StubOutWithMock(api, 'quantum_list_ports') api.quantum_list_ports(IsA(http.HttpRequest), 'n1').AndReturn(self.ports) self.mox.StubOutWithMock(api, 'quantum_port_attachment') api.quantum_port_attachment(IsA(http.HttpRequest), 'n1', 'p1').AndReturn(self.port_attachment) self.mox.StubOutWithMock(api, 'quantum_port_details') api.quantum_port_details(IsA(http.HttpRequest), 'n1', 'p1').AndReturn(self.port_details) self.mox.StubOutWithMock(api, 'get_vif_ids') api.get_vif_ids(IsA(http.HttpRequest)).AndReturn(self.vifs) self.mox.ReplayAll() res = self.client.get( reverse('dash_networks_detail', args=['tenant', 'n1'])) self.assertTemplateUsed(res, 'django_openstack/dash/networks/detail.html') self.assertIn('network', res.context) network = res.context['network'] self.assertEqual(network['name'], 'test_network') self.assertEqual(network['id'], 'n1') self.mox.VerifyAll()
def test_network_index(self): self.mox.StubOutWithMock(api, 'quantum_list_networks') api.quantum_list_networks(IsA(http.HttpRequest)).\ AndReturn(self.network) self.mox.StubOutWithMock(api, 'quantum_network_details') api.quantum_network_details(IsA(http.HttpRequest), 'n1').AndReturn(self.network_details) self.mox.StubOutWithMock(api, 'quantum_list_ports') api.quantum_list_ports(IsA(http.HttpRequest), 'n1').AndReturn(self.ports) self.mox.StubOutWithMock(api, 'quantum_port_attachment') api.quantum_port_attachment(IsA(http.HttpRequest), 'n1', 'p1').AndReturn(self.port_attachment) self.mox.ReplayAll() res = self.client.get(reverse('dash_networks', args=['tenant'])) self.assertTemplateUsed(res, 'django_openstack/dash/networks/index.html') self.assertIn('networks', res.context) networks = res.context['networks'] self.assertEqual(len(networks), 1) self.assertEqual(networks[0]['name'], 'test_network') self.assertEqual(networks[0]['id'], 'n1') self.assertEqual(networks[0]['total'], 1) self.assertEqual(networks[0]['used'], 1) self.assertEqual(networks[0]['available'], 0) self.mox.VerifyAll()
def test_network_details(self): self.mox.StubOutWithMock(api, 'quantum_network_details') api.quantum_network_details(IsA(http.HttpRequest), 'n1').AndReturn(self.network_details) self.mox.StubOutWithMock(api, 'quantum_list_ports') api.quantum_list_ports(IsA(http.HttpRequest), 'n1').AndReturn(self.ports) self.mox.StubOutWithMock(api, 'quantum_port_attachment') api.quantum_port_attachment(IsA(http.HttpRequest), 'n1', 'p1').AndReturn(self.port_attachment) self.mox.StubOutWithMock(api, 'quantum_port_details') api.quantum_port_details(IsA(http.HttpRequest), 'n1', 'p1').AndReturn(self.port_details) self.mox.StubOutWithMock(api, 'get_vif_ids') api.get_vif_ids(IsA(http.HttpRequest)).AndReturn(self.vifs) self.mox.ReplayAll() res = self.client.get(reverse('dash_networks_detail', args=['tenant', 'n1'])) self.assertTemplateUsed(res, 'django_openstack/dash/networks/detail.html') self.assertIn('network', res.context) network = res.context['network'] self.assertEqual(network['name'], 'test_network') self.assertEqual(network['id'], 'n1') self.mox.VerifyAll()
def test_network_rename(self): self.mox.StubOutWithMock(api, "quantum_update_network") api.quantum_update_network(IsA(http.HttpRequest), 'n1', dict).AndReturn(True) self.mox.StubOutWithMock(api, 'quantum_list_networks') api.quantum_list_networks(IsA(http.HttpRequest)).\ AndReturn(self.network) self.mox.StubOutWithMock(api, 'quantum_network_details') api.quantum_network_details(IsA(http.HttpRequest), 'n1').AndReturn(self.network_details) self.mox.StubOutWithMock(api, 'quantum_list_ports') api.quantum_list_ports(IsA(http.HttpRequest), 'n1').AndReturn(self.ports) self.mox.StubOutWithMock(api, 'quantum_port_attachment') api.quantum_port_attachment(IsA(http.HttpRequest), 'n1', 'p1').AndReturn(self.port_attachment) self.mox.ReplayAll() formData = {'new_name': 'Test1', 'method': 'RenameNetwork'} res = self.client.post(reverse('dash_network_rename', args=[self.request.user.tenant, "n1"]), formData)
def index(request, tenant_id): delete_form, delete_handled = DeleteNetwork.maybe_handle(request) networks = [] instances = [] try: networks_list = api.quantum_list_networks(request) details = [] for network in networks_list['networks']: net_stats = _calc_network_stats(request, tenant_id, network['id']) # Get network details like name and id details = api.quantum_network_details(request, network['id']) networks.append({ 'name': details['network']['name'], 'id': network['id'], 'total': net_stats['total'], 'available': net_stats['available'], 'used': net_stats['used'], 'tenant': tenant_id }) except Exception, e: messages.error(request, _('Unable to get network list: %s') % e.message)
def rename(request, tenant_id, network_id): rename_form, handled = RenameNetwork.maybe_handle(request) network_details = api.quantum_network_details(request, network_id) if handled: return shortcuts.redirect('dash_networks', request.user.tenant_id) return shortcuts.render_to_response( 'django_openstack/dash/networks/rename.html', { 'network': network_details, 'rename_form': rename_form }, context_instance=template.RequestContext(request))
def detail(request, tenant_id, network_id): delete_port_form, delete_handled = DeletePort.maybe_handle(request) detach_port_form, detach_handled = DetachPort.maybe_handle(request) toggle_port_form, port_toggle_handled = TogglePort.maybe_handle(request) network = {} try: network_details = api.quantum_network_details(request, network_id) network['name'] = network_details['network']['name'] network['id'] = network_id network['ports'] = _get_port_states(request, tenant_id, network_id) except Exception, e: messages.error(request, 'Unable to get network details:%s' % e.message)