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

AttributeError: 'list' object has no attribute 'get' #7639

Open
freyes opened this issue Aug 10, 2022 · 4 comments
Open

AttributeError: 'list' object has no attribute 'get' #7639

freyes opened this issue Aug 10, 2022 · 4 comments
Labels

Comments

@freyes
Copy link

freyes commented Aug 10, 2022

Describe the bug

c7n fails to filter OpenStack instances by tags.

OpenStack has a slightly different semantic for the tags in comparison with AWS, OpenStack tags are a list of values while in AWS is a list of key-value. OpenStack has properties which are equivalent to AWS tags.

Here it's an example of a running instance:

$ openstack --os-compute-api-version 2.26  server show -f json -c tags -c properties juju-383df8-ubuntu-19 
{
  "properties": {
    "juju-controller-uuid": "f3693780-7b65-4675-871e-f848d91a4b68",
    "juju-machine-id": "ubuntu-machine-19",
    "juju-model-uuid": "80ffa965-4ba9-4f0c-8a15-6aeae9383df8",
    "juju-units-deployed": "ubuntu/0",
    "foo": "bar"
  },
  "tags": [
    "foo"
  ]
}

What did you expect to happen?

I expected to get the list of instances that don't have the tag locked set, and I get the error AttributeError: 'list' object has no attribute 'get' instead.

Cloud Provider

OpenStack (Alpha)

Cloud Custodian version and dependency information

Custodian:   0.9.17
Python:      3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]
Platform:    posix.uname_result(sysname='Linux', nodename='maul', release='5.15.0-43-generic', version='#46-Ubuntu SMP Tue Jul 12 10:30:17 UTC 2022', machine='x86_64')
Using venv:  True
Docker: False
Installed: 

PyYAML==6.0
appdirs==1.4.4
argcomplete==2.0.0
attrs==21.4.0
boto3==1.24.10
botocore==1.27.10
c7n==0.9.17
certifi==2022.6.15
cffi==1.15.0
charset-normalizer==2.0.12
cryptography==37.0.2
decorator==5.1.1
docutils==0.17.1
dogpile.cache==1.1.6
idna==3.3
importlib-metadata==4.11.4
importlib-resources==5.7.1
iso8601==1.0.2
jmespath==1.0.0
jsonpatch==1.32
jsonpointer==2.3
jsonschema==4.6.0
keystoneauth1==4.6.0
munch==2.5.0
netifaces==0.11.0
openstacksdk==0.52.0
os-service-types==1.7.0
pbr==5.9.0
pycparser==2.21
pyrsistent==0.18.1
python-dateutil==2.8.2
pyyaml==6.0
requests==2.28.0
requestsexceptions==1.4.0
s3transfer==0.6.0
six==1.16.0
stevedore==3.5.0
tabulate==0.8.9
typing-extensions==4.2.0
urllib3==1.26.9
zipp==3.8.0

Policy

policies:
  - name: test
    resource: openstack.server
    filters:
      - "tag:locked": absent

Relevant log/traceback output

2022-08-10 14:27:50,661: custodian.output:ERROR Error while executing policy
Traceback (most recent call last):
  File "/home/freyes/.local/pipx/venvs/c7n/lib/python3.10/site-packages/c7n/policy.py", line 290, in run
    resources = self.policy.resource_manager.resources()
  File "/home/freyes/.local/pipx/venvs/c7n/lib/python3.10/site-packages/c7n_openstack/query.py", line 99, in resources
    return self.filter_resources(resources)
  File "/home/freyes/.local/pipx/venvs/c7n/lib/python3.10/site-packages/c7n/manager.py", line 111, in filter_resources
    resources = f.process(resources, event)
  File "/home/freyes/.local/pipx/venvs/c7n/lib/python3.10/site-packages/c7n/filters/core.py", line 553, in process
    return super(ValueFilter, self).process(resources, event)
  File "/home/freyes/.local/pipx/venvs/c7n/lib/python3.10/site-packages/c7n/filters/core.py", line 190, in process
    return list(filter(self, resources))
  File "/home/freyes/.local/pipx/venvs/c7n/lib/python3.10/site-packages/c7n/filters/core.py", line 540, in __call__
    matched = self.match(i)
  File "/home/freyes/.local/pipx/venvs/c7n/lib/python3.10/site-packages/c7n/filters/core.py", line 576, in match
    r = self.get_resource_value(self.k, i)
  File "/home/freyes/.local/pipx/venvs/c7n/lib/python3.10/site-packages/c7n/filters/core.py", line 556, in get_resource_value
    return super(ValueFilter, self).get_resource_value(k, i, self.data.get('value_regex'))
  File "/home/freyes/.local/pipx/venvs/c7n/lib/python3.10/site-packages/c7n/filters/core.py", line 246, in get_resource_value
    r = i.get('tags', {}).get(tk, None)
AttributeError: 'list' object has no attribute 'get'

Extra information or context

No response

@Rajath-55
Copy link
Contributor

Hello, I want to work on this issue. Is it available right now?

@freyes
Copy link
Author

freyes commented Sep 12, 2022 via email

@thisisshi
Copy link
Member

@Rajath-55 if you are interested in contributing please take a look at our contribution docs: https://cloudcustodian.io/docs/contribute.html

@Rajath-55
Copy link
Contributor

@thisisshi Thanks! Will go through it.
I am interested in contributing to this issue, and will try to work on it now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants