def test_handle_tries_to_install_squashfuse(self, m_squash): """If squashfuse_in_container is True, try installing squashfuse.""" cfg = {'snap': {'squashfuse_in_container': True}} mycloud = FakeCloud(None) handle('snap', cfg=cfg, cloud=mycloud, log=self.logger, args=None) self.assertEqual( [mock.call(mycloud)], m_squash.call_args_list)
def test_handle_tries_to_install_squashfuse(self, m_squash): """If squashfuse_in_container is True, try installing squashfuse.""" cfg = {'snap': {'squashfuse_in_container': True}} mycloud = FakeCloud(None) handle('snap', cfg=cfg, cloud=mycloud, log=self.logger, args=None) self.assertEqual( [mock.call(mycloud)], m_squash.call_args_list)
def test_handle_no_config(self, m_schema, m_add, m_run): """When no snap-related configuration is provided, nothing happens.""" cfg = {} handle('snap', cfg=cfg, cloud=None, log=self.logger, args=None) self.assertIn( "DEBUG: Skipping module named snap, no 'snap' key in config", self.logs.getvalue()) m_schema.assert_not_called() m_add.assert_not_called() m_run.assert_not_called()
def test_handle_no_config(self, m_schema, m_add, m_run): """When no snap-related configuration is provided, nothing happens.""" cfg = {} handle('snap', cfg=cfg, cloud=None, log=self.logger, args=None) self.assertIn( "DEBUG: Skipping module named snap, no 'snap' key in config", self.logs.getvalue()) m_schema.assert_not_called() m_add.assert_not_called() m_run.assert_not_called()
def test_handle_runs_commands_provided(self): """If commands are specified as a list, run them.""" outfile = self.tmp_path('output.log', dir=self.tmp) cfg = { 'snap': {'commands': ['echo "HI" >> %s' % outfile, 'echo "MOM" >> %s' % outfile]}} mock_path = 'cloudinit.config.cc_snap.sys.stderr' with mock.patch(mock_path, new_callable=StringIO): handle('snap', cfg=cfg, cloud=None, log=self.logger, args=None) self.assertEqual('HI\nMOM\n', util.load_file(outfile))
def test_handle_runs_commands_provided(self): """If commands are specified as a list, run them.""" outfile = self.tmp_path('output.log', dir=self.tmp) cfg = { 'snap': {'commands': ['echo "HI" >> %s' % outfile, 'echo "MOM" >> %s' % outfile]}} mock_path = 'cloudinit.config.cc_snap.sys.stderr' with self.allow_subp([CiTestCase.SUBP_SHELL_TRUE]): with mock.patch(mock_path, new_callable=StringIO): handle('snap', cfg=cfg, cloud=None, log=self.logger, args=None) self.assertEqual('HI\nMOM\n', util.load_file(outfile))
def test_handle_runs_commands_provided(self): """If commands are specified as a list, run them.""" outfile = self.tmp_path("output.log", dir=self.tmp) cfg = { "snap": { "commands": [ 'echo "HI" >> %s' % outfile, 'echo "MOM" >> %s' % outfile, ] } } mock_path = "cloudinit.config.cc_snap.sys.stderr" with self.allow_subp([CiTestCase.SUBP_SHELL_TRUE]): with mock.patch(mock_path, new_callable=StringIO): handle("snap", cfg=cfg, cloud=None, log=self.logger, args=None) self.assertEqual("HI\nMOM\n", util.load_file(outfile))
def test_handle_skips_squashfuse_when_unconfigured(self, m_squash, m_add, m_run): """When squashfuse_in_container is unset, don't attempt to install.""" handle('snap', cfg={'snap': {}}, cloud=None, log=self.logger, args=None) handle('snap', cfg={'snap': { 'squashfuse_in_container': None }}, cloud=None, log=self.logger, args=None) handle('snap', cfg={'snap': { 'squashfuse_in_container': False }}, cloud=None, log=self.logger, args=None) self.assertEqual([], m_squash.call_args_list) # No calls # snap configuration missing assertions and commands will default to [] self.assertIn(mock.call([]), m_add.call_args_list) self.assertIn(mock.call([]), m_run.call_args_list)
def test_handle_skips_squashfuse_when_unconfigured(self, m_squash, m_add, m_run): """When squashfuse_in_container is unset, don't attempt to install.""" handle( 'snap', cfg={'snap': {}}, cloud=None, log=self.logger, args=None) handle( 'snap', cfg={'snap': {'squashfuse_in_container': None}}, cloud=None, log=self.logger, args=None) handle( 'snap', cfg={'snap': {'squashfuse_in_container': False}}, cloud=None, log=self.logger, args=None) self.assertEqual([], m_squash.call_args_list) # No calls # snap configuration missing assertions and commands will default to [] self.assertIn(mock.call([]), m_add.call_args_list) self.assertIn(mock.call([]), m_run.call_args_list)