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('horizon:nova:networks:index')) self.assertTemplateUsed(res, 'nova/networks/index.html') networks = res.context['table'].data 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)
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('horizon:nova:networks:rename', args=["n1"]), formData)
def test_port_detach(self): self.mox.StubOutWithMock(api, 'quantum_network_details') self.mox.StubOutWithMock(api, 'quantum_list_ports') self.mox.StubOutWithMock(api, 'quantum_port_attachment') self.mox.StubOutWithMock(api, 'quantum_port_details') self.mox.StubOutWithMock(api, 'get_vif_ids') self.mox.StubOutWithMock(api, "quantum_set_port_state") network_details = {'network': {'id': 'n1', 'name': 'network1'}} api.quantum_network_details(IsA(http.HttpRequest), 'n1').AndReturn(network_details) api.quantum_list_ports(IsA(http.HttpRequest), 'n1').AndReturn(self.ports) api.quantum_port_attachment(IsA(http.HttpRequest), 'n1', 'p1').AndReturn(self.port_attachment) api.quantum_port_details(IsA(http.HttpRequest), 'n1', 'p1').AndReturn(self.port_details) api.get_vif_ids(IsA(http.HttpRequest)).AndReturn(self.vifs) api.quantum_set_port_state(IsA(http.HttpRequest), 'n1', 'p1', {'port': {'state': 'DOWN'}}).AndReturn(True) formData = {'action': "network_details__detach_port__p1"} self.mox.ReplayAll() detail_url = reverse('horizon:nova:networks:detail', args=["n1"]) res = self.client.post(detail_url, formData) self.assertRedirectsNoFollow(res, detail_url)
def test_port_delete(self): self.mox.StubOutWithMock(api, 'quantum_network_details') self.mox.StubOutWithMock(api, 'quantum_list_ports') self.mox.StubOutWithMock(api, 'quantum_port_attachment') self.mox.StubOutWithMock(api, 'quantum_port_details') self.mox.StubOutWithMock(api, 'get_vif_ids') self.mox.StubOutWithMock(api, "quantum_delete_port") network_details = {'network': {'id': 'n1', 'name': 'network1'}} api.quantum_network_details(IsA(http.HttpRequest), 'n1').AndReturn(network_details) api.quantum_list_ports(IsA(http.HttpRequest), 'n1').AndReturn(self.ports) api.quantum_port_attachment(IsA(http.HttpRequest), 'n1', 'p1').AndReturn(self.port_attachment) api.quantum_port_details(IsA(http.HttpRequest), 'n1', 'p1').AndReturn(self.port_details) api.get_vif_ids(IsA(http.HttpRequest)).AndReturn(self.vifs) api.quantum_delete_port(IsA(http.HttpRequest), 'n1', 'p1').AndReturn(True) formData = {'action': 'network_details__delete__p1'} self.mox.StubOutWithMock(messages, 'success') messages.success(IgnoreArg(), IsA(basestring)) self.mox.ReplayAll() detail_url = reverse('horizon:nova:networks:detail', args=["n1"]) self.client.post(detail_url, formData)
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 = {'network': 'n1', 'method': 'DeleteNetwork'} res = self.client.post(reverse('horizon:nova:networks:index'), formData)
def test_port_attach(self): self.mox.StubOutWithMock(api, "quantum_network_details") self.mox.StubOutWithMock(api, "quantum_attach_port") self.mox.StubOutWithMock(api, "get_vif_ids") network_details = {'network': {'id': 'n1'}} api.quantum_network_details(IsA(http.HttpRequest), 'n1').AndReturn(network_details) api.quantum_attach_port(IsA(http.HttpRequest), 'n1', 'p1', IsA(dict)).AndReturn(True) api.get_vif_ids(IsA(http.HttpRequest)).AndReturn([{ 'id': 'v1', 'instance_name': 'instance1', 'available': True}]) formData = {'port': 'p1', 'network': 'n1', 'vif_id': 'v1', 'method': 'AttachPort'} self.mox.ReplayAll() res = self.client.post(reverse('horizon:nova:networks:port_attach', args=["n1", "p1"]), formData) self.assertRedirectsNoFollow(res, reverse('horizon:nova:networks:detail', args=["n1"]))
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('horizon:nova:networks:detail', args=['n1'])) self.assertTemplateUsed(res, 'nova/networks/detail.html') self.assertIn('network', res.context) network = res.context['network'] self.assertEqual(network['name'], 'test_network') self.assertEqual(network['id'], 'n1')
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('horizon:nova:networks:index')) self.assertTemplateUsed(res, 'nova/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)
def test_port_attach(self): self.mox.StubOutWithMock(api, "quantum_network_details") self.mox.StubOutWithMock(api, "quantum_attach_port") self.mox.StubOutWithMock(api, "get_vif_ids") network_details = {'network': {'id': 'n1'}} api.quantum_network_details(IsA(http.HttpRequest), 'n1').AndReturn(network_details) api.quantum_attach_port(IsA(http.HttpRequest), 'n1', 'p1', IsA(dict)).AndReturn(True) api.get_vif_ids(IsA(http.HttpRequest)).AndReturn([{ 'id': 'v1', 'instance_name': 'instance1', 'available': True }]) formData = { 'port': 'p1', 'network': 'n1', 'vif_id': 'v1', 'method': 'AttachPort' } self.mox.ReplayAll() res = self.client.post( reverse('horizon:nova:networks:port_attach', args=["n1", "p1"]), formData) self.assertRedirectsNoFollow( res, reverse('horizon:nova:networks:detail', args=["n1"]))
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 = {'action': 'networks__delete__n1'} self.client.post(reverse('horizon:nova:networks:index'), formData)
def index(request): tenant_id = request.user.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, 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: LOG.exception("Unable to get network list.") messages.error(request, _('Unable to get network list: %s') % e.message)
def get_data(self): network_id = self.kwargs['network_id'] network_details = api.quantum_network_details(self.request, network_id) self.network = {'id': network_id, 'name': network_details['network']['name'], 'ports': _get_port_states(self.request, network_id)} return self.network['ports']
def get_object(self, *args, **kwargs): network_id = kwargs["network_id"] try: return api.quantum_network_details(self.request, network_id)["network"] except: redirect = reverse("horizon:nova:networks:detail", args=(network_id,)) exceptions.handle(self.request, _("Unable to retrieve network information."), redirect=redirect)
def get_data(self): tenant_id = self.request.user.tenant_id networks = [] try: networks_list = api.quantum_list_networks(self.request) details = [] for network in networks_list["networks"]: net_stats = _calc_network_stats(self.request, network["id"]) # Get network details like name and id details = api.quantum_network_details(self.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: LOG.exception("Unable to get network list.") if not hasattr(e, "message"): e.message = str(e) messages.error(self.request, _("Unable to get network list: %s") % e.message)
def get_data(self): tenant_id = self.request.user.tenant_id networks = [] try: networks_list = api.quantum_list_networks(self.request) details = [] for network in networks_list['networks']: net_stats = _calc_network_stats(self.request, network['id']) # Get network details like name and id details = api.quantum_network_details(self.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: LOG.exception("Unable to get network list.") if not hasattr(e, 'message'): e.message = str(e) messages.error(self.request, _('Unable to get network list: %s') % e.message)
def get_data(self): tenant_id = self.request.user.tenant_id networks = [] try: networks_list = api.quantum_list_networks(self.request) details = [] for network in networks_list['networks']: net_stats = _calc_network_stats(self.request, network['id']) # Get network details like name and id details = api.quantum_network_details(self.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: LOG.exception("Unable to get network list.") if not hasattr(e, 'message'): e.message = str(e) messages.error(self.request, _('Unable to get network list: %s') % e.message)
def index(request): tenant_id = request.user.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, 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: LOG.exception("Unable to get network list.") messages.error(request, _('Unable to get network list: %s') % e.message)
def get_data(self): network_id = self.kwargs["network_id"] network_details = api.quantum_network_details(self.request, network_id) self.network = { "id": network_id, "name": network_details["network"]["name"], "ports": _get_port_states(self.request, network_id), } return self.network["ports"]
def get_data(self): network_id = self.kwargs['network_id'] network_details = api.quantum_network_details(self.request, network_id) self.network = { 'id': network_id, 'name': network_details['network']['name'], 'ports': _get_port_states(self.request, network_id) } return self.network['ports']
def rename(request, network_id): rename_form, handled = RenameNetwork.maybe_handle(request) network_details = api.quantum_network_details(request, network_id) if handled: return shortcuts.redirect('horizon:nova:networks:index') return shortcuts.render(request, 'nova/networks/rename.html', { 'network': network_details, 'rename_form': rename_form})
def get_object(self, *args, **kwargs): network_id = kwargs['network_id'] try: return api.quantum_network_details(self.request, network_id)['network'] except: redirect = reverse("horizon:nova:networks:detail", args=(network_id, )) exceptions.handle(self.request, _('Unable to retrieve network information.'), redirect=redirect)
def get_object(self, *args, **kwargs): network_id = kwargs['network_id'] try: return api.quantum_network_details(self.request, network_id)['network'] except: redirect = reverse("horizon:nova:networks:detail", args=(network_id,)) exceptions.handle(self.request, _('Unable to attach port.'), redirect=redirect)
def test_port_create(self): self.mox.StubOutWithMock(api, "quantum_network_details") self.mox.StubOutWithMock(api, "quantum_create_port") network_details = {'network': {'id': 'n1'}} api.quantum_network_details(IsA(http.HttpRequest), 'n1').AndReturn(network_details) api.quantum_create_port(IsA(http.HttpRequest), 'n1').AndReturn(True) formData = {'ports_num': 1, 'network': 'n1', 'method': 'CreatePort'} self.mox.StubOutWithMock(messages, 'success') messages.success(IgnoreArg(), IsA(basestring)) self.mox.ReplayAll() res = self.client.post( reverse('horizon:nova:networks:port_create', args=["n1"]), formData) self.assertRedirectsNoFollow( res, reverse('horizon:nova:networks:detail', args=["n1"]))
def test_network_rename(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_update_network') api.quantum_update_network(IsA(http.HttpRequest), 'n1', {'network': {'name': "Test1"}}) self.mox.ReplayAll() formData = {'network': 'n1', 'new_name': 'Test1', 'method': 'RenameNetwork'} res = self.client.post(reverse('horizon:nova:networks:rename', args=["n1"]), formData) self.assertRedirectsNoFollow(res, reverse('horizon:nova:networks:index'))
def test_port_create(self): self.mox.StubOutWithMock(api, "quantum_network_details") self.mox.StubOutWithMock(api, "quantum_create_port") network_details = {'network': {'id': 'n1'}} api.quantum_network_details(IsA(http.HttpRequest), 'n1').AndReturn(network_details) api.quantum_create_port(IsA(http.HttpRequest), 'n1').AndReturn(True) formData = {'ports_num': 1, 'network': 'n1', 'method': 'CreatePort'} self.mox.ReplayAll() res = self.client.post(reverse('horizon:nova:networks:port_create', args=["n1"]), formData) self.assertRedirectsNoFollow(res, reverse('horizon:nova:networks:detail', args=["n1"]))
def rename(request, network_id): network_details = api.quantum_network_details(request, network_id) network = network_details['network'] rename_form, handled = RenameNetwork.maybe_handle(request, initial={ 'network': network['id'], 'new_name': network['name']}) if handled: return shortcuts.redirect('horizon:nova:networks:index') return shortcuts.render(request, 'nova/networks/rename.html', { 'network': network, 'rename_form': rename_form})
def detail(request, network_id): tenant_id = request.user.tenant_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, network_id) except Exception, e: LOG.exception("Unable to get network details.") messages.error(request, _('Unable to get network details: %s') % e.message)
def rename(request, network_id): network_details = api.quantum_network_details(request, network_id) network = network_details['network'] rename_form, handled = RenameNetwork.maybe_handle(request, initial={ 'network': network['id'], 'new_name': network['name'] }) if handled: return shortcuts.redirect('horizon:nova:networks:index') return shortcuts.render(request, 'nova/networks/rename.html', { 'network': network, 'rename_form': rename_form })
def detail(request, network_id): tenant_id = request.user.tenant_id delete_port_form, delete_handled = DeletePort.maybe_handle( request, initial={"network": network_id}) detach_port_form, detach_handled = DetachPort.maybe_handle( request, initial={"network": network_id}) toggle_port_form, port_toggle_handled = TogglePort.maybe_handle( request, initial={"network": network_id}) network = {} network['id'] = network_id try: network_details = api.quantum_network_details(request, network_id) network['name'] = network_details['network']['name'] network['ports'] = _get_port_states(request, network_id) except Exception, e: LOG.exception("Unable to get network details.") messages.error(request, _('Unable to get network details: %s') % e.message) return shortcuts.redirect("horizon:nova:networks:index")
def detail(request, network_id): tenant_id = request.user.tenant_id delete_port_form, delete_handled = DeletePort.maybe_handle(request, initial={"network": network_id}) detach_port_form, detach_handled = DetachPort.maybe_handle(request, initial={"network": network_id}) toggle_port_form, port_toggle_handled = TogglePort.maybe_handle(request, initial={"network": network_id}) network = {} network['id'] = network_id try: network_details = api.quantum_network_details(request, network_id) network['name'] = network_details['network']['name'] network['ports'] = _get_port_states(request, network_id) except Exception, e: LOG.exception("Unable to get network details.") messages.error(request, _('Unable to get network details: %s') % e.message) return shortcuts.redirect("horizon:nova:networks:index")