test 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/bin/bash
  2. shellfu import jat_dump
  3. shellfu import preupg
  4. shellfu import preupg_fupath
  5. assert_html_ok() {
  6. #
  7. # Do sanity test for result.html
  8. #
  9. local fpath="$1"
  10. jat__cmd -h "it's not empty: $fpath" \
  11. test -s "$fpath"
  12. jat__cmd -h "no _SOLUTION_MSG* placeholders: $fpath" \
  13. -S 1 \
  14. grep _SOLUTION_MSG "$fpath"
  15. }
  16. assert_xml_ok() {
  17. #
  18. # Do sanity test for result.html
  19. #
  20. local fpath="$1"
  21. jat__cmd -h "its not empty: $fpath" \
  22. test -s "$fpath"
  23. jat__cmd -h "it's a valid XML: $fpath" \
  24. xmllint "$fpath"
  25. }
  26. assert_tarball_ok() {
  27. #
  28. # Do sanity test for tarball
  29. #
  30. local fpath="$1" # path to tarball
  31. local fname # tarball filename
  32. local path # one of mandatory paths from enum_tarball_paths()
  33. local pfx # volatile path prefix (also part of tarball name)
  34. fname=$(basename "$fpath")
  35. pfx=${fname%.tar.gz}
  36. jat__cmd -h "file name determined" \
  37. test -n "$fpath" || return 1
  38. jat__cmd -h "file is not empty" \
  39. test -s "$fpath" || return 1
  40. preupg__tar_list > tarball_contents.txt
  41. jat__cmd -h "file contents are not empty" \
  42. test -s tarball_contents.txt || return 1
  43. jat__cmd -h "file layout is nested" -S 1 \
  44. grep -v "^$pfx/" tarball_contents.txt
  45. jat__cmd -h "shadow and gshadow files are not packed" -S 1 \
  46. grep -we 'shadow$' -e 'gshadow$' tarball_contents.txt
  47. for path in $(enum_tarball_paths);
  48. do
  49. jat__cmd -h "file $path is present" \
  50. grep -qxF "$pfx/$path" tarball_contents.txt
  51. done
  52. for path in $(enum_tarball_nopaths);
  53. do
  54. jat__cmd -h "file $path is not present" -S 1 \
  55. grep -qxF "$pfx/$path" tarball_contents.txt
  56. done
  57. jat_dump__file tarball_contents.txt
  58. }
  59. enum_tarball_paths() {
  60. #
  61. # Enumerate relative paths that must exist in tarball
  62. #
  63. # Paths here are listed *without* the "preupg_results-160608163404"
  64. # prefix as that is volatile but expected.
  65. #
  66. echo README
  67. echo cleanconf/
  68. echo common/
  69. echo dirtyconf/
  70. echo kickstart/
  71. echo noauto_postupgrade.d/
  72. echo postupgrade.d/
  73. echo preupgrade-scripts/
  74. echo result.html
  75. echo result.xml
  76. }
  77. enum_tarball_nopaths() {
  78. #
  79. # Enumerate relative paths that must NOT exist in tarball
  80. #
  81. # Paths here are listed *without* the "preupg_results-160608163404"
  82. # prefix as that is volatile but expected.
  83. #
  84. echo result-admin.html # BZ#1414322
  85. echo result-admin.xml # BZ#1414322
  86. }
  87. add_3pmod() {
  88. #
  89. # Add 3rdparty module
  90. #
  91. # 3rdparty modules need to be added *after* composing, so in order
  92. # to take advantage of preupgrade-assistant/fupath, we'll build
  93. # separate throw-away set and just move the source files.
  94. #
  95. preupg_fupath \
  96. THIRD \
  97. @3rdparty
  98. mkdir -p FOO/3rdparty/a_custom_module
  99. {
  100. echo '[preupgrade]'
  101. echo 'group_title = A nice group title'
  102. } >FOO/3rdparty/group.ini
  103. mv THIRD/3rdparty/a_custom_module/{solution.txt,check,module.ini} \
  104. FOO/3rdparty/a_custom_module
  105. }
  106. jat__pstarts "prepare fake upgrade path"
  107. preupg_fupath \
  108. FOO \
  109. @failed \
  110. @fixed \
  111. @informational \
  112. @needs_action \
  113. @needs_inspection \
  114. @not_applicable \
  115. @pass
  116. add_3pmod
  117. jat__cmd -h "make backup of upgrade path" \
  118. cp -ar FOO FOO-backup
  119. jat__pend
  120. jat__pstarts "prepare results"
  121. PREUPG__UPATH="FOO/all-xccdf.xml" \
  122. preupg__run1
  123. jat__cmd -h "tarball found" \
  124. test -n "$(preupg__get_latest_tar)"
  125. preupg__lsrules_ast \
  126. | jat_dump__pipe AST_RULES
  127. jat__pend
  128. jat__pstartt "check if upgrade path has been changed - BZ#1368823"
  129. jat__cmd -h "custom upgrade path has not been changed (bz1368823)" \
  130. -o updiff \
  131. diff -ru FOO FOO-backup
  132. jat_dump__file -E updiff
  133. test -s updiff && jat__submit updiff FOO.diff
  134. jat__pend
  135. jat__pstartt "check result*.html"
  136. assert_html_ok /root/preupgrade/result.html
  137. jat__pend
  138. jat__pstartt "check result*.xml"
  139. assert_xml_ok /root/preupgrade/result.xml
  140. jat__pend
  141. jat__pstartt "check tarball"
  142. assert_tarball_ok "$(preupg__get_latest_tar)"
  143. jat__pend
  144. jat__pstartt "check that 3rdparty module has run"
  145. preupg__assert -r xccdf_preupg_rule_3rdparty_a_custom_module_check \
  146. result pass
  147. jat__pend
  148. preupg__Cleanup