/tools/xm-test/tests/restore/04_restore_withdevices_pos.py

https://gitlab.com/wkyu/gxen
Python | 130 lines | 92 code | 32 blank | 6 comment | 34 complexity | a14637a128d290b183d621917e10797c MD5 | raw file
  1. #!/usr/bin/python
  2. # Copyright (C) International Business Machines Corp., 2005
  3. # Author: Dan Smith <danms@us.ibm.com>
  4. from XmTestLib import *
  5. import re
  6. if ENABLE_HVM_SUPPORT:
  7. SKIP("Restore currently not supported for HVM domains")
  8. config = {"disk": ["phy:/dev/ram0,xvda1,w", "phy:/dev/ram1,xvdb2,w"],
  9. "vif": ['', '']}
  10. domain = XmTestDomain(extraConfig=config)
  11. s, o = traceCommand("mke2fs -j -q /dev/ram0")
  12. if s != 0:
  13. FAIL("Unable to mke2fs /dev/ram0 in dom0")
  14. s, o = traceCommand("mke2fs -j -q /dev/ram1")
  15. if s != 0:
  16. FAIL("Unable to mke2fs /dev/ram1 in dom0")
  17. try:
  18. console = domain.start()
  19. except DomainError, e:
  20. FAIL(str(e))
  21. try:
  22. run = console.runCmd("mkdir /mnt/a /mnt/b")
  23. if run["return"] != 0:
  24. FAIL("Unable to mkdir /mnt/a /mnt/b")
  25. run = console.runCmd("mount /dev/xvda1 /mnt/a")
  26. if run["return"] != 0:
  27. FAIL("Unable to mount /dev/xvda1")
  28. run = console.runCmd("mount /dev/xvdb2 /mnt/b")
  29. if run["return"] != 0:
  30. FAIL("Unable to mount /dev/xvdb2")
  31. run = console.runCmd("echo xvda1 > /mnt/a/foo")
  32. if run["return"] != 0:
  33. FAIL("Unable to write to block device xvda1!")
  34. run = console.runCmd("echo xvdb2 > /mnt/b/foo")
  35. if run["return"] != 0:
  36. FAIL("Unable to write to block device xvdb2!")
  37. run = console.runCmd("ifconfig eth0 172.30.206.1 netmask 255.255.255.240")
  38. if run["return"] != 0:
  39. FAIL("Unable to configure DomU's eth0")
  40. run = console.runCmd("ifconfig eth1 172.30.206.17 netmask 255.255.255.240")
  41. if run["return"] != 0:
  42. FAIL("Unable to configure DomU's eth1")
  43. run = console.runCmd("ifconfig lo 127.0.0.1")
  44. if run["return"] != 0:
  45. FAIL("Unable to configure DomU's lo")
  46. except ConsoleError, e:
  47. FAIL(str(e))
  48. domain.closeConsole()
  49. try:
  50. s, o = traceCommand("xm save %s /tmp/test.state" % domain.getName(),
  51. timeout=30)
  52. except TimeoutError, e:
  53. FAIL(str(e))
  54. if s != 0:
  55. FAIL("xm save exited with %i != 0" % s)
  56. # Let things settle
  57. time.sleep(15)
  58. try:
  59. s, o = traceCommand("xm restore /tmp/test.state",
  60. timeout=30)
  61. except TimeoutError, e:
  62. FAIL(str(e))
  63. if s != 0:
  64. FAIL("xm restore exited with %i != 0" % s)
  65. try:
  66. console = domain.getConsole()
  67. # Enable debug dumping, as this causes an Oops on x86_64
  68. console.debugMe = True
  69. # In case the domain is rebooted
  70. console.sendInput("ls")
  71. run = console.runCmd("ls | grep proc")
  72. if run["return"] != 0:
  73. FAIL("ls failed on restored domain")
  74. run = console.runCmd("cat /mnt/a/foo")
  75. if run["return"] != 0:
  76. FAIL("Unable to read from block device xvda1")
  77. if not re.search("xvda1", run["output"]):
  78. FAIL("Failed to read correct data from xvda1")
  79. run = console.runCmd("cat /mnt/b/foo")
  80. if run["return"] != 0:
  81. FAIL("Unable to read from block device xvdb2")
  82. if not re.search("xvdb2", run["output"]):
  83. FAIL("Failed to read correct data from xvdb2")
  84. run = console.runCmd("ifconfig")
  85. if not re.search("eth0", run["output"]):
  86. FAIL("DomU's eth0 disappeared")
  87. if not re.search("172.30.206.1", run["output"]):
  88. FAIL("DomU's eth0 lost its IP")
  89. if not re.search("eth1", run["output"]):
  90. FAIL("DomU's eth1 disappeared")
  91. if not re.search("172.30.206.17", run["output"]):
  92. FAIL("DomU's eth1 lost its IP")
  93. if not re.search("Loopback", run["output"]):
  94. FAIL("DomU's lo disappeared")
  95. if not re.search("127.0.0.1", run["output"]):
  96. FAIL("DomU's lo lost its IP")
  97. except ConsoleError, e:
  98. FAIL(str(e))