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
2 changes: 1 addition & 1 deletion cloudinit/net/network_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def _is_default_route(self, route):
return (
route.get('prefix') == 0
and route.get('network') in default_nets
)
)


class NetworkStateInterpreter(metaclass=CommandHandlerMeta):
Expand Down
12 changes: 6 additions & 6 deletions cloudinit/reporting/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def _decode_kvp_item(self, record_data):
v = (
record_data[
self.HV_KVP_EXCHANGE_MAX_KEY_SIZE:self.HV_KVP_RECORD_SIZE
].decode('utf-8').strip('\x00'))
].decode('utf-8').strip('\x00'))

return {'key': k, 'value': v}

Expand Down Expand Up @@ -265,11 +265,11 @@ def _encode_event(self, event):
"""
key = self._event_key(event)
meta_data = {
"name": event.name,
"type": event.event_type,
"ts": (datetime.utcfromtimestamp(event.timestamp)
.isoformat() + 'Z'),
}
"name": event.name,
"type": event.event_type,
"ts": (datetime.utcfromtimestamp(event.timestamp)
.isoformat() + 'Z'),
}
if hasattr(event, self.RESULT_KEY):
meta_data[self.RESULT_KEY] = event.result
meta_data[self.MSG_KEY] = event.description
Expand Down
6 changes: 4 additions & 2 deletions cloudinit/sources/helpers/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ def swap_bytestring(s, width=2):
return ''.join(dd)

parts = current_id.split('-')
swapped_id = '-'.join([
swapped_id = '-'.join(
[
swap_bytestring(parts[0]),
swap_bytestring(parts[1]),
swap_bytestring(parts[2]),
parts[3],
parts[4]
])
]
)

return previous_id == swapped_id

Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/test_datasource/test_aliyun.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_with_mock_server(self, m_is_aliyun):
self.assertEqual('aliyun', self.ds.cloud_name)
self.assertEqual('ec2', self.ds.platform)
self.assertEqual(
'metadata (http://100.100.100.200)', self.ds.subplatform)
'metadata (http://100.100.100.200)', self.ds.subplatform)

@mock.patch("cloudinit.sources.DataSourceAliYun._is_aliyun")
def test_returns_false_when_not_on_aliyun(self, m_is_aliyun):
Expand Down
8 changes: 4 additions & 4 deletions tests/unittests/test_datasource/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ def construct_valid_ovf_env(data=None, pubkeys=None,
"ipv4": {
"subnet": [
{
"prefix": "24",
"address": "10.0.0.0"
"prefix": "24",
"address": "10.0.0.0"
}
],
"ipAddress": [
{
"privateIpAddress": "10.0.0.4",
"publicIpAddress": "104.46.124.81"
"privateIpAddress": "10.0.0.4",
"publicIpAddress": "104.46.124.81"
}
]
}
Expand Down
15 changes: 8 additions & 7 deletions tests/unittests/test_datasource/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,8 @@ def test_aws_inaccessible_imds_service_fails_with_retries(self):
md=None)

conn_error = requests.exceptions.ConnectionError(
'[Errno 113] no route to host')
'[Errno 113] no route to host'
)

mock_success = mock.MagicMock(contents=b'fakesuccess')
mock_success.ok.return_value = True
Expand Down Expand Up @@ -777,12 +778,12 @@ def test_invalid_ipv4_ipv6_cidr_metadata_logged_with_defaults(self):
'2600:1f16:292:100:f153:12a3:c37c:11f9/128'],
ec2.get_secondary_addresses(invalid_cidr_md, self.mac))
expected_logs = [
"WARNING: Could not parse subnet-ipv4-cidr-block"
" something-unexpected for mac 06:17:04:d7:26:ff."
" ipv4 network config prefix defaults to /24",
"WARNING: Could not parse subnet-ipv6-cidr-block"
" not/sure/what/this/is for mac 06:17:04:d7:26:ff."
" ipv6 network config prefix defaults to /128"
"WARNING: Could not parse subnet-ipv4-cidr-block"
" something-unexpected for mac 06:17:04:d7:26:ff."
" ipv4 network config prefix defaults to /24",
"WARNING: Could not parse subnet-ipv6-cidr-block"
" not/sure/what/this/is for mac 06:17:04:d7:26:ff."
" ipv6 network config prefix defaults to /128"
]
logs = self.logs.getvalue()
for log in expected_logs:
Expand Down
39 changes: 23 additions & 16 deletions tests/unittests/test_datasource/test_scaleway.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,25 +371,32 @@ def test_network_config_ipv6_ok(self, m_get_cmdline, fallback_nic):
m_get_cmdline.return_value = 'scaleway'
fallback_nic.return_value = 'ens2'
self.datasource.metadata['ipv6'] = {
'address': '2000:abc:4444:9876::42:999',
'gateway': '2000:abc:4444:9876::42:000',
'netmask': '127',
}
'address': '2000:abc:4444:9876::42:999',
'gateway': '2000:abc:4444:9876::42:000',
'netmask': '127',
}

netcfg = self.datasource.network_config
resp = {'version': 1,
'config': [{
'type': 'physical',
'name': 'ens2',
'subnets': [{'type': 'dhcp4'},
{'type': 'static',
'address': '2000:abc:4444:9876::42:999',
'gateway': '2000:abc:4444:9876::42:000',
'netmask': '127', }
]

}]
resp = {
'version': 1,
'config': [
{
'type': 'physical',
'name': 'ens2',
'subnets': [
{
'type': 'dhcp4'
},
{
'type': 'static',
'address': '2000:abc:4444:9876::42:999',
'gateway': '2000:abc:4444:9876::42:000',
'netmask': '127',
}
]
}
]
}
self.assertEqual(netcfg, resp)

@mock.patch('cloudinit.sources.DataSourceScaleway.net.find_fallback_nic')
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/test_distros/test_netconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def test_apply_network_config_ipv6_rh(self):
NETWORKING_IPV6=yes
IPV6_AUTOCONF=no
"""),
}
}
# rh_distro.apply_network_config(V1_NET_CFG_IPV6, False)
self._apply_and_verify(self.distro.apply_network_config,
V1_NET_CFG_IPV6,
Expand Down Expand Up @@ -656,7 +656,7 @@ def test_apply_network_config_v1_without_netplan(self):
IP=dhcp
Interface=eth1
"""),
}
}

# ub_distro.apply_network_config(V1_NET_CFG, False)
self._apply_and_verify(self.distro.apply_network_config,
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/test_ds_identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,11 +1040,11 @@ def _print_run_output(rc, out, err, cfg, files):
'Ec2-E24Cloud': {
'ds': 'Ec2',
'files': {P_SYS_VENDOR: 'e24cloud\n'},
},
},
'Ec2-E24Cloud-negative': {
'ds': 'Ec2',
'files': {P_SYS_VENDOR: 'e24cloudyday\n'},
}
}
}

# vi: ts=4 expandtab
23 changes: 14 additions & 9 deletions tests/unittests/test_handler/test_handler_puppet.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,20 @@ def test_handler_puppet_writes_csr_attributes_file(self, m_subp, m_auto):
mycloud.distro = mock.MagicMock()
cfg = {
'puppet': {
'csr_attributes': {
'custom_attributes': {
'1.2.840.113549.1.9.7': '342thbjkt82094y0ut'
'hhor289jnqthpc2290'},
'extension_requests': {
'pp_uuid': 'ED803750-E3C7-44F5-BB08-41A04433FE2E',
'pp_image_name': 'my_ami_image',
'pp_preshared_key': '342thbjkt82094y0uthhor289jnqthpc2290'}
}}}
'csr_attributes': {
'custom_attributes': {
'1.2.840.113549.1.9.7':
'342thbjkt82094y0uthhor289jnqthpc2290'
},
'extension_requests': {
'pp_uuid': 'ED803750-E3C7-44F5-BB08-41A04433FE2E',
'pp_image_name': 'my_ami_image',
'pp_preshared_key':
'342thbjkt82094y0uthhor289jnqthpc2290'
}
}
}
}
csr_attributes = 'cloudinit.config.cc_puppet.' \
'PUPPET_CSR_ATTRIBUTES_PATH'
with mock.patch(csr_attributes, self.csr_attributes_path):
Expand Down
18 changes: 9 additions & 9 deletions tests/unittests/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -3332,7 +3332,7 @@ def test_from_v2_vlan_mtu(self):
USERCTL=no
VLAN=yes
""")
}
}
self._compare_files_to_expected(
expected, self._render_and_read(network_config=v2data))

Expand Down Expand Up @@ -3406,7 +3406,7 @@ def test_from_v2_route_metric(self):
TYPE=Ethernet
USERCTL=no
"""),
}
}
for dhcp_ver in ('dhcp4', 'dhcp6'):
v2data = copy.deepcopy(v2base)
if dhcp_ver == 'dhcp6':
Expand Down Expand Up @@ -4765,13 +4765,13 @@ def test_select_none_found_raises(self, m_eni_avail, m_sysc_avail):
def test_sysconfig_available_uses_variant_mapping(self, m_distro, m_avail):
m_avail.return_value = True
distro_values = [
('opensuse', '', ''),
('opensuse-leap', '', ''),
('opensuse-tumbleweed', '', ''),
('sles', '', ''),
('centos', '', ''),
('fedora', '', ''),
('redhat', '', ''),
('opensuse', '', ''),
('opensuse-leap', '', ''),
('opensuse-tumbleweed', '', ''),
('sles', '', ''),
('centos', '', ''),
('fedora', '', ''),
('redhat', '', ''),
]
for (distro_name, distro_version, flavor) in distro_values:
m_distro.return_value = (distro_name, distro_version, flavor)
Expand Down
4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ basepython = python2.7
deps = -r{toxinidir}/test-requirements.txt

[flake8]
# E121: continuation line under-indented for hanging indent
# E123: closing bracket does not match indentation of opening bracket’s line
# E126: continuation line over-indented for hanging indent
# E226: missing whitespace around arithmetic operator
# W503: line break before binary operator
# W504: line break after binary operator
ignore=E121,E123,E126,E226,W503,W504
ignore=E126,E226,W503,W504
exclude = .venv,.tox,dist,doc,*egg,.git,build,tools
per-file-ignores =
cloudinit/cmd/main.py:E402
Expand Down