Make sure security_groups is always a list

In https://github.com/ansible/ansible/issues/24675 we see that sometimes
security_groups is coming back None. The data model in shade says it's a
list, so make sure it is one.

Change-Id: I6db45ba7c3d630812ea58353d3eaddbb98cb8c1f
This commit is contained in:
Monty Taylor 2017-05-17 12:02:31 -05:00
parent 750e0a9803
commit b9872da5f0
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
2 changed files with 4 additions and 2 deletions

View File

@ -39,7 +39,6 @@ _SERVER_FIELDS = (
'private_v4',
'public_v4',
'public_v6',
'security_groups',
'status',
'updated',
'user_id',
@ -441,6 +440,9 @@ class Normalizer(object):
short_key = key.split(':')[1]
ret[short_key] = _pop_or_get(server, key, None, self.strict_mode)
# Protect against security_groups being None
ret['security_groups'] = server.pop('security_groups', None) or []
for field in _SERVER_FIELDS:
ret[field] = server.pop(field, None)
ret['interface_ip'] = ''

View File

@ -407,7 +407,7 @@ def expand_server_security_groups(cloud, server):
groups = cloud.list_server_security_groups(server)
except exc.OpenStackCloudException:
groups = []
server['security_groups'] = groups
server['security_groups'] = groups or []
def get_hostvars_from_server(cloud, server, mounts=None):