Ejemplo n.º 1
0
    def testGetCloudSDKRoot(self):
        class SDKRootValue(object):
            def __init__(self, sdk_root=None):
                # Accessed as a property.
                self.sdk_root = sdk_root

        # Limit the patch scope to this method, because TearDown() logic from other
        # modules also accesses util.config.Paths().
        with mock.patch.object(util.config, 'Paths') as paths_mock:
            paths_mock.return_value = SDKRootValue()
            with self.assertRaises(util.NoCloudSDKError):
                util.GetCloudSDKRoot()

            paths_mock.return_value = SDKRootValue('valid_root')
            self.assertEqual('valid_root', util.GetCloudSDKRoot())
def _BuildStartArgsForNativeExecutable(args):
    spanner_executable = os.path.join(util.GetCloudSDKRoot(), 'bin',
                                      SPANNER_EMULATOR_EXECUTABLE_DIR,
                                      SPANNER_EMULATOR_EXECUTABLE_FILE)
    return execution_utils.ArgsForExecutableTool(
        spanner_executable, '--hostname', args.host_port.host, '--grpc_port',
        args.host_port.port, '--http_port', six.text_type(args.rest_port))
Ejemplo n.º 3
0
def GetGCDRoot():
    """Gets the directory of the GCD emulator installation in the Cloud SDK.

  Raises:
    NoCloudSDKError: If there is no SDK root.
    NoGCDError: If the GCD installation dir does not exist.

  Returns:
    str, The path to the root of the GCD emulator installation within Cloud SDK.
  """
    sdk_root = util.GetCloudSDKRoot()
    gcd_dir = os.path.join(sdk_root, 'platform', 'cloud-datastore-emulator')
    if not os.path.isdir(gcd_dir):
        raise NoGCDError()
    return gcd_dir
Ejemplo n.º 4
0
def GetFirestoreEmulatorRoot():
  """Gets the directory of the Firestore emulator installation in the Cloud SDK.

  Raises:
    NoCloudSDKError: If there is no SDK root.
    NoFirestoreEmulatorError: If the installation dir does not exist.

  Returns:
    str, The path to the root of the Firestore emulator installation within
    Cloud SDK.
  """
  sdk_root = util.GetCloudSDKRoot()
  firestore_dir = os.path.join(sdk_root, 'platform', 'cloud-firestore-emulator')
  if not os.path.isdir(firestore_dir):
    raise NoFirestoreEmulatorError()
  return firestore_dir
Ejemplo n.º 5
0
def GetGCDRoot(args):
  """Gets the directory of the GCD emulator installation in the Cloud SDK.

  Args:
    args: Arguments passed to the command.

  Raises:
    NoCloudSDKError: If there is no SDK root.
    NoGCDError: If the GCD installation dir does not exist.

  Returns:
    str, The path to the root of the GCD emulator installation within Cloud SDK.
  """
  sdk_root = util.GetCloudSDKRoot()
  if args.legacy:
    gcd_dir = os.path.join(sdk_root, 'platform', 'gcd')
  else:
    gcd_dir = os.path.join(sdk_root, 'platform', 'cloud-datastore-emulator')
  if not os.path.isdir(gcd_dir):
    raise NoGCDError()
  return gcd_dir
  def __init__(self, address, config_file=None, broker_dir=None):
    """Constructor.

    Args:
      address: (str) The host or host-port of the broker server. The server may
          already be running.
      config_file: (str) The full path to the broker config file.
      broker_dir: (str) A custom path to the broker directory.
    """
    if config_file is not None:
      assert os.path.isabs(config_file)

    self._address = address
    self._config_file = config_file
    if broker_dir:
      self._broker_dir = broker_dir
    else:
      self._broker_dir = os.path.join(util.GetCloudSDKRoot(), 'bin', 'broker')

    self._host_port = arg_parsers.HostPort.Parse(address)
    self._current_platform = platforms.Platform.Current()
    self._process = None
    self._comm_thread = None