test_smartos_imgadm.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Jorge Schrauwen <info@blackdot.be>
  4. """
  5. # Import python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Libs
  8. import salt.modules.smartos_imgadm as imgadm
  9. from salt.modules.smartos_imgadm import _parse_image_meta
  10. # Import Salt Testing Libs
  11. from tests.support.mixins import LoaderModuleMockMixin
  12. from tests.support.unit import TestCase
  13. image_orphan = {
  14. "manifest": {"uuid": "07f360fd-12d5-e624-a279-eb8a15b630f6"},
  15. "zpool": "zones",
  16. "cloneNames": [],
  17. "clones": 0,
  18. }
  19. image_native = {
  20. "manifest": {
  21. "v": 2,
  22. "uuid": "9d91e334-3bcf-11e8-bb0b-e7b49eb01e38",
  23. "owner": "00000000-0000-0000-0000-000000000000",
  24. "name": "pkgbuild",
  25. "version": "18.1.0",
  26. "state": "active",
  27. "disabled": False,
  28. "public": True,
  29. "published_at": "2018-04-09T08:25:52Z",
  30. "type": "zone-dataset",
  31. "os": "smartos",
  32. "files": [
  33. {
  34. "sha1": "5efaf95b7f226eb09c7d5e6c3734f8aa654b811d",
  35. "size": 465411979,
  36. "compression": "gzip",
  37. }
  38. ],
  39. "description": "A SmartOS image pre-configured for building pkgsrc packages.",
  40. "homepage": "https://docs.joyent.com/images/smartos/pkgbuild",
  41. "urn": "sdc:sdc:pkgbuild:18.1.0",
  42. "requirements": {
  43. "min_platform": {"7.0": "20141030T081701Z"},
  44. "networks": [{"name": "net0", "description": "public"}],
  45. },
  46. "tags": {"role": "os", "group": "pkgbuild"},
  47. },
  48. "zpool": "zones",
  49. "source": "https://images.joyent.com",
  50. "cloneNames": ["zones/dda70f61-70fe-65e7-cf70-d878d69442d4"],
  51. "clones": 1,
  52. }
  53. image_lx = {
  54. "manifest": {
  55. "v": 2,
  56. "uuid": "05140a7e-279f-11e6-aedf-47d4f69d2887",
  57. "owner": "00000000-0000-0000-0000-000000000000",
  58. "name": "ubuntu-16.04",
  59. "version": "20160601",
  60. "state": "active",
  61. "disabled": False,
  62. "public": True,
  63. "published_at": "2016-06-01T02:17:41Z",
  64. "type": "lx-dataset",
  65. "os": "linux",
  66. "files": [
  67. {
  68. "sha1": "d342f137c5ccef0702ec479acb63c196cf81b38a",
  69. "size": 134969110,
  70. "compression": "gzip",
  71. }
  72. ],
  73. "description": "Container-native Ubuntu 16.04 64-bit image. Built to run on containers with bare metal speed, while offering all the services of a typical unix host.",
  74. "homepage": "https://docs.joyent.com/images/container-native-linux",
  75. "requirements": {
  76. "networks": [{"name": "net0", "description": "public"}],
  77. "min_platform": {"7.0": "20160225T122859Z"},
  78. "brand": "lx",
  79. },
  80. "tags": {"role": "os", "kernel_version": "4.3.0"},
  81. },
  82. "zpool": "zones",
  83. "source": "https://images.joyent.com",
  84. "cloneNames": ["zones/e4c1f6b5-4429-e6c2-ae2a-d6aa58bdeebb"],
  85. "clones": 1,
  86. }
  87. image_zvol = {
  88. "manifest": {
  89. "v": 2,
  90. "uuid": "ac99517a-72ac-44c0-90e6-c7ce3d944a0a",
  91. "owner": "00000000-0000-0000-0000-000000000000",
  92. "name": "ubuntu-certified-18.04",
  93. "version": "20180808",
  94. "state": "active",
  95. "disabled": False,
  96. "public": True,
  97. "published_at": "2018-10-11T12:45:24.804Z",
  98. "type": "zvol",
  99. "os": "linux",
  100. "files": [
  101. {
  102. "sha1": "9f7704969507bd97e160a8f42a3631487644e457",
  103. "size": 372276887,
  104. "compression": "gzip",
  105. }
  106. ],
  107. "description": "Ubuntu 18.04 LTS (20180808 64-bit). Certified Ubuntu Server Cloud Image from Canonical. For kvm and bhyve.",
  108. "homepage": "https://docs.joyent.com/images/linux/ubuntu-certified",
  109. "requirements": {
  110. "min_platform": {"7.0": "20150929T232348Z"},
  111. "networks": [{"name": "net0", "description": "public"}],
  112. "ssh_key": True,
  113. },
  114. "nic_driver": "virtio",
  115. "disk_driver": "virtio",
  116. "cpu_type": "host",
  117. "image_size": 10240,
  118. "tags": {"default_user": "ubuntu", "role": "os"},
  119. },
  120. "zpool": "zones",
  121. "source": "https://images.joyent.com",
  122. "cloneNames": [],
  123. "clones": 0,
  124. }
  125. image_docker = {
  126. "manifest": {
  127. "v": 2,
  128. "uuid": "4a3db8cb-0e94-ae23-588c-ee7934088927",
  129. "owner": "00000000-0000-0000-0000-000000000000",
  130. "name": "docker-layer",
  131. "version": "62487cf6a7f6",
  132. "disabled": False,
  133. "public": True,
  134. "published_at": "2019-03-23T01:32:25.320Z",
  135. "type": "docker",
  136. "os": "linux",
  137. "description": '/bin/sh -c #(nop) CMD ["/bin/bash" "/opt/start.sh" "-bash"]',
  138. "tags": {
  139. "docker:repo": "busybox42/zimbra-docker-centos",
  140. "docker:id": "sha256:62487cf6a7f698af4edc20707e14b1b3bba13b98bea3375f05af04859a30b222",
  141. "docker:architecture": "amd64",
  142. "docker:tag:latest": True,
  143. "docker:config": {
  144. "Cmd": ["/bin/bash", "/opt/start.sh", "-bash"],
  145. "Entrypoint": None,
  146. "Env": [
  147. "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  148. ],
  149. "WorkingDir": "",
  150. },
  151. },
  152. "origin": "2f0c529b-7bab-28d1-ff34-bdc9281b7a4b",
  153. },
  154. "zpool": "zones",
  155. "source": "https://docker.io",
  156. "cloneNames": [],
  157. "clones": 0,
  158. }
  159. class ImgadmTestCase(TestCase, LoaderModuleMockMixin):
  160. """
  161. TestCase for salt.modules.smartos_imgadm module
  162. """
  163. def setup_loader_modules(self):
  164. return {imgadm: {}}
  165. def test_parse_image_meta_orphan(self):
  166. """
  167. Test the internal _parse_image_meta methode
  168. Feed it an 'orphan' image as we get it from from imgadm list -j
  169. """
  170. ret = {"Error": "This looks like an orphaned image, image payload was invalid."}
  171. self.assertEqual(_parse_image_meta(image_orphan, True), ret)
  172. def test_parse_image_meta_native(self):
  173. """
  174. Test the internal _parse_image_meta methode
  175. Feed it an 'native' image as we get it from from imgadm list -j
  176. """
  177. ret = {
  178. "description": "A SmartOS image pre-configured for building pkgsrc packages.",
  179. "name": "pkgbuild",
  180. "os": "smartos",
  181. "published": "2018-04-09T08:25:52Z",
  182. "source": "https://images.joyent.com",
  183. "version": "18.1.0",
  184. }
  185. self.assertEqual(_parse_image_meta(image_native, True), ret)
  186. def test_parse_image_meta_lx(self):
  187. """
  188. Test the internal _parse_image_meta methode
  189. Feed it an 'lx' image as we get it from from imgadm list -j
  190. """
  191. ret = {
  192. "description": "Container-native Ubuntu 16.04 64-bit image. Built to run on "
  193. "containers with bare metal speed, while offering all the "
  194. "services of a typical unix host.",
  195. "name": "ubuntu-16.04",
  196. "os": "linux",
  197. "published": "2016-06-01T02:17:41Z",
  198. "source": "https://images.joyent.com",
  199. "version": "20160601",
  200. }
  201. self.assertEqual(_parse_image_meta(image_lx, True), ret)
  202. def test_parse_image_meta_zvol(self):
  203. """
  204. Test the internal _parse_image_meta methode
  205. Feed it an 'zvol' image as we get it from from imgadm list -j
  206. """
  207. ret = {
  208. "description": "Ubuntu 18.04 LTS (20180808 64-bit). Certified Ubuntu Server "
  209. "Cloud Image from Canonical. For kvm and bhyve.",
  210. "name": "ubuntu-certified-18.04",
  211. "os": "linux",
  212. "published": "2018-10-11T12:45:24.804Z",
  213. "source": "https://images.joyent.com",
  214. "version": "20180808",
  215. }
  216. self.assertEqual(_parse_image_meta(image_zvol, True), ret)
  217. def test_parse_image_meta_docker(self):
  218. """
  219. Test the internal _parse_image_meta methode
  220. Feed it an 'docker' image as we get it from from imgadm list -j
  221. """
  222. ret = {
  223. "description": "Docker image imported from "
  224. "busybox42/zimbra-docker-centos:latest on "
  225. "2019-03-23T01:32:25.320Z.",
  226. "name": "busybox42/zimbra-docker-centos:latest",
  227. "os": "linux",
  228. "published": "2019-03-23T01:32:25.320Z",
  229. "source": "https://docker.io",
  230. "version": "62487cf6a7f6",
  231. }
  232. self.assertEqual(_parse_image_meta(image_docker, True), ret)