test_distribution_registry.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import infra.basetest
  2. import os
  3. import time
  4. class TestDistributionRegistry(infra.basetest.BRTest):
  5. config = \
  6. """
  7. BR2_arm=y
  8. BR2_cortex_a9=y
  9. BR2_ARM_ENABLE_VFP=y
  10. BR2_TOOLCHAIN_EXTERNAL=y
  11. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
  12. BR2_PER_PACKAGE_DIRECTORIES=y
  13. BR2_SYSTEM_DHCP="eth0"
  14. BR2_LINUX_KERNEL=y
  15. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  16. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.10.202"
  17. BR2_LINUX_KERNEL_DEFCONFIG="vexpress"
  18. BR2_LINUX_KERNEL_DTS_SUPPORT=y
  19. BR2_LINUX_KERNEL_INTREE_DTS_NAME="vexpress-v2p-ca9"
  20. BR2_PACKAGE_CA_CERTIFICATES=y
  21. BR2_PACKAGE_DISTRIBUTION_REGISTRY=y
  22. BR2_PACKAGE_SKOPEO=y
  23. BR2_PACKAGE_HOST_GO_BIN=y
  24. BR2_TARGET_ROOTFS_CPIO=y
  25. # BR2_TARGET_ROOTFS_TAR is not set
  26. """
  27. def test_run(self):
  28. kernel_file = os.path.join(self.builddir, "images", "zImage")
  29. dtb_file = os.path.join(self.builddir, "images", "vexpress-v2p-ca9.dtb")
  30. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  31. self.emulator.boot(
  32. arch="armv5",
  33. kernel=kernel_file,
  34. kernel_cmdline=[
  35. 'console=ttyAMA0',
  36. ],
  37. options=[
  38. '-M', 'vexpress-a9',
  39. "-m", "1G",
  40. "-nic", "user,model=lan9118",
  41. "-dtb", dtb_file,
  42. "-initrd", cpio_file,
  43. ],
  44. )
  45. self.emulator.login()
  46. # Allow unfettered access to the local registry:
  47. registry_conf = "\\n".join( # \\n to be interpreted by printf in the target
  48. [
  49. '[[registry]]',
  50. 'location = "localhost:5000"',
  51. 'insecure = true',
  52. ],
  53. )
  54. self.assertRunOk("mkdir /etc/containers/registries.conf.d")
  55. self.assertRunOk(
  56. f"printf '{registry_conf}\\n' >/etc/containers/registries.conf.d/localhost.conf",
  57. )
  58. # Check we can at least run
  59. self.assertRunOk("distribution-registry --version", timeout=30)
  60. # Spawn the registry and wait for it to be ready
  61. self.assertRunOk(
  62. "distribution-registry serve /etc/docker/registry/config.yml >/tmp/registry.log 2>&1 &",
  63. )
  64. for i in range(60):
  65. time.sleep(1)
  66. _, ret = self.emulator.run("test -s /tmp/registry.log")
  67. if ret == 0:
  68. time.sleep(2) # Wait just a little tiny bit more...
  69. break
  70. else:
  71. raise SystemError("Cannot start the registry")
  72. # Get a multi-arch image from the Docker hub registry
  73. # Huge timeout because qemu-system-arm has slirp issues
  74. self.assertRunOk(
  75. "skopeo copy -a docker://busybox:1.37.0-glibc oci-archive:busybox-1.37.0-glibc.oci",
  76. timeout=600,
  77. )
  78. # Push the multi-arch image to the local registry
  79. self.assertRunOk(
  80. "skopeo copy -a oci-archive:busybox-1.37.0-glibc.oci docker://localhost:5000/busybox:1.37.0-glibc",
  81. timeout=120,
  82. )
  83. # Pull the image back
  84. self.assertRunOk(
  85. "skopeo copy -a docker://localhost:5000/busybox:1.37.0-glibc oci-archive:busybox-1.37.0-glibc-2.oci",
  86. timeout=120,
  87. )