Scaleway: Fix DatasourceScaleway to avoid backtrace (#128)
BZ: 1869757 commit 9e3ac98097ed1c7f49ec8975a40aec7229231aae Author: Louis Bouchard <bouchard.louis@gmail.com> Date: Wed Jan 29 16:55:09 2020 +0100 Scaleway: Fix DatasourceScaleway to avoid backtrace (#128) Make sure network_config is created when self._network_config is unset. Co-authored-by: Scott Moser <smoser@brickies.net> Signed-off-by: Eduardo Otubo <otubo@redhat.com>
This commit is contained in:
parent
9f56f665cd
commit
f536fb57ea
@ -0,0 +1,107 @@
|
|||||||
|
From 9e3ac98097ed1c7f49ec8975a40aec7229231aae Mon Sep 17 00:00:00 2001
|
||||||
|
From: Louis Bouchard <bouchard.louis@gmail.com>
|
||||||
|
Date: Wed, 29 Jan 2020 16:55:09 +0100
|
||||||
|
Subject: [PATCH] Scaleway: Fix DatasourceScaleway to avoid backtrace (#128)
|
||||||
|
|
||||||
|
Make sure network_config is created when self._network_config is unset.
|
||||||
|
|
||||||
|
Co-authored-by: Scott Moser <smoser@brickies.net>
|
||||||
|
---
|
||||||
|
cloudinit/sources/DataSourceScaleway.py | 9 +++-
|
||||||
|
.../test_datasource/test_scaleway.py | 49 +++++++++++++++++++
|
||||||
|
2 files changed, 56 insertions(+), 2 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/cloudinit/sources/DataSourceScaleway.py b/cloudinit/sources/DataSourceScaleway.py
|
||||||
|
index b573b382..83c2bf65 100644
|
||||||
|
--- a/cloudinit/sources/DataSourceScaleway.py
|
||||||
|
+++ b/cloudinit/sources/DataSourceScaleway.py
|
||||||
|
@@ -188,7 +188,7 @@ class DataSourceScaleway(sources.DataSource):
|
||||||
|
self.retries = int(self.ds_cfg.get('retries', DEF_MD_RETRIES))
|
||||||
|
self.timeout = int(self.ds_cfg.get('timeout', DEF_MD_TIMEOUT))
|
||||||
|
self._fallback_interface = None
|
||||||
|
- self._network_config = None
|
||||||
|
+ self._network_config = sources.UNSET
|
||||||
|
|
||||||
|
def _crawl_metadata(self):
|
||||||
|
resp = url_helper.readurl(self.metadata_address,
|
||||||
|
@@ -227,7 +227,12 @@ class DataSourceScaleway(sources.DataSource):
|
||||||
|
Configure networking according to data received from the
|
||||||
|
metadata API.
|
||||||
|
"""
|
||||||
|
- if self._network_config:
|
||||||
|
+ if self._network_config is None:
|
||||||
|
+ LOG.warning('Found None as cached _network_config. '
|
||||||
|
+ 'Resetting to %s', sources.UNSET)
|
||||||
|
+ self._network_config = sources.UNSET
|
||||||
|
+
|
||||||
|
+ if self._network_config != sources.UNSET:
|
||||||
|
return self._network_config
|
||||||
|
|
||||||
|
if self._fallback_interface is None:
|
||||||
|
diff --git a/tests/unittests/test_datasource/test_scaleway.py b/tests/unittests/test_datasource/test_scaleway.py
|
||||||
|
index f96bf0a2..1b4dd0ad 100644
|
||||||
|
--- a/tests/unittests/test_datasource/test_scaleway.py
|
||||||
|
+++ b/tests/unittests/test_datasource/test_scaleway.py
|
||||||
|
@@ -7,6 +7,7 @@ import requests
|
||||||
|
|
||||||
|
from cloudinit import helpers
|
||||||
|
from cloudinit import settings
|
||||||
|
+from cloudinit import sources
|
||||||
|
from cloudinit.sources import DataSourceScaleway
|
||||||
|
|
||||||
|
from cloudinit.tests.helpers import mock, HttprettyTestCase, CiTestCase
|
||||||
|
@@ -403,3 +404,51 @@ class TestDataSourceScaleway(HttprettyTestCase):
|
||||||
|
|
||||||
|
netcfg = self.datasource.network_config
|
||||||
|
self.assertEqual(netcfg, '0xdeadbeef')
|
||||||
|
+
|
||||||
|
+ @mock.patch('cloudinit.sources.DataSourceScaleway.net.find_fallback_nic')
|
||||||
|
+ @mock.patch('cloudinit.util.get_cmdline')
|
||||||
|
+ def test_network_config_unset(self, m_get_cmdline, fallback_nic):
|
||||||
|
+ """
|
||||||
|
+ _network_config will be set to sources.UNSET after the first boot.
|
||||||
|
+ Make sure it behave correctly.
|
||||||
|
+ """
|
||||||
|
+ m_get_cmdline.return_value = 'scaleway'
|
||||||
|
+ fallback_nic.return_value = 'ens2'
|
||||||
|
+ self.datasource.metadata['ipv6'] = None
|
||||||
|
+ self.datasource._network_config = sources.UNSET
|
||||||
|
+
|
||||||
|
+ resp = {'version': 1,
|
||||||
|
+ 'config': [{
|
||||||
|
+ 'type': 'physical',
|
||||||
|
+ 'name': 'ens2',
|
||||||
|
+ 'subnets': [{'type': 'dhcp4'}]}]
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ netcfg = self.datasource.network_config
|
||||||
|
+ self.assertEqual(netcfg, resp)
|
||||||
|
+
|
||||||
|
+ @mock.patch('cloudinit.sources.DataSourceScaleway.LOG.warning')
|
||||||
|
+ @mock.patch('cloudinit.sources.DataSourceScaleway.net.find_fallback_nic')
|
||||||
|
+ @mock.patch('cloudinit.util.get_cmdline')
|
||||||
|
+ def test_network_config_cached_none(self, m_get_cmdline, fallback_nic,
|
||||||
|
+ logwarning):
|
||||||
|
+ """
|
||||||
|
+ network_config() should return config data if cached data is None
|
||||||
|
+ rather than sources.UNSET
|
||||||
|
+ """
|
||||||
|
+ m_get_cmdline.return_value = 'scaleway'
|
||||||
|
+ fallback_nic.return_value = 'ens2'
|
||||||
|
+ self.datasource.metadata['ipv6'] = None
|
||||||
|
+ self.datasource._network_config = None
|
||||||
|
+
|
||||||
|
+ resp = {'version': 1,
|
||||||
|
+ 'config': [{
|
||||||
|
+ 'type': 'physical',
|
||||||
|
+ 'name': 'ens2',
|
||||||
|
+ 'subnets': [{'type': 'dhcp4'}]}]
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ netcfg = self.datasource.network_config
|
||||||
|
+ self.assertEqual(netcfg, resp)
|
||||||
|
+ logwarning.assert_called_with('Found None as cached _network_config. '
|
||||||
|
+ 'Resetting to %s', sources.UNSET)
|
||||||
|
--
|
||||||
|
2.18.1
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
Name: cloud-init
|
Name: cloud-init
|
||||||
Version: 19.4
|
Version: 19.4
|
||||||
Release: 6%{?dist}
|
Release: 7%{?dist}
|
||||||
Summary: Cloud instance init scripts
|
Summary: Cloud instance init scripts
|
||||||
License: ASL 2.0 or GPLv3
|
License: ASL 2.0 or GPLv3
|
||||||
URL: http://launchpad.net/cloud-init
|
URL: http://launchpad.net/cloud-init
|
||||||
@ -25,6 +25,9 @@ Patch3: cloud-init-19.4-no-override-default-network.patch
|
|||||||
Patch4: cloud-init-19.4-cc_set_password-increase-random-pwlength-from-9-to-2.patch
|
Patch4: cloud-init-19.4-cc_set_password-increase-random-pwlength-from-9-to-2.patch
|
||||||
Patch5: cloud-init-19.4-utils-use-SystemRandom-when-generating-random-passwo.patch
|
Patch5: cloud-init-19.4-utils-use-SystemRandom-when-generating-random-passwo.patch
|
||||||
|
|
||||||
|
# https://bugzilla.redhat.com/show_bug.cgi?id=1869757
|
||||||
|
Patch6: cloud-init-19.4-Scaleway-Fix-DatasourceScaleway-to-avoid-backtrace-1.patch
|
||||||
|
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
|
|
||||||
BuildRequires: pkgconfig(systemd)
|
BuildRequires: pkgconfig(systemd)
|
||||||
@ -167,6 +170,9 @@ nosetests-%{python3_version} tests/unittests/
|
|||||||
|
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon Sep 07 2020 Eduardo Otubo <otubo@redhat.com> - 19.4-7
|
||||||
|
- Fix execution fail with backtrace
|
||||||
|
|
||||||
* Mon Sep 07 2020 Eduardo Otubo <otubo@redhat.com> - 19.4-6
|
* Mon Sep 07 2020 Eduardo Otubo <otubo@redhat.com> - 19.4-6
|
||||||
- Adding missing patches to spec file
|
- Adding missing patches to spec file
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user