Esempio n. 1
0
    def EnableNetworkInterfaces(self,
                                interfaces,
                                logger,
                                dhclient_script=None):
        """Enable the list of network interfaces.

    Args:
      interfaces: list of string, the output device names to enable.
      logger: logger object, used to write to SysLog and serial port.
      dhclient_script: string, the path to a dhclient script used by dhclient.
    """
        helpers.CallDhclient(interfaces, logger)
    def testCallDhclient(self, mock_call, mock_exists):
        mocks = mock.Mock()
        mocks.attach_mock(mock_exists, 'exists')
        mocks.attach_mock(mock_call, 'call')
        mocks.attach_mock(self.mock_logger, 'logger')

        mock_exists.side_effect = [False, True]
        mock_call.side_effect = [
            None,
            None,
            None,
            None,
            None,
            None,
            subprocess.CalledProcessError(1, 'Test'),
        ]

        helpers.CallDhclient(['a', 'b'], self.mock_logger, 'test_script')
        helpers.CallDhclient(['c', 'd'], self.mock_logger, 'test_script')
        helpers.CallDhclient(['e', 'f'], self.mock_logger, None)
        helpers.CallDhclient(['g', 'h'], self.mock_logger, None)

        expected_calls = [
            mock.call.logger.info(mock.ANY, ['a', 'b']),
            mock.call.exists('test_script'),
            mock.call.call(['dhclient', '-x', 'a', 'b']),
            mock.call.call(['dhclient', 'a', 'b']),
            mock.call.logger.info(mock.ANY, ['c', 'd']),
            mock.call.exists('test_script'),
            mock.call.call(['dhclient', '-sf', 'test_script', '-x', 'c', 'd']),
            mock.call.call(['dhclient', '-sf', 'test_script', 'c', 'd']),
            mock.call.logger.info(mock.ANY, ['e', 'f']),
            mock.call.call(['dhclient', '-x', 'e', 'f']),
            mock.call.call(['dhclient', 'e', 'f']),
            mock.call.logger.info(mock.ANY, ['g', 'h']),
            mock.call.call(['dhclient', '-x', 'g', 'h']),
            mock.call.logger.warning(mock.ANY, ['g', 'h']),
        ]

        self.assertEqual(mocks.mock_calls, expected_calls)
Esempio n. 3
0
    def EnableNetworkInterfaces(self,
                                interfaces,
                                logger,
                                dhclient_script=None):
        """Enable the list of network interfaces.

    Args:
      interfaces: list of string, the output device names to enable.
      logger: logger object, used to write to SysLog and serial port.
      dhclient_script: string, the path to a dhclient script used by dhclient.
    """
        # Should always exist in EL 7.
        if os.path.exists(self.network_path):
            self._DisableNetworkManager(interfaces, logger)
        helpers.CallDhclient(interfaces, logger)