def test_check_modules_double_open(self, requirements, expected_return, m_get_version, m_stderr, m_open): """Test _check_module for different requirements (opening 2 files) Use parameterized requirements to test a variety of states in which modules may or not be found. Check the number of calls to open(). Numbered modules exist within the mocked files and should be valid. check_modules should return False if searching for the invalid module. """ m_file = Mock() m_file.readlines.side_effect = [ ["/mod_one.ko", "/mod_two.ko", "/mod_three.ko"], # Mocked Available modules ["/mod_four.ko", "/mod_five.ko"], # Mocked Builtin modules ] m_open.return_value = m_file with patch('calico_ctl.checksystem.REQUIRED_MODULES', requirements): return_val = _check_modules() self.assertEquals(return_val, expected_return) m_open.assert_has_calls([ call("/lib/modules/version/modules.dep"), call().readlines(), call("/lib/modules/version/modules.builtin"), call().readlines(), ])
def test_check_modules_double_open(self, requirements, expected_return, m_get_version, m_stderr, m_open): """Test _check_module for different requirements (opening 2 files) Use parameterized requirements to test a variety of states in which modules may or not be found. Check the number of calls to open(). Numbered modules exist within the mocked files and should be valid. check_modules should return False if searching for the invalid module. """ m_file = Mock() m_file.readlines.side_effect = [ ["/mod_one.ko", "/mod_two.ko", "/mod_three.ko"], # Mocked Available modules ["/mod_four.ko", "/mod_five.ko"], # Mocked Builtin modules ] m_open.return_value = m_file with patch("calico_ctl.checksystem.REQUIRED_MODULES", requirements): return_val = _check_modules() self.assertEquals(return_val, expected_return) m_open.assert_has_calls( [ call("/lib/modules/version/modules.dep"), call().readlines(), call("/lib/modules/version/modules.builtin"), call().readlines(), ] )
def test_check_modules_error(self, m_check_out, m_stderr): """Test _check_module lsmod failure All check_output calls raise an error, meaning check_system should return false. """ m_check_out.side_effect = CalledProcessError return_val = _check_modules() self.assertFalse(return_val)
def test_check_modules_lsmod(self, requirements, expected_return, m_check_out, m_stderr, m_open): """Test _check_module using lsmod Cause failure on file open and check_system should find modules in lsmod output. """ m_open.side_effect = CalledProcessError m_check_out.return_value = "mod_one\n mod_two\n mod_three\n" with patch("calico_ctl.checksystem.REQUIRED_MODULES", requirements): return_val = _check_modules() self.assertEquals(return_val, expected_return)
def test_check_modules_lsmod(self, requirements, expected_return, m_check_out, m_stderr, m_open): """Test _check_module using lsmod Cause failure on file open and check_system should find modules in lsmod output. """ m_open.side_effect = CalledProcessError m_check_out.return_value = "mod_one\n mod_two\n mod_three\n" with patch('calico_ctl.checksystem.REQUIRED_MODULES', requirements): return_val = _check_modules() self.assertEquals(return_val, expected_return)
def test_check_modules_single_open(self, requirements, expected_return, m_get_version, m_stderr, m_open): """Test _check_module for different requirements (opening 1 file) Use parameterized requirements to test a variety of states in which modules may or not be found. Check the number of calls to open(). Numbered modules exist within the mocked file and should be valid. """ m_file = Mock() m_file.readlines.return_value = ["/mod_one.ko", "/mod_two.ko", "/mod_three.ko"] # Mocked Available modules m_open.return_value = m_file with patch("calico_ctl.checksystem.REQUIRED_MODULES", requirements): return_val = _check_modules() m_open.assert_called_once_with("/lib/modules/version/modules.dep") self.assertEquals(return_val, expected_return)
def test_check_modules_single_open(self, requirements, expected_return, m_get_version, m_stderr, m_open): """Test _check_module for different requirements (opening 1 file) Use parameterized requirements to test a variety of states in which modules may or not be found. Check the number of calls to open(). Numbered modules exist within the mocked file and should be valid. """ m_file = Mock() m_file.readlines.return_value = ["/mod_one.ko", "/mod_two.ko", "/mod_three.ko"] # Mocked Available modules m_open.return_value = m_file with patch('calico_ctl.checksystem.REQUIRED_MODULES', requirements): return_val = _check_modules() m_open.assert_called_once_with("/lib/modules/version/modules.dep") self.assertEquals(return_val, expected_return)