Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ jobs=4
# W0631(undefined-loop-variable)
# W0703(broad-except)
# W1401(anomalous-backslash-in-string)
# W1514(unspecified-encoding)

disable=C, F, I, R, W0201, W0212, W0221, W0222, W0223, W0231, W0311, W0511, W0602, W0603, W0611, W0613, W0621, W0622, W0631, W0703, W1401
disable=C, F, I, R, W0201, W0212, W0221, W0222, W0223, W0231, W0311, W0511, W0602, W0603, W0611, W0613, W0621, W0622, W0631, W0703, W1401, W1514


[REPORTS]
Expand Down
10 changes: 5 additions & 5 deletions cloudinit/reporting/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def __init__(self,
self._event_types = event_types
self.q = queue.Queue()
self.incarnation_no = self._get_incarnation_no()
self.event_key_prefix = u"{0}|{1}".format(self.EVENT_PREFIX,
self.incarnation_no)
self.event_key_prefix = "{0}|{1}".format(self.EVENT_PREFIX,
self.incarnation_no)
self.publish_thread = threading.Thread(
target=self._publish_event_routine
)
Expand Down Expand Up @@ -200,9 +200,9 @@ def _event_key(self, event):
CLOUD_INIT|<incarnation number>|<event_type>|<event_name>|<uuid>
[|subevent_index]
"""
return u"{0}|{1}|{2}|{3}".format(self.event_key_prefix,
event.event_type, event.name,
uuid.uuid4())
return "{0}|{1}|{2}|{3}".format(self.event_key_prefix,
event.event_type, event.name,
uuid.uuid4())

def _encode_kvp_item(self, key, value):
data = struct.pack(
Expand Down
2 changes: 1 addition & 1 deletion cloudinit/safeyaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def construct_python_unicode(self, node):


_CustomSafeLoader.add_constructor(
u'tag:yaml.org,2002:python/unicode',
'tag:yaml.org,2002:python/unicode',
_CustomSafeLoader.construct_python_unicode)


Expand Down
2 changes: 1 addition & 1 deletion cloudinit/sources/DataSourceNoCloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def _quick_read_instance_id(dirs=None):
try:
data = util.pathprefix2dict(d, required=['meta-data'])
md = util.load_yaml(data['meta-data'])
if iid_key in md:
if md and iid_key in md:
return md[iid_key]
except ValueError:
pass
Expand Down
4 changes: 2 additions & 2 deletions cloudinit/templater.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
LOG = logging.getLogger(__name__)
TYPE_MATCHER = re.compile(r"##\s*template:(.*)", re.I)
BASIC_MATCHER = re.compile(r'\$\{([A-Za-z0-9_.]+)\}|\$([A-Za-z0-9_.]+)')
MISSING_JINJA_PREFIX = u'CI_MISSING_JINJA_VAR/'
MISSING_JINJA_PREFIX = 'CI_MISSING_JINJA_VAR/'


class UndefinedJinjaVariable(JUndefined):
"""Class used to represent any undefined jinja template variable."""

def __str__(self):
return u'%s%s' % (MISSING_JINJA_PREFIX, self._undefined_name)
return '%s%s' % (MISSING_JINJA_PREFIX, self._undefined_name)

def __sub__(self, other):
other = str(other).replace(MISSING_JINJA_PREFIX, '')
Expand Down
8 changes: 4 additions & 4 deletions cloudinit/tests/test_subp.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ def test_subp_handles_bytestrings(self):
tmp_file = self.tmp_path('test.out')
cmd = 'echo HI MOM >> {tmp_file}'.format(tmp_file=tmp_file)
(out, _err) = subp.subp(cmd.encode('utf-8'), shell=True)
self.assertEqual(u'', out)
self.assertEqual(u'', _err)
self.assertEqual('', out)
self.assertEqual('', _err)
self.assertEqual('HI MOM\n', util.load_file(tmp_file))

def test_subp_handles_strings(self):
"""subp can run a string command if shell is True."""
tmp_file = self.tmp_path('test.out')
cmd = 'echo HI MOM >> {tmp_file}'.format(tmp_file=tmp_file)
(out, _err) = subp.subp(cmd, shell=True)
self.assertEqual(u'', out)
self.assertEqual(u'', _err)
self.assertEqual('', out)
self.assertEqual('', _err)
self.assertEqual('HI MOM\n', util.load_file(tmp_file))

def test_subp_handles_utf8(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/unittests/test_datasource/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,13 +912,13 @@ def test_crawl_metadata_returns_structured_data_and_caches_nothing(self):
'PreprovisionedVMType': None,
'PreprovisionedVm': False,
'datasource': {'Azure': {'agent_command': 'my_command'}},
'system_info': {'default_user': {'name': u'myuser'}}}
'system_info': {'default_user': {'name': 'myuser'}}}
expected_metadata = {
'azure_data': {
'configurationsettype': 'LinuxProvisioningConfiguration'},
'imds': NETWORK_METADATA,
'instance-id': EXAMPLE_UUID,
'local-hostname': u'myhost',
'local-hostname': 'myhost',
'random_seed': 'wild'}

crawled_metadata = dsrc.crawl_metadata()
Expand Down Expand Up @@ -1385,7 +1385,7 @@ def test_ovf_env_arrives_in_waagent_dir(self):

def test_ovf_can_include_unicode(self):
xml = construct_valid_ovf_env(data={})
xml = u'\ufeff{0}'.format(xml)
xml = '\ufeff{0}'.format(xml)
dsrc = self._get_ds({'ovfcontent': xml})
dsrc.get_data()

Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/test_datasource/test_configdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from cloudinit.tests.helpers import CiTestCase, ExitStack, mock, populate_dir


PUBKEY = u'ssh-rsa AAAAB3NzaC1....sIkJhq8wdX+4I3A4cYbYP ubuntu@server-460\n'
PUBKEY = 'ssh-rsa AAAAB3NzaC1....sIkJhq8wdX+4I3A4cYbYP ubuntu@server-460\n'
EC2_META = {
'ami-id': 'ami-00000001',
'ami-launch-index': 0,
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/test_datasource/test_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from cloudinit import util

BASE_URL = "http://169.254.169.254"
PUBKEY = u'ssh-rsa AAAAB3NzaC1....sIkJhq8wdX+4I3A4cYbYP ubuntu@server-460\n'
PUBKEY = 'ssh-rsa AAAAB3NzaC1....sIkJhq8wdX+4I3A4cYbYP ubuntu@server-460\n'
EC2_META = {
'ami-id': 'ami-00000001',
'ami-launch-index': '0',
Expand Down
22 changes: 11 additions & 11 deletions tests/unittests/test_datasource/test_scaleway.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ def test_metadata_ok(self, sleep, m_get_cmdline, dhcpv4):
self.assertEqual(self.datasource.get_instance_id(),
MetadataResponses.FAKE_METADATA['id'])
self.assertEqual(self.datasource.get_public_ssh_keys().sort(), [
u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABCCCCC',
u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABDDDDD',
u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABA',
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABCCCCC',
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABDDDDD',
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABA',
].sort())
self.assertEqual(self.datasource.get_hostname(),
MetadataResponses.FAKE_METADATA['hostname'])
Expand Down Expand Up @@ -242,8 +242,8 @@ def test_ssh_keys_only_tags(self):
]
self.datasource.metadata['ssh_public_keys'] = []
self.assertEqual(self.datasource.get_public_ssh_keys().sort(), [
u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABDDDDD',
u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABCCCCC',
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABDDDDD',
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABCCCCC',
].sort())

def test_ssh_keys_only_conf(self):
Expand All @@ -260,9 +260,9 @@ def test_ssh_keys_only_conf(self):
'fingerprint': '2048 06:ff:... login2 (RSA)'
}]
self.assertEqual(self.datasource.get_public_ssh_keys().sort(), [
u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABCCCCC',
u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABDDDDD',
u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABA',
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABCCCCC',
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABDDDDD',
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABA',
].sort())

def test_ssh_keys_both(self):
Expand All @@ -282,9 +282,9 @@ def test_ssh_keys_both(self):
'fingerprint': '2048 06:ff:... login2 (RSA)'
}]
self.assertEqual(self.datasource.get_public_ssh_keys().sort(), [
u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABCCCCC',
u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABDDDDD',
u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABA',
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABCCCCC',
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABDDDDD',
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABA',
].sort())

@mock.patch('cloudinit.sources.DataSourceScaleway.EphemeralDHCPv4')
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/test_handler/test_handler_apt_source_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from cloudinit.tests import helpers as t_help

EXPECTEDKEY = u"""-----BEGIN PGP PUBLIC KEY BLOCK-----
EXPECTEDKEY = """-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1

mI0ESuZLUgEEAKkqq3idtFP7g9hzOu1a8+v8ImawQN4TrvlygfScMU1TIS1eC7UQ
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/test_handler/test_handler_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_debug_write(self, m_locale):
m_locale.return_value = 'en_US.UTF-8'
cfg = {
'abc': '123',
'c': u'\u20a0',
'c': '\u20a0',
'debug': {
'verbose': True,
# Does not actually write here due to mocking...
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def test_given_log_level_used(self):
class TestMessageFromString(helpers.TestCase):

def test_unicode_not_messed_up(self):
roundtripped = util.message_from_string(u'\n').as_string()
roundtripped = util.message_from_string('\n').as_string()
self.assertNotIn('\x00', roundtripped)


Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ passenv=
[testenv:flake8]
basepython = python3
deps =
flake8==3.8.2
flake8==3.9.2
commands = {envpython} -m flake8 {posargs:cloudinit/ tests/ tools/ setup.py}

# https://github.com/gabrielfalcao/HTTPretty/issues/223
Expand All @@ -23,7 +23,7 @@ setenv =
basepython = python3
deps =
# requirements
pylint==2.9.3
pylint==2.11.1
# test-requirements because unit tests are now present in cloudinit tree
-r{toxinidir}/test-requirements.txt
-r{toxinidir}/integration-requirements.txt
Expand Down