Skip to content

Commit

Permalink
Fix the logic of look up xtest
Browse files Browse the repository at this point in the history
Handle  no xtest installed

Handle find different snap of xtest and tee
  • Loading branch information
rickwu666666 committed Oct 8, 2024
1 parent 1e69f77 commit 0be9f75
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,20 @@ def list_apps(self, snaps):
return self._get(self._apps, params={"names": snaps})


def look_up_apps(apps, snap_name=None):
def look_up_xtest():
"""Lookup xtest and tee-supplicant apps."""
a = ExtendSanpd()
snap = os.environ.get("XTEST")
apps = a.list_apps(snap)
results = {"xtest": None, "tee": None}
if apps:
for app in apps:
if apps["result"]:
for app in apps["result"]:
if app["name"] == "xtest":
results["xtest"] = "{}.xtest".format(app["snap"])
if app["name"] == "tee-supplicant":
results["tee"] = "{}.tee-supplicant".format(app["snap"])
if snap_name:
results["xtest"] = "{}.xtest".format(snap_name)
results["tee"] = "{}.tee-supplicant".format(snap_name)
if results["xtest"] is None or results["tee"] is None:
raise SystemError("Can not find xtest snap in the system.")
if results["xtest"].split('.')[0] != results["tee"].split('.')[0]:
raise SystemError("Find more then one xtest snap in the system.")
return results


def main():
a = ExtendSanpd()
snap = os.environ.get("XTEST")

apps = a.list_apps()
app_results = look_up_apps(apps, snap)
return app_results


if __name__ == "__main__":
print(main())
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import json
import argparse
import look_up_xtest
from look_up_xtest import look_up_xtest


def parse_json_file(filepath, filter=False, xtest=None):
Expand Down Expand Up @@ -38,10 +38,11 @@ def main():
)
args = parser.parse_args()
try:
xtest = look_up_xtest.main()
except SystemExit:
xtest = look_up_xtest()
xtest = xtest["xtest"]
except SystemError:
xtest = None
parse_json_file(args.filepath, args.pkcs11, xtest["xtest"])
parse_json_file(args.filepath, args.pkcs11, xtest)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

import look_up_xtest
from look_up_xtest import look_up_xtest
from subprocess import run, CalledProcessError


Expand Down Expand Up @@ -52,7 +52,7 @@ def enable_tee_supplicant(tee):


def main():
xtest = look_up_xtest.main()
xtest = look_up_xtest()
enable_tee_supplicant(xtest["tee"])
ta_path = find_ta_path()
install_ta(xtest["xtest"], ta_path)
Expand Down

0 comments on commit 0be9f75

Please sign in to comment.