imagefeatures.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. from oeqa.selftest.case import OESelftestTestCase
  2. from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
  3. from oeqa.utils.sshcontrol import SSHControl
  4. import os
  5. import json
  6. class ImageFeatures(OESelftestTestCase):
  7. test_user = 'tester'
  8. root_user = 'root'
  9. def test_non_root_user_can_connect_via_ssh_without_password(self):
  10. """
  11. Summary: Check if non root user can connect via ssh without password
  12. Expected: 1. Connection to the image via ssh using root user without providing a password should be allowed.
  13. 2. Connection to the image via ssh using tester user without providing a password should be allowed.
  14. Product: oe-core
  15. Author: Ionut Chisanovici <ionutx.chisanovici@intel.com>
  16. AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
  17. """
  18. features = 'EXTRA_IMAGE_FEATURES = "ssh-server-openssh empty-root-password allow-empty-password allow-root-login"\n'
  19. features += 'INHERIT += "extrausers"\n'
  20. features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user)
  21. self.write_config(features)
  22. # Build a core-image-minimal
  23. bitbake('core-image-minimal')
  24. with runqemu("core-image-minimal") as qemu:
  25. # Attempt to ssh with each user into qemu with empty password
  26. for user in [self.root_user, self.test_user]:
  27. ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user=user)
  28. status, output = ssh.run("true")
  29. self.assertEqual(status, 0, 'ssh to user %s failed with %s' % (user, output))
  30. def test_all_users_can_connect_via_ssh_without_password(self):
  31. """
  32. Summary: Check if all users can connect via ssh without password
  33. Expected: 1. Connection to the image via ssh using root user without providing a password should NOT be allowed.
  34. 2. Connection to the image via ssh using tester user without providing a password should be allowed.
  35. Product: oe-core
  36. Author: Ionut Chisanovici <ionutx.chisanovici@intel.com>
  37. AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
  38. """
  39. features = 'EXTRA_IMAGE_FEATURES = "ssh-server-openssh allow-empty-password allow-root-login"\n'
  40. features += 'INHERIT += "extrausers"\n'
  41. features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user)
  42. self.write_config(features)
  43. # Build a core-image-minimal
  44. bitbake('core-image-minimal')
  45. with runqemu("core-image-minimal") as qemu:
  46. # Attempt to ssh with each user into qemu with empty password
  47. for user in [self.root_user, self.test_user]:
  48. ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user=user)
  49. status, output = ssh.run("true")
  50. if user == 'root':
  51. self.assertNotEqual(status, 0, 'ssh to user root was allowed when it should not have been')
  52. else:
  53. self.assertEqual(status, 0, 'ssh to user tester failed with %s' % output)
  54. def test_clutter_image_can_be_built(self):
  55. """
  56. Summary: Check if clutter image can be built
  57. Expected: 1. core-image-clutter can be built
  58. Product: oe-core
  59. Author: Ionut Chisanovici <ionutx.chisanovici@intel.com>
  60. AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
  61. """
  62. # Build a core-image-clutter
  63. bitbake('core-image-clutter')
  64. def test_wayland_support_in_image(self):
  65. """
  66. Summary: Check Wayland support in image
  67. Expected: 1. Wayland image can be build
  68. 2. Wayland feature can be installed
  69. Product: oe-core
  70. Author: Ionut Chisanovici <ionutx.chisanovici@intel.com>
  71. AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
  72. """
  73. distro_features = get_bb_var('DISTRO_FEATURES')
  74. if not ('opengl' in distro_features and 'wayland' in distro_features):
  75. self.skipTest('neither opengl nor wayland present on DISTRO_FEATURES so core-image-weston cannot be built')
  76. # Build a core-image-weston
  77. bitbake('core-image-weston')
  78. def test_bmap(self):
  79. """
  80. Summary: Check bmap support
  81. Expected: 1. core-image-minimal can be build with bmap support
  82. 2. core-image-minimal is sparse
  83. Product: oe-core
  84. Author: Ed Bartosh <ed.bartosh@linux.intel.com>
  85. """
  86. features = 'IMAGE_FSTYPES += " ext4 ext4.bmap ext4.bmap.gz"'
  87. self.write_config(features)
  88. image_name = 'core-image-minimal'
  89. bitbake(image_name)
  90. deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
  91. link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
  92. image_path = os.path.join(deploy_dir_image, "%s.ext4" % link_name)
  93. bmap_path = "%s.bmap" % image_path
  94. gzip_path = "%s.gz" % bmap_path
  95. # check if result image, bmap and bmap.gz files are in deploy directory
  96. self.assertTrue(os.path.exists(image_path))
  97. self.assertTrue(os.path.exists(bmap_path))
  98. self.assertTrue(os.path.exists(gzip_path))
  99. # check if result image is sparse
  100. image_stat = os.stat(image_path)
  101. self.assertTrue(image_stat.st_size > image_stat.st_blocks * 512)
  102. # check if the resulting gzip is valid
  103. self.assertTrue(runCmd('gzip -t %s' % gzip_path))
  104. def test_hypervisor_fmts(self):
  105. """
  106. Summary: Check various hypervisor formats
  107. Expected: 1. core-image-minimal can be built with vmdk, vdi and
  108. qcow2 support.
  109. 2. qemu-img says each image has the expected format
  110. Product: oe-core
  111. Author: Tom Rini <trini@konsulko.com>
  112. """
  113. img_types = [ 'vmdk', 'vdi', 'qcow2' ]
  114. features = ""
  115. for itype in img_types:
  116. features += 'IMAGE_FSTYPES += "wic.%s"\n' % itype
  117. self.write_config(features)
  118. image_name = 'core-image-minimal'
  119. bitbake(image_name)
  120. deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
  121. link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
  122. for itype in img_types:
  123. image_path = os.path.join(deploy_dir_image, "%s.wic.%s" %
  124. (link_name, itype))
  125. # check if result image file is in deploy directory
  126. self.assertTrue(os.path.exists(image_path))
  127. # check if result image is vmdk
  128. sysroot = get_bb_var('STAGING_DIR_NATIVE', 'core-image-minimal')
  129. result = runCmd('qemu-img info --output json %s' % image_path,
  130. native_sysroot=sysroot)
  131. self.assertTrue(json.loads(result.output).get('format') == itype)
  132. def test_long_chain_conversion(self):
  133. """
  134. Summary: Check for chaining many CONVERSION_CMDs together
  135. Expected: 1. core-image-minimal can be built with
  136. ext4.bmap.gz.bz2.lzo.xz.u-boot and also create a
  137. sha256sum
  138. 2. The above image has a valid sha256sum
  139. Product: oe-core
  140. Author: Tom Rini <trini@konsulko.com>
  141. """
  142. conv = "ext4.bmap.gz.bz2.lzo.xz.u-boot"
  143. features = 'IMAGE_FSTYPES += "%s %s.sha256sum"' % (conv, conv)
  144. self.write_config(features)
  145. image_name = 'core-image-minimal'
  146. bitbake(image_name)
  147. deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
  148. link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
  149. image_path = os.path.join(deploy_dir_image, "%s.%s" %
  150. (link_name, conv))
  151. # check if resulting image is in the deploy directory
  152. self.assertTrue(os.path.exists(image_path))
  153. self.assertTrue(os.path.exists(image_path + ".sha256sum"))
  154. # check if the resulting sha256sum agrees
  155. self.assertTrue(runCmd('cd %s;sha256sum -c %s.%s.sha256sum' %
  156. (deploy_dir_image, link_name, conv)))
  157. def test_image_fstypes(self):
  158. """
  159. Summary: Check if image of supported image fstypes can be built
  160. Expected: core-image-minimal can be built for various image types
  161. Product: oe-core
  162. Author: Ed Bartosh <ed.bartosh@linux.intel.com>
  163. """
  164. image_name = 'core-image-minimal'
  165. img_types = [itype for itype in get_bb_var("IMAGE_TYPES", image_name).split() \
  166. if itype not in ('container', 'elf', 'f2fs', 'multiubi')]
  167. config = 'IMAGE_FSTYPES += "%s"\n'\
  168. 'MKUBIFS_ARGS ?= "-m 2048 -e 129024 -c 2047"\n'\
  169. 'UBINIZE_ARGS ?= "-m 2048 -p 128KiB -s 512"' % ' '.join(img_types)
  170. self.write_config(config)
  171. bitbake(image_name)
  172. deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
  173. link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
  174. for itype in img_types:
  175. image_path = os.path.join(deploy_dir_image, "%s.%s" % (link_name, itype))
  176. # check if result image is in deploy directory
  177. self.assertTrue(os.path.exists(image_path),
  178. "%s image %s doesn't exist" % (itype, image_path))
  179. def test_useradd_static(self):
  180. config = """
  181. USERADDEXTENSION = "useradd-staticids"
  182. USERADD_ERROR_DYNAMIC = "skip"
  183. USERADD_UID_TABLES += "files/static-passwd"
  184. USERADD_GID_TABLES += "files/static-group"
  185. """
  186. self.write_config(config)
  187. bitbake("core-image-base")
  188. def test_no_busybox_base_utils(self):
  189. config = """
  190. # Enable x11
  191. DISTRO_FEATURES_append += "x11"
  192. # Switch to systemd
  193. DISTRO_FEATURES += "systemd"
  194. VIRTUAL-RUNTIME_init_manager = "systemd"
  195. VIRTUAL-RUNTIME_initscripts = ""
  196. VIRTUAL-RUNTIME_syslog = ""
  197. VIRTUAL-RUNTIME_login_manager = "shadow-base"
  198. DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
  199. # Replace busybox
  200. PREFERRED_PROVIDER_virtual/base-utils = "packagegroup-core-base-utils"
  201. VIRTUAL-RUNTIME_base-utils = "packagegroup-core-base-utils"
  202. VIRTUAL-RUNTIME_base-utils-hwclock = "util-linux-hwclock"
  203. VIRTUAL-RUNTIME_base-utils-syslog = ""
  204. # Blacklist busybox
  205. PNBLACKLIST[busybox] = "Don't build this"
  206. """
  207. self.write_config(config)
  208. bitbake("--graphviz core-image-sato")