imagefeatures.py 9.7 KB

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