Attribute mac address

This commit is contained in:
Julien Duponchelle committed 2015-01-22 16:12:21 +01:00
1 parent 08b2dc6369
commit 6644c640db
5 files changed
+101 -9

No files matched your search

+8
View File
@@ -53,6 +53,8 @@ def _get_unused_port():
@pytest.fixture(scope="session")
def server(request, loop, port_manager):
"""A GNS 3 server"""
port = _get_unused_port()
host = "localhost"
app = web.Application()
@@ -75,16 +77,22 @@ def server(request, loop, port_manager):
@pytest.fixture(scope="module")
def project():
"""A GNS3 lab"""
return ProjectManager.instance().create_project(uuid="a1e920ca-338a-4e9f-b363-aa607b09dd80")
@pytest.fixture(scope="session")
def port_manager():
"""An instance of port manager"""
return PortManager("127.0.0.1", False)
@pytest.fixture(scope="function")
def free_console_port(request, port_manager):
"""Get a free TCP port"""
# In case of already use ports we will raise an exception
port = port_manager.get_free_console_port()
# We release the port immediately in order to allow
+56
View File
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import asyncio
import uuid
from gns3server.modules.vpcs import VPCS
from gns3server.modules.vpcs.vpcs_error import VPCSError
from gns3server.modules.project_manager import ProjectManager
def test_get_mac_id(loop, project, port_manager):
# Cleanup the VPCS object
VPCS._instance = None
vpcs = VPCS.instance()
vpcs.port_manager = port_manager
vm1_uuid = str(uuid.uuid4())
vm2_uuid = str(uuid.uuid4())
vm3_uuid = str(uuid.uuid4())
loop.run_until_complete(vpcs.create_vm("PC 1", project.uuid, vm1_uuid))
loop.run_until_complete(vpcs.create_vm("PC 2", project.uuid, vm2_uuid))
assert vpcs.get_mac_id(vm1_uuid) == 0
assert vpcs.get_mac_id(vm1_uuid) == 0
assert vpcs.get_mac_id(vm2_uuid) == 1
loop.run_until_complete(vpcs.delete_vm(vm1_uuid))
loop.run_until_complete(vpcs.create_vm("PC 3", project.uuid, vm3_uuid))
assert vpcs.get_mac_id(vm3_uuid) == 0
def test_get_mac_id_no_id_available(loop, project, port_manager):
# Cleanup the VPCS object
VPCS._instance = None
vpcs = VPCS.instance()
vpcs.port_manager = port_manager
with pytest.raises(VPCSError):
for i in range(0, 256):
vm_uuid = str(uuid.uuid4())
loop.run_until_complete(vpcs.create_vm("PC {}".format(i), project.uuid, vm_uuid))
assert vpcs.get_mac_id(vm_uuid) == i