cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #06184
[Merge] ~jasonzio/cloud-init:mockSLG into cloud-init:master
Jason Zions has proposed merging ~jasonzio/cloud-init:mockSLG into cloud-init:master.
Commit message:
Mock util.SeLinuxGuard to do nothing within tests that mock functions used by the guard, when those mocks confuse the guard. This has no impact when executing unit tests on systems which do not enable selinux (e.g. Ubuntu). Fixes https://bugs.launchpad.net/cloud-init/+bug/1825253
Requested reviews:
cloud-init commiters (cloud-init-dev)
Related bugs:
Bug #1825253 in cloud-init: "Unit tests with filesystem-related mocks fail in SeLinuxGuard when run on RHEL or CentOS"
https://bugs.launchpad.net/cloud-init/+bug/1825253
For more details, see:
https://code.launchpad.net/~jasonzio/cloud-init/+git/cloud-init/+merge/366236
--
Your team cloud-init commiters is requested to review the proposed merge of ~jasonzio/cloud-init:mockSLG into cloud-init:master.
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index 53c56cd..ab77c03 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -1375,12 +1375,15 @@ class TestCanDevBeReformatted(CiTestCase):
self._domock(p + "util.mount_cb", 'm_mount_cb')
self._domock(p + "os.path.realpath", 'm_realpath')
self._domock(p + "os.path.exists", 'm_exists')
+ self._domock(p + "util.SeLinuxGuard", 'm_selguard')
self.m_exists.side_effect = lambda p: p in bypath
self.m_realpath.side_effect = realpath
self.m_has_ntfs_filesystem.side_effect = has_ntfs_fs
self.m_mount_cb.side_effect = mount_cb
self.m_partitions_on_device.side_effect = partitions_on_device
+ self.m_selguard.__enter__ = mock.Mock(return_value=False)
+ self.m_selguard.__exit__ = mock.Mock()
def test_three_partitions_is_false(self):
"""A disk with 3 partitions can not be formatted."""
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index fd03deb..ca6ef97 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -3269,9 +3269,12 @@ class TestNetplanPostcommands(CiTestCase):
mock_netplan_generate.assert_called_with(run=True)
mock_net_setup_link.assert_called_with(run=True)
+ @mock.patch('cloudinit.util.SeLinuxGuard')
@mock.patch.object(netplan, "get_devicelist")
@mock.patch('cloudinit.util.subp')
- def test_netplan_postcmds(self, mock_subp, mock_devlist):
+ def test_netplan_postcmds(self, mock_subp, mock_devlist, mock_sel):
+ mock_sel.__enter__ = mock.Mock(return_value=False)
+ mock_sel.__exit__ = mock.Mock()
mock_devlist.side_effect = [['lo']]
tmp_dir = self.tmp_dir()
ns = network_state.parse_net_config_data(self.mycfg,
Follow ups