def setUp(self): self.mock_instance_config = mock.Mock() self.mock_logger = mock.Mock() self.mock_setup = mock.create_autospec(instance_setup.InstanceSetup) self.mock_setup.debug = False self.mock_setup.instance_config = self.mock_instance_config self.mock_setup.logger = self.mock_logger
def setUp(self): self.mock_logger = mock.Mock() self.sudoers_group = 'google-sudoers' self.sudoers_file = '/sudoers/file' self.users_dir = '/users' self.users_file = '/users/file' self.gpasswd_add_cmd = 'gpasswd -a {user} {group}' self.gpasswd_remove_cmd = 'gpasswd -d {user} {group}' self.groupadd_cmd = 'groupadd {group}' self.useradd_cmd = 'useradd -m -s /bin/bash -p * {user}' self.userdel_cmd = 'userdel -r {user}' self.usermod_cmd = 'usermod -G {groups} {user}' self.mock_utils = mock.create_autospec(accounts_utils.AccountsUtils) self.mock_utils.google_comment = accounts_utils.AccountsUtils.google_comment self.mock_utils.google_sudoers_group = self.sudoers_group self.mock_utils.google_sudoers_file = self.sudoers_file self.mock_utils.google_users_dir = self.users_dir self.mock_utils.google_users_file = self.users_file self.mock_utils.logger = self.mock_logger self.mock_utils.gpasswd_add_cmd = self.gpasswd_add_cmd self.mock_utils.gpasswd_remove_cmd = self.gpasswd_remove_cmd self.mock_utils.groupadd_cmd = self.groupadd_cmd self.mock_utils.useradd_cmd = self.useradd_cmd self.mock_utils.userdel_cmd = self.userdel_cmd self.mock_utils.usermod_cmd = self.usermod_cmd
def setUp(self): self.mock_logger = mock.Mock() self.mock_watcher = mock.Mock() self.mock_ip_forwarding_utils = mock.Mock() self.mock_setup = mock.create_autospec(ip_forwarding.IpForwarding) self.mock_setup.logger = self.mock_logger self.mock_setup.ip_forwarding_utils = self.mock_ip_forwarding_utils
def testInstanceConfigExists(self, mock_init, mock_set, mock_parser, mock_exists): mock_config = mock.create_autospec( instance_config.parser.SafeConfigParser) mock_config.read = mock.Mock() mock_config.sections = mock.Mock() mock_config.sections.return_value = ['a', 'b'] mock_config.items = lambda key: {'key: %s' % key: 'value: %s' % key} mock_parser.SafeConfigParser.return_value = mock_config mocks = mock.Mock() mocks.attach_mock(mock_init, 'init') mocks.attach_mock(mock_set, 'set') mocks.attach_mock(mock_parser, 'parser') mocks.attach_mock(mock_exists, 'exists') mock_exists.return_value = True instance_config.InstanceConfig() expected_calls = [ mock.call.init(config_file='template', config_header='/tmp/test.py template'), mock.call.exists('config'), mock.call.parser.SafeConfigParser(), mock.call.parser.SafeConfigParser().read('config'), mock.call.parser.SafeConfigParser().sections(), mock.call.set('a', 'key: a', 'value: a', overwrite=False), mock.call.set('b', 'key: b', 'value: b', overwrite=False), ] self.assertEqual(mocks.mock_calls, expected_calls)
def testInstanceSetupException(self, mock_logger, mock_watcher, mock_config): mock_setup = mock.create_autospec(instance_setup.InstanceSetup) mocks = mock.Mock() mocks.attach_mock(mock_logger, 'logger') mocks.attach_mock(mock_watcher, 'watcher') mocks.attach_mock(mock_config, 'config') mocks.attach_mock(mock_setup, 'setup') mock_logger_instance = mock.Mock() mock_logger.Logger.return_value = mock_logger_instance mock_config_instance = mock.Mock() mock_config_instance.GetOptionBool.return_value = False mock_config_instance.WriteConfig.side_effect = IOError('Test Error') mock_config.InstanceConfig.return_value = mock_config_instance instance_setup.InstanceSetup.__init__(mock_setup) expected_calls = [ mock.call.logger.Logger( name=mock.ANY, debug=False, facility=mock.ANY), mock.call.watcher.MetadataWatcher(logger=mock_logger_instance), mock.call.config.InstanceConfig(logger=mock_logger_instance), mock.call.config.InstanceConfig().GetOptionBool( 'InstanceSetup', 'network_enabled'), mock.call.config.InstanceConfig().GetOptionBool( 'InstanceSetup', 'optimize_local_ssd'), mock.call.config.InstanceConfig().GetOptionBool( 'InstanceSetup', 'set_multiqueue'), mock.call.config.InstanceConfig().WriteConfig(), mock.call.logger.Logger().warning('Test Error'), ] self.assertEqual(mocks.mock_calls, expected_calls) self.assertIsNone(mock_setup.metadata_dict)
def setUp(self): self.mock_logger = mock.Mock() self.oslogin_control_script = 'google_oslogin_control' self.mock_oslogin = mock.create_autospec(oslogin_utils.OsLoginUtils) self.mock_oslogin.logger = self.mock_logger self.mock_oslogin.oslogin_installed = True
def testInstanceConfigExists(self, mock_init, mock_set, mock_parser, mock_exists): mock_config = mock.create_autospec(instance_config.parser.SafeConfigParser) mock_config.read = mock.Mock() mock_config.sections = mock.Mock() mock_config.sections.return_value = ['a', 'b'] mock_config.items = lambda key: {'key: %s' % key: 'value: %s' % key} mock_parser.SafeConfigParser.return_value = mock_config mocks = mock.Mock() mocks.attach_mock(mock_init, 'init') mocks.attach_mock(mock_set, 'set') mocks.attach_mock(mock_parser, 'parser') mocks.attach_mock(mock_exists, 'exists') mock_exists.return_value = True instance_config.InstanceConfig() expected_calls = [ mock.call.init( config_file='template', config_header='/tmp/test.py template'), mock.call.exists('config'), mock.call.parser.SafeConfigParser(), mock.call.parser.SafeConfigParser().read('config'), mock.call.parser.SafeConfigParser().sections(), mock.call.set('a', 'key: a', 'value: a', overwrite=False), mock.call.set('b', 'key: b', 'value: b', overwrite=False), ] self.assertEqual(mocks.mock_calls, expected_calls)
def setUp(self): self.mock_logger = mock.Mock() self.mock_distro_utils = mock.Mock() self.mock_setup = mock.create_autospec(network_setup.NetworkSetup) self.mock_setup.logger = self.mock_logger self.mock_setup.distro_utils = self.mock_distro_utils self.mock_setup.dhclient_script = '/bin/script' self.mock_setup.dhcp_command = ''
def testAddAuth(self, mock_watcher): mock_auth = mock.create_autospec(compute_auth.ComputeAuth) mock_auth._GetAccessToken.return_value = 'token' mock_request = mock.Mock() mock_request.headers = {} compute_auth.ComputeAuth.add_auth(mock_auth, mock_request) self.assertEqual(mock_request.headers['Authorization'], 'OAuth token')
def setUp(self): self.mock_logger = mock.Mock() self.mock_watcher = mock.Mock() self.mock_utils = mock.Mock() self.mock_setup = mock.create_autospec(accounts_daemon.AccountsDaemon) self.mock_setup.logger = self.mock_logger self.mock_setup.watcher = self.mock_watcher self.mock_setup.utils = self.mock_utils
def testInstanceSetup(self, mock_logger, mock_watcher, mock_config): mock_setup = mock.create_autospec(instance_setup.InstanceSetup) mocks = mock.Mock() mocks.attach_mock(mock_logger, 'logger') mocks.attach_mock(mock_watcher, 'watcher') mocks.attach_mock(mock_config, 'config') mocks.attach_mock(mock_setup, 'setup') mock_logger_instance = mock.Mock() mock_logger.Logger.return_value = mock_logger_instance mock_watcher_instance = mock.Mock() mock_watcher_instance.GetMetadata.return_value = {'hello': 'world'} mock_watcher.MetadataWatcher.return_value = mock_watcher_instance mock_config_instance = mock.Mock() mock_config_instance.GetOptionBool.return_value = True mock_config_instance.GetOptionString.return_value = 'type' mock_config.InstanceConfig.return_value = mock_config_instance mock_setup._GetInstanceConfig.return_value = 'config' instance_setup.InstanceSetup.__init__(mock_setup) expected_calls = [ # Setup and reading the configuration file. mock.call.logger.Logger(name=mock.ANY, debug=False, facility=mock.ANY), mock.call.watcher.MetadataWatcher(logger=mock_logger_instance), mock.call.config.InstanceConfig(logger=mock_logger_instance), # Check network access for reaching the metadata server. mock.call.config.InstanceConfig().GetOptionBool( 'InstanceSetup', 'network_enabled'), mock.call.watcher.MetadataWatcher().GetMetadata(), # Get the instance config if specified in metadata. mock.call.setup._GetInstanceConfig(), mock.call.config.InstanceConfig(logger=mock_logger_instance, instance_config_metadata='config'), # Setup for SSH host keys if necessary. mock.call.config.InstanceConfig().GetOptionBool( 'InstanceSetup', 'set_host_keys'), mock.call.config.InstanceConfig().GetOptionString( 'InstanceSetup', 'host_key_types'), mock.call.setup._SetSshHostKeys(host_key_types='type'), # Setup for the boto config if necessary. mock.call.config.InstanceConfig().GetOptionBool( 'InstanceSetup', 'set_boto_config'), mock.call.setup._SetupBotoConfig(), # Setup for local SSD. mock.call.config.InstanceConfig().GetOptionBool( 'InstanceSetup', 'optimize_local_ssd'), mock.call.setup._RunScript('google_optimize_local_ssd'), # Setup for multiqueue virtio driver. mock.call.config.InstanceConfig().GetOptionBool( 'InstanceSetup', 'set_multiqueue'), mock.call.setup._RunScript('google_set_multiqueue'), # Write the updated config file. mock.call.config.InstanceConfig().WriteConfig(), ] self.assertEqual(mocks.mock_calls, expected_calls) self.assertEqual(mock_setup.metadata_dict, {'hello': 'world'})
def testInstanceSetup(self, mock_logger, mock_watcher, mock_config): mock_setup = mock.create_autospec(instance_setup.InstanceSetup) mocks = mock.Mock() mocks.attach_mock(mock_logger, 'logger') mocks.attach_mock(mock_watcher, 'watcher') mocks.attach_mock(mock_config, 'config') mocks.attach_mock(mock_setup, 'setup') mock_logger_instance = mock.Mock() mock_logger.Logger.return_value = mock_logger_instance mock_watcher_instance = mock.Mock() mock_watcher_instance.GetMetadata.return_value = {'hello': 'world'} mock_watcher.MetadataWatcher.return_value = mock_watcher_instance mock_config_instance = mock.Mock() mock_config_instance.GetOptionBool.return_value = True mock_config_instance.GetOptionString.return_value = 'type' mock_config.InstanceConfig.return_value = mock_config_instance mock_setup._GetInstanceConfig.return_value = 'config' instance_setup.InstanceSetup.__init__(mock_setup) expected_calls = [ # Setup and reading the configuration file. mock.call.logger.Logger( name=mock.ANY, debug=False, facility=mock.ANY), mock.call.watcher.MetadataWatcher(logger=mock_logger_instance), mock.call.config.InstanceConfig(logger=mock_logger_instance), # Check network access for reaching the metadata server. mock.call.config.InstanceConfig().GetOptionBool( 'InstanceSetup', 'network_enabled'), mock.call.watcher.MetadataWatcher().GetMetadata(), # Get the instance config if specified in metadata. mock.call.setup._GetInstanceConfig(), mock.call.config.InstanceConfig( logger=mock_logger_instance, instance_config_metadata='config'), # Setup for SSH host keys if necessary. mock.call.config.InstanceConfig().GetOptionBool( 'InstanceSetup', 'set_host_keys'), mock.call.config.InstanceConfig().GetOptionString( 'InstanceSetup', 'host_key_types'), mock.call.setup._SetSshHostKeys(host_key_types='type'), # Setup for the boto config if necessary. mock.call.config.InstanceConfig().GetOptionBool( 'InstanceSetup', 'set_boto_config'), mock.call.setup._SetupBotoConfig(), # Setup for local SSD. mock.call.config.InstanceConfig().GetOptionBool( 'InstanceSetup', 'optimize_local_ssd'), mock.call.setup._RunScript('google_optimize_local_ssd'), # Setup for multiqueue virtio driver. mock.call.config.InstanceConfig().GetOptionBool( 'InstanceSetup', 'set_multiqueue'), mock.call.setup._RunScript('google_set_multiqueue'), # Write the updated config file. mock.call.config.InstanceConfig().WriteConfig(), ] self.assertEqual(mocks.mock_calls, expected_calls) self.assertEqual(mock_setup.metadata_dict, {'hello': 'world'})
def setUp(self): self.mock_logger = mock.Mock() self.mock_watcher = mock.Mock() self.mock_utils = mock.Mock() self.mock_setup = mock.create_autospec( ip_forwarding_daemon.IpForwardingDaemon) self.mock_setup.logger = self.mock_logger self.mock_setup.watcher = self.mock_watcher self.mock_setup.utils = self.mock_utils
def setUp(self): self.mock_logger = mock.Mock() self.oslogin_control_script = 'google_oslogin_control' self.oslogin_nss_cache = '/etc/oslogin_passwd.cache' self.oslogin_nss_cache_script = 'google_oslogin_nss_cache' self.mock_oslogin = mock.create_autospec(oslogin_utils.OsLoginUtils) self.mock_oslogin.logger = self.mock_logger self.mock_oslogin.oslogin_installed = True self.mock_oslogin.update_time = 0
def testHandleClockSync(self, mock_distro_utils): mock_sync = mock.create_autospec(clock_skew_daemon.ClockSkewDaemon) mock_logger = mock.Mock() mock_sync.logger = mock_logger mock_sync.distro_utils = mock_distro_utils clock_skew_daemon.ClockSkewDaemon.HandleClockSync(mock_sync, 'Response') expected_calls = [mock.call.info(mock.ANY, 'Response')] self.assertEqual(mock_logger.mock_calls, expected_calls) expected_calls = [mock.call.HandleClockSync(mock_logger)] self.assertEqual(mock_distro_utils.mock_calls, expected_calls)
def setUp(self): self.mock_logger = mock.Mock() self.mock_watcher = mock.Mock() self.mock_setup = mock.create_autospec(network_daemon.NetworkDaemon) self.mock_setup.logger = self.mock_logger self.mock_setup.watcher = self.mock_watcher self.mock_ip_forwarding = mock.Mock() self.mock_network_setup = mock.Mock() self.mock_network_utils = mock.Mock() self.mock_setup.ip_forwarding = self.mock_ip_forwarding self.mock_setup.network_setup = self.mock_network_setup self.mock_setup.network_utils = self.mock_network_utils
def testHandleClockSync(self, mock_distro_utils): mock_sync = mock.create_autospec(clock_skew_daemon.ClockSkewDaemon) mock_logger = mock.Mock() mock_sync.logger = mock_logger mock_sync.distro_utils = mock_distro_utils clock_skew_daemon.ClockSkewDaemon.HandleClockSync( mock_sync, 'Response') expected_calls = [mock.call.info(mock.ANY, 'Response')] self.assertEqual(mock_logger.mock_calls, expected_calls) expected_calls = [mock.call.HandleClockSync(mock_logger)] self.assertEqual(mock_distro_utils.mock_calls, expected_calls)
def testInstanceConfigExists(self, mock_init, mock_set, mock_exists): config_parser = instance_config.parser.SafeConfigParser() config_metadata = '[first]\na = true' mock_config = mock.create_autospec( instance_config.parser.SafeConfigParser) with mock.patch('google_compute_engine.instance_setup.instance_config' '.parser') as mock_parser: mock_config.read = mock.Mock() mock_config.sections = mock.Mock() mock_config.sections.return_value = ['a', 'b'] mock_config.items = lambda key: { 'key: %s' % key: 'value: %s' % key } mock_parser.SafeConfigParser.side_effect = [ config_parser, mock_config, mock_config ] mocks = mock.Mock() mocks.attach_mock(mock_init, 'init') mocks.attach_mock(mock_set, 'set') mocks.attach_mock(mock_parser, 'parser') mocks.attach_mock(mock_config, 'config') mocks.attach_mock(mock_exists, 'exists') mocks.attach_mock(self.mock_logger, 'logger') mock_exists.return_value = True instance_config.InstanceConfig( logger=self.mock_logger, instance_config_metadata=config_metadata) expected_calls = [ mock.call.init(config_file='template', config_header='/tmp/test.py template'), mock.call.parser.SafeConfigParser(), mock.call.exists('config'), mock.call.parser.SafeConfigParser(), mock.call.config.read('config'), mock.call.config.sections(), mock.call.exists('distro'), mock.call.parser.SafeConfigParser(), mock.call.config.read('distro'), mock.call.config.sections(), mock.call.set('first', 'a', 'true', overwrite=False), mock.call.set('a', 'key: a', 'value: a', overwrite=False), mock.call.set('b', 'key: b', 'value: b', overwrite=False), mock.call.set('a', 'key: a', 'value: a', overwrite=False), mock.call.set('b', 'key: b', 'value: b', overwrite=False), mock.call.set('first', 'a', 'false', overwrite=False), mock.call.set('second', 'b', 'true', overwrite=False), mock.call.set('third', 'c', '1', overwrite=False), mock.call.set('third', 'd', '2', overwrite=False), mock.call.set('third', 'e', '3', overwrite=False) ] self.assertEqual(mocks.mock_calls, expected_calls)
def testHandleClockSync(self, mock_call): command = ['/sbin/hwclock', '--hctosys'] mock_sync = mock.create_autospec(clock_skew_daemon.ClockSkewDaemon) mock_logger = mock.Mock() mock_sync.logger = mock_logger clock_skew_daemon.ClockSkewDaemon.HandleClockSync(mock_sync, 'Response') mock_call.assert_called_once_with(command) expected_calls = [ mock.call.info(mock.ANY, 'Response'), mock.call.info(mock.ANY), ] self.assertEqual(mock_logger.mock_calls, expected_calls)
def setUp(self): self.mock_logger = mock.Mock() self.mock_watcher = mock.Mock() self.mock_ip_forwarding_utils = mock.Mock() self.mock_network_utils = mock.Mock() self.metadata_key = 'metadata_key' self.mock_setup = mock.create_autospec(network_setup.NetworkSetup) self.mock_setup.logger = self.mock_logger self.mock_setup.watcher = self.mock_watcher self.mock_setup.network_utils = self.mock_network_utils self.mock_setup.network_interfaces = self.metadata_key self.mock_setup.dhcp_command = ''
def testHandleClockSyncError(self, mock_call): command = ['/sbin/hwclock', '--hctosys'] mock_sync = mock.create_autospec(clock_skew_daemon.ClockSkewDaemon) mock_logger = mock.Mock() mock_sync.logger = mock_logger mock_call.side_effect = subprocess.CalledProcessError(1, 'Test') clock_skew_daemon.ClockSkewDaemon.HandleClockSync(mock_sync, 'Response') mock_call.assert_called_once_with(command) expected_calls = [ mock.call.info(mock.ANY, 'Response'), mock.call.warning(mock.ANY), ] self.assertEqual(mock_logger.mock_calls, expected_calls)
def testHandleClockSync(self, mock_call): command = ['/sbin/hwclock', '--hctosys'] mock_sync = mock.create_autospec(clock_skew_daemon.ClockSkewDaemon) mock_logger = mock.Mock() mock_sync.logger = mock_logger clock_skew_daemon.ClockSkewDaemon.HandleClockSync( mock_sync, 'Response') mock_call.assert_called_once_with(command) expected_calls = [ mock.call.info(mock.ANY, 'Response'), mock.call.info(mock.ANY), ] self.assertEqual(mock_logger.mock_calls, expected_calls)
def setUp(self): self.mock_logger = mock.Mock() self.sudoers_group = 'google-sudoers' self.sudoers_file = '/sudoers/file' self.users_dir = '/users' self.users_file = '/users/file' self.mock_utils = mock.create_autospec(accounts_utils.AccountsUtils) self.mock_utils.google_comment = accounts_utils.AccountsUtils.google_comment self.mock_utils.google_sudoers_group = self.sudoers_group self.mock_utils.google_sudoers_file = self.sudoers_file self.mock_utils.google_users_dir = self.users_dir self.mock_utils.google_users_file = self.users_file self.mock_utils.logger = self.mock_logger
def testHandleClockSyncError(self, mock_call): command = ['/sbin/hwclock', '--hctosys'] mock_sync = mock.create_autospec(clock_skew_daemon.ClockSkewDaemon) mock_logger = mock.Mock() mock_sync.logger = mock_logger mock_call.side_effect = subprocess.CalledProcessError(1, 'Test') clock_skew_daemon.ClockSkewDaemon.HandleClockSync( mock_sync, 'Response') mock_call.assert_called_once_with(command) expected_calls = [ mock.call.info(mock.ANY, 'Response'), mock.call.warning(mock.ANY), ] self.assertEqual(mock_logger.mock_calls, expected_calls)
def testInstanceConfigExists(self, mock_init, mock_set, mock_exists): config_parser = instance_config.parser.Parser() config_metadata = '[first]\na = true' mock_config = mock.create_autospec(instance_config.parser.Parser) with mock.patch( 'google_compute_engine.instance_setup.instance_config' '.parser') as mock_parser: mock_config.read = mock.Mock() mock_config.sections = mock.Mock() mock_config.sections.return_value = ['a', 'b'] mock_config.items = lambda key: {'key: %s' % key: 'value: %s' % key} mock_parser.Parser.side_effect = [ config_parser, mock_config, mock_config] mocks = mock.Mock() mocks.attach_mock(mock_init, 'init') mocks.attach_mock(mock_set, 'set') mocks.attach_mock(mock_parser, 'parser') mocks.attach_mock(mock_config, 'config') mocks.attach_mock(mock_exists, 'exists') mocks.attach_mock(self.mock_logger, 'logger') mock_exists.return_value = True instance_config.InstanceConfig( logger=self.mock_logger, instance_config_metadata=config_metadata) expected_calls = [ mock.call.init( config_file='template', config_header='/tmp/test.py template'), mock.call.parser.Parser(), mock.call.exists('config'), mock.call.parser.Parser(), mock.call.config.read('config'), mock.call.config.sections(), mock.call.exists('distro'), mock.call.parser.Parser(), mock.call.config.read('distro'), mock.call.config.sections(), mock.call.set('first', 'a', 'true', overwrite=False), mock.call.set('a', 'key: a', 'value: a', overwrite=False), mock.call.set('b', 'key: b', 'value: b', overwrite=False), mock.call.set('a', 'key: a', 'value: a', overwrite=False), mock.call.set('b', 'key: b', 'value: b', overwrite=False), mock.call.set('first', 'a', 'false', overwrite=False), mock.call.set('second', 'b', 'true', overwrite=False), mock.call.set('third', 'c', '1', overwrite=False), mock.call.set('third', 'd', '2', overwrite=False), mock.call.set('third', 'e', '3', overwrite=False) ] self.assertEqual(mocks.mock_calls, expected_calls)
def testGetAccessToken(self, mock_watcher): mock_auth = mock.create_autospec(compute_auth.ComputeAuth) mock_auth.watcher = mock_watcher mock_auth.metadata_key = self.metadata_key mock_auth.service_account = self.service_account mock_watcher.GetMetadata.side_effect = [ {self.service_account: {'token': {'access_token': 'test'}}}, {}, ] self.assertEqual( compute_auth.ComputeAuth._GetAccessToken(mock_auth), 'test') self.assertEqual( compute_auth.ComputeAuth._GetAccessToken(mock_auth), None) expected_calls = [mock.call(metadata_key=self.metadata_key)] * 2 self.assertEqual(mock_watcher.GetMetadata.mock_calls, expected_calls)
def setUp(self): # Create a temporary directory. self.test_dir = tempfile.mkdtemp() self.mock_logger = mock.Mock() self.mock_watcher = mock.Mock() self.mock_ip_forwarding_utils = mock.Mock() self.mock_network_utils = mock.Mock() self.metadata_key = 'metadata_key' self.mock_setup = mock.create_autospec(network_setup.NetworkSetup) self.mock_setup.logger = self.mock_logger self.mock_setup.watcher = self.mock_watcher self.mock_setup.network_utils = self.mock_network_utils self.mock_setup.network_interfaces = self.metadata_key self.mock_setup.dhclient_script = '/bin/script' self.mock_setup.dhcp_command = ''
def setUp(self): # Create a temporary directory. self.test_dir = tempfile.mkdtemp() self.mock_logger = mock.Mock() self.mock_watcher = mock.Mock() self.mock_ip_forwarding_utils = mock.Mock() self.mock_network_utils = mock.Mock() self.metadata_key = 'metadata_key' self.mock_setup = mock.create_autospec(network_setup.NetworkSetup) self.mock_setup.logger = self.mock_logger self.mock_setup.watcher = self.mock_watcher self.mock_setup.network_utils = self.mock_network_utils self.mock_setup.network_interfaces = self.metadata_key self.mock_setup.network_path = '/etc/sysconfig/network-scripts' self.mock_setup.dhclient_script = '/bin/script' self.mock_setup.dhcp_command = ''
def setUp(self): self.mock_logger = mock.Mock() self.sudoers_group = 'google-sudoers' self.sudoers_file = '/sudoers/file' self.users_dir = '/users' self.users_file = '/users/file' self.useradd_cmd = 'useradd -m -s /bin/bash -p * {user}' self.userdel_cmd = 'userdel -r {user}' self.usermod_cmd = 'usermod -G {groups} {user}' self.groupadd_cmd = 'groupadd {group}' self.mock_utils = mock.create_autospec(accounts_utils.AccountsUtils) self.mock_utils.google_comment = accounts_utils.AccountsUtils.google_comment self.mock_utils.google_sudoers_group = self.sudoers_group self.mock_utils.google_sudoers_file = self.sudoers_file self.mock_utils.google_users_dir = self.users_dir self.mock_utils.google_users_file = self.users_file self.mock_utils.logger = self.mock_logger self.mock_utils.useradd_cmd = self.useradd_cmd self.mock_utils.userdel_cmd = self.userdel_cmd self.mock_utils.usermod_cmd = self.usermod_cmd self.mock_utils.groupadd_cmd = self.groupadd_cmd
def testGetAccessToken(self, mock_watcher): mock_auth = mock.create_autospec(compute_auth.ComputeAuth) mock_auth.watcher = mock_watcher mock_auth.metadata_key = self.metadata_key mock_auth.service_account = self.service_account mock_watcher.GetMetadata.side_effect = [ { self.service_account: { 'token': { 'access_token': 'test' } } }, {}, ] self.assertEqual(compute_auth.ComputeAuth._GetAccessToken(mock_auth), 'test') self.assertEqual(compute_auth.ComputeAuth._GetAccessToken(mock_auth), None) expected_calls = [mock.call(metadata_key=self.metadata_key)] * 2 self.assertEqual(mock_watcher.GetMetadata.mock_calls, expected_calls)
def setUp(self): self.mock_logger = mock.Mock() self.mock_setup = mock.create_autospec(utils.Utils)
def setUp(self): # Create a temporary directory. self.test_dir = tempfile.mkdtemp() self.mock_logger = mock.Mock() self.mock_setup = mock.create_autospec(utils.Utils) self.mock_setup.network_path = '/etc/sysconfig/network-scripts'
def setUp(self): self.mock_logger = mock.Mock() self.mock_setup = mock.create_autospec(utils.Utils) self.mock_setup.network_path = '/etc/sysconfig/network'