Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows/Ubuntu autoinstaller tests #4

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions pikvm_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import websocket
import time
import ssl
import json
from websocket import WebSocketBadStatusException
import requests
from robot.api.deco import keyword
ROBOT = False
except Exception:
Expand Down Expand Up @@ -200,3 +203,45 @@ def WriteTextPiKVM(text=str, pikvm_ip=str, login="admin", password="admin"):
time.sleep(0.2)
ws.send('{"event_type": "key", "event": {"key": "' + keymap[char] + '", "state": false}}')
ws.close()

@keyword("Iso image present")
def iso_image_present(image_name, pikvm_ip=str, login="admin", password="admin"):
"""
image_name - name of the iso image to be found
pikvm_ip - IP of the piKVM to send key input,\n
login - piKVM login\n
password - piKVM password\n
"""
images = get_all_images(pikvm_ip, login, password)
return image_name in images

@keyword("Upload image")
def upload_image(image_name, path_to_image, pikvm_ip, login="admin", password="admin"):
url = f"https://{pikvm_ip}/api/msd/write?image={image_name}"

with open(path_to_image, "rb") as iso_file:
binary_data = iso_file.read()

headers = {"X-KVMD-User": login, "X-KVMD-Passwd": password}

response = requests.post(url, data=binary_data, headers=headers, verify=False)
return response

def get_all_images(pikvm_ip, login, password):
url = f"https://{pikvm_ip}/api/msd"
headers = {"X-KVMD-User": login, "X-KVMD-Passwd": password}

response = requests.get(url, headers=headers, verify=False)

parsed_json = json.loads(response.content)

return parsed_json["result"]["storage"]["images"].keys()

@keyword("Iso image mount")
def iso_image_mount(image_name, pikvm_ip, login, password):
url = f"https://{pikvm_ip}/api/msd/set_params?image={image_name}&cdrom=0"

headers = {"X-KVMD-User": login, "X-KVMD-Passwd": password}

response = requests.post(url, headers=headers, verify=False)
return response
20 changes: 20 additions & 0 deletions pikvm_comm.robot
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,23 @@ Key Combination PiKVM
... possible keys can be found in `lib/pikvm_comm.py`
[Arguments] ${key} ${login}=admin ${password}=admin ${press_time}=0.05
Send Key Combination PiKVM ${key_list} ${pikvm_ip} ${login} ${password} ${press_time}

Check if iso image is present
[Documentation] Checks if image with name ${image_name} exists.
... Returns True/False
[Arguments] ${image_name} ${pikvm_ip}
${result}= Iso image present ${image_name} ${pikvm_ip}
[Return] ${result}

Upload iso image
[Documentation] Uploads given iso image (${path_to_image}) and saves it
... as ${image_name}
[Arguments] ${image_name} ${path_to_image} ${pikvm_ip}
${res}= Upload image ${image_name} ${path_to_image} ${pikvm_ip}
[Return] ${res}

Mount iso image
[Documentation] Mounts given iso image to CD-ROM. Assumes that
... ${image_name} is already uploaded.
[Arguments] ${image_name} ${pikvm_ip} ${login}=admin ${password}=admin
Iso image mount ${image_name} ${pikvm_ip} ${login} ${password}