Skip to content

Commit

Permalink
tests: Get host_data based on libvirt version
Browse files Browse the repository at this point in the history
Decode host_data if needed. Based on host libvirt
version, platform is setting the host_data as
b64 encoded or plain text string.

Signed-off-by: Smit Gardhariya <[email protected]>
  • Loading branch information
smit-gardhariya authored and LiliDeng committed Jan 28, 2025
1 parent 0707df4 commit 7f14064
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion microsoft/testsuites/cvm/cvm_attestation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import base64
import binascii
from pathlib import Path
from typing import Any, Dict

Expand Down Expand Up @@ -124,7 +126,7 @@ def verify_nested_cvm_attestation_report(
from lisa.sut_orchestrator.libvirt.context import get_node_context

node_context = get_node_context(node)
host_data = node_context.host_data
host_data = self._get_host_data(node_context.host_data)
if not host_data:
raise SkippedException("host_data is empty")
node.tools[NestedCVMAttestationTests].run_cvm_attestation(
Expand All @@ -133,3 +135,16 @@ def verify_nested_cvm_attestation_report(
log_path,
host_data,
)

def _get_host_data(self, host_data: str) -> str:
# Based on libvirt version our libvirt platform will set
# either plain text or b64 encoded string as host data.
# We need to decode it as this test would get host_data
# from attestation tool as plain text
# or
# Return original data if decoding fails considering
# this is non-encoded string
try:
return base64.b64decode(host_data).decode("utf-8")
except (binascii.Error, UnicodeDecodeError):
return host_data

0 comments on commit 7f14064

Please sign in to comment.