Ejemplo n.º 1
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('steer:engine:networks:index'),
                               formData)
Ejemplo n.º 2
0
    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('steer:engine:networks:detail',
                                      args=['n1']))

        self.assertTemplateUsed(res, 'engine/networks/detail.html')
        self.assertIn('network', res.context)

        network = res.context['network']

        self.assertEqual(network['name'], 'test_network')
        self.assertEqual(network['id'], 'n1')
Ejemplo n.º 3
0
    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('steer:engine:networks:index'))

        self.assertTemplateUsed(res, 'engine/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)
Ejemplo n.º 4
0
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.")
        if not hasattr(e, 'message'):
            e.message = str(e)
        messages.error(request,
                       _('Unable to get network list: %s') % e.message)
Ejemplo n.º 5
0
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.")
        if not hasattr(e, "message"):
            e.message = str(e)
        messages.error(request, _("Unable to get network list: %s") % e.message)
Ejemplo n.º 6
0
    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('steer:engine:networks:rename',
                                       args=["n1"]),
                               formData)

        self.assertRedirectsNoFollow(res,
                                     reverse('steer:engine:networks:index'))
Ejemplo n.º 7
0
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("steer:engine:networks:index")

    return shortcuts.render(request, "engine/networks/rename.html", {"network": network, "rename_form": rename_form})
Ejemplo n.º 8
0
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('steer:engine:networks:index')

    return shortcuts.render(request,
                            'engine/networks/rename.html', {
                                'network': network,
                                'rename_form': rename_form})
Ejemplo n.º 9
0
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.")
        if not hasattr(e, "message"):
            e.message = str(e)
        messages.error(request, _("Unable to get network details: %s") % e.message)
        return shortcuts.redirect("steer:engine:networks:index")
Ejemplo n.º 10
0
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.")
        if not hasattr(e, 'message'):
            e.message = str(e)
        messages.error(request,
                       _('Unable to get network details: %s') % e.message)
        return shortcuts.redirect("steer:engine:networks:index")