Ejemplo n.º 1
0
    def test_main_unhandled_exception(self, m_conf_log, m_plugin, m_sys, m_os):
        """Test main() unhandled Exception"""
        # Mock out _execute to throw SystemExit
        m_os.environ = self.env
        m_sys.stdin.readlines.return_value = json.dumps(self.network_config)
        m_plugin(self.env, self.network_config).execute.side_effect = Exception 
        m_plugin.reset_mock()

        # Call
        main()

        # Assert
        m_sys.exit.assert_called_once_with(ERR_CODE_GENERIC)
Ejemplo n.º 2
0
    def test_main_sys_exit(self, m_conf_log, m_plugin, m_sys, m_os):
        """Test main() SystemExit handling"""
        # Mock out _execute to throw SystemExit
        m_os.environ = self.env
        m_sys.stdin.readlines.return_value = json.dumps(self.network_config)
        m_plugin(self.env, self.network_config).execute.side_effect = SystemExit(5)
        m_plugin.reset_mock()

        # Call
        main()

        # Assert
        m_sys.exit.assert_called_once_with(5)
Ejemplo n.º 3
0
    def test_main_unhandled_exception(self, m_conf_log, m_plugin, m_sys, m_os):
        """Test main() unhandled Exception"""
        # Mock out _execute to throw SystemExit
        m_os.environ = self.env
        m_sys.stdin.readlines.return_value = json.dumps(self.network_config)
        m_plugin(self.env, self.network_config).execute.side_effect = Exception
        m_plugin.reset_mock()

        # Call
        main()

        # Assert
        m_sys.exit.assert_called_once_with(ERR_CODE_GENERIC)
Ejemplo n.º 4
0
    def test_main(self, m_conf_log, m_plugin, m_sys, m_os):
        # Mock
        m_os.environ = self.env
        m_sys.stdin.readlines.return_value = json.dumps(self.network_config)
        m_plugin(self.env, self.network_config).execute.return_value = 0
        m_plugin.reset_mock()

        # Call
        main()

        # Assert
        m_plugin.assert_called_once_with(self.network_config, self.env)
        m_conf_log.assert_called_once_with(ANY, "cni.log", log_level="INFO")
        m_sys.exit.assert_called_once_with(0)
Ejemplo n.º 5
0
    def test_main_sys_exit(self, m_conf_log, m_plugin, m_sys, m_os):
        """Test main() SystemExit handling"""
        # Mock out _execute to throw SystemExit
        m_os.environ = self.env
        m_sys.stdin.readlines.return_value = json.dumps(self.network_config)
        m_plugin(self.env,
                 self.network_config).execute.side_effect = SystemExit(5)
        m_plugin.reset_mock()

        # Call
        main()

        # Assert
        m_sys.exit.assert_called_once_with(5)
Ejemplo n.º 6
0
    def test_main(self, m_conf_log, m_plugin, m_sys, m_os):
        # Mock
        m_os.environ = self.env
        m_sys.stdin.readlines.return_value = json.dumps(self.network_config)
        m_plugin(self.env, self.network_config).execute.return_value = 0
        m_plugin.reset_mock()

        # Call
        main()

        # Assert
        m_plugin.assert_called_once_with(self.network_config, self.env)
        m_conf_log.assert_called_with(ANY, "WARNING", "WARNING", "cni.log")
        m_sys.exit.assert_called_once_with(0)