forked from canonical/cloud-init
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to manage fallback network config on PhotonOS (canonical#941
) Currently cloud-init generates fallback network config on various scenarios. For example: 1. When no DS found 2. There is no 'network' info given in DS metadata. 3. If a DS gives a network config once and upon reboot if DS doesn't give any network info, previously set network data will be overridden. A newly introduced key in cloud.cfg.tmpl can be used to control this behavior on PhotonOS. Also, if OS comes with a set of default network files(configs), like in PhotonOS, cloud-init should not overwrite them by default. This change also includes some nitpicking changes of reorganizing few config variables. Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
- Loading branch information
1 parent
3be4f60
commit 27e49b7
Showing
5 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# This file is part of cloud-init. See LICENSE file for license information. | ||
|
||
from . import _get_distro | ||
from cloudinit import util | ||
from cloudinit.tests.helpers import mock | ||
from cloudinit.tests.helpers import CiTestCase | ||
|
||
SYSTEM_INFO = { | ||
'paths': { | ||
'cloud_dir': '/var/lib/cloud/', | ||
'templates_dir': '/etc/cloud/templates/', | ||
}, | ||
'network': {'renderers': 'networkd'}, | ||
} | ||
|
||
|
||
class TestPhoton(CiTestCase): | ||
with_logs = True | ||
distro = _get_distro('photon', SYSTEM_INFO) | ||
expected_log_line = 'Rely on PhotonOS default network config' | ||
|
||
def test_network_renderer(self): | ||
self.assertEqual(self.distro._cfg['network']['renderers'], 'networkd') | ||
|
||
def test_get_distro(self): | ||
self.assertEqual(self.distro.osfamily, 'photon') | ||
|
||
def test_write_hostname(self): | ||
hostname = 'myhostname' | ||
hostfile = self.tmp_path('hostfile') | ||
self.distro._write_hostname(hostname, hostfile) | ||
self.assertEqual(hostname + '\n', util.load_file(hostfile)) | ||
|
||
@mock.patch('cloudinit.net.generate_fallback_config') | ||
def test_fallback_netcfg(self, m_fallback_cfg): | ||
|
||
key = 'disable_fallback_netcfg' | ||
# Don't use fallback if no setting given | ||
self.logs.truncate(0) | ||
assert(self.distro.generate_fallback_config() is None) | ||
self.assertIn(self.expected_log_line, self.logs.getvalue()) | ||
|
||
self.logs.truncate(0) | ||
self.distro._cfg[key] = True | ||
assert(self.distro.generate_fallback_config() is None) | ||
self.assertIn(self.expected_log_line, self.logs.getvalue()) | ||
|
||
self.logs.truncate(0) | ||
self.distro._cfg[key] = False | ||
assert(self.distro.generate_fallback_config() is not None) | ||
self.assertNotIn(self.expected_log_line, self.logs.getvalue()) |