diff options
Diffstat (limited to 'packages/python-google-compute-engine/google_compute_engine/distro_lib')
14 files changed, 192 insertions, 17 deletions
diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_8/tests/utils_test.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_8/tests/utils_test.py index 6ff9f9c..f714ba8 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_8/tests/utils_test.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_8/tests/utils_test.py @@ -26,6 +26,15 @@ class UtilsTest(unittest.TestCase): self.mock_logger = mock.Mock() self.mock_setup = mock.create_autospec(utils.Utils) + @mock.patch('google_compute_engine.distro_lib.helpers.CallDhclientIpv6') + def testEnableIpv6(self, mock_call): + mocks = mock.Mock() + mocks.attach_mock(mock_call, 'call') + + utils.Utils.EnableIpv6(self.mock_setup, ['A', 'B'], self.mock_logger) + expected_calls = [mock.call.call(['A', 'B'], mock.ANY)] + self.assertEqual(mocks.mock_calls, expected_calls) + @mock.patch('google_compute_engine.distro_lib.helpers.CallDhclient') def testEnableNetworkInterfaces(self, mock_call): mocks = mock.Mock() diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_8/utils.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_8/utils.py index 9bdccb8..f58e09d 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_8/utils.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_8/utils.py @@ -23,8 +23,17 @@ from google_compute_engine.distro_lib import utils class Utils(utils.Utils): """Utilities used by Linux guest services on Debian 8.""" - def EnableNetworkInterfaces( - self, interfaces, logger, dhclient_script=None): + 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.CallDhclientIpv6(interfaces, logger) + + def EnableNetworkInterfaces(self, interfaces, logger, dhclient_script=None): """Enable the list of network interfaces. Args: diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_9/tests/utils_test.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_9/tests/utils_test.py index 2717f00..fbb9a8e 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_9/tests/utils_test.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_9/tests/utils_test.py @@ -26,6 +26,15 @@ class UtilsTest(unittest.TestCase): self.mock_logger = mock.Mock() self.mock_setup = mock.create_autospec(utils.Utils) + @mock.patch('google_compute_engine.distro_lib.helpers.CallDhclientIpv6') + def testEnableIpv6(self, mock_call): + mocks = mock.Mock() + mocks.attach_mock(mock_call, 'call') + + utils.Utils.EnableIpv6(self.mock_setup, ['A', 'B'], self.mock_logger) + expected_calls = [mock.call.call(['A', 'B'], mock.ANY)] + self.assertEqual(mocks.mock_calls, expected_calls) + @mock.patch('google_compute_engine.distro_lib.helpers.CallDhclient') def testEnableNetworkInterfaces(self, mock_call): mocks = mock.Mock() diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_9/utils.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_9/utils.py index 452e02f..11a5cbd 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_9/utils.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/debian_9/utils.py @@ -23,8 +23,17 @@ from google_compute_engine.distro_lib import utils class Utils(utils.Utils): """Utilities used by Linux guest services on Debian 9.""" - def EnableNetworkInterfaces( - self, interfaces, logger, dhclient_script=None): + 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.CallDhclientIpv6(interfaces, logger) + + def EnableNetworkInterfaces(self, interfaces, logger, dhclient_script=None): """Enable the list of network interfaces. Args: diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_6/tests/utils_test.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_6/tests/utils_test.py index 539b059..f47f5c7 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_6/tests/utils_test.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_6/tests/utils_test.py @@ -29,6 +29,19 @@ class UtilsTest(unittest.TestCase): def tearDown(self): pass + @mock.patch('google_compute_engine.distro_lib.helpers.CallDhclientIpv6') + def testEnableIpv6(self, mock_call): + mocks = mock.Mock() + mocks.attach_mock(mock_call, 'call') + + utils.Utils.EnableIpv6( + self.mock_setup, ['A', 'B'], self.mock_logger, + dhclient_script='test_script') + expected_calls = [ + mock.call.call(['A', 'B'], mock.ANY, dhclient_script='test_script'), + ] + self.assertEqual(mocks.mock_calls, expected_calls) + @mock.patch('google_compute_engine.distro_lib.helpers.CallDhclient') def testEnableNetworkInterfaces(self, mock_call): mocks = mock.Mock() diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_6/utils.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_6/utils.py index 20b8e2f..43b8769 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_6/utils.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_6/utils.py @@ -21,10 +21,20 @@ from google_compute_engine.distro_lib import utils class Utils(utils.Utils): - """Utilities used by Linux guest services on Debian 8.""" + """Utilities used by Linux guest services on EL 6.""" - def EnableNetworkInterfaces( - self, interfaces, logger, dhclient_script=None): + 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.CallDhclientIpv6( + interfaces, logger, dhclient_script=dhclient_script) + + def EnableNetworkInterfaces(self, interfaces, logger, dhclient_script=None): """Enable the list of network interfaces. Args: diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_7/tests/utils_test.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_7/tests/utils_test.py index d726c3d..0e096db 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_7/tests/utils_test.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_7/tests/utils_test.py @@ -96,6 +96,15 @@ class UtilsTest(unittest.TestCase): ] self.assertEqual(mocks.mock_calls, expected_calls) + @mock.patch('google_compute_engine.distro_lib.helpers.CallDhclientIpv6') + def testEnableIpv6(self, mock_call): + mocks = mock.Mock() + mocks.attach_mock(mock_call, 'call') + + utils.Utils.EnableIpv6(self.mock_setup, ['A', 'B'], self.mock_logger) + expected_calls = [mock.call.call(['A', 'B'], mock.ANY)] + self.assertEqual(mocks.mock_calls, expected_calls) + @mock.patch('google_compute_engine.distro_lib.el_7.utils.os.path.exists') @mock.patch('google_compute_engine.distro_lib.helpers.CallDhclient') def testEnableNetworkInterfaces(self, mock_call, mock_exists): diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_7/utils.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_7/utils.py index b11a98f..062d471 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_7/utils.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/el_7/utils.py @@ -30,8 +30,17 @@ class Utils(utils.Utils): network_path = constants.LOCALBASE + '/etc/sysconfig/network-scripts' - def EnableNetworkInterfaces( - self, interfaces, logger, dhclient_script=None): + 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.CallDhclientIpv6(interfaces, logger) + + def EnableNetworkInterfaces(self, interfaces, logger, dhclient_script=None): """Enable the list of network interfaces. Args: diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/freebsd_11/utils.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/freebsd_11/utils.py index 4a9e706..2734c8f 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/freebsd_11/utils.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/freebsd_11/utils.py @@ -23,8 +23,17 @@ from google_compute_engine.distro_lib import utils class Utils(utils.Utils): """Utilities used by Linux guest services on FreeBSD 11.""" - def EnableNetworkInterfaces( - self, interfaces, logger, dhclient_script=None): + 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. + """ + pass + + def EnableNetworkInterfaces(self, interfaces, logger, dhclient_script=None): """Enable the list of network interfaces. Args: diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/helpers.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/helpers.py index 93902b3..cbe810e 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/helpers.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/helpers.py @@ -42,6 +42,29 @@ def CallDhclient( logger.warning('Could not enable interfaces %s.', interfaces) +def CallDhclientIpv6(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. + """ + logger.info('Enabling IPv6 on the Ethernet interfaces %s.', interfaces) + + timeout_command = ['timeout', '5'] + dhclient_command = ['dhclient'] + + if dhclient_script and os.path.exists(dhclient_script): + dhclient_command += ['-sf', dhclient_script] + + try: + subprocess.check_call( + timeout_command + dhclient_command + ['-1', '-6', '-v'] + interfaces) + except subprocess.CalledProcessError: + logger.warning('Could not enable IPv6 on interface %s.', interfaces) + + def CallHwclock(logger): """Sync clock using hwclock. diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/sles_11/utils.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/sles_11/utils.py index 6d1d0f2..623505c 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/sles_11/utils.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/sles_11/utils.py @@ -27,8 +27,17 @@ from google_compute_engine.distro_lib import utils class Utils(utils.Utils): """Utilities used by Linux guest services on SUSE 11.""" - def EnableNetworkInterfaces( - self, interfaces, logger, dhclient_script=None): + 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. + """ + pass + + def EnableNetworkInterfaces(self, interfaces, logger, dhclient_script=None): """Enable the list of network interfaces. Args: diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/sles_12/utils.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/sles_12/utils.py index 380df7b..b4a3d00 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/sles_12/utils.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/sles_12/utils.py @@ -29,8 +29,17 @@ class Utils(utils.Utils): network_path = constants.LOCALBASE + '/etc/sysconfig/network' - def EnableNetworkInterfaces( - self, interfaces, logger, dhclient_script=None): + 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. + """ + pass + + def EnableNetworkInterfaces(self, interfaces, logger, dhclient_script=None): """Enable the list of network interfaces. Args: diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/tests/helpers_test.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/tests/helpers_test.py index 7533b20..7c2c0b6 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/tests/helpers_test.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/tests/helpers_test.py @@ -65,6 +65,45 @@ class HelpersTest(unittest.TestCase): self.assertEqual(mocks.mock_calls, expected_calls) + @mock.patch('google_compute_engine.distro_lib.helpers.os.path.exists') + @mock.patch('google_compute_engine.distro_lib.helpers.subprocess.check_call') + def testCallDhclientIpv6(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, subprocess.CalledProcessError(1, 'Test'), + ] + + helpers.CallDhclientIpv6(['a', 'b'], self.mock_logger, 'test_script') + helpers.CallDhclientIpv6(['c', 'd'], self.mock_logger, 'test_script') + helpers.CallDhclientIpv6(['e', 'f'], self.mock_logger, None) + helpers.CallDhclientIpv6(['g', 'h'], self.mock_logger, None) + + expected_calls = [ + mock.call.logger.info(mock.ANY, ['a', 'b']), + mock.call.exists('test_script'), + mock.call.call( + ['timeout', '5', 'dhclient', '-1', '-6', '-v', 'a', 'b']), + mock.call.logger.info(mock.ANY, ['c', 'd']), + mock.call.exists('test_script'), + mock.call.call( + ['timeout', '5', 'dhclient', '-sf', 'test_script', '-1', '-6', + '-v', 'c', 'd']), + mock.call.logger.info(mock.ANY, ['e', 'f']), + mock.call.call( + ['timeout', '5', 'dhclient', '-1', '-6', '-v', 'e', 'f']), + mock.call.logger.info(mock.ANY, ['g', 'h']), + mock.call.call( + ['timeout', '5', 'dhclient', '-1', '-6', '-v', 'g', 'h']), + mock.call.logger.warning(mock.ANY, ['g', 'h']), + ] + + self.assertEqual(mocks.mock_calls, expected_calls) + @mock.patch('google_compute_engine.distro_lib.helpers.subprocess.check_call') def testCallHwclock(self, mock_call): command = ['/sbin/hwclock', '--hctosys'] diff --git a/packages/python-google-compute-engine/google_compute_engine/distro_lib/utils.py b/packages/python-google-compute-engine/google_compute_engine/distro_lib/utils.py index 75b656e..df1d45c 100644 --- a/packages/python-google-compute-engine/google_compute_engine/distro_lib/utils.py +++ b/packages/python-google-compute-engine/google_compute_engine/distro_lib/utils.py @@ -27,8 +27,17 @@ class Utils(object): """ self.debug = debug - def EnableNetworkInterfaces( - self, interfaces, logger, dhclient_script=None): + def EnableIpv6(self, interfaces, logger, dhclient_script=None): + """Enable IPv6 on the list of network interfaces. + + Args: + interfaces: list of 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. + """ + pass + + def EnableNetworkInterfaces(self, interfaces, logger, dhclient_script=None): """Enable the list of network interfaces. Args: |