2015-02-11 15:31:21 +02:00
# -*- coding: utf-8 -*-
#
2020-06-16 07:29:03 +03:00
# Copyright (C) 2020 GNS3 Technologies Inc.
2015-02-11 15:31:21 +02: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
2022-08-24 22:03:16 +03:00
import pytest_asyncio
2015-02-11 15:31:21 +02:00
import asyncio
import os
import stat
2015-03-16 12:52:22 +02:00
import socket
2015-10-21 15:28:39 +03:00
import uuid
import shutil
2015-02-11 15:31:21 +02:00
2020-06-16 07:29:03 +03:00
from tests . utils import asyncio_patch , AsyncioMagicMock
2015-02-11 15:31:21 +02:00
2022-01-19 13:58:36 +02:00
from unittest . mock import MagicMock
from gns3server . compute . iou . iou_vm import IOUVM
from gns3server . compute . iou . iou_error import IOUError
from gns3server . compute . iou import IOU
2015-04-27 16:09:42 +03:00
2015-03-19 18:42:43 +02:00
2022-08-24 22:03:16 +03:00
@pytest_asyncio.fixture
2020-10-02 09:37:50 +03:00
async def manager ( port_manager ) :
2020-06-16 07:29:03 +03:00
2015-02-11 15:31:21 +02:00
m = IOU . instance ( )
m . port_manager = port_manager
return m
2022-08-24 22:03:16 +03:00
@pytest_asyncio.fixture ( scope = " function " )
2021-04-12 10:32:23 +03:00
async def vm ( compute_project , manager , config , tmpdir , fake_iou_bin , iourc_file ) :
2020-06-16 07:29:03 +03:00
vm = IOUVM ( " test " , str ( uuid . uuid4 ( ) ) , compute_project , manager , application_id = 1 )
2021-04-12 10:32:23 +03:00
config . settings . IOU . iourc_path = iourc_file
2015-11-10 16:21:10 +02:00
vm . path = " iou.bin "
2022-07-16 12:38:51 +03:00
vm . _loader = [ ]
2015-02-11 15:31:21 +02:00
return vm
2015-03-16 12:52:22 +02:00
@pytest.fixture
def iourc_file ( tmpdir ) :
2020-06-16 07:29:03 +03:00
2015-03-16 12:52:22 +02:00
path = str ( tmpdir / " iourc " )
with open ( path , " w+ " ) as f :
hostname = socket . gethostname ( )
f . write ( " [license] \n {} = aaaaaaaaaaaaaaaa; " . format ( hostname ) )
return path
2015-02-11 15:31:21 +02:00
@pytest.fixture
2016-06-07 16:34:04 +03:00
def fake_iou_bin ( images_dir ) :
2015-02-11 15:31:21 +02:00
""" Create a fake IOU image on disk """
2016-06-07 16:34:04 +03:00
path = os . path . join ( images_dir , " iou.bin " )
2015-02-11 15:31:21 +02:00
with open ( path , " w+ " ) as f :
f . write ( ' \x7f ELF \x01 \x01 \x01 ' )
os . chmod ( path , stat . S_IREAD | stat . S_IEXEC )
return path
2020-06-16 07:29:03 +03:00
def test_vm ( compute_project , manager ) :
vm = IOUVM ( " test " , " 00010203-0405-0607-0809-0a0b0c0d0e0f " , compute_project , manager )
2015-02-11 15:31:21 +02:00
assert vm . name == " test "
assert vm . id == " 00010203-0405-0607-0809-0a0b0c0d0e0f "
2020-06-16 07:29:03 +03:00
def test_vm_startup_config_content ( compute_project , manager ) :
vm = IOUVM ( " test " , " 00010203-0405-0607-0808-0a0b0c0d0e0f " , compute_project , manager , application_id = 1 )
2015-06-07 00:15:03 +03:00
vm . startup_config_content = " hostname % h "
2015-02-16 11:05:17 +02:00
assert vm . name == " test "
2015-06-07 00:15:03 +03:00
assert vm . startup_config_content == " hostname test "
2015-02-16 11:05:17 +02:00
assert vm . id == " 00010203-0405-0607-0808-0a0b0c0d0e0f "
2015-02-13 23:16:43 +02:00
2020-10-02 09:37:50 +03:00
@pytest.mark.asyncio
2020-06-16 07:29:03 +03:00
async def test_start ( vm ) :
2015-02-11 15:31:21 +02:00
2016-11-06 22:22:48 +02:00
mock_process = MagicMock ( )
vm . _check_requirements = AsyncioMagicMock ( return_value = True )
vm . _check_iou_licence = AsyncioMagicMock ( return_value = True )
vm . _start_ubridge = AsyncioMagicMock ( return_value = True )
vm . _ubridge_send = AsyncioMagicMock ( )
2015-03-12 07:09:01 +02:00
2016-11-06 22:22:48 +02:00
with asyncio_patch ( " asyncio.create_subprocess_exec " , return_value = mock_process ) as mock_exec :
mock_process . returncode = None
2023-05-14 09:20:45 +03:00
mock_process . communicate = AsyncioMagicMock ( return_value = ( None , None ) )
2020-06-16 07:29:03 +03:00
await vm . start ( )
2016-11-06 22:22:48 +02:00
assert vm . is_running ( )
assert vm . command_line == ' ' . join ( mock_exec . call_args [ 0 ] )
2015-02-11 15:31:21 +02:00
2016-11-06 22:22:48 +02:00
assert vm . _check_requirements . called
assert vm . _check_iou_licence . called
assert vm . _start_ubridge . called
vm . _ubridge_send . assert_any_call ( " iol_bridge delete IOL-BRIDGE-513 " )
vm . _ubridge_send . assert_any_call ( " iol_bridge create IOL-BRIDGE-513 513 " )
vm . _ubridge_send . assert_any_call ( " iol_bridge start IOL-BRIDGE-513 " )
2016-03-08 17:12:46 +02:00
2016-11-06 22:22:48 +02:00
2020-10-02 09:37:50 +03:00
@pytest.mark.asyncio
2021-04-12 10:32:23 +03:00
async def test_start_with_iourc ( vm , tmpdir , config ) :
2015-02-17 17:40:45 +02:00
fake_file = str ( tmpdir / " iourc " )
with open ( fake_file , " w+ " ) as f :
f . write ( " 1 " )
2015-03-26 18:43:00 +02:00
mock_process = MagicMock ( )
2016-11-06 22:22:48 +02:00
vm . _check_requirements = AsyncioMagicMock ( return_value = True )
vm . _check_iou_licence = AsyncioMagicMock ( return_value = True )
vm . _start_ioucon = AsyncioMagicMock ( return_value = True )
vm . _start_ubridge = AsyncioMagicMock ( return_value = True )
vm . _ubridge_send = AsyncioMagicMock ( )
2021-04-12 10:32:23 +03:00
config . settings . IOU . iourc_path = fake_file
with asyncio_patch ( " asyncio.create_subprocess_exec " , return_value = mock_process ) as exec_mock :
mock_process . returncode = None
2023-06-20 09:36:53 +03:00
mock_process . communicate = AsyncioMagicMock ( return_value = ( None , None ) )
2021-04-12 10:32:23 +03:00
await vm . start ( )
assert vm . is_running ( )
arsgs , kwargs = exec_mock . call_args
assert kwargs [ " env " ] [ " IOURC " ] == fake_file
2016-11-06 22:22:48 +02:00
2020-10-02 09:37:50 +03:00
@pytest.mark.asyncio
2020-06-16 07:29:03 +03:00
async def test_rename_nvram_file ( vm ) :
2015-02-13 21:57:20 +02:00
"""
It should rename the nvram file to the correct name before launching the VM
"""
with open ( os . path . join ( vm . working_dir , " nvram_0000 {} " . format ( vm . application_id + 1 ) ) , ' w+ ' ) as f :
f . write ( " 1 " )
2015-03-05 18:00:25 +02:00
with open ( os . path . join ( vm . working_dir , " vlan.dat-0000 {} " . format ( vm . application_id + 1 ) ) , ' w+ ' ) as f :
f . write ( " 1 " )
2015-02-13 21:57:20 +02:00
vm . _rename_nvram_file ( )
assert os . path . exists ( os . path . join ( vm . working_dir , " nvram_0000 {} " . format ( vm . application_id ) ) )
2015-03-05 18:00:25 +02:00
assert os . path . exists ( os . path . join ( vm . working_dir , " vlan.dat-0000 {} " . format ( vm . application_id ) ) )
2015-02-13 21:57:20 +02:00
2020-10-02 09:37:50 +03:00
@pytest.mark.asyncio
2020-06-16 07:29:03 +03:00
async def test_stop ( vm ) :
2015-02-11 15:31:21 +02:00
2020-06-16 07:29:03 +03:00
process = MagicMock ( )
2016-11-06 22:22:48 +02:00
vm . _check_requirements = AsyncioMagicMock ( return_value = True )
vm . _check_iou_licence = AsyncioMagicMock ( return_value = True )
vm . _start_ioucon = AsyncioMagicMock ( return_value = True )
vm . _start_ubridge = AsyncioMagicMock ( return_value = True )
vm . _ubridge_send = AsyncioMagicMock ( )
2015-02-11 15:31:21 +02:00
# Wait process kill success
future = asyncio . Future ( )
future . set_result ( True )
process . wait . return_value = future
2023-05-14 09:20:45 +03:00
process . returncode = None
process . communicate = AsyncioMagicMock ( return_value = ( None , None ) )
2015-02-11 15:31:21 +02:00
2016-11-06 22:22:48 +02:00
with asyncio_patch ( " asyncio.create_subprocess_exec " , return_value = process ) :
with asyncio_patch ( " gns3server.utils.asyncio.wait_for_process_termination " ) :
2020-06-16 07:29:03 +03:00
await vm . start ( )
2016-11-06 22:22:48 +02:00
assert vm . is_running ( )
2020-06-16 07:29:03 +03:00
await vm . stop ( )
2016-11-06 22:22:48 +02:00
assert vm . is_running ( ) is False
process . terminate . assert_called_with ( )
2015-02-11 15:31:21 +02:00
2020-10-02 09:37:50 +03:00
@pytest.mark.asyncio
2020-06-16 07:29:03 +03:00
async def test_reload ( vm , fake_iou_bin ) :
2015-02-11 15:31:21 +02:00
2020-06-16 07:29:03 +03:00
process = MagicMock ( )
2016-11-06 22:22:48 +02:00
vm . _check_requirements = AsyncioMagicMock ( return_value = True )
vm . _check_iou_licence = AsyncioMagicMock ( return_value = True )
vm . _start_ioucon = AsyncioMagicMock ( return_value = True )
vm . _start_ubridge = AsyncioMagicMock ( return_value = True )
vm . _ubridge_send = AsyncioMagicMock ( )
2015-02-11 15:31:21 +02:00
# Wait process kill success
future = asyncio . Future ( )
future . set_result ( True )
process . wait . return_value = future
2015-03-26 18:43:00 +02:00
process . returncode = None
2023-05-14 09:20:45 +03:00
process . communicate = AsyncioMagicMock ( return_value = ( None , None ) )
2015-02-11 15:31:21 +02:00
2016-11-06 22:22:48 +02:00
with asyncio_patch ( " asyncio.create_subprocess_exec " , return_value = process ) :
with asyncio_patch ( " gns3server.utils.asyncio.wait_for_process_termination " ) :
2020-06-16 07:29:03 +03:00
await vm . start ( )
2016-11-06 22:22:48 +02:00
assert vm . is_running ( )
2020-06-16 07:29:03 +03:00
await vm . reload ( )
2016-11-06 22:22:48 +02:00
assert vm . is_running ( ) is True
process . terminate . assert_called_with ( )
2015-02-11 15:31:21 +02:00
2020-10-02 09:37:50 +03:00
@pytest.mark.asyncio
2020-06-16 07:29:03 +03:00
async def test_close ( vm , port_manager ) :
2023-05-14 09:20:45 +03:00
process = MagicMock ( )
process . returncode = None
process . communicate = AsyncioMagicMock ( return_value = ( None , None ) )
2018-10-17 13:32:10 +03:00
vm . _start_ubridge = AsyncioMagicMock ( return_value = True )
vm . _ubridge_send = AsyncioMagicMock ( )
2016-04-15 18:57:06 +03:00
with asyncio_patch ( " gns3server.compute.iou.iou_vm.IOUVM._check_requirements " , return_value = True ) :
2023-05-14 09:20:45 +03:00
with asyncio_patch ( " asyncio.create_subprocess_exec " , return_value = process ) :
2020-06-16 07:29:03 +03:00
await vm . start ( )
2015-02-11 15:31:21 +02:00
port = vm . console
2020-06-16 07:29:03 +03:00
await vm . close ( )
2015-02-11 15:31:21 +02:00
# Raise an exception if the port is not free
2015-03-22 01:19:12 +02:00
port_manager . reserve_tcp_port ( port , vm . project )
2015-02-11 15:31:21 +02:00
assert vm . is_running ( ) is False
2016-11-04 16:42:29 +02:00
def test_path ( vm , fake_iou_bin , config ) :
2020-06-16 07:29:03 +03:00
2016-11-04 16:42:29 +02:00
vm . path = fake_iou_bin
assert vm . path == fake_iou_bin
2015-02-11 15:31:21 +02:00
2020-06-16 07:29:03 +03:00
def test_path_relative ( vm , fake_iou_bin ) :
2015-02-25 17:26:17 +02:00
2015-03-19 16:36:06 +02:00
vm . path = " iou.bin "
2015-02-25 17:26:17 +02:00
assert vm . path == fake_iou_bin
2022-07-16 12:38:51 +03:00
@pytest.mark.asyncio
async def test_path_invalid_bin ( vm , tmpdir , config ) :
2015-02-11 15:31:21 +02:00
2022-03-31 07:05:47 +03:00
config . settings . Server . images_path = str ( tmpdir )
2016-11-04 16:42:29 +02:00
path = str ( tmpdir / " test.bin " )
2015-02-11 15:31:21 +02:00
2016-11-04 16:42:29 +02:00
with open ( path , " w+ " ) as f :
f . write ( " BUG " )
2015-02-11 15:31:21 +02:00
2016-11-04 16:42:29 +02:00
with pytest . raises ( IOUError ) :
vm . path = path
2022-07-16 12:38:51 +03:00
await vm . _check_requirements ( )
2015-02-11 15:31:21 +02:00
def test_create_netmap_config ( vm ) :
vm . _create_netmap_config ( )
netmap_path = os . path . join ( vm . working_dir , " NETMAP " )
with open ( netmap_path ) as f :
content = f . read ( )
assert " 513:0/0 1:0/0 " in content
assert " 513:15/3 1:15/3 " in content
2020-10-02 09:37:50 +03:00
@pytest.mark.asyncio
2020-06-16 07:29:03 +03:00
async def test_build_command ( vm ) :
2015-02-11 15:31:21 +02:00
2020-06-16 07:29:03 +03:00
assert await vm . _build_command ( ) == [ vm . path , str ( vm . application_id ) ]
2015-02-13 23:16:43 +02:00
2015-06-19 17:35:19 +03:00
2015-06-07 00:15:03 +03:00
def test_get_startup_config ( vm ) :
2015-02-13 23:16:43 +02:00
content = " service timestamps debug datetime msec \n service timestamps log datetime msec \n no service password-encryption "
2015-06-07 00:15:03 +03:00
vm . startup_config = content
assert vm . startup_config == content
2015-02-13 23:16:43 +02:00
2015-06-07 00:15:03 +03:00
def test_update_startup_config ( vm ) :
2020-06-16 07:29:03 +03:00
2015-02-13 23:16:43 +02:00
content = " service timestamps debug datetime msec \n service timestamps log datetime msec \n no service password-encryption "
2015-06-07 00:15:03 +03:00
vm . startup_config_content = content
filepath = os . path . join ( vm . working_dir , " startup-config.cfg " )
2015-02-13 23:16:43 +02:00
assert os . path . exists ( filepath )
with open ( filepath ) as f :
assert f . read ( ) == content
2015-06-07 00:15:03 +03:00
def test_update_startup_config_empty ( vm ) :
2020-06-16 07:29:03 +03:00
2015-04-06 22:30:57 +03:00
content = " service timestamps debug datetime msec \n service timestamps log datetime msec \n no service password-encryption "
2015-06-07 00:15:03 +03:00
vm . startup_config_content = content
filepath = os . path . join ( vm . working_dir , " startup-config.cfg " )
2015-04-06 22:30:57 +03:00
assert os . path . exists ( filepath )
with open ( filepath ) as f :
assert f . read ( ) == content
2015-06-07 00:15:03 +03:00
vm . startup_config_content = " "
2015-04-06 22:30:57 +03:00
with open ( filepath ) as f :
assert f . read ( ) == content
2015-06-07 00:15:03 +03:00
def test_update_startup_config_content_hostname ( vm ) :
2020-06-16 07:29:03 +03:00
2015-02-13 23:16:43 +02:00
content = " hostname % h \n "
vm . name = " pc1 "
2015-06-07 00:15:03 +03:00
vm . startup_config_content = content
with open ( vm . startup_config_file ) as f :
2015-02-13 23:16:43 +02:00
assert f . read ( ) == " hostname pc1 \n "
2020-06-16 07:29:03 +03:00
def test_change_name ( vm ) :
2015-06-07 00:15:03 +03:00
path = os . path . join ( vm . working_dir , " startup-config.cfg " )
2015-02-13 23:16:43 +02:00
vm . name = " world "
with open ( path , ' w+ ' ) as f :
f . write ( " hostname world " )
vm . name = " hello "
assert vm . name == " hello "
with open ( path ) as f :
assert f . read ( ) == " hostname hello "
2017-02-27 13:48:05 +02:00
# support hostname not sync
vm . name = " alpha "
with open ( path , ' w+ ' ) as f :
f . write ( " no service password-encryption \n hostname beta \n no ip icmp rate-limit unreachable " )
vm . name = " charlie "
assert vm . name == " charlie "
with open ( path ) as f :
assert f . read ( ) == " no service password-encryption \n hostname charlie \n no ip icmp rate-limit unreachable "
2015-02-16 18:20:07 +02:00
2020-10-02 09:37:50 +03:00
@pytest.mark.asyncio
2020-06-16 07:29:03 +03:00
async def test_library_check ( vm ) :
2015-02-16 18:20:07 +02:00
2020-06-16 07:29:03 +03:00
with asyncio_patch ( " gns3server.utils.asyncio.subprocess_check_output " , return_value = " " ) :
await vm . _library_check ( )
2015-02-16 18:20:07 +02:00
2020-06-16 07:29:03 +03:00
with asyncio_patch ( " gns3server.utils.asyncio.subprocess_check_output " , return_value = " libssl => not found " ) :
2015-02-16 18:20:07 +02:00
with pytest . raises ( IOUError ) :
2020-06-16 07:29:03 +03:00
await vm . _library_check ( )
2015-02-16 18:20:07 +02:00
2020-10-02 09:37:50 +03:00
@pytest.mark.asyncio
2020-06-16 07:29:03 +03:00
async def test_enable_l1_keepalives ( vm ) :
2015-02-16 18:20:07 +02:00
2020-06-16 07:29:03 +03:00
with asyncio_patch ( " gns3server.utils.asyncio.subprocess_check_output " , return_value = " *************************************************************** \n \n -l Enable Layer 1 keepalive messages \n -u <n> UDP port base for distributed networks \n " ) :
2015-02-16 18:20:07 +02:00
command = [ " test " ]
2020-06-16 07:29:03 +03:00
await vm . _enable_l1_keepalives ( command )
2015-02-16 18:20:07 +02:00
assert command == [ " test " , " -l " ]
2020-06-16 07:29:03 +03:00
with asyncio_patch ( " gns3server.utils.asyncio.subprocess_check_output " , return_value = " *************************************************************** \n \n -u <n> UDP port base for distributed networks \n " ) :
2015-02-16 18:20:07 +02:00
command = [ " test " ]
with pytest . raises ( IOUError ) :
2020-06-16 07:29:03 +03:00
await vm . _enable_l1_keepalives ( command )
2015-02-16 18:20:07 +02:00
assert command == [ " test " ]
2015-02-16 21:08:04 +02:00
2020-10-02 09:37:50 +03:00
@pytest.mark.asyncio
2020-06-16 07:29:03 +03:00
async def test_start_capture ( vm , tmpdir , manager , free_console_port ) :
2015-02-16 21:08:04 +02:00
output_file = str ( tmpdir / " test.pcap " )
2016-06-25 03:35:39 +03:00
nio = manager . create_nio ( { " type " : " nio_udp " , " lport " : free_console_port , " rport " : free_console_port , " rhost " : " 127.0.0.1 " } )
2020-06-16 07:29:03 +03:00
await vm . adapter_add_nio_binding ( 0 , 0 , nio )
await vm . start_capture ( 0 , 0 , output_file )
2015-02-16 21:08:04 +02:00
assert vm . _adapters [ 0 ] . get_nio ( 0 ) . capturing
2020-10-02 09:37:50 +03:00
@pytest.mark.asyncio
2020-06-16 07:29:03 +03:00
async def test_stop_capture ( vm , tmpdir , manager , free_console_port ) :
2015-02-16 21:08:04 +02:00
output_file = str ( tmpdir / " test.pcap " )
2016-06-25 03:35:39 +03:00
nio = manager . create_nio ( { " type " : " nio_udp " , " lport " : free_console_port , " rport " : free_console_port , " rhost " : " 127.0.0.1 " } )
2020-06-16 07:29:03 +03:00
await vm . adapter_add_nio_binding ( 0 , 0 , nio )
await vm . start_capture ( 0 , 0 , output_file )
2015-02-16 21:08:04 +02:00
assert vm . _adapters [ 0 ] . get_nio ( 0 ) . capturing
2020-06-16 07:29:03 +03:00
await vm . stop_capture ( 0 , 0 )
2015-02-17 17:40:45 +02:00
assert vm . _adapters [ 0 ] . get_nio ( 0 ) . capturing is False
2015-02-25 17:35:13 +02:00
2015-02-26 03:55:35 +02:00
def test_get_legacy_vm_workdir ( ) :
2015-02-25 17:35:13 +02:00
2015-02-26 11:45:37 +02:00
assert IOU . get_legacy_vm_workdir ( 42 , " bla " ) == " iou/device-42 "
2015-03-16 12:52:22 +02:00
2020-10-02 09:37:50 +03:00
@pytest.mark.asyncio
2020-06-16 07:29:03 +03:00
async def test_invalid_iou_file ( vm , iourc_file ) :
2015-03-16 12:52:22 +02:00
hostname = socket . gethostname ( )
2020-06-16 07:29:03 +03:00
await vm . _check_iou_licence ( )
2015-03-16 12:52:22 +02:00
# Missing ;
with pytest . raises ( IOUError ) :
with open ( iourc_file , " w+ " ) as f :
f . write ( " [license] \n {} = aaaaaaaaaaaaaaaa " . format ( hostname ) )
2020-06-16 07:29:03 +03:00
await vm . _check_iou_licence ( )
2015-03-16 12:52:22 +02:00
# Key too short
with pytest . raises ( IOUError ) :
with open ( iourc_file , " w+ " ) as f :
f . write ( " [license] \n {} = aaaaaaaaaaaaaa; " . format ( hostname ) )
2020-06-16 07:29:03 +03:00
await vm . _check_iou_licence ( )
2015-03-16 12:52:22 +02:00
# Invalid hostname
with pytest . raises ( IOUError ) :
with open ( iourc_file , " w+ " ) as f :
f . write ( " [license] \n bla = aaaaaaaaaaaaaa; " )
2020-06-16 07:29:03 +03:00
await vm . _check_iou_licence ( )
2015-03-16 12:52:22 +02:00
# Missing licence section
with pytest . raises ( IOUError ) :
with open ( iourc_file , " w+ " ) as f :
f . write ( " [licensetest] \n {} = aaaaaaaaaaaaaaaa; " )
2020-06-16 07:29:03 +03:00
await vm . _check_iou_licence ( )
2015-03-16 12:52:22 +02:00
# Broken config file
with pytest . raises ( IOUError ) :
with open ( iourc_file , " w+ " ) as f :
f . write ( " [ " )
2020-06-16 07:29:03 +03:00
await vm . _check_iou_licence ( )
2015-03-16 12:52:22 +02:00
# Missing file
with pytest . raises ( IOUError ) :
os . remove ( iourc_file )
2020-06-16 07:29:03 +03:00
await vm . _check_iou_licence ( )
2015-03-17 17:31:45 +02:00
def test_iourc_content ( vm ) :
vm . iourc_content = " test "
with open ( os . path . join ( vm . temporary_directory , " iourc " ) ) as f :
assert f . read ( ) == " test "
2015-10-21 15:28:39 +03:00
2016-03-21 17:53:11 +02:00
def test_iourc_content_fix_carriage_return ( vm ) :
vm . iourc_content = " test \r \n 12 "
with open ( os . path . join ( vm . temporary_directory , " iourc " ) ) as f :
assert f . read ( ) == " test \n 12 "
2015-10-21 15:28:39 +03:00
def test_extract_configs ( vm ) :
assert vm . extract_configs ( ) == ( None , None )
with open ( os . path . join ( vm . working_dir , " nvram_00001 " ) , " w+ " ) as f :
f . write ( " CORRUPTED " )
assert vm . extract_configs ( ) == ( None , None )
with open ( os . path . join ( vm . working_dir , " nvram_00001 " ) , " w+ " ) as f :
f . write ( " CORRUPTED " )
assert vm . extract_configs ( ) == ( None , None )
shutil . copy ( " tests/resources/nvram_iou " , os . path . join ( vm . working_dir , " nvram_00001 " ) )
startup_config , private_config = vm . extract_configs ( )
assert len ( startup_config ) == 1392
assert len ( private_config ) == 0
2017-06-27 11:09:21 +03:00
2020-06-16 07:29:03 +03:00
def test_application_id ( compute_project , manager ) :
2017-06-27 11:09:21 +03:00
"""
Checks if uses local manager to get application_id when not set
"""
2020-06-16 07:29:03 +03:00
vm = IOUVM ( " test " , str ( uuid . uuid4 ( ) ) , compute_project , manager , application_id = 1 )
2017-06-27 11:09:21 +03:00
assert vm . application_id == 1
vm . application_id = 3
assert vm . application_id == 3