Python3: Replace dict.iterkeys with six.iterkeys

This also adds a check to murano/hacking/checks.py that should
catch this error in the future.

Blueprint murano-python-3-support

Change-Id: I172e257d0b8a89eff89e35a2f87bb42d769cad62
This commit is contained in:
Ravi Shekhar Jethani 2016-01-18 02:05:43 -08:00 committed by Abhishek Kekane
parent 7b7dfdf7fb
commit d99904e38b
6 changed files with 23 additions and 11 deletions

View File

@ -8,3 +8,4 @@ Murano Specific Commandments
- [M322] Method's default argument shouldn't be mutable.
- [M323] Python 3: do not use dict.iteritems.
- [M324] Python 3: do not use dict.iterkeys.

View File

@ -96,7 +96,7 @@ class CloudifyToscaPackage(package_base.PackageBase):
prop['Default'] = value['default']
contracts[name] = prop
for name in outputs.iterkeys():
for name in six.iterkeys(outputs):
contracts[name] = {
'Contract': YAQL('$.string()'),
'Usage': 'Out'
@ -107,7 +107,7 @@ class CloudifyToscaPackage(package_base.PackageBase):
def _generate_describe_method(self, inputs):
input_values = {
name: YAQL('$.' + name)
for name in inputs.iterkeys()
for name in six.iterkeys(inputs)
}
return {
@ -123,7 +123,7 @@ class CloudifyToscaPackage(package_base.PackageBase):
def _generate_update_outputs_method(outputs):
assignments = [
{YAQL('$.' + name): YAQL('$outputs.get({0})'.format(name))}
for name in outputs.iterkeys()
for name in six.iterkeys(outputs)
]
return {
'Arguments': [{
@ -145,7 +145,8 @@ class CloudifyToscaPackage(package_base.PackageBase):
def _generate_application_ui_section(self, inputs):
section = {
key: YAQL('$.appConfiguration.' + key) for key in inputs.iterkeys()
key: YAQL(
'$.appConfiguration.' + key) for key in six.iterkeys(inputs)
}
section.update({
'?': {

View File

@ -14,6 +14,8 @@
import weakref
import six
from murano.dsl import constants
from murano.dsl import dsl
from murano.dsl import dsl_types
@ -88,7 +90,7 @@ class MuranoObject(dsl_types.MuranoObject):
used_names = set()
names = set(self.__type.properties)
if init:
names.update(init.arguments_scheme.iterkeys())
names.update(six.iterkeys(init.arguments_scheme))
last_errors = len(names)
init_args = {}
while True:

View File

@ -23,6 +23,7 @@ import uuid
from muranoclient.common import exceptions as muranoclient_exc
from oslo_config import cfg
from oslo_log import log as logging
import six
from murano.common.i18n import _LE, _LI
from murano.dsl import constants
@ -51,7 +52,7 @@ class ApiPackageLoader(package_loader.MuranoPackageLoader):
def load_class_package(self, class_name, version_spec):
packages = self._class_cache.get(class_name)
if packages:
version = version_spec.select(packages.iterkeys())
version = version_spec.select(six.iterkeys(packages))
if version:
return packages[version]
@ -70,7 +71,7 @@ class ApiPackageLoader(package_loader.MuranoPackageLoader):
def load_package(self, package_name, version_spec):
packages = self._package_cache.get(package_name)
if packages:
version = version_spec.select(packages.iterkeys())
version = version_spec.select(six.iterkeys(packages))
if version:
return packages[version]
@ -237,7 +238,7 @@ class DirectoryPackageLoader(package_loader.MuranoPackageLoader):
packages = self._packages_by_class.get(class_name)
if not packages:
raise exceptions.NoPackageForClassFound(class_name)
version = version_spec.select(packages.iterkeys())
version = version_spec.select(six.iterkeys(packages))
if not version:
raise exceptions.NoPackageForClassFound(class_name)
return packages[version]
@ -246,7 +247,7 @@ class DirectoryPackageLoader(package_loader.MuranoPackageLoader):
packages = self._packages_by_name.get(package_name)
if not packages:
raise exceptions.NoPackageFound(package_name)
version = version_spec.select(packages.iterkeys())
version = version_spec.select(six.iterkeys(packages))
if not version:
raise exceptions.NoPackageFound(package_name)
return packages[version]

View File

@ -39,10 +39,17 @@ def no_mutable_default_args(logical_line):
def check_python3_no_iteritems(logical_line):
if re.search(r".*\.iteritems\(\)", logical_line):
msg = ("M322: Use six.iteritems() instead of dict.iteritems().")
msg = ("M323: Use six.iteritems() instead of dict.iteritems().")
yield(0, msg)
def check_python3_no_iterkeys(logical_line):
if re.search(r".*\.iterkeys\(\)", logical_line):
msg = ("M324: Use six.iterkeys() instead of dict.iterkeys().")
yield(0, msg)
def factory(register):
register(no_mutable_default_args)
register(check_python3_no_iteritems)
register(check_python3_no_iterkeys)

View File

@ -177,7 +177,7 @@ class HotPackage(package_base.PackageBase):
@staticmethod
def _translate_outputs(hot):
contract = {}
for key in (hot.get('outputs') or {}).iterkeys():
for key in six.iterkeys(hot.get('outputs') or {}):
contract[key] = YAQL("$.string()")
return {
'templateOutputs': {