1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-25 01:38:08 +00:00
gns3-server/tests/controller/gns3vm/test_remote_gns3_vm.py

76 lines
2.4 KiB
Python
Raw Normal View History

2016-08-30 08:19:01 +00:00
#!/usr/bin/env python
#
# Copyright (C) 2020 GNS3 Technologies Inc.
2016-08-30 08:19:01 +00:00
#
# 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
from gns3server.controller.gns3vm.remote_gns3_vm import RemoteGNS3VM
from gns3server.controller.gns3vm.gns3_vm_error import GNS3VMError
from pydantic import SecretStr
2016-08-30 08:19:01 +00:00
@pytest.fixture
def gns3vm(controller):
2016-08-30 08:19:01 +00:00
return RemoteGNS3VM(controller)
2020-10-02 06:37:50 +00:00
@pytest.mark.asyncio
async def test_list(gns3vm, controller):
await controller.add_compute("r1", name="R1", host="r1.local", connect=False)
res = await gns3vm.list()
2016-08-30 08:19:01 +00:00
assert res == [{"vmname": "R1"}]
2020-10-02 06:37:50 +00:00
@pytest.mark.asyncio
async def test_start(gns3vm, controller):
await controller.add_compute("r1",
name="R1",
protocol="https",
host="r1.local",
port=8484,
user="hello",
password=SecretStr("world"),
connect=False)
2016-08-30 08:19:01 +00:00
gns3vm.vmname = "R1"
await gns3vm.start()
2016-08-30 08:19:01 +00:00
assert gns3vm.running
assert gns3vm.protocol == "https"
assert gns3vm.ip_address == "r1.local"
assert gns3vm.port == 8484
assert gns3vm.user == "hello"
assert gns3vm.password.get_secret_value() == "world"
2016-08-30 08:19:01 +00:00
2020-10-02 06:37:50 +00:00
@pytest.mark.asyncio
async def test_start_invalid_vm(gns3vm, controller):
await controller.add_compute("r1",
2023-08-19 02:29:25 +00:00
connect=False,
name="R1",
protocol="https",
host="r1.local",
port=8484,
user="hello",
password=SecretStr("world"))
2016-08-30 08:19:01 +00:00
gns3vm.vmname = "R2"
with pytest.raises(GNS3VMError):
await gns3vm.start()
2016-08-30 08:19:01 +00:00
assert not gns3vm.running