Skip to content

Commit 2962304

Browse files
handle http:// while creating storage control client
1 parent a455909 commit 2962304

3 files changed

Lines changed: 40 additions & 16 deletions

File tree

gcsfs/extended_gcsfs.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from enum import Enum
99
from glob import has_magic
1010

11+
import grpc
1112
from fsspec import asyn
1213
from fsspec.callbacks import NoOpCallback
1314
from google.api_core import exceptions as api_exceptions
@@ -188,7 +189,14 @@ async def _get_control_plane_client(self):
188189
endpoint = self._location.split("://")[-1]
189190
channel_kwargs["host"] = endpoint
190191

191-
channel = transport_cls.create_channel(**channel_kwargs)
192+
if self._location and self._location.startswith("http://"):
193+
host = channel_kwargs["host"]
194+
channel = grpc.aio.insecure_channel(
195+
host, options=channel_kwargs.get("options")
196+
)
197+
else:
198+
channel = transport_cls.create_channel(**channel_kwargs)
199+
192200
transport = transport_cls(channel=channel)
193201
self._storage_control_client = storage_control_v2.StorageControlAsyncClient(
194202
transport=transport

gcsfs/tests/test_extended_hns_gcsfs.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,39 +2175,49 @@ async def test_get_control_plane_client_quota_project_id(
21752175

21762176
@pytest.mark.asyncio
21772177
@pytest.mark.parametrize(
2178-
"endpoint_url, env_updates, expected_host",
2178+
"endpoint_url, env_updates, expected_host, expected_insecure",
21792179
[
2180-
("https://my-endpoint.com", {}, "my-endpoint.com"),
2180+
("https://my-endpoint.com", {}, "my-endpoint.com", False),
21812181
(
21822182
None,
21832183
{
21842184
"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "apis-tpczero.goog",
21852185
"STORAGE_EMULATOR_HOST": "",
21862186
},
21872187
"storage.apis-tpczero.goog",
2188+
False,
21882189
),
21892190
(
21902191
None,
21912192
{
21922193
"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "apis-tpczero.goog",
2193-
"STORAGE_EMULATOR_HOST": "my-emulator.com",
2194+
"STORAGE_EMULATOR_HOST": "http://my-emulator.com",
21942195
},
21952196
"my-emulator.com",
2197+
True,
21962198
),
2197-
(None, {"STORAGE_EMULATOR_HOST": "my-emulator.com"}, "my-emulator.com"),
2198-
(None, {"STORAGE_EMULATOR_HOST": "http://my-emulator.com"}, "my-emulator.com"),
2199-
(None, {"STORAGE_EMULATOR_HOST": ""}, "storage.googleapis.com"),
2199+
(
2200+
None,
2201+
{"STORAGE_EMULATOR_HOST": "http://my-emulator.com"},
2202+
"my-emulator.com",
2203+
True,
2204+
),
2205+
(
2206+
None,
2207+
{"STORAGE_EMULATOR_HOST": "https://my-emulator.com"},
2208+
"my-emulator.com",
2209+
False,
2210+
),
2211+
(None, {"STORAGE_EMULATOR_HOST": ""}, "storage.googleapis.com", False),
22002212
],
22012213
)
22022214
async def test_get_control_plane_client_endpoint(
2203-
endpoint_url, env_updates, expected_host
2215+
endpoint_url, env_updates, expected_host, expected_insecure
22042216
):
22052217
fs_kwargs = {"token": "anon"}
22062218
if endpoint_url:
22072219
fs_kwargs["endpoint_url"] = endpoint_url
22082220

2209-
fs = ExtendedGcsFileSystem(**fs_kwargs)
2210-
22112221
mock_transport_cls = mock.Mock()
22122222
mock_channel = mock.Mock()
22132223
mock_transport_cls.create_channel.return_value = mock_channel
@@ -2220,16 +2230,22 @@ async def test_get_control_plane_client_endpoint(
22202230
"get_transport_class",
22212231
return_value=mock_transport_cls,
22222232
),
2233+
mock.patch("grpc.aio.insecure_channel") as mock_insecure_channel,
22232234
mock.patch.dict(os.environ, env_updates),
22242235
):
2225-
# Clear cached client to force re-initialization
2226-
fs._storage_control_client = None
2236+
ExtendedGcsFileSystem.clear_instance_cache()
2237+
fs = ExtendedGcsFileSystem(**fs_kwargs)
22272238

22282239
await fs._get_control_plane_client()
22292240

2230-
mock_transport_cls.create_channel.assert_called_once()
2231-
kwargs = mock_transport_cls.create_channel.call_args.kwargs
2232-
assert kwargs.get("host") == expected_host
2241+
if expected_insecure:
2242+
mock_insecure_channel.assert_called_once_with(
2243+
expected_host, options=mock.ANY
2244+
)
2245+
else:
2246+
mock_transport_cls.create_channel.assert_called_once()
2247+
kwargs = mock_transport_cls.create_channel.call_args.kwargs
2248+
assert kwargs.get("host") == expected_host
22332249

22342250

22352251
def test_extended_gcsfs_retry_init():

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ log_cli_level = "DEBUG"
7373

7474
[tool.isort]
7575
profile = "black"
76-
known_third_party = ["aiohttp", "click", "decorator", "fsspec", "fuse", "google", "google_auth_oauthlib", "numpy", "prettytable", "psutil", "pytest", "pytest_asyncio", "requests", "resource_monitor", "yaml"]
76+
known_third_party = ["aiohttp", "click", "decorator", "fsspec", "fuse", "google", "google_auth_oauthlib", "grpc", "numpy", "prettytable", "psutil", "pytest", "pytest_asyncio", "requests", "resource_monitor", "yaml"]

0 commit comments

Comments
 (0)