/tools/xm-test/tests/vtpm/08_vtpm-mig_pcrs.py

https://gitlab.com/wkyu/gxen · Python · 119 lines · 83 code · 28 blank · 8 comment · 25 complexity · 5822e714e6e515ef503e313d6ee904ad MD5 · raw file

  1. #!/usr/bin/python
  2. # Copyright (C) International Business Machines Corp., 2006
  3. # Author: Stefan Berger <stefanb@us.ibm.com>
  4. # Positive Test: create domain with virtual TPM attached at build time,
  5. # extend a pcr
  6. # check list of pcrs; locally migrate the domain and
  7. # check list of pcrs again and validate extended pcr
  8. # This test does local (non-live) migration.
  9. from XmTestLib import *
  10. from vtpm_utils import *
  11. import commands
  12. import os
  13. import os.path
  14. import atexit
  15. config = {"vtpm":"instance=1,backend=0"}
  16. domain = XmTestDomain(extraConfig=config)
  17. domName = domain.getName()
  18. consoleHistory = ""
  19. try:
  20. console = domain.start()
  21. except DomainError, e:
  22. if verbose:
  23. print e.extra
  24. FAIL("Unable to create domain (%s)" % domName)
  25. atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
  26. try:
  27. console.sendInput("input")
  28. except ConsoleError, e:
  29. saveLog(console.getHistory())
  30. FAIL(str(e))
  31. try:
  32. run = console.runCmd("mknod /dev/tpm0 c 10 224")
  33. except ConsoleError, e:
  34. saveLog(console.getHistory())
  35. FAIL("Error while creating /dev/tpm0")
  36. try:
  37. run = console.runCmd("echo -ne \"\\x00\\xc1\\x00\\x00\\x00\\x22\\x00\\x00\\x00\\x14\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\0xf\\x10\\x11\\x12\\x13\\x14\" > seq; cat seq > /dev/tpm0")
  38. except ConsoleError, e:
  39. saveLog(console.getHistory())
  40. FAIL("Error while extending PCR 0")
  41. try:
  42. run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
  43. except ConsoleError, e:
  44. saveLog(console.getHistory())
  45. FAIL("No result from dumping the PCRs")
  46. if re.search("No such file",run["output"]):
  47. FAIL("TPM frontend support not compiled into (domU?) kernel")
  48. if not re.search("PCR-00:",run["output"]):
  49. saveLog(console.getHistory())
  50. FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"])
  51. if not re.search("PCR-00: 1E A7 BD",run["output"]):
  52. saveLog(console.getHistory())
  53. FAIL("Extend did not lead to expected result (1E A7 BD ...): \n%s" % run["output"])
  54. consoleHistory = console.getHistory()
  55. domain.closeConsole()
  56. old_domid = domid(domName)
  57. loop = 0
  58. while loop < 3:
  59. try:
  60. status, ouptut = traceCommand("xm migrate %s localhost" %
  61. domName,
  62. timeout=90)
  63. except TimeoutError, e:
  64. saveLog(consoleHistory)
  65. FAIL(str(e))
  66. if status != 0:
  67. saveLog(consoleHistory)
  68. FAIL("xm migrate did not succeed. External device migration activated?")
  69. domName = domain.getName()
  70. new_domid = domid(domName)
  71. if (old_domid == new_domid):
  72. FAIL("xm migrate failed, domain id is still %s (loop=%d)" %
  73. (old_domid,loop))
  74. try:
  75. console = domain.getConsole()
  76. except ConsoleError, e:
  77. FAIL(str(e))
  78. try:
  79. run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
  80. except ConsoleError, e:
  81. saveLog(console.getHistory())
  82. FAIL("No result from dumping the PCRs")
  83. if not re.search("PCR-00:",run["output"]):
  84. saveLog(console.getHistory())
  85. FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
  86. if not re.search("PCR-00: 1E A7 BD",run["output"]):
  87. saveLog(console.getHistory())
  88. FAIL("Virtual TPM lost PCR 0 value: \n%s" % run["output"])
  89. loop += 1
  90. domain.closeConsole()
  91. domain.stop()