saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.12k stars 5.47k forks source link

Salt-Virt pre-seeding fails #47052

Closed bruceborrett closed 1 year ago

bruceborrett commented 6 years ago

I am having issues creating a VM using Salt-Virt, the VM gets created but it does not get pre-seeded. I have a basic setup from following the tutorial in the docs.

Command used to create the VM:

salt "kvm-01" virt.init "zarf-dev-01" 2 512 image="salt://kvm_images/trusty-server-cloudimg-amd64-disk1.img" enable_vnc=True enable_qcow=True

Output:

kvm-01:
    The minion function caused an exception: Traceback (most recent call last):
      File "/usr/lib/python2.7/dist-packages/salt/minion.py", line 1493, in _thread_return
        return_data = executor.execute()
      File "/usr/lib/python2.7/dist-packages/salt/executors/direct_call.py", line 28, in execute
        return self.func(*self.args, **self.kwargs)
      File "/usr/lib/python2.7/dist-packages/salt/modules/virt.py", line 697, in init
        priv_key=priv_key,
      File "/usr/lib/python2.7/dist-packages/salt/modules/seed.py", line 142, in apply_
        mpt = _mount(path, ftype, mount_point)
      File "/usr/lib/python2.7/dist-packages/salt/modules/seed.py", line 80, in _mount
        mpt = __salt__['mount.mount'](path, device=root, util=util)
      File "/usr/lib/python2.7/dist-packages/salt/modules/mount.py", line 993, in mount
        return __salt__['guestfs.mount'](name, root=device)
      File "/usr/lib/python2.7/dist-packages/salt/modules/guestfs.py", line 54, in mount
        if os.listdir(root):
    OSError: [Errno 2] No such file or directory: '/tmp/guest/srv.salt-images.zarf-dev-01.system.qcow2952984f5301f249996d99e5e9dcfe9fc22c73d02bcd1ede2fe11b5d084984f26'

Checking in that directory on the KVM server I see:

root@kvm-01:~$ ls /tmp/guest/
srv.salt-images.zarf-dev-01.system.qcow2

Minion version:

Salt Version:
           Salt: 2017.7.4

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-87-generic
         system: Linux
        version: Ubuntu 16.04 xenial

Master version:

Salt Version:
           Salt: 2017.7.4

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 1.5
      docker-py: Not Installed
          gitdb: 0.5.4
      gitpython: 0.3.2 RC1
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 0.9.1
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: 1.2.3
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.6 (default, Oct 26 2016, 20:30:19)
   python-gnupg: Not Installed
         PyYAML: 3.10
          PyZMQ: 14.0.1
           RAET: Not Installed
          smmap: 0.8.2
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.4

System Versions:
           dist: Ubuntu 14.04 trusty
         locale: UTF-8
        machine: x86_64
        release: 3.13.0-24-generic
         system: Linux
        version: Ubuntu 14.04 trusty
garethgreenaway commented 6 years ago

@bruceborrett Thanks for the report. We'll get this one fixed.

zer0def commented 6 years ago

Just to provide some hints, in case this was left out - this behavior occurs only when a previous seeding of the machine with the same name, disk profile name (in this case: system) and extension (?) failed with a traceback and the guestfs mount wasn't properly cleaned up.

This would've been more apparent, if the output's command was called with -l.

brianthelion commented 5 years ago

This is still an issue on 2019.02. The relevant code in guestfs.py is pretty short:

https://github.com/saltstack/salt/blob/705e8cca0b9ad6441c3884e76798cac1ff7859d7/salt/modules/guestfs.py#L30-L68

Looks like @thatch45 meant os.path.exists instead of os.listdir. Simple but potent bug. Are there no tests for guestfs.py?

Also, not to be a nit-picker, but do we really need the while loop? The likelihood of a os.urandom collision is so low, it's probably not worth the cost of maintaining the extra while...if...else logic (as we have discovered here).

cbosdo commented 4 years ago

isn't this one a duplicate of issue #55349 ?

brianthelion commented 4 years ago

@cbosdo A quick look suggests yes.

twangboy commented 1 year ago

Closing this issue because it is a duplicate of #55349 which has been resolved.