GoogleCloudPlatform / deploymentmanager-samples

Deployment Manager samples and templates.
Apache License 2.0
939 stars 718 forks source link

The template is incompatible with Python3 - AttributeError: 'dict' object has no attribute 'iteritems' #516

Closed georgezoto closed 4 years ago

georgezoto commented 4 years ago

Hello there GCP Team,

I just finished the Deployment Manager - Full Production Qwiklab at https://google.qwiklabs.com/focuses/981?parent=catalog and I see an issue with container_helper.py available at: https://github.com/GoogleCloudPlatform/deploymentmanager-samples/blob/master/examples/v2/common/python/container_helper.py

The issue comes after deploying an application using the Deployment Manager: gcloud deployment-manager deployments create advanced-configuration --config nodejs.yaml

message: |- The template is incompatible with Python3. Please fix the following errors: Exception in container_vm.py Traceback (most recent call last): return constructor[m](evaluation_context) File "container_vm.py", line 48, in GenerateConfig File "container_helper.py", line 32, in GenerateManifest AttributeError: 'dict' object has no attribute 'iteritems' Resource: container_vm.py Resource: config https://cloud.google.com/deployment-manager/docs/migrate-to-python3

As you might know, in python3, dict.iteritems is no longer available.

Line 32 should instead be corrected to: from future.utils import iteritems

for key, value in iteritems(context.properties['dockerEnv']):

Happy to help more if needed 😃, George Zoto

andudo commented 4 years ago

Hi George,

Thank you for reporting this issue!

I added a fix for this (and some other templates) - 001516f.

Please confirm that: a) the fix is working for you; b) the error that you mentioned was a warning and wasn't blocking you from completing a deployment.

georgezoto commented 4 years ago

Thank you @andudo for updating all these files. This was a breaking bug and not just a warning previously preventing me from completing this lab.

Using library six seems to be working but I get the following warning:

gcloud deployment-manager deployments create advanced-configuration --config nodejs.yaml The fingerprint of the deployment is ...== Waiting for create [operation-...]...done. WARNING: Create operation operation-... completed with warnings: --- code: NOT_CRITICAL_ERROR message: |- The template produces different results with Python3 and Python2. This could be because of the non determinism of your configuration, or a potential incompatibility with Python3. Make sure that your templates are compatible with Python3. https://cloud.google.com/deployment-manager/docs/migrate-to-python3

Also I did a quick search in this repository and I found the following files that might need to be updated as well: internal_lb_haproxy/instance.py: for key, value in context.properties['metadata'].iteritems(): internal_lb_haproxy/instance.py: for key, value in context.properties['metadata-from-file'].iteritems(): waiter/instance.py: for key, value in context.properties['metadata'].iteritems():

Let me know is this is helpful, George

andudo commented 4 years ago

Could you provide the config files you are using, with which you get this warning message? I don't get this warning when using examples/v2/nodejs/python/nodejs.yaml from this repo.

As for the other files that you found, we'll do some additional clean up and fix these. Thank you for pointing this out!