Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smartos_imgadm cannot deal with orphan images #55136

Closed
sjorge opened this issue Oct 26, 2019 · 5 comments
Closed

smartos_imgadm cannot deal with orphan images #55136

sjorge opened this issue Oct 26, 2019 · 5 comments
Labels
Bug broken, incorrect, or confusing behavior fixed-pls-verify fix is linked, bug author to confirm fix
Milestone

Comments

@sjorge
Copy link
Contributor

sjorge commented Oct 26, 2019

Description of Issue

While testing 2019.2.2 I noticed that smartos_imgadm cannot deal with orphaned images due to them not having a 'name' key.

According to the SmartOS folks this should not happend unless you messed up with image creation. I'll try and write a fix for this to go into master.

Setup

n/a

Steps to Reproduce Issue

Have a SmartOS node with a broken image, rather hard to do unfortunately.

Versions Report

Salt Version:
           Salt: 2019.2.2

Dependency Versions:
           cffi: 1.11.5
       cherrypy: 17.3.0
       dateutil: 2.7.3
      docker-py: Not Installed
          gitdb: 2.0.5
      gitpython: 2.1.11
          ioflo: Not Installed
         Jinja2: 2.10
        libgit2: Not Installed
        libnacl: 1.6.1
       M2Crypto: 0.30.1
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: 2.19
       pycrypto: 3.6.6
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.15 (default, Oct 23 2018, 17:11:49)
   python-gnupg: 0.4.3
         PyYAML: 3.13
          PyZMQ: 17.1.2
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 5.1.1
            ZMQ: 4.2.5

System Versions:
           dist:
         locale: UTF-8
        machine: i86pc
        release: 5.11
         system: SunOS
        version: Not Installed
@sjorge
Copy link
Contributor Author

sjorge commented Oct 26, 2019

Extra data to help with writing a unit test, output of 'imgadm list -j' with a broken image:

[
  {
    "manifest": {
      "v": 2,
      "uuid": "05140a7e-279f-11e6-aedf-47d4f69d2887",
      "owner": "00000000-0000-0000-0000-000000000000",
      "name": "ubuntu-16.04",
      "version": "20160601",
      "state": "active",
      "disabled": false,
      "public": true,
      "published_at": "2016-06-01T02:17:41Z",
      "type": "lx-dataset",
      "os": "linux",
      "files": [
        {
          "sha1": "d342f137c5ccef0702ec479acb63c196cf81b38a",
          "size": 134969110,
          "compression": "gzip"
        }
      ],
      "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.",
      "homepage": "https://docs.joyent.com/images/container-native-linux",
      "requirements": {
        "networks": [
          {
            "name": "net0",
            "description": "public"
          }
        ],
        "min_platform": {
          "7.0": "20160225T122859Z"
        },
        "brand": "lx"
      },
      "tags": {
        "role": "os",
        "kernel_version": "4.3.0"
      }
    },
    "zpool": "zones",
    "source": "https://images.joyent.com",
    "cloneNames": [
      "zones/e4c1f6b5-4429-e6c2-ae2a-d6aa58bdeebb"
    ],
    "clones": 1
  },
  {
    "manifest": {
      "uuid": "07f360fd-12d5-e624-a279-eb8a15b630f6"
    },
    "zpool": "zones",
    "cloneNames": [],
    "clones": 0
  },
  {
    "manifest": {
      "v": 2,
      "uuid": "2f0c529b-7bab-28d1-ff34-bdc9281b7a4b",
      "owner": "00000000-0000-0000-0000-000000000000",
      "name": "docker-layer",
      "version": "6e295a464695",
      "disabled": false,
      "public": true,
      "published_at": "2019-03-23T01:32:25.320Z",
      "type": "docker",
      "os": "linux",
      "description": "/bin/sh -c #(nop)  CMD [\"/bin/bash\" \"/opt/start.sh\" \"-bash\"]",
      "tags": {
        "docker:repo": "busybox42/zimbra-docker-centos",
        "docker:id": "sha256:6e295a464695daabb6d18f399b8fbefb4c056db7a13c4a3762031ef0517fd01b",
        "docker:architecture": "amd64",
        "docker:config": {
          "Cmd": [
            "/bin/bash",
            "/opt/start.sh",
            "-bash"
          ],
          "Entrypoint": null,
          "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
          ],
          "WorkingDir": ""
        }
      },
      "origin": "d2ab6be7-92b3-f470-fc6a-8771582a3c0b"
    },
    "zpool": "zones",
    "source": "https://docker.io",
    "cloneNames": [
      "zones/4a3db8cb-0e94-ae23-588c-ee7934088927"
    ],
    "clones": 1
  },
  {
    "manifest": {
      "v": 2,
      "uuid": "4a3db8cb-0e94-ae23-588c-ee7934088927",
      "owner": "00000000-0000-0000-0000-000000000000",
      "name": "docker-layer",
      "version": "62487cf6a7f6",
      "disabled": false,
      "public": true,
      "published_at": "2019-03-23T01:32:25.320Z",
      "type": "docker",
      "os": "linux",
      "description": "/bin/sh -c #(nop)  CMD [\"/bin/bash\" \"/opt/start.sh\" \"-bash\"]",
      "tags": {
        "docker:repo": "busybox42/zimbra-docker-centos",
        "docker:id": "sha256:62487cf6a7f698af4edc20707e14b1b3bba13b98bea3375f05af04859a30b222",
        "docker:architecture": "amd64",
        "docker:tag:latest": true,
        "docker:config": {
          "Cmd": [
            "/bin/bash",
            "/opt/start.sh",
            "-bash"
          ],
          "Entrypoint": null,
          "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
          ],
          "WorkingDir": ""
        }
      },
      "origin": "2f0c529b-7bab-28d1-ff34-bdc9281b7a4b"
    },
    "zpool": "zones",
    "source": "https://docker.io",
    "cloneNames": [],
    "clones": 0
  },
  {
    "manifest": {
      "uuid": "73e18268-9f3e-e662-92e7-f6b326859d2a"
    },
    "zpool": "zones",
    "cloneNames": [],
    "clones": 0
  },
  {
    "manifest": {
      "v": 2,
      "uuid": "9d91e334-3bcf-11e8-bb0b-e7b49eb01e38",
      "owner": "00000000-0000-0000-0000-000000000000",
      "name": "pkgbuild",
      "version": "18.1.0",
      "state": "active",
      "disabled": false,
      "public": true,
      "published_at": "2018-04-09T08:25:52Z",
      "type": "zone-dataset",
      "os": "smartos",
      "files": [
        {
          "sha1": "5efaf95b7f226eb09c7d5e6c3734f8aa654b811d",
          "size": 465411979,
          "compression": "gzip"
        }
      ],
      "description": "A SmartOS image pre-configured for building pkgsrc packages.",
      "homepage": "https://docs.joyent.com/images/smartos/pkgbuild",
      "urn": "sdc:sdc:pkgbuild:18.1.0",
      "requirements": {
        "min_platform": {
          "7.0": "20141030T081701Z"
        },
        "networks": [
          {
            "name": "net0",
            "description": "public"
          }
        ]
      },
      "tags": {
        "role": "os",
        "group": "pkgbuild"
      }
    },
    "zpool": "zones",
    "source": "https://images.joyent.com",
    "cloneNames": [
      "zones/dda70f61-70fe-65e7-cf70-d878d69442d4"
    ],
    "clones": 1
  },
  {
    "manifest": {
      "v": 2,
      "uuid": "ac99517a-72ac-44c0-90e6-c7ce3d944a0a",
      "owner": "00000000-0000-0000-0000-000000000000",
      "name": "ubuntu-certified-18.04",
      "version": "20180808",
      "state": "active",
      "disabled": false,
      "public": true,
      "published_at": "2018-10-11T12:45:24.804Z",
      "type": "zvol",
      "os": "linux",
      "files": [
        {
          "sha1": "9f7704969507bd97e160a8f42a3631487644e457",
          "size": 372276887,
          "compression": "gzip"
        }
      ],
      "description": "Ubuntu 18.04 LTS (20180808 64-bit). Certified Ubuntu Server Cloud Image from Canonical. For kvm and bhyve.",
      "homepage": "https://docs.joyent.com/images/linux/ubuntu-certified",
      "requirements": {
        "min_platform": {
          "7.0": "20150929T232348Z"
        },
        "networks": [
          {
            "name": "net0",
            "description": "public"
          }
        ],
        "ssh_key": true
      },
      "nic_driver": "virtio",
      "disk_driver": "virtio",
      "cpu_type": "host",
      "image_size": 10240,
      "tags": {
        "default_user": "ubuntu",
        "role": "os"
      }
    },
    "zpool": "zones",
    "source": "https://images.joyent.com",
    "cloneNames": [],
    "clones": 0
  },
  {
    "manifest": {
      "v": 2,
      "uuid": "c193a558-1d63-11e9-97cf-97bb3ee5c14f",
      "owner": "00000000-0000-0000-0000-000000000000",
      "name": "base-64-lts",
      "version": "18.4.0",
      "state": "active",
      "disabled": false,
      "public": true,
      "published_at": "2019-01-21T10:03:09Z",
      "type": "zone-dataset",
      "os": "smartos",
      "files": [
        {
          "sha1": "f8aa4579144cd7303046f0135aa2044c88e497e8",
          "size": 155843390,
          "compression": "gzip"
        }
      ],
      "description": "A 64-bit SmartOS image with just essential packages installed. Ideal for users who are comfortable with setting up their own environment and tools.",
      "homepage": "https://docs.joyent.com/images/smartos/base",
      "urn": "sdc:sdc:base-64-lts:18.4.0",
      "requirements": {
        "min_platform": {
          "7.0": "20141030T081701Z"
        },
        "networks": [
          {
            "name": "net0",
            "description": "public"
          }
        ]
      },
      "tags": {
        "role": "os",
        "group": "base-64-lts"
      }
    },
    "zpool": "zones",
    "source": "https://images.joyent.com",
    "cloneNames": [
      "zones/bb8ac299-aba9-458f-b4a1-f9393cf23f9c"
    ],
    "clones": 1
  },
  {
    "manifest": {
      "v": 2,
      "uuid": "c6a275e4-c730-11e8-8c5f-9b24fe560a8f",
      "owner": "00000000-0000-0000-0000-000000000000",
      "name": "base-64",
      "version": "18.3.0",
      "state": "active",
      "disabled": false,
      "public": true,
      "published_at": "2018-10-03T17:21:33Z",
      "type": "zone-dataset",
      "os": "smartos",
      "files": [
        {
          "sha1": "3d0310b3f9f70c3ecca9b59d396e8c764adc0eb5",
          "size": 155220569,
          "compression": "gzip"
        }
      ],
      "description": "A 64-bit SmartOS image with just essential packages installed. Ideal for users who are comfortable with setting up their own environment and tools.",
      "homepage": "https://docs.joyent.com/images/smartos/base",
      "urn": "sdc:sdc:base-64:18.3.0",
      "requirements": {
        "min_platform": {
          "7.0": "20141030T081701Z"
        },
        "networks": [
          {
            "name": "net0",
            "description": "public"
          }
        ]
      },
      "tags": {
        "role": "os",
        "group": "base-64"
      }
    },
    "zpool": "zones",
    "source": "https://images.joyent.com",
    "cloneNames": [
      "zones/47b39ec5-d783-c7f7-d5ca-f5cd7aff31af",
      "zones/5c9eaccf-8ecc-6fc8-ec74-af9cd85a133b",
      "zones/5ee07c30-ceb8-4e1d-f862-b71374607e93",
      "zones/91176aa6-eeef-488b-842a-db7ac9f23ffb",
      "zones/bae504b1-4594-47de-e2ed-e4f454776689",
      "zones/dd224c75-44b7-c713-e661-83577da603ea"
    ],
    "clones": 6
  },
  {
    "manifest": {
      "v": 2,
      "uuid": "d2ab6be7-92b3-f470-fc6a-8771582a3c0b",
      "owner": "00000000-0000-0000-0000-000000000000",
      "name": "docker-layer",
      "version": "ef64fbdc785e",
      "disabled": false,
      "public": true,
      "published_at": "2019-03-23T01:32:25.320Z",
      "type": "docker",
      "os": "linux",
      "description": "/bin/sh -c #(nop)  CMD [\"/bin/bash\" \"/opt/start.sh\" \"-bash\"]",
      "tags": {
        "docker:repo": "busybox42/zimbra-docker-centos",
        "docker:id": "sha256:ef64fbdc785ec968ee1b19b39a1ff4723a78686b20eaff270ea7bab245c292cb",
        "docker:architecture": "amd64",
        "docker:config": {
          "Cmd": [
            "/bin/bash",
            "/opt/start.sh",
            "-bash"
          ],
          "Entrypoint": null,
          "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
          ],
          "WorkingDir": ""
        }
      },
      "origin": "ffd8dee6-d567-2bcd-c0f6-5c681647c785"
    },
    "zpool": "zones",
    "source": "https://docker.io",
    "cloneNames": [
      "zones/2f0c529b-7bab-28d1-ff34-bdc9281b7a4b"
    ],
    "clones": 1
  },
  {
    "manifest": {
      "v": 2,
      "uuid": "d6e56c0e-1e51-11e9-8ff1-2fecf38a5566",
      "owner": "00000000-0000-0000-0000-000000000000",
      "name": "centos-7",
      "version": "20190122",
      "state": "active",
      "disabled": false,
      "public": true,
      "published_at": "2019-01-22T14:27:25Z",
      "type": "zvol",
      "os": "linux",
      "files": [
        {
          "sha1": "eea7d4cf1c19d35464f6ed4ef2f8ccf232644cba",
          "size": 507103646,
          "compression": "gzip"
        }
      ],
      "description": "CentOS 7.5 64-bit image with just essential packages installed, built to run on KVM virtual machines. For kvm and bhyve.",
      "homepage": "https://docs.joyent.com/images/linux/centos",
      "requirements": {
        "networks": [
          {
            "name": "net0",
            "description": "public"
          }
        ],
        "ssh_key": true
      },
      "users": [
        {
          "name": "root"
        }
      ],
      "nic_driver": "virtio",
      "disk_driver": "virtio",
      "cpu_type": "host",
      "image_size": 10240,
      "tags": {
        "role": "os"
      }
    },
    "zpool": "zones",
    "source": "https://images.joyent.com",
    "cloneNames": [],
    "clones": 0
  },
  {
    "manifest": {
      "v": 2,
      "uuid": "e69a0918-055d-11e5-8912-e3ceb6df4cf8",
      "owner": "00000000-0000-0000-0000-000000000000",
      "name": "base-multiarch-lts",
      "version": "14.4.2",
      "state": "active",
      "disabled": false,
      "public": true,
      "published_at": "2015-05-28T17:20:56Z",
      "type": "zone-dataset",
      "os": "smartos",
      "files": [
        {
          "sha1": "e9b1b0c9f4375a15d10309ab37263c94ec269dd2",
          "size": 168998978,
          "compression": "gzip"
        }
      ],
      "description": "A multiarch SmartOS image with just essential packages installed. Ideal for users who are comfortable with setting up their own environment and tools.",
      "homepage": "https://docs.joyent.com/images/smartos/base",
      "urn": "sdc:sdc:base-multiarch-lts:14.4.2",
      "requirements": {
        "min_platform": {
          "7.0": "20141030T081701Z"
        },
        "networks": [
          {
            "name": "net0",
            "description": "public"
          }
        ]
      },
      "tags": {
        "role": "os",
        "group": "base-multiarch-lts"
      }
    },
    "zpool": "zones",
    "source": "https://images.joyent.com",
    "cloneNames": [],
    "clones": 0
  },
  {
    "manifest": {
      "v": 2,
      "uuid": "ffd8dee6-d567-2bcd-c0f6-5c681647c785",
      "owner": "00000000-0000-0000-0000-000000000000",
      "name": "docker-layer",
      "version": "8ba884070f61",
      "disabled": false,
      "public": true,
      "published_at": "2019-03-23T01:32:25.320Z",
      "type": "docker",
      "os": "linux",
      "description": "/bin/sh -c #(nop)  CMD [\"/bin/bash\" \"/opt/start.sh\" \"-bash\"]",
      "tags": {
        "docker:repo": "busybox42/zimbra-docker-centos",
        "docker:id": "sha256:8ba884070f611d31cb2c42eddb691319dc9facf5e0ec67672fcfa135181ab3df",
        "docker:architecture": "amd64",
        "docker:config": {
          "Cmd": [
            "/bin/bash",
            "/opt/start.sh",
            "-bash"
          ],
          "Entrypoint": null,
          "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
          ],
          "WorkingDir": ""
        }
      }
    },
    "zpool": "zones",
    "source": "https://docker.io",
    "cloneNames": [
      "zones/d2ab6be7-92b3-f470-fc6a-8771582a3c0b"
    ],
    "clones": 1
  }
]

There are two broken images in this output:

  {
    "manifest": {
      "uuid": "73e18268-9f3e-e662-92e7-f6b326859d2a"
    },
    "zpool": "zones",
    "cloneNames": [],
    "clones": 0
  },

and

  {
    "manifest": {
      "uuid": "07f360fd-12d5-e624-a279-eb8a15b630f6"
    },
    "zpool": "zones",
    "cloneNames": [],
    "clones": 0
  },

We hit this exception due to the missinbg name, version, ... keys

An exception occurred in this state: Traceback (most recent call last):
                File "/opt/tools/lib/python2.7/site-packages/salt/state.py", line 1933, in call
                  **cdata['kwargs'])
                File "/opt/tools/lib/python2.7/site-packages/salt/loader.py", line 1951, in wrapper
                  return f(*args, **kwargs)
                File "/opt/tools/var/cache/salt/minion/extmods/states/smartos.py", line 507, in image_present
                  elif name in __salt__['imgadm.list']():
                File "/opt/tools/var/cache/salt/minion/extmods/modules/smartos_imgadm.py", line 259, in list_installed
                  data = _parse_image_meta(image, verbose)
                File "/opt/tools/var/cache/salt/minion/extmods/modules/smartos_imgadm.py", line 61, in _parse_image_meta
                  name = image['manifest']['name']
              KeyError: u'name'

@sjorge
Copy link
Contributor Author

sjorge commented Oct 26, 2019

We also depend on #51563 being ported to master, as without this we hit problems fixed in that PR.

@sjorge
Copy link
Contributor Author

sjorge commented Oct 26, 2019

Initial patch for fix that goes on top of #51563

--- smartos_imgadm.py.1	Sat Oct 26 12:52:34 2019
+++ smartos_imgadm.py	Sat Oct 26 12:46:38 2019
@@ -56,7 +56,7 @@

     if image and 'Error' in image:
         ret = image
-    elif image and 'manifest' in image:
+    elif image and 'manifest' in image and 'name' in image['manifest']:
         name = image['manifest']['name']
         version = image['manifest']['version']
         os = image['manifest']['os']
@@ -97,6 +97,11 @@
                 version=version,
                 published=published,
             )
+    else:
+        log.debug("smartos_image - encountered invalid image payload: {}".format(image))
+        ret = {
+            'Error': 'This looks like an orphaned image, image payload was invalid.'
+        }

     return ret

Will try to get this into a PR and add some tests for this next week

@sjorge
Copy link
Contributor Author

sjorge commented Oct 26, 2019

@frogunder
Copy link
Contributor

@sjorge Thank you for reporting this issue and for the fix.

@frogunder frogunder added this to the Approved milestone Oct 28, 2019
@frogunder frogunder added Bug broken, incorrect, or confusing behavior fixed-pls-verify fix is linked, bug author to confirm fix labels Oct 28, 2019
@sjorge sjorge closed this as completed Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior fixed-pls-verify fix is linked, bug author to confirm fix
Projects
None yet
Development

No branches or pull requests

2 participants