def _RunDaemonIteration(args, host=None): """Run one iteration of daemon task. Args: args: a parsed argparse.Namespace object. host: an instance of host_util.Host. """ if not args.no_check_update: try: new_path = cli_util.CheckAndUpdateTool( args.cli_path, cli_update_url=args.cli_update_url) if new_path: logger.debug('CLI is updated.') os.execv(new_path, [new_path] + sys.argv[1:]) except Exception as e: logger.warning('Failed to check/update tool: %s', e) host = host or host_util.CreateHost(args) if host.config.enable_autoupdate: logger.debug('Auto-update enabled.') _UpdateMttNode(args, host) return if host.config.enable_ui_update: logger.debug('Update from UI enabled.') metadata = host.control_server_client.GetHostMetadata( host.config.hostname) test_harness_image = metadata.get(_TEST_HARNESS_IMAGE_KEY) logger.debug('Found metadata: %s.', metadata) if test_harness_image: logger.debug('Pinned to image: %s.', test_harness_image) host.config = host.config.SetDockerImage(test_harness_image) else: logger.warning( 'No test_harness_image is found in HostMetadata, updating with ' 'image from lab config file.') _UpdateMttNode(args, host)
def testCreateHost_withoutLabConfig(self, mock_getfqdn): mock_getfqdn.return_value = 'host1.google.com' args = mock.MagicMock(lab_config_path=None, service_account_json_key_path=None) host = host_util.CreateHost(args) self.assertEqual('host1.google.com', host.config.hostname) self.assertEqual(host_util._DEFAULT_MTT_IMAGE, host.config.docker_image) self.assertIsNotNone(host.context)
def testCreateHost(self, mock_gethostname, mock_build_lab_config_pool): mock_gethostname.return_value = 'host1' mock_build_lab_config_pool.return_value = self.mock_lab_config_pool self.mock_lab_config_pool.GetHostConfig.return_value = self.host_config1 args = mock.MagicMock(lab_config_path='lab_config.yaml', service_account_json_key_path=None) host = host_util.CreateHost(args) self.assertEqual(self.host_config1, host.config) self.assertIsNotNone(host.context)
def Stop(args, host=None): """Execute 'mtt stop [OPTION] ...' on local host. Args: args: a parsed argparse.Namespace object. host: an instance of host_util.Host. """ host = host or host_util.CreateHost(args) _StopMttDaemon(host) _StopMttNode(args, host)
def testCreateHost_WithOverrideValue(self, mock_gethostname, mock_build_lab_config_pool): json_key_path = '/path/to/key.json' mock_gethostname.return_value = 'host1' mock_build_lab_config_pool.return_value = self.mock_lab_config_pool self.mock_lab_config_pool.GetHostConfig.return_value = self.host_config1 args = mock.MagicMock(lab_config_path='lab_config.yaml', service_account_json_key_path=json_key_path) host = host_util.CreateHost(args) self.assertEqual(json_key_path, host.config.service_account_json_key_path) self.assertIsNotNone(host.context)
def Update(args, host=None): """Execute 'mtt update [OPTION] ...' on the local host. Args: args: a parsed argparse.Namespace object. host: an instance of host_util.Host. """ host = host or host_util.CreateHost(args) _StopMttDaemon(host) if host.config.enable_autoupdate: _StartMttDaemon(args, host) return if host.config.enable_ui_update: host.control_server_client.PatchTestHarnessImageToHostMetadata( host.config.hostname, host.config.docker_image) _StartMttDaemon(args, host) return _UpdateMttNode(args, host)
def Start(args, host=None): """Execute 'mtt start [OPTION] ...' on local host. Args: args: a parsed argparse.Namespace object. host: an instance of host_util.Host. Raises: RuntimeError: if a MTT node fails to start. """ host = host or host_util.CreateHost(args) if host.config.enable_autoupdate: _StartMttDaemon(args, host) return if host.config.enable_ui_update: host.control_server_client.PatchTestHarnessImageToHostMetadata( host.config.hostname, host.config.docker_image) _StartMttDaemon(args, host) return _StartMttNode(args, host)