示例#1
0
    def DisableIpv6(self, interfaces, logger):
        """Disable Ipv6 by giving up the DHCP lease using dhclient.

    Args:
      interface: string, the output device names for enabling IPv6.
      logger: logger object, used to write to SysLog and serial port.
    """
        helpers.CallDhclientIpv6(interfaces, logger, None, release_lease=True)
    def testCallDhclientIpv6NonExistentScript(self, mock_call, mock_exists):
        mock_logger = mock.Mock()

        mock_exists.side_effect = [False]
        helpers.CallDhclientIpv6(['a', 'b'], mock_logger, 'test_script')
        mock_call.assert_has_calls([
            mock.call.call(
                ['timeout', '5', 'dhclient', '-1', '-6', '-v', 'a', 'b']),
        ])
示例#3
0
    def EnableIpv6(self, interfaces, logger, dhclient_script=None):
        """Configure the network interfaces for IPv6 using dhclient.

    Args:
      interface: string, the output device names for enabling IPv6.
      logger: logger object, used to write to SysLog and serial port.
      dhclient_script: string, the path to a dhclient script used by dhclient.
    """
        helpers.CallEnableRouteAdvertisements(interfaces, logger)
        helpers.CallDhclientIpv6(interfaces, logger)
    def testCallDhclientIpv6(self, mock_call, mock_exists):
        mock_logger = mock.Mock()
        mock_exists.side_effect = [True]
        mock_call.side_effect = [
            None,
            None,
            subprocess.CalledProcessError(1, 'Test'),
            None,
            None,
            subprocess.CalledProcessError(1, 'Test'),
        ]

        helpers.CallDhclientIpv6(['a', 'b'], mock_logger, 'test_script')
        helpers.CallDhclientIpv6(['c', 'd'], mock_logger, None)
        helpers.CallDhclientIpv6(['e', 'f'], mock_logger, None)
        helpers.CallDhclientIpv6(['g', 'h'],
                                 mock_logger,
                                 'test_script',
                                 release_lease=True)
        helpers.CallDhclientIpv6(['i', 'j'],
                                 mock_logger,
                                 None,
                                 release_lease=True)
        helpers.CallDhclientIpv6(['k', 'l'],
                                 mock_logger,
                                 None,
                                 release_lease=True)

        expected_calls = [
            mock.call.call([
                'timeout',
                '5',
                'dhclient',
                '-sf',
                'test_script',
                '-1',
                '-6',
                '-v',
                'a',
                'b',
            ]),
            mock.call.call([
                'timeout',
                '5',
                'dhclient',
                '-1',
                '-6',
                '-v',
                'c',
                'd',
            ]),
            mock.call.call([
                'timeout',
                '5',
                'dhclient',
                '-1',
                '-6',
                '-v',
                'e',
                'f',
            ]),
            mock.call.call([
                'timeout',
                '5',
                'dhclient',
                '-6',
                '-r',
                '-v',
                'g',
                'h',
            ]),
            mock.call.call([
                'timeout',
                '5',
                'dhclient',
                '-6',
                '-r',
                '-v',
                'i',
                'j',
            ]),
            mock.call.call([
                'timeout',
                '5',
                'dhclient',
                '-6',
                '-r',
                '-v',
                'k',
                'l',
            ]),
        ]

        self.assertEqual(mock_call.mock_calls, expected_calls)
        mock_logger.assert_has_calls([
            mock.call.warning(mock.ANY, ['e', 'f']),
        ])
        mock_logger.assert_has_calls([
            mock.call.warning(mock.ANY, ['k', 'l']),
        ])