1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-26 00:38:10 +00:00

Add tests for all appliance types.

This commit is contained in:
grossmj 2018-11-17 15:37:20 +07:00
parent 627c7e9cfe
commit 71fcf855b4
3 changed files with 851 additions and 82 deletions

View File

@ -169,12 +169,6 @@ C7200_DYNAMIPS_APPLIANCE_PROPERTIES = {
"description": "Platform type", "description": "Platform type",
"enum": ["c7200"] "enum": ["c7200"]
}, },
# "chassis": {
# "description": "Chassis type",
# "type": ["string", "null"],
# "maxLength": 0,
# "default": None
# },
"ram": { "ram": {
"description": "Amount of RAM in MB", "description": "Amount of RAM in MB",
"type": "integer", "type": "integer",
@ -209,12 +203,6 @@ C3745_DYNAMIPS_APPLIANCE_PROPERTIES = {
"description": "Platform type", "description": "Platform type",
"enum": ["c3745"] "enum": ["c3745"]
}, },
# "chassis": {
# "description": "Chassis type",
# "type": ["string", "null"],
# "maxLength": 0,
# "default": None
# },
"ram": { "ram": {
"description": "Amount of RAM in MB", "description": "Amount of RAM in MB",
"type": "integer", "type": "integer",
@ -246,12 +234,6 @@ C3725_DYNAMIPS_APPLIANCE_PROPERTIES = {
"description": "Platform type", "description": "Platform type",
"enum": ["c3725"] "enum": ["c3725"]
}, },
# "chassis": {
# "description": "Chassis type",
# "type": ["string", "null"],
# "maxLength": 0,
# "default": None
# },
"ram": { "ram": {
"description": "Amount of RAM in MB", "description": "Amount of RAM in MB",
"type": "integer", "type": "integer",
@ -320,12 +302,6 @@ C2691_DYNAMIPS_APPLIANCE_PROPERTIES = {
"description": "Platform type", "description": "Platform type",
"enum": ["c2691"] "enum": ["c2691"]
}, },
# "chassis": {
# "description": "Chassis type",
# "type": ["string", "null"],
# "maxLength": 0,
# "default": None
# },
"ram": { "ram": {
"description": "Amount of RAM in MB", "description": "Amount of RAM in MB",
"type": "integer", "type": "integer",
@ -461,7 +437,7 @@ IOU_APPLIANCE_PROPERTIES = {
"startup_config": { "startup_config": {
"description": "Startup-config of IOU", "description": "Startup-config of IOU",
"type": "string", "type": "string",
"default": "iou_l2_base_startup-config.txt" "default": "iou_l3_base_startup-config.txt"
}, },
"private_config": { "private_config": {
"description": "Private-config of IOU", "description": "Private-config of IOU",
@ -504,13 +480,11 @@ DOCKER_APPLIANCE_PROPERTIES = {
"start_command": { "start_command": {
"description": "Docker CMD entry", "description": "Docker CMD entry",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"environment": { "environment": {
"description": "Docker environment variables", "description": "Docker environment variables",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"console_type": { "console_type": {
@ -545,7 +519,6 @@ DOCKER_APPLIANCE_PROPERTIES = {
"extra_hosts": { "extra_hosts": {
"description": "Docker extra hosts (added to /etc/hosts)", "description": "Docker extra hosts (added to /etc/hosts)",
"type": "string", "type": "string",
"minLength": 1,
"default": "", "default": "",
}, },
"custom_adapters": CUSTOM_ADAPTERS_ARRAY_SCHEMA "custom_adapters": CUSTOM_ADAPTERS_ARRAY_SCHEMA
@ -563,13 +536,11 @@ QEMU_APPLIANCE_PROPERTIES = {
"usage": { "usage": {
"description": "How to use the Qemu VM", "description": "How to use the Qemu VM",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"qemu_path": { "qemu_path": {
"description": "Path to QEMU", "description": "Path to QEMU",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"platform": { "platform": {
@ -604,13 +575,14 @@ QEMU_APPLIANCE_PROPERTIES = {
"adapter_type": { "adapter_type": {
"description": "QEMU adapter type", "description": "QEMU adapter type",
"type": "string", "type": "string",
"minLength": 1, "enum": ["e1000", "i82550", "i82551", "i82557a", "i82557b", "i82557c", "i82558a","i82558b", "i82559a",
"i82559b", "i82559c", "i82559er", "i82562", "i82801", "ne2k_pci", "pcnet", "rtl8139", "virtio",
"virtio-net-pci", "vmxnet3"],
"default": "e1000" "default": "e1000"
}, },
"mac_address": { "mac_address": {
"description": "QEMU MAC address", "description": "QEMU MAC address",
"type": "string", "type": "string",
"minLength": 1,
"anyOf": [ "anyOf": [
{"pattern": "^([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})$"}, {"pattern": "^([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})$"},
{"pattern": "^$"} {"pattern": "^$"}
@ -620,13 +592,11 @@ QEMU_APPLIANCE_PROPERTIES = {
"first_port_name": { "first_port_name": {
"description": "Optional name of the first networking port example: eth0", "description": "Optional name of the first networking port example: eth0",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"port_name_format": { "port_name_format": {
"description": "Optional formatting of the networking port example: eth{0}", "description": "Optional formatting of the networking port example: eth{0}",
"type": "string", "type": "string",
"minLength": 1,
"default": "Ethernet{0}" "default": "Ethernet{0}"
}, },
"port_segment_size": { "port_segment_size": {
@ -652,79 +622,66 @@ QEMU_APPLIANCE_PROPERTIES = {
"hda_disk_image": { "hda_disk_image": {
"description": "QEMU hda disk image path", "description": "QEMU hda disk image path",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"hda_disk_interface": { "hda_disk_interface": {
"description": "QEMU hda interface", "description": "QEMU hda interface",
"type": "string", "enum": ["ide", "sata", "scsi", "sd", "mtd", "floppy", "pflash", "virtio", "none"],
"minLength": 1,
"default": "ide" "default": "ide"
}, },
"hdb_disk_image": { "hdb_disk_image": {
"description": "QEMU hdb disk image path", "description": "QEMU hdb disk image path",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"hdb_disk_interface": { "hdb_disk_interface": {
"description": "QEMU hdb interface", "description": "QEMU hdb interface",
"type": "string", "enum": ["ide", "sata", "scsi", "sd", "mtd", "floppy", "pflash", "virtio", "none"],
"minLength": 1,
"default": "ide" "default": "ide"
}, },
"hdc_disk_image": { "hdc_disk_image": {
"description": "QEMU hdc disk image path", "description": "QEMU hdc disk image path",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"hdc_disk_interface": { "hdc_disk_interface": {
"description": "QEMU hdc interface", "description": "QEMU hdc interface",
"type": "string", "enum": ["ide", "sata", "scsi", "sd", "mtd", "floppy", "pflash", "virtio", "none"],
"minLength": 1,
"default": "ide" "default": "ide"
}, },
"hdd_disk_image": { "hdd_disk_image": {
"description": "QEMU hdd disk image path", "description": "QEMU hdd disk image path",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"hdd_disk_interface": { "hdd_disk_interface": {
"description": "QEMU hdd interface", "description": "QEMU hdd interface",
"type": "string", "enum": ["ide", "sata", "scsi", "sd", "mtd", "floppy", "pflash", "virtio", "none"],
"minLength": 1,
"default": "ide" "default": "ide"
}, },
"cdrom_image": { "cdrom_image": {
"description": "QEMU cdrom image path", "description": "QEMU cdrom image path",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"initrd": { "initrd": {
"description": "QEMU initrd path", "description": "QEMU initrd path",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"kernel_image": { "kernel_image": {
"description": "QEMU kernel image path", "description": "QEMU kernel image path",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"bios_image": { "bios_image": {
"description": "QEMU bios image path", "description": "QEMU bios image path",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"kernel_command_line": { "kernel_command_line": {
"description": "QEMU kernel command line", "description": "QEMU kernel command line",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"legacy_networking": { "legacy_networking": {
@ -752,7 +709,6 @@ QEMU_APPLIANCE_PROPERTIES = {
"options": { "options": {
"description": "Additional QEMU options", "description": "Additional QEMU options",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"custom_adapters": CUSTOM_ADAPTERS_ARRAY_SCHEMA "custom_adapters": CUSTOM_ADAPTERS_ARRAY_SCHEMA
@ -788,13 +744,11 @@ VMWARE_APPLIANCE_PROPERTIES = {
"first_port_name": { "first_port_name": {
"description": "Optional name of the first networking port example: eth0", "description": "Optional name of the first networking port example: eth0",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"port_name_format": { "port_name_format": {
"description": "Optional formatting of the networking port example: eth{0}", "description": "Optional formatting of the networking port example: eth{0}",
"type": "string", "type": "string",
"minLength": 1,
"default": "Ethernet{0}" "default": "Ethernet{0}"
}, },
"port_segment_size": { "port_segment_size": {
@ -811,8 +765,7 @@ VMWARE_APPLIANCE_PROPERTIES = {
}, },
"adapter_type": { "adapter_type": {
"description": "VMware adapter type", "description": "VMware adapter type",
"type": "string", "enum": ["default", "e1000", "e1000e", "flexible", "vlance", "vmxnet", "vmxnet2", "vmxnet3"],
"minLength": 1,
"default": "e1000" "default": "e1000"
}, },
"use_any_adapter": { "use_any_adapter": {
@ -883,20 +836,22 @@ VIRTUALBOX_APPLIANCE_PROPERTIES = {
}, },
"adapter_type": { "adapter_type": {
"description": "VirtualBox adapter type", "description": "VirtualBox adapter type",
"type": "string", "enum": ["PCnet-PCI II (Am79C970A)",
"minLength": 1, "PCNet-FAST III (Am79C973)",
"Intel PRO/1000 MT Desktop (82540EM)",
"Intel PRO/1000 T Server (82543GC)",
"Intel PRO/1000 MT Server (82545EM)",
"Paravirtualized Network (virtio-net)"],
"default": "Intel PRO/1000 MT Desktop (82540EM)" "default": "Intel PRO/1000 MT Desktop (82540EM)"
}, },
"first_port_name": { "first_port_name": {
"description": "Optional name of the first networking port example: eth0", "description": "Optional name of the first networking port example: eth0",
"type": "string", "type": "string",
"minLength": 1,
"default": "" "default": ""
}, },
"port_name_format": { "port_name_format": {
"description": "Optional formatting of the networking port example: eth{0}", "description": "Optional formatting of the networking port example: eth{0}",
"type": "string", "type": "string",
"minLength": 1,
"default": "Ethernet{0}" "default": "Ethernet{0}"
}, },
"port_segment_size": { "port_segment_size": {
@ -991,6 +946,55 @@ ETHERNET_SWITCH_APPLIANCE_PROPERTIES = {
}, },
"ports_mapping": { "ports_mapping": {
"type": "array", "type": "array",
"default": [{"ethertype": "",
"name": "Ethernet0",
"vlan": 1,
"type": "access",
"port_number": 0
},
{"ethertype": "",
"name": "Ethernet1",
"vlan": 1,
"type": "access",
"port_number": 1
},
{"ethertype": "",
"name": "Ethernet2",
"vlan": 1,
"type": "access",
"port_number": 2
},
{"ethertype": "",
"name": "Ethernet3",
"vlan": 1,
"type": "access",
"port_number": 3
},
{"ethertype": "",
"name": "Ethernet4",
"vlan": 1,
"type": "access",
"port_number": 4
},
{"ethertype": "",
"name": "Ethernet5",
"vlan": 1,
"type": "access",
"port_number": 5
},
{"ethertype": "",
"name": "Ethernet6",
"vlan": 1,
"type": "access",
"port_number": 6
},
{"ethertype": "",
"name": "Ethernet7",
"vlan": 1,
"type": "access",
"port_number": 7
}
],
"items": [ "items": [
{"type": "object", {"type": "object",
"oneOf": [ "oneOf": [
@ -1044,27 +1048,46 @@ ETHERNET_HUB_APPLIANCE_PROPERTIES = {
}, },
"ports_mapping": { "ports_mapping": {
"type": "array", "type": "array",
"default": [{"port_number": 0,
"name": "Ethernet0"
},
{"port_number": 1,
"name": "Ethernet1"
},
{"port_number": 2,
"name": "Ethernet2"
},
{"port_number": 3,
"name": "Ethernet3"
},
{"port_number": 4,
"name": "Ethernet4"
},
{"port_number": 5,
"name": "Ethernet5"
},
{"port_number": 6,
"name": "Ethernet6"
},
{"port_number": 7,
"name": "Ethernet7"
}
],
"items": [ "items": [
{"type": "object", {"type": "object",
"oneOf": [ "oneOf": [{"description": "Ethernet port",
{ "properties": {"name": {"description": "Port name",
"description": "Ethernet port", "type": "string",
"properties": { "minLength": 1},
"name": { "port_number": {
"description": "Port name", "description": "Port number",
"type": "string", "type": "integer",
"minLength": 1 "minimum": 0}
}, },
"port_number": { "required": ["name", "port_number"],
"description": "Port number", "additionalProperties": False}
"type": "integer", ],
"minimum": 0 }
},
},
"required": ["name", "port_number"],
"additionalProperties": False
},
]},
] ]
} }
} }

View File

@ -86,8 +86,10 @@ async def parse_request(request, input_schema, raw, set_input_schema_defaults=Fa
try: try:
validator.validate(request.json) validator.validate(request.json)
except jsonschema.ValidationError as e: except jsonschema.ValidationError as e:
best_match = jsonschema.exceptions.best_match(validator.iter_errors(request.json)) message = "JSON schema error with API request '{}': {}".format(request.path_qs, e.message)
message = "JSON schema error with API request '{}': {} (best matched error: {})".format(request.path_qs, e.message, best_match.message) if "is not valid under any of the given schemas" not in message:
best_match = jsonschema.exceptions.best_match(validator.iter_errors(request.json))
message += " (best matched error: {})".format(best_match.message)
log.error(message) log.error(message)
log.debug("Input schema: {}".format(json.dumps(input_schema))) log.debug("Input schema: {}".format(json.dumps(input_schema)))
raise aiohttp.web.HTTPBadRequest(text=message) raise aiohttp.web.HTTPBadRequest(text=message)

View File

@ -113,6 +113,24 @@ def test_appliance_create_with_id(http_controller, controller):
assert len(controller.appliances) == 1 assert len(controller.appliances) == 1
def test_appliance_create_wrong_type(http_controller, controller):
params = {"appliance_id": str(uuid.uuid4()),
"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"appliance_type": "invalid_appliance_type"}
response = http_controller.post("/appliances", params)
assert response.status == 400
assert len(controller.appliances) == 0
def test_appliance_get(http_controller, controller): def test_appliance_get(http_controller, controller):
appliance_id = str(uuid.uuid4()) appliance_id = str(uuid.uuid4())
@ -192,6 +210,733 @@ def test_appliance_delete(http_controller, controller):
assert len(controller.appliances) == 0 assert len(controller.appliances) == 0
def test_c7200_dynamips_appliance_create(http_controller):
params = {"name": "Cisco c7200 appliance",
"platform": "c7200",
"compute_id": "local",
"image": "c7200-adventerprisek9-mz.124-24.T5.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c7200-adventerprisek9-mz.124-24.T5.image",
"mac_addr": "",
"midplane": "vxr",
"mmap": True,
"name": "Cisco c7200 appliance",
"npe": "npe-400",
"nvram": 512,
"platform": "c7200",
"private_config": "",
"ram": 512,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c3745_dynamips_appliance_create(http_controller):
params = {"name": "Cisco c3745 appliance",
"platform": "c3745",
"compute_id": "local",
"image": "c3745-adventerprisek9-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c3745-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c3745 appliance",
"iomem": 5,
"nvram": 256,
"platform": "c3745",
"private_config": "",
"ram": 256,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c3725_dynamips_appliance_create(http_controller):
params = {"name": "Cisco c3725 appliance",
"platform": "c3725",
"compute_id": "local",
"image": "c3725-adventerprisek9-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c3725-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c3725 appliance",
"iomem": 5,
"nvram": 256,
"platform": "c3725",
"private_config": "",
"ram": 128,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c3600_dynamips_appliance_create(http_controller):
params = {"name": "Cisco c3600 appliance",
"platform": "c3600",
"chassis": "3660",
"compute_id": "local",
"image": "c3660-a3jk9s-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c3660-a3jk9s-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c3600 appliance",
"iomem": 5,
"nvram": 128,
"platform": "c3600",
"chassis": "3660",
"private_config": "",
"ram": 192,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c3600_dynamips_appliance_create_wrong_chassis(http_controller):
params = {"name": "Cisco c3600 appliance",
"platform": "c3600",
"chassis": "3650",
"compute_id": "local",
"image": "c3660-a3jk9s-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 400
assert "is not valid under any of the given schemas" in response.json["message"]
def test_c2691_dynamips_appliance_create(http_controller):
params = {"name": "Cisco c2691 appliance",
"platform": "c2691",
"compute_id": "local",
"image": "c2691-adventerprisek9-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c2691-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c2691 appliance",
"iomem": 5,
"nvram": 256,
"platform": "c2691",
"private_config": "",
"ram": 192,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c2600_dynamips_appliance_create(http_controller):
params = {"name": "Cisco c2600 appliance",
"platform": "c2600",
"chassis": "2651XM",
"compute_id": "local",
"image": "c2600-adventerprisek9-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c2600-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c2600 appliance",
"iomem": 15,
"nvram": 128,
"platform": "c2600",
"chassis": "2651XM",
"private_config": "",
"ram": 160,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c2600_dynamips_appliance_create_wrong_chassis(http_controller):
params = {"name": "Cisco c2600 appliance",
"platform": "c2600",
"chassis": "2660XM",
"compute_id": "local",
"image": "c2600-adventerprisek9-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 400
assert "is not valid under any of the given schemas" in response.json["message"]
def test_c1700_dynamips_appliance_create(http_controller):
params = {"name": "Cisco c1700 appliance",
"platform": "c1700",
"chassis": "1760",
"compute_id": "local",
"image": "c1700-adventerprisek9-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c1700-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c1700 appliance",
"iomem": 15,
"nvram": 128,
"platform": "c1700",
"chassis": "1760",
"private_config": "",
"ram": 160,
"sparsemem": False,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c1700_dynamips_appliance_create_wrong_chassis(http_controller):
params = {"name": "Cisco c1700 appliance",
"platform": "c1700",
"chassis": "1770",
"compute_id": "local",
"image": "c1700-adventerprisek9-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 400
assert "is not valid under any of the given schemas" in response.json["message"]
def test_dynamips_appliance_create_wrong_platform(http_controller):
params = {"name": "Cisco c3900 appliance",
"platform": "c3900",
"compute_id": "local",
"image": "c3900-test.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 400
assert "is not valid under any of the given schemas" in response.json["message"]
def test_iou_appliance_create(http_controller):
params = {"name": "IOU appliance",
"compute_id": "local",
"path": "/path/to/i86bi_linux-ipbase-ms-12.4.bin",
"appliance_type": "iou"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "iou",
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "IOU{0}",
"ethernet_adapters": 2,
"name": "IOU appliance",
"nvram": 128,
"path": "/path/to/i86bi_linux-ipbase-ms-12.4.bin",
"private_config": "",
"ram": 256,
"serial_adapters": 2,
"startup_config": "iou_l3_base_startup-config.txt",
"symbol": ":/symbols/multilayer_switch.svg",
"use_default_iou_values": True}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_docker_appliance_create(http_controller):
params = {"name": "Docker appliance",
"compute_id": "local",
"image": "gns3/endhost:latest",
"appliance_type": "docker"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"adapters": 1,
"appliance_type": "docker",
"builtin": False,
"category": "guest",
"compute_id": "local",
"console_auto_start": False,
"console_http_path": "/",
"console_http_port": 80,
"console_resolution": "1024x768",
"console_type": "telnet",
"default_name_format": "{name}-{0}",
"environment": "",
"extra_hosts": "",
"image": "gns3/endhost:latest",
"name": "Docker appliance",
"start_command": "",
"symbol": ":/symbols/docker_guest.svg"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_qemu_appliance_create(http_controller):
params = {"name": "Qemu appliance",
"compute_id": "local",
"platform": "i386",
"hda_disk_image": "IOSvL2-15.2.4.0.55E.qcow2",
"ram": 512,
"appliance_type": "qemu"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"adapter_type": "e1000",
"adapters": 1,
"appliance_type": "qemu",
"bios_image": "",
"boot_priority": "c",
"builtin": False,
"category": "guest",
"cdrom_image": "",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"cpu_throttling": 0,
"cpus": 1,
"default_name_format": "{name}-{0}",
"first_port_name": "",
"hda_disk_image": "IOSvL2-15.2.4.0.55E.qcow2",
"hda_disk_interface": "ide",
"hdb_disk_image": "",
"hdb_disk_interface": "ide",
"hdc_disk_image": "",
"hdc_disk_interface": "ide",
"hdd_disk_image": "",
"hdd_disk_interface": "ide",
"initrd": "",
"kernel_command_line": "",
"kernel_image": "",
"legacy_networking": False,
"linked_clone": True,
"mac_address": "",
"name": "Qemu appliance",
"on_close": "power_off",
"options": "",
"platform": "i386",
"port_name_format": "Ethernet{0}",
"port_segment_size": 0,
"process_priority": "normal",
"qemu_path": "",
"ram": 512,
"symbol": ":/symbols/qemu_guest.svg",
"usage": ""}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_vmware_appliance_create(http_controller):
params = {"name": "VMware appliance",
"compute_id": "local",
"appliance_type": "vmware",
"vmx_path": "/path/to/vm.vmx"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"adapter_type": "e1000",
"adapters": 1,
"appliance_type": "vmware",
"builtin": False,
"category": "guest",
"compute_id": "local",
"console_auto_start": False,
"console_type": "none",
"default_name_format": "{name}-{0}",
"first_port_name": "",
"headless": False,
"linked_clone": False,
"name": "VMware appliance",
"on_close": "power_off",
"port_name_format": "Ethernet{0}",
"port_segment_size": 0,
"symbol": ":/symbols/vmware_guest.svg",
"use_any_adapter": False,
"vmx_path": "/path/to/vm.vmx"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_virtualbox_appliance_create(http_controller):
params = {"name": "VirtualBox appliance",
"compute_id": "local",
"appliance_type": "virtualbox",
"vmname": "My VirtualBox VM"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"adapter_type": "Intel PRO/1000 MT Desktop (82540EM)",
"adapters": 1,
"appliance_type": "virtualbox",
"builtin": False,
"category": "guest",
"compute_id": "local",
"console_auto_start": False,
"console_type": "none",
"default_name_format": "{name}-{0}",
"first_port_name": "",
"headless": False,
"linked_clone": False,
"name": "VirtualBox appliance",
"on_close": "power_off",
"port_name_format": "Ethernet{0}",
"port_segment_size": 0,
"ram": 256,
"symbol": ":/symbols/vbox_guest.svg",
"use_any_adapter": False,
"vmname": "My VirtualBox VM"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_vpcs_appliance_create(http_controller):
params = {"name": "VPCS appliance",
"compute_id": "local",
"appliance_type": "vpcs"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "vpcs",
"base_script_file": "vpcs_base_config.txt",
"builtin": False,
"category": "guest",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS appliance",
"symbol": ":/symbols/vpcs_guest.svg"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_ethernet_switch_appliance_create(http_controller):
params = {"name": "Ethernet switch appliance",
"compute_id": "local",
"appliance_type": "ethernet_switch"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "ethernet_switch",
"builtin": False,
"category": "switch",
"compute_id": "local",
"console_type": "telnet",
"default_name_format": "Switch{0}",
"name": "Ethernet switch appliance",
"ports_mapping": [{"ethertype": "",
"name": "Ethernet0",
"port_number": 0,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet1",
"port_number": 1,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet2",
"port_number": 2,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet3",
"port_number": 3,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet4",
"port_number": 4,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet5",
"port_number": 5,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet6",
"port_number": 6,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet7",
"port_number": 7,
"type": "access",
"vlan": 1
}],
"symbol": ":/symbols/ethernet_switch.svg"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_cloud_appliance_create(http_controller):
params = {"name": "Cloud appliance",
"compute_id": "local",
"appliance_type": "cloud"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "cloud",
"builtin": False,
"category": "guest",
"compute_id": "local",
"default_name_format": "Cloud{0}",
"name": "Cloud appliance",
"symbol": ":/symbols/cloud.svg"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_ethernet_hub_appliance_create(http_controller):
params = {"name": "Ethernet hub appliance",
"compute_id": "local",
"appliance_type": "ethernet_hub"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"ports_mapping": [{"port_number": 0,
"name": "Ethernet0"
},
{"port_number": 1,
"name": "Ethernet1"
},
{"port_number": 2,
"name": "Ethernet2"
},
{"port_number": 3,
"name": "Ethernet3"
},
{"port_number": 4,
"name": "Ethernet4"
},
{"port_number": 5,
"name": "Ethernet5"
},
{"port_number": 6,
"name": "Ethernet6"
},
{"port_number": 7,
"name": "Ethernet7"
}],
"compute_id": "local",
"name": "Ethernet hub appliance",
"symbol": ":/symbols/hub.svg",
"default_name_format": "Hub{0}",
"appliance_type": "ethernet_hub",
"category": "switch",
"builtin": False}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_create_node_from_appliance(http_controller, controller, project, compute): def test_create_node_from_appliance(http_controller, controller, project, compute):
id = str(uuid.uuid4()) id = str(uuid.uuid4())
@ -209,6 +954,5 @@ def test_create_node_from_appliance(http_controller, controller, project, comput
"y": 12 "y": 12
}) })
mock.assert_called_with(id, x=42, y=12, compute_id=None) mock.assert_called_with(id, x=42, y=12, compute_id=None)
print(response.body)
assert response.route == "/projects/{project_id}/appliances/{appliance_id}" assert response.route == "/projects/{project_id}/appliances/{appliance_id}"
assert response.status == 201 assert response.status == 201