Skip to content

Commit

Permalink
Merge pull request #2379 from GNS3/fix-warnings-in-tests
Browse files Browse the repository at this point in the history
Fix warnings in tests
  • Loading branch information
grossmj authored May 9, 2024
2 parents 3fd44f5 + 7030dad commit cdcfc65
Show file tree
Hide file tree
Showing 32 changed files with 56 additions and 56 deletions.
6 changes: 2 additions & 4 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
-rrequirements.txt

pytest==7.2.0; python_version >= '3.7'
pytest==7.0.1; python_version < '3.7' # v7.0.1 is the last version to support Python 3.6
pytest==7.2.0
flake8==5.0.4
pytest-timeout==2.1.0
pytest-aiohttp==1.0.4; python_version >= '3.7'
pytest-aiohttp==0.3.0; python_version < '3.7' # last version to support Python 3.6
pytest-aiohttp==1.0.4
2 changes: 1 addition & 1 deletion gns3server/controller/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def get_url(self, path):
return self._getUrl(path)

async def _run_http_query(self, method, path, data=None, timeout=20, raw=False):
with async_timeout.timeout(timeout):
async with async_timeout.timeout(delay=timeout):
url = self._getUrl(path)
headers = {}
headers['content-type'] = 'application/json'
Expand Down
6 changes: 3 additions & 3 deletions gns3server/controller/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ def __init__(self, project, name=None, filename=None):
self._project = project
if name:
self._name = name
self._created_at = datetime.now().timestamp()
filename = self._name + "_" + datetime.utcfromtimestamp(self._created_at).replace(tzinfo=None).strftime(FILENAME_TIME_FORMAT) + ".gns3project"
self._created_at = datetime.now(timezone.utc).timestamp()
filename = self._name + "_" + datetime.fromtimestamp(self._created_at, tz=timezone.utc).replace(tzinfo=None).strftime(FILENAME_TIME_FORMAT) + ".gns3project"
else:
self._name = filename.split("_")[0]
datestring = filename.replace(self._name + "_", "").split(".")[0]
try:
self._created_at = datetime.strptime(datestring, FILENAME_TIME_FORMAT).replace(tzinfo=timezone.utc).timestamp()
except ValueError:
self._created_at = datetime.utcnow().timestamp()
self._created_at = datetime.now(timezone.utc)
self._path = os.path.join(project.path, "snapshots", filename)

@property
Expand Down
1 change: 0 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[pytest]
asyncio_mode=auto
log_level=NOTSET
ignore=env
8 changes: 4 additions & 4 deletions tests/compute/builtin/nodes/test_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def nio():


@pytest.fixture
async def manager(loop):
async def manager():

m = MagicMock()
m.module_name = "builtins"
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_json_without_ports(on_gns3vm, compute_project, manager):
}


async def test_update_port_mappings(loop, on_gns3vm, compute_project):
async def test_update_port_mappings(on_gns3vm, compute_project):
"""
We don't allow an empty interface in the middle of port list
"""
Expand Down Expand Up @@ -153,7 +153,7 @@ async def test_update_port_mappings(loop, on_gns3vm, compute_project):
assert cloud.ports_mapping == ports1


async def test_linux_ethernet_raw_add_nio(loop, linux_platform, compute_project, nio):
async def test_linux_ethernet_raw_add_nio(linux_platform, compute_project, nio):
ports = [
{
"interface": "eth0",
Expand All @@ -180,7 +180,7 @@ async def test_linux_ethernet_raw_add_nio(loop, linux_platform, compute_project,
])


async def test_linux_ethernet_raw_add_nio_bridge(loop, linux_platform, compute_project, nio):
async def test_linux_ethernet_raw_add_nio_bridge(linux_platform, compute_project, nio):
"""
Bridge can't be connected directly to a cloud we use a tap in the middle
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/compute/docker/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


@pytest.fixture
async def vm(loop):
async def vm():

vm = Docker()
vm._connected = True
Expand Down
7 changes: 5 additions & 2 deletions tests/compute/docker/test_docker_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@
from unittest.mock import patch, MagicMock, call


pytestmark = pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")


@pytest.fixture()
async def manager(loop, port_manager):
async def manager(port_manager):

m = Docker.instance()
m.port_manager = port_manager
return m


@pytest.fixture(scope="function")
async def vm(loop, compute_project, manager):
async def vm(compute_project, manager):

vm = DockerVM("test", str(uuid.uuid4()), compute_project, manager, "ubuntu:latest")
vm._cid = "e90e34656842"
Expand Down
2 changes: 1 addition & 1 deletion tests/compute/dynamips/test_dynamips_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


@pytest.fixture
async def manager(loop, port_manager):
async def manager(port_manager):

m = Dynamips.instance()
m.port_manager = port_manager
Expand Down
2 changes: 1 addition & 1 deletion tests/compute/dynamips/test_dynamips_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


@pytest.fixture
async def manager(loop, port_manager):
async def manager(port_manager):

m = Dynamips.instance()
m.port_manager = port_manager
Expand Down
4 changes: 2 additions & 2 deletions tests/compute/iou/test_iou_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@


@pytest.fixture
async def manager(loop, port_manager):
async def manager(port_manager):

m = IOU.instance()
m.port_manager = port_manager
return m


@pytest.fixture(scope="function")
async def vm(loop, compute_project, manager, tmpdir, fake_iou_bin, iourc_file):
async def vm(compute_project, manager, tmpdir, fake_iou_bin, iourc_file):

vm = IOUVM("test", str(uuid.uuid4()), compute_project, manager, application_id=1)
config = manager.config.get_section_config("IOU")
Expand Down
2 changes: 1 addition & 1 deletion tests/compute/qemu/test_qcow2.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_invalid_empty_file(tmpdir):


@pytest.mark.skipif(qemu_img() is None, reason="qemu-img is not available")
async def test_rebase(loop, tmpdir):
async def test_rebase(tmpdir):

shutil.copy("tests/resources/empty8G.qcow2", str(tmpdir / "empty16G.qcow2"))
shutil.copy("tests/resources/linked.qcow2", str(tmpdir / "linked.qcow2"))
Expand Down
2 changes: 1 addition & 1 deletion tests/compute/qemu/test_qemu_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


@pytest.fixture
async def manager(loop, port_manager):
async def manager(port_manager):

m = Qemu.instance()
m.port_manager = port_manager
Expand Down
2 changes: 1 addition & 1 deletion tests/compute/test_base_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


@pytest.fixture(scope="function")
async def manager(loop, port_manager):
async def manager(port_manager):

m = VPCS.instance()
m.port_manager = port_manager
Expand Down
4 changes: 2 additions & 2 deletions tests/compute/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


@pytest.fixture(scope="function")
async def vpcs(loop, port_manager):
async def vpcs(port_manager):

VPCS._instance = None
vpcs = VPCS.instance()
Expand All @@ -38,7 +38,7 @@ async def vpcs(loop, port_manager):


@pytest.fixture(scope="function")
async def qemu(loop, port_manager):
async def qemu(port_manager):

Qemu._instance = None
Qemu._init_config_disk = MagicMock() # do not create the config.img image
Expand Down
2 changes: 1 addition & 1 deletion tests/compute/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


@pytest.fixture(scope="function")
async def manager(loop, port_manager):
async def manager(port_manager):

m = VPCS.instance()
m.port_manager = port_manager
Expand Down
2 changes: 1 addition & 1 deletion tests/compute/traceng/test_traceng_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


@pytest.fixture
async def manager(loop, port_manager):
async def manager(port_manager):

m = TraceNG.instance()
m.port_manager = port_manager
Expand Down
2 changes: 1 addition & 1 deletion tests/compute/virtualbox/test_virtualbox_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


@pytest.fixture
async def manager(loop, port_manager):
async def manager(port_manager):

m = VirtualBox.instance()
m.port_manager = port_manager
Expand Down
2 changes: 1 addition & 1 deletion tests/compute/virtualbox/test_virtualbox_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


@pytest.fixture
async def manager(loop, port_manager):
async def manager(port_manager):

m = VirtualBox.instance()
m.port_manager = port_manager
Expand Down
2 changes: 1 addition & 1 deletion tests/compute/vmware/test_vmware_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


@pytest.fixture
async def manager(loop, port_manager):
async def manager(port_manager):

m = VMware.instance()
m.port_manager = port_manager
Expand Down
2 changes: 1 addition & 1 deletion tests/compute/vmware/test_vmware_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


@pytest.fixture
async def manager(loop, port_manager):
async def manager(port_manager):

m = VMware.instance()
m.port_manager = port_manager
Expand Down
4 changes: 2 additions & 2 deletions tests/compute/vpcs/test_vpcs_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@


@pytest.fixture
async def manager(loop, port_manager):
async def manager(port_manager):

m = VPCS.instance()
m.port_manager = port_manager
return m


@pytest.fixture(scope="function")
async def vm(loop, compute_project, manager, tmpdir, ubridge_path):
async def vm(compute_project, manager, tmpdir, ubridge_path):

vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager)
vm._vpcs_version = parse_version("0.9")
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


if sys.platform.startswith("win"):
@pytest.yield_fixture(scope="session")
@pytest.fixture(scope="session")
def loop(request):
"""Return an event loop and destroy it at the end of test"""

Expand Down Expand Up @@ -72,7 +72,7 @@ def compute(controller):


@pytest.fixture
async def project(loop, tmpdir, controller):
async def project(tmpdir, controller):

return await controller.add_project(name="Test")

Expand Down
2 changes: 1 addition & 1 deletion tests/controller/gns3vm/test_remote_gns3_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def test_start(gns3vm, controller):
assert gns3vm.password == "world"


async def test_start_invalid_vm(loop, gns3vm, controller):
async def test_start_invalid_vm(gns3vm, controller):

await controller.add_compute("r1",
name="R1",
Expand Down
2 changes: 1 addition & 1 deletion tests/controller/gns3vm/test_virtualbox_gns3_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


@pytest.fixture
async def gns3vm(loop, controller):
async def gns3vm(controller):

vm = VirtualBoxGNS3VM(controller)
vm.vmname = "GNS3 VM"
Expand Down
2 changes: 1 addition & 1 deletion tests/controller/gns3vm/test_vmware_gns3_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


@pytest.fixture
async def gns3vm(loop, controller):
async def gns3vm(controller):

vm = VMwareGNS3VM(controller)
vm.vmname = "GNS3 VM"
Expand Down
2 changes: 1 addition & 1 deletion tests/controller/test_export_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


@pytest.fixture
async def project(loop, controller):
async def project(controller):

p = Project(controller=controller, name="test")
p.dump = MagicMock()
Expand Down
6 changes: 3 additions & 3 deletions tests/controller/test_gns3vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def dummy_gns3vm(controller, dummy_engine):
return vm


async def test_list(loop, controller):
async def test_list(controller):

vm = GNS3VM(controller)
with asyncio_patch("gns3server.controller.gns3vm.vmware_gns3_vm.VMwareGNS3VM.list", return_value=[{"vmname": "test", "vmx_path": "test"}]):
Expand All @@ -60,14 +60,14 @@ async def test_list(loop, controller):
await vm.list("hyperv")


async def test_json(loop, controller):
async def test_json(controller):

vm = GNS3VM(controller)
assert vm.__json__() == vm._settings


@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not working well on Windows")
async def test_update_settings(loop, controller):
async def test_update_settings(controller):

vm = GNS3VM(controller)
vm.settings = {
Expand Down
12 changes: 6 additions & 6 deletions tests/controller/test_import_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async def test_import_with_images(tmpdir, controller):
assert os.path.exists(path), path


async def test_import_iou_linux_no_vm(loop, linux_platform, tmpdir, controller):
async def test_import_iou_linux_no_vm(linux_platform, tmpdir, controller):
"""
On non linux host IOU should be local if we don't have a GNS3 VM
"""
Expand Down Expand Up @@ -210,7 +210,7 @@ async def test_import_iou_linux_no_vm(loop, linux_platform, tmpdir, controller):
assert topo["topology"]["nodes"][0]["compute_id"] == "local"


async def test_import_iou_linux_with_vm(loop, linux_platform, tmpdir, controller):
async def test_import_iou_linux_with_vm(linux_platform, tmpdir, controller):
"""
On non linux host IOU should be vm if we have a GNS3 VM configured
"""
Expand Down Expand Up @@ -255,7 +255,7 @@ async def test_import_iou_linux_with_vm(loop, linux_platform, tmpdir, controller
assert topo["topology"]["nodes"][0]["compute_id"] == "vm"


async def test_import_nat_non_linux(loop, windows_platform, tmpdir, controller):
async def test_import_nat_non_linux(windows_platform, tmpdir, controller):
"""
On non linux host NAT should be moved to the GNS3 VM
"""
Expand Down Expand Up @@ -300,7 +300,7 @@ async def test_import_nat_non_linux(loop, windows_platform, tmpdir, controller):
assert topo["topology"]["nodes"][0]["compute_id"] == "vm"


async def test_import_iou_non_linux(loop, windows_platform, tmpdir, controller):
async def test_import_iou_non_linux(windows_platform, tmpdir, controller):
"""
On non linux host IOU should be moved to the GNS3 VM
"""
Expand Down Expand Up @@ -356,7 +356,7 @@ async def test_import_iou_non_linux(loop, windows_platform, tmpdir, controller):
mock.assert_called_with(controller._computes["vm"], project_id, project.path, os.path.join('project-files', 'iou', topo["topology"]["nodes"][0]['node_id']))


async def test_import_node_id(loop, linux_platform, tmpdir, controller):
async def test_import_node_id(linux_platform, tmpdir, controller):
"""
When importing a node, node_id should change
"""
Expand Down Expand Up @@ -449,7 +449,7 @@ async def test_import_node_id(loop, linux_platform, tmpdir, controller):
assert os.path.exists(os.path.join(project.path, "project-files", "iou", topo["topology"]["nodes"][0]["node_id"], "startup.cfg"))


async def test_import_keep_compute_id(loop, windows_platform, tmpdir, controller):
async def test_import_keep_compute_id(windows_platform, tmpdir, controller):
"""
On linux host IOU should be moved to the GNS3 VM
"""
Expand Down
Loading

0 comments on commit cdcfc65

Please sign in to comment.