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 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_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_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_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_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_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 _get_port_states(request, network_id): """ Helper method to find port states for a network """ network_ports = [] # Get all vifs for comparison with port attachments vifs = api.get_vif_ids(request) # Get all ports on this network ports = api.quantum_list_ports(request, network_id) for port in ports['ports']: port_details = api.quantum_port_details(request, network_id, port['id']) # Get port attachments port_attachment = api.quantum_port_attachment(request, network_id, port['id']) # Find instance the attachment belongs to connected_instance = None if port_attachment['attachment']: for vif in vifs: if str(vif['id']) == str(port_attachment['attachment']['id']): connected_instance = vif['instance_name'] break network_ports.append({ 'id': port_details['port']['id'], 'state': port_details['port']['state'], 'attachment': port_attachment['attachment'], 'instance': connected_instance}) return network_ports
def _get_port_states(request, network_id): """ Helper method to find port states for a network """ network_ports = [] # Get all vifs for comparison with port attachments vifs = api.get_vif_ids(request) # Get all ports on this network ports = api.quantum_list_ports(request, network_id) for port in ports['ports']: port_details = api.quantum_port_details(request, network_id, port['id']) # Get port attachments port_attachment = api.quantum_port_attachment(request, network_id, port['id']) # Find instance the attachment belongs to connected_instance = None if port_attachment['attachment']: for vif in vifs: if str(vif['id']) == str(port_attachment['attachment']['id']): connected_instance = vif['id'] break network_ports.append({ 'id': port_details['port']['id'], 'state': port_details['port']['state'], 'attachment': port_attachment['attachment'], 'instance': connected_instance }) return network_ports
def _get_port_states(request, network_id): """ Helper method to find port states for a network """ network_ports = [] # Get all vifs for comparison with port attachments vifs = api.get_vif_ids(request) # Get all ports on this network ports = api.quantum_list_ports(request, network_id) for port in ports["ports"]: port_details = api.quantum_port_details(request, network_id, port["id"]) # Get port attachments port_attachment = api.quantum_port_attachment(request, network_id, port["id"]) # Find instance the attachment belongs to connected_instance = None if port_attachment["attachment"]: for vif in vifs: if str(vif["id"]) == str(port_attachment["attachment"]["id"]): connected_instance = vif["id"] break network_ports.append( { "id": port_details["port"]["id"], "state": port_details["port"]["state"], "attachment": port_attachment["attachment"], "instance": connected_instance, } ) return network_ports
def _calc_network_stats(request, network_id): """ Helper method to calculate statistics for a network """ # Get all ports statistics for the network total = 0 available = 0 used = 0 ports = api.quantum_list_ports(request, network_id) for port in ports["ports"]: total += 1 # Get port attachment port_attachment = api.quantum_port_attachment(request, network_id, port["id"]) if port_attachment["attachment"]: used += 1 else: available += 1 return {"total": total, "used": used, "available": available}
def _calc_network_stats(request, network_id): """ Helper method to calculate statistics for a network """ # Get all ports statistics for the network total = 0 available = 0 used = 0 ports = api.quantum_list_ports(request, network_id) for port in ports['ports']: total += 1 # Get port attachment port_attachment = api.quantum_port_attachment(request, network_id, port['id']) if port_attachment['attachment']: used += 1 else: available += 1 return {'total': total, 'used': used, 'available': available}