-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement zapper_iot method Signed-off-by: ChunAn Wu <an.wu@canonical.com> * 1. Rename validate_data function to validate_tplan 2. Rename LAUNCHER_SCHEMA to TPLAN_SCHEMA 3. using link instead lnk as variable name in validate_url function Signed-off-by: ChunAn Wu <an.wu@canonical.com> * Add zapper_iot to device-connector-types.rst Signed-off-by: ChunAn Wu <an.wu@canonical.com> --------- Signed-off-by: ChunAn Wu <an.wu@canonical.com>
- Loading branch information
Showing
4 changed files
with
223 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 198 additions & 0 deletions
198
device-connectors/src/testflinger_device_connectors/devices/zapper_iot/parser.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
"""provision yaml verify""" | ||
|
||
import logging | ||
import validators | ||
import jsonschema | ||
from jsonschema import validate | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
TPLAN_SCHEMA = { | ||
"type": "object", | ||
"properties": { | ||
"config": { | ||
"type": "object", | ||
"properties": { | ||
"project_name": {"type": "string"}, | ||
"username": {"type": "string"}, | ||
"password": {"type": "string"}, | ||
"serial_console": { | ||
"type": "object", | ||
"properties": { | ||
"port": {"type": "string"}, | ||
"baud_rate": { | ||
"type": "integer", | ||
"enum": [115200, 9600], | ||
"default": 115200, | ||
}, | ||
}, | ||
"required": ["port", "baud_rate"], | ||
}, | ||
"network": {"type": "string"}, | ||
"recipients": { | ||
"type": "array", | ||
"items": {"$ref": "#/$defs/mail_format"}, | ||
}, | ||
"hostname": {"type": "string"}, | ||
}, | ||
"required": [ | ||
"project_name", | ||
"username", | ||
"password", | ||
"serial_console", | ||
"network", | ||
], | ||
}, | ||
"run_stage": { | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"oneOf": [ | ||
{ | ||
"type": "string", | ||
"enum": ["login", "run_login", "reboot"], | ||
}, | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"deploy": { | ||
"type": "object", | ||
"properties": { | ||
"utility": { | ||
"type": "string", | ||
"enum": [ | ||
"utp_com", | ||
"uuu", | ||
"uuu_bootloader", | ||
"seed_override", | ||
"seed_override_lk", | ||
], | ||
}, | ||
"method": {"$ref": "#/$defs/method"}, | ||
"timeout": { | ||
"type": "integer", | ||
"default": 600, | ||
}, | ||
"update_boot_assets": {"type": "boolean"}, | ||
}, | ||
"required": ["utility", "method"], | ||
}, | ||
"checkbox": { | ||
"type": "object", | ||
"properties": { | ||
"snap_name": {"type": "string"}, | ||
"launcher": {"type": "string"}, | ||
"secure_id": { | ||
"type": "string", | ||
"pattern": "^[0-9a-zA-Z]{22}$", | ||
}, | ||
"submission_description": { | ||
"type": "string" | ||
}, | ||
}, | ||
"required": [ | ||
"snap_name", | ||
"launcher", | ||
"secure_id", | ||
], | ||
}, | ||
"initial_login": { | ||
"type": "object", | ||
"properties": { | ||
"method": {"$ref": "#/$defs/method"}, | ||
"timeout": { | ||
"type": "integer", | ||
"default": 600, | ||
}, | ||
}, | ||
"required": ["method"], | ||
}, | ||
"reboot_install": { | ||
"type": "object", | ||
"properties": { | ||
"method": {"$ref": "#/$defs/method"}, | ||
"timeout": { | ||
"type": "integer", | ||
"default": 600, | ||
}, | ||
}, | ||
"required": ["method"], | ||
}, | ||
"sys_commands": { | ||
"type": "array", | ||
"items": {"type": "string"}, | ||
}, | ||
"eof_commands": { | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"cmd": {"type": "string"}, | ||
"expected": {"type": "string"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
] | ||
}, | ||
}, | ||
"period": { | ||
"type": "object", | ||
"properties": { | ||
"mode": {"$ref": "#/$defs/mode"}, | ||
"day": {"$ref": "#/$defs/day"}, | ||
"time": {"$ref": "#/$defs/time"}, | ||
}, | ||
"required": ["mode"], | ||
"allOf": [ | ||
{ | ||
"if": {"properties": {"mode": {"enum": ["day"]}}}, | ||
"then": {"required": ["time"]}, | ||
}, | ||
{ | ||
"if": {"properties": {"mode": {"enum": ["week"]}}}, | ||
"then": {"required": ["time", "day"]}, | ||
}, | ||
], | ||
}, | ||
}, | ||
"required": ["config", "run_stage"], | ||
"$defs": { | ||
"time": {"type": "string", "pattern": "^[0-2][0-9]:[0-5][0-9]$"}, | ||
"day": { | ||
"type": "string", | ||
"enum": ["mon", "tue", "wed", "thu", "fri", "sat", "sun"], | ||
}, | ||
"mode": {"type": "string", "enum": ["hour", "day", "week", "test"]}, | ||
"mail_format": { | ||
"type": "string", | ||
"pattern": "^[a-zA-Z0-9.]+@[a-zA-Z0-9.]+$", | ||
}, | ||
"method": { | ||
"type": "string", | ||
"enum": [ | ||
"cloud-init", | ||
"console-conf", | ||
"system-user", | ||
], | ||
}, | ||
}, | ||
} | ||
|
||
|
||
def validate_tplan(data): | ||
"""for verify provision yaml""" | ||
try: | ||
validate(instance=data, schema=TPLAN_SCHEMA) | ||
logger.info("the JSON data is valid") | ||
except jsonschema.exceptions.ValidationError as err: | ||
raise ValueError("the JSON data is invalid") from err | ||
|
||
|
||
def validate_url(url): | ||
"""for verify url""" | ||
for link in url: | ||
if not validators.url(link): | ||
raise ValueError("url format is not correct") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters