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

Key error with salt.utils.cloud.cache_node and EC2 #33162

Closed
jfindlay opened this issue May 11, 2016 · 1 comment

Comments

Projects
None yet
3 participants
@jfindlay
Copy link
Contributor

commented May 11, 2016

Description of Issue/Question

salt.cloud.clouds.ec2._get_node returns data inconsistent with what salt.utils.cloud.cache_node expects. It is returning a dictionary with a single key, value pair, whose key seems to be the name the cache_node function is looking for:

{'jmoney-git-ec2-amazon-6':
  {'amiLaunchIndex': '0',
   ...
   'keyName': 'jmoney',
   'launchTime': '2016-05-10T23:00:26.000Z',
   'monitoring': {'state': 'disabled'},
   'name': 'jmoney-git-ec2-amazon-6',
   ...
   'virtualizationType': 'hvm'}
}

Contrast this with a digital ocean node dictionary, which has the required name attribute in the top level dictionary and does not cause the stack trace:

{
  ...
  u'kernel': None,
  u'locked': True,
  u'memory': 2048,
  u'name': u'jmoney-stable-do-fedora-23',
  u'networks': {u'v4': [], u'v6': []},
  u'next_backup_window': None,
  ...
}

Setup

Provision an amazon VM: salt-cloud -p amazon-6 jmoney-git-ec2-amazon-6.

Steps to Reproduce Issue

# salt-call --local cloud.has_instance jmoney-git-ec2-amazon-6
[INFO    ] Starting new HTTPS connection (1): api.digitalocean.com
[INFO    ] Starting new HTTPS connection (1): ec2.us-east-1.amazonaws.com
[INFO    ] Starting new HTTPS connection (1): identity.api.rackspacecloud.com
[INFO    ] Starting new HTTPS connection (1): ec2.us-east-1.amazonaws.com
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
KeyError: 'name'
Traceback (most recent call last):
  File "/usr/local/bin/salt-call", line 6, in <module>
    exec(compile(open(__file__).read(), __file__, 'exec'))
  File "/root/salt/scripts/salt-call", line 11, in <module>
    salt_call()
  File "/root/salt/salt/scripts.py", line 341, in salt_call
    client.run()
  File "/root/salt/salt/cli/call.py", line 53, in run
    caller.run()
  File "/root/salt/salt/cli/caller.py", line 133, in run
    ret = self.call()
  File "/root/salt/salt/cli/caller.py", line 196, in call
    ret['return'] = func(*args, **kwargs)
  File "/root/salt/salt/modules/cloud.py", line 149, in has_instance
    data = get_instance(name, provider)
  File "/root/salt/salt/modules/cloud.py", line 175, in get_instance
    data = action(fun='show_instance', names=[name], provider=provider)
  File "/root/salt/salt/modules/cloud.py", line 234, in action
    info = client.action(fun, cloudmap, names, provider, instance, kwargs)
  File "/root/salt/salt/cloud/__init__.py", line 482, in action
    return mapper.do_action(names, kwargs)
  File "/root/salt/salt/cloud/__init__.py", line 1511, in do_action
    vm_name, call='action'
  File "/root/salt/salt/cloud/clouds/ec2.py", line 3171, in show_instance
    salt.utils.cloud.cache_node(node, __active_provider_name__, __opts__)
  File "/root/salt/salt/utils/cloud.py", line 2821, in cache_node
    path = os.path.join(prov_dir, '{0}.p'.format(node['name']))
KeyError: 'name'

Versions Report

# salt-call --versions
Salt Version:
           Salt: 2015.8.8.2

Dependency Versions:
         Jinja2: 2.7.3
       M2Crypto: 0.21.1
           Mako: 1.0.0
         PyYAML: 3.11
          PyZMQ: 14.4.0
         Python: 2.7.9 (default, Mar  1 2015, 12:57:24)
           RAET: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5
           cffi: 0.8.6
       cherrypy: Not Installed
       dateutil: Not Installed
          gitdb: 0.5.4
      gitpython: 0.3.2 RC1
          ioflo: Not Installed
        libgit2: Not Installed
        libnacl: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.2
   mysql-python: Not Installed
      pycparser: 2.10
       pycrypto: 2.6.1
         pygit2: Not Installed
   python-gnupg: Not Installed
          smmap: 0.8.2
        timelib: Not Installed

System Versions:
           dist: debian 8.4
        machine: x86_64
        release: 3.16.0-4-amd64
         system: debian 8.4
@cachedout

This comment has been minimized.

Copy link
Collaborator

commented May 12, 2016

Should be fixed by #33164

@cachedout cachedout closed this May 12, 2016

sergeizv added a commit to sergeizv/salt that referenced this issue Mar 2, 2017

Revert "cloud.clouds.ec2: cache each named node (saltstack#33164)"
This reverts commit b3805d8 ("cloud.clouds.ec2: cache each named
node (saltstack#33164)").

Commit 25771fc ("_get_node return instance info directly, not a
dict of instances") from 2016.3 feature release changed how the result
of _get_node should be interpreted. Before it was like

  res = _get_node(...)
  node = res[name]

and after the commit it became

  node = _get_node(...)

Commit b3805d8 ("cloud.clouds.ec2: cache each named node (saltstack#33164)")
submitted into 2015.8 as a bugfix for saltstack#33162 added loops over the keys
of a dictionary returned by _get_node, fixing
salt.utils.cloud.cache_node calls in queue_instances() and
show_instance().

But after being merged into 2016.3 with merge commit 679200a
("Merge branch '2015.8' into '2016.3'"), the commit in question
reintroduced the bug on 2016.3 because of changed return value of
_get_node.

Fixes saltstack#39782

@sergeizv sergeizv referenced this issue Mar 2, 2017

Merged

Fix 39782 #39784

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.