saltstack-formulas / lxd-formula

http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Other
21 stars 17 forks source link

lxd_profile.present exceptions #5

Closed noelmcloughlin closed 3 years ago

noelmcloughlin commented 6 years ago

The following failure occurs on rerun. Function needs fixing or state needs unless/onlyif clause.

lxd:
  profiles:
    local:
      shared_mount:
        devices:
          shared_mount:
            type: "disk"
            # Source on the host
            source: "/home/shared"
            # Path in the container
            path: "home/shared"
          ID: lxd_profile_local_shared_mount
    Function: lxd_profile.present
        Name: shared_mount
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1851, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1795, in wrapper
                  return f(*args, **kwargs)
                File "/var/cache/salt/minion/extmods/states/lxd_profile.py", line 148, in present
                  verify_cert
                File "/var/cache/salt/minion/extmods/modules/lxd.py", line 2029, in profile_create
                  profile = client.profiles.create(name, config, devices)
                File "/usr/local/lib/python2.7/dist-packages/pylxd/models/profile.py", line 60, in create
                  client.api.profiles.post(json=profile)
                File "/usr/local/lib/python2.7/dist-packages/pylxd/client.py", line 134, in post
                  self._assert_response(response, allowed_status_codes=(200, 201, 202))
                File "/usr/local/lib/python2.7/dist-packages/pylxd/client.py", line 91, in _assert_response
                  raise exceptions.LXDAPIException(response)
              LXDAPIException: The profile already exists
     Started: 05:28:14.949598
    Duration: 13.404 ms
     Changes: 

          ID: lxd_profile_local_trusty_amd64
    Function: lxd_profile.present
        Name: trusty_amd64
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1851, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1795, in wrapper
                  return f(*args, **kwargs)
                File "/var/cache/salt/minion/extmods/states/lxd_profile.py", line 148, in present
                  verify_cert
                File "/var/cache/salt/minion/extmods/modules/lxd.py", line 2029, in profile_create
                  profile = client.profiles.create(name, config, devices)
                File "/usr/local/lib/python2.7/dist-packages/pylxd/models/profile.py", line 60, in create
                  client.api.profiles.post(json=profile)
                File "/usr/local/lib/python2.7/dist-packages/pylxd/client.py", line 134, in post
                  self._assert_response(response, allowed_status_codes=(200, 201, 202))
                File "/usr/local/lib/python2.7/dist-packages/pylxd/client.py", line 91, in _assert_response
                  raise exceptions.LXDAPIException(response)
              LXDAPIException: The profile already exists
     Started: 05:33:06.746238
    Duration: 17.565 ms
     Changes:   
----------
          ID: lxd_profile_local_trusty_busybox_amd64
    Function: lxd_profile.present
        Name: trusty_busybox_amd64
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1851, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1795, in wrapper
                  return f(*args, **kwargs)
                File "/var/cache/salt/minion/extmods/states/lxd_profile.py", line 148, in present
                  verify_cert
                File "/var/cache/salt/minion/extmods/modules/lxd.py", line 2029, in profile_create
                  profile = client.profiles.create(name, config, devices)
                File "/usr/local/lib/python2.7/dist-packages/pylxd/models/profile.py", line 60, in create
                  client.api.profiles.post(json=profile)
                File "/usr/local/lib/python2.7/dist-packages/pylxd/client.py", line 134, in post
                  self._assert_response(response, allowed_status_codes=(200, 201, 202))
                File "/usr/local/lib/python2.7/dist-packages/pylxd/client.py", line 91, in _assert_response
                  raise exceptions.LXDAPIException(response)
              LXDAPIException: The profile already exists
     Started: 05:33:06.764225
    Duration: 20.877 ms
     Changes:   

          ID: lxd_container_local_ubuntu-xenial_0
    Function: lxd_container.present
        Name: ubuntu-xenial_0
      Result: False
     Comment: not found
     Started: 05:18:56.906750
    Duration: 16.564 ms
     Changes:   
----------
          ID: lxd_container_local_ubuntu-xenial2
    Function: lxd_container.present
        Name: ubuntu-xenial2
      Result: False
     Comment: not found
     Started: 05:18:56.924760
    Duration: 18.552 ms
     Changes:   
----------
          ID: lxd_container_local_ubuntu-xenial3
    Function: lxd_container.present
        Name: ubuntu-xenial3
      Result: False
     Comment: not found
     Started: 05:18:56.943609
    Duration: 15.791 ms
     Changes:   
----------
          ID: lxd_container_local_ubuntu-xenial3_check_executed
    Function: module.run
        Name: lxd.container_execute
      Result: False
     Comment: One or more requisite failed: lxd.containers.lxd_container_local_ubuntu-xenial3
     Changes:   
----------
          ID: lxd_container_local_ubuntu-xenial3_bse_1
    Function: module.run
        Name: lxd.container_execute
      Result: False
     Comment: Module function lxd.container_execute threw an exception. Exception: Container 'ubuntu-xenial3' not found
     Started: 05:18:56.962870
    Duration: 8.785 ms
     Changes: 
jochumdev commented 6 years ago

Thanks for reporting, will look into this.

jochumdev commented 6 years ago

Hmm I don't see that error here. Please give more infos about your LXD Version and PyLXD Version.

root@srv01:~# salt-call --local lxd.version
local:
    2.21
root@srv01:~# salt-call --local lxd.pylxd_version
local:
    2.2.5
noelmcloughlin commented 6 years ago

Sure.

$ sudo salt-call --local lxd.version
local:
    2.0.11

$ sudo  salt-call --local lxd.pylxd_version
local:
    2.2.6
jochumdev commented 6 years ago

Seems related to: https://github.com/lxc/pylxd/issues/282 but there was no solution how did you install LXD and on which OS?

Can you upgrade LXD on that box (Its a big upgrade, may breaks stuff!)?

apt install -t xenial-backports lxd lxd-tools

Hey btw. I would love a star for this formula :)

noelmcloughlin commented 6 years ago

This is Ubuntu 16.04.

$ apt-file search /usr/bin/lxd
lxd: /usr/bin/lxd

$ apt-cache policy lxd
lxd:
  Installed: 2.0.11-0ubuntu1~16.04.4
  Candidate: 2.0.11-0ubuntu1~16.04.4
  Version table:
     2.21-0ubuntu3~16.04.1 100
        100 http://us.archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages
 *** 2.0.11-0ubuntu1~16.04.4 500
        500 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     2.0.2-0ubuntu1~16.04.1 500
        500 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages
     2.0.0-0ubuntu4 500
        500 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 Packages

I installed pylxd manually.

pip install -U pylxd
noelmcloughlin commented 6 years ago

Will I upgrade?

jochumdev commented 6 years ago

Join us on freenode please: https://webchat.freenode.net/?channels=lxcontainers

noelmcloughlin commented 6 years ago
$ sudo salt-call --local lxd.version
sudo  salt-call --local lxd.pylxd_version
local:
    2.21
nmcloughlin@iedx7:~$ sudo  salt-call --local lxd.pylxd_version
local:
    2.2.6

Same issue after upgrading (apt install -t xenial-backports lxd lxd-tools).

 ID: lxd_profile_local_shared_mount
    Function: lxd_profile.present
        Name: shared_mount
      Result: False
     Comment: The profile already exists
     Started: 10:35:05.495187
    Duration: 14.496 ms
     Changes:   

  ID: lxd_image_local_busybox
    Function: lxd_image.present
        Name: busybox
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1851, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1795, in wrapper
                  return f(*args, **kwargs)
                File "/var/cache/salt/minion/extmods/states/lxd_image.py", line 222, in present
                  _raw=True
                File "/var/cache/salt/minion/extmods/modules/lxd.py", line 2941, in image_from_file
                  image = client.images.create(data, public=public, wait=True)
                File "/usr/local/lib/python2.7/dist-packages/pylxd/models/image.py", line 135, in create
                  response.json()['operation'])
                File "/usr/local/lib/python2.7/dist-packages/pylxd/models/operation.py", line 32, in wait_for_operation
                  operation.wait()
                File "/usr/local/lib/python2.7/dist-packages/pylxd/models/operation.py", line 63, in wait
                  raise exceptions.LXDAPIException(response)
              LXDAPIException: Image with same fingerprint already exists
     Started: 10:35:05.523103
    Duration: 168.362 ms
noelmcloughlin commented 6 years ago

I rebooted Ubuntu and tried again. More problems logged this time.

[ERROR   ] State 'lxd.init' was not found in SLS 'lxd.lxd'
Reason: 'lxd.init' is not available.

[ERROR   ] State 'lxd.config_managed' was not found in SLS 'lxd.lxd'
Reason: 'lxd.config_managed' is not available.

[ERROR   ] State 'lxd_profile.present' was not found in SLS 'lxd.profiles'
Reason: 'lxd_profile.present' is not available.

[ERROR   ] State 'lxd_profile.present' was not found in SLS 'lxd.profiles'
Reason: 'lxd_profile.present' is not available.

[ERROR   ] State 'lxd_profile.present' was not found in SLS 'lxd.profiles'
Reason: 'lxd_profile.present' is not available.

[ERROR   ] State 'lxd_image.present' was not found in SLS 'lxd.images'
Reason: 'lxd_image.present' is not available.

[ERROR   ] State 'lxd_image.present' was not found in SLS 'lxd.images'
Reason: 'lxd_image.present' is not available.

[ERROR   ] State 'lxd_image.present' was not found in SLS 'lxd.images'
Reason: 'lxd_image.present' is not available.

[ERROR   ] State 'lxd_image.present' was not found in SLS 'lxd.images'
Reason: 'lxd_image.present' is not available.

[ERROR   ] State 'lxd_container.present' was not found in SLS 'lxd.containers'
Reason: 'lxd_container.present' is not available.

[ERROR   ] State 'lxd_container.present' was not found in SLS 'lxd.containers'
Reason: 'lxd_container.present' is not available.

[WARNING ] The function "module.run" is using its deprecated version and will expire in version "Sodium".
[ERROR   ] Module function lxd.container_execute is not available
[WARNING ] The function "module.run" is using its deprecated version and will expire in version "Sodium".
[ERROR   ] Module function lxd.container_file_put is not available
[WARNING ] The function "module.run" is using its deprecated version and will expire in version "Sodium".
[ERROR   ] Module function lxd.container_execute is not available
local:
jochumdev commented 6 years ago

Seems salt ins't able to find pylxd anymore.

What gives:

$ python -c "import pylxd; print pylxd.__version__"
noelmcloughlin commented 6 years ago

Ahh, okay, good catch. I fixed things up and better now. Thx.

# salt-call --local saltutil.sync_modules
local:
    - modules.lxd
# salt-call --local saltutil.sync_states
local:
    - states.lxd
    - states.lxd_container
    - states.lxd_image
    - states.lxd_profile
# sudo salt-call --local lxd.version
local:
    2.21
# salt-call --local lxd.pylxd_version
local:
    2.2.6
# python -c "import pylxd; print pylxd.__version__"
2.2.6

[ERROR   ] The profile already exists
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1851, in call
    **cdata['kwargs'])
  File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1795, in wrapper
    return f(*args, **kwargs)
  File "/var/cache/salt/minion/extmods/states/lxd_image.py", line 222, in present
    _raw=True
  File "/var/cache/salt/minion/extmods/modules/lxd.py", line 2941, in image_from_file
    image = client.images.create(data, public=public, wait=True)
  File "/usr/local/lib/python2.7/dist-packages/pylxd/models/image.py", line 135, in create
    response.json()['operation'])
  File "/usr/local/lib/python2.7/dist-packages/pylxd/models/operation.py", line 32, in wait_for_operation
    operation.wait()
  File "/usr/local/lib/python2.7/dist-packages/pylxd/models/operation.py", line 63, in wait
    raise exceptions.LXDAPIException(response)
LXDAPIException: Image with same fingerprint already exists

local:
----------
          ID: lxd_client
    Function: pkg.installed
      Result: True
     Comment: All specified packages are already installed
     Started: 13:05:35.808193
    Duration: 1416.817 ms
     Changes:   
----------
          ID: lxd_python
    Function: pkg.installed
      Result: True
     Comment: All specified packages are already installed
     Started: 13:05:37.225428
    Duration: 16.218 ms
     Changes:   
----------
          ID: lxd_lxd
    Function: pkg.installed
      Result: True
     Comment: All specified packages are already installed
     Started: 13:05:37.241952
    Duration: 15.828 ms
     Changes:   
----------
          ID: lxd_lxd
    Function: lxd.init
      Result: True
     Comment: LXD is already initialized
     Started: 13:05:37.263475
    Duration: 1.208 ms
     Changes:   
----------
          ID: lxd_config_password
    Function: lxd.config_managed
        Name: core.trust_password
      Result: True
     Comment: Config value "core.trust_password" successfully set.
     Started: 13:05:37.265479
    Duration: 378.662 ms
     Changes:   
              ----------
              core.trust_password:
                  Changed the password
----------
          ID: lxd_profile_local_autostart
    Function: lxd_profile.present
        Name: autostart
      Result: True
     Comment: No changes
     Started: 13:05:37.648731
    Duration: 43.904 ms
     Changes:   
----------
          ID: lxd_profile_local_shared_mount
    Function: lxd_profile.present
        Name: shared_mount
      Result: False
     Comment: The profile already exists
     Started: 13:05:37.693039
    Duration: 29.37 ms
     Changes:   
----------
          ID: lxd_profile_local_small
    Function: lxd_profile.present
        Name: small
      Result: True
     Comment: No changes
     Started: 13:05:37.722738
    Duration: 25.06 ms
     Changes:   
----------
          ID: lxd_image_local_busybox
    Function: lxd_image.present
        Name: busybox
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1851, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1795, in wrapper
                  return f(*args, **kwargs)
                File "/var/cache/salt/minion/extmods/states/lxd_image.py", line 222, in present
                  _raw=True
                File "/var/cache/salt/minion/extmods/modules/lxd.py", line 2941, in image_from_file
                  image = client.images.create(data, public=public, wait=True)
                File "/usr/local/lib/python2.7/dist-packages/pylxd/models/image.py", line 135, in create
                  response.json()['operation'])
                File "/usr/local/lib/python2.7/dist-packages/pylxd/models/operation.py", line 32, in wait_for_operation
                  operation.wait()
                File "/usr/local/lib/python2.7/dist-packages/pylxd/models/operation.py", line 63, in wait
                  raise exceptions.LXDAPIException(response)
              LXDAPIException: Image with same fingerprint already exists
     Started: 13:05:37.752493
    Duration: 303.445 ms
     Changes:   
----------
          ID: lxd_image_local_xenial_amd64
    Function: lxd_image.present
        Name: xenial/amd64
      Result: True
     Comment: 0 changes
     Started: 13:05:38.056419
    Duration: 29.935 ms
     Changes:   
----------
          ID: lxd_image_local_trusty_amd64
    Function: lxd_image.present
        Name: trusty_amd64
      Result: True
     Comment: 0 changes
     Started: 13:05:38.086638
    Duration: 78.868 ms
     Changes:   
----------
          ID: lxd_image_local_trusty_amd64_url
    Function: lxd_image.present
        Name: trusty_amd64_url
      Result: True
     Comment: 1 changes
     Started: 13:05:38.165780
    Duration: 881.105 ms
     Changes:   
              ----------
              aliases:
                  - Removed alias "trusty_busybox_amd64"
----------
          ID: lxd_container_local_ubuntu-xenial0
    Function: lxd_container.present
        Name: ubuntu-xenial0
      Result: True
     Comment: No changes
     Started: 13:05:39.053469
    Duration: 35.99 ms
     Changes:   
----------
          ID: lxd_container_local_ubuntu-xenial2
    Function: lxd_container.present
        Name: ubuntu-xenial2
      Result: True
     Comment: No changes
     Started: 13:05:39.090472
    Duration: 52.65 ms
     Changes:   
----------
          ID: lxd_container_local_ubuntu-xenial3
    Function: lxd_container.present
        Name: ubuntu-xenial3
      Result: True
     Comment: No changes
     Started: 13:05:39.143376
    Duration: 44.123 ms
     Changes:   
----------
          ID: lxd_container_local_ubuntu-xenial3_check_executed
    Function: module.run
        Name: lxd.container_execute
      Result: True
     Comment: State was not run because none of the onchanges reqs changed
     Changes:   
----------
          ID: lxd_container_local_ubuntu-xenial3_bse_1
    Function: module.run
        Name: lxd.container_execute
      Result: True
     Comment: State was not run because onfail req did not change
     Changes:   
----------
          ID: lxd_container_local_ubuntu-xenial3_bsc_2
    Function: module.run
        Name: lxd.container_file_put
      Result: True
     Comment: State was not run because onfail req did not change
     Changes:   
----------
          ID: lxd_container_local_ubuntu-xenial3_bse_2
    Function: module.run
        Name: lxd.container_execute
      Result: True
     Comment: State was not run because none of the onchanges reqs changed
     Changes:   
----------
          ID: lxd_container_local_ubuntu-xenial3_bse_3
    Function: module.run
        Name: lxd.container_execute
      Result: True
     Comment: State was not run because onfail req did not change
     Changes:   
----------
          ID: lxd_container_local_ubuntu-xenial3_restart
    Function: module.run
        Name: lxd.container_restart
      Result: True
     Comment: State was not run because none of the onchanges reqs changed
     Changes:   
----------
          ID: lxd_container_local_ubuntu-xenial3_make_executed
    Function: module.run
        Name: lxd.container_execute
      Result: True
     Comment: State was not run because none of the onchanges reqs changed
     Changes:   

Summary for local
-------------
Succeeded: 20 (changed=2)
Failed:     2
-------------
Total states run:     22
Total run time:    3.353 s
jochumdev commented 6 years ago

I can't do anything with the busybox image, that image gets created on the fly and i cannot check if its there, the only thing i could do is silence the error.

noelmcloughlin commented 6 years ago

@pcdummy sorry for not replying. Silencing the error is better user experience. thanks.

noelmcloughlin commented 3 years ago

Included in master https://github.com/saltstack-formulas/lxd-formula/commit/909fe5441a082f3ccf8fb7f07108d25ee8a30ffb