Skip to content

Commit 2d66bbc

Browse files
authored
Merge ace6540 into 8670901
2 parents 8670901 + ace6540 commit 2d66bbc

File tree

11 files changed

+30
-32
lines changed

11 files changed

+30
-32
lines changed

packages/postgres-database/src/simcore_postgres_database/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ def build_url(
1414
database: str = "",
1515
user: str = "",
1616
password: str = "",
17-
host: str = "localhost",
17+
host: str = "127.0.0.1",
1818
port: int = 5432,
1919
**_kwargs,
2020
) -> URL:
2121
"""
22-
Safe build pg url as 'postgresql+psycopg2://{user}:{password}@{host}:{port}/{database}'
22+
Safe build pg url as 'postgresql+psycopg2://{user}:{password}@{host}:{port}/{database}'
2323
"""
2424
dsn = URL.build(
2525
scheme="postgresql+psycopg2",

packages/postgres-database/tests/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
POSTGRES_USER: test
77
POSTGRES_PASSWORD: test
88
POSTGRES_DB: test
9-
POSTGRES_HOST: localhost
9+
POSTGRES_HOST: 127.0.0.1
1010
POSTGRES_PORT: 5432
1111
# NOTE: DO NOT ADD PERSISTENCE!
1212
ports:

packages/postgres-database/tests/test_utils.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
from yarl import URL
2-
31
from simcore_postgres_database.utils import hide_dict_pass, hide_url_pass
2+
from yarl import URL
43

54

65
def test_hide_url_pass():
76

87
assert (
9-
hide_url_pass(URL("postgres://username:password@localhost/myrailsdb"))
10-
== "postgres://username:********@localhost/myrailsdb"
8+
hide_url_pass(URL("postgres://username:password@127.0.0.1/myrailsdb"))
9+
== "postgres://username:********@127.0.0.1/myrailsdb"
1110
)
1211

1312

packages/service-library/src/servicelib/aiopg_utils.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class DataSourceName:
4343
user: str
4444
password: str = attr.ib(repr=False)
4545
database: str
46-
host: str = "localhost"
46+
host: str = "127.0.0.1"
4747
port: int = 5432
4848

4949
# Attributes about the caller
@@ -60,14 +60,14 @@ def to_uri(self, with_query=False) -> str:
6060

6161

6262
def create_pg_engine(dsn: DataSourceName, minsize: int = 1, maxsize: int = 4):
63-
""" Adapts the arguments of aiopg.sa.create_engine
63+
"""Adapts the arguments of aiopg.sa.create_engine
6464
65-
Returns a coroutine that is awaitable, i.e.
65+
Returns a coroutine that is awaitable, i.e.
6666
67-
async with create_pg_engine as engine:
68-
assert not engine.closed
67+
async with create_pg_engine as engine:
68+
assert not engine.closed
6969
70-
assert engine.closed
70+
assert engine.closed
7171
"""
7272
awaitable_engine_coro = create_engine(
7373
dsn.to_uri(),
@@ -154,8 +154,7 @@ def raise_http_unavailable_error(retry_state: RetryCallState):
154154

155155

156156
class PostgresRetryPolicyUponInitialization:
157-
""" Retry policy upon service initialization
158-
"""
157+
"""Retry policy upon service initialization"""
159158

160159
WAIT_SECS = 5
161160
ATTEMPTS_COUNT = 20
@@ -172,8 +171,7 @@ def __init__(self, logger: Optional[logging.Logger] = None):
172171

173172

174173
class PostgresRetryPolicyUponOperation:
175-
""" Retry policy upon service operation
176-
"""
174+
"""Retry policy upon service operation"""
177175

178176
WAIT_SECS = 2
179177
ATTEMPTS_COUNT = 3
@@ -195,8 +193,8 @@ def __init__(self, logger: Optional[logging.Logger] = None):
195193

196194

197195
def retry_pg_api(func):
198-
""" Decorator to implement postgres service retry policy and
199-
keep global statistics on service attempt fails
196+
"""Decorator to implement postgres service retry policy and
197+
keep global statistics on service attempt fails
200198
"""
201199
# TODO: temporary. For the time being, use instead postgres_service_retry_policy_kwargs
202200
_deco_func = retry(**postgres_service_retry_policy_kwargs)(func)

packages/service-library/tests/with_postgres/test_aiopg_utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import pytest
1515
import sqlalchemy as sa
1616
from aiohttp import web
17-
1817
from servicelib.aiopg_utils import (
1918
DatabaseError,
2019
DataSourceName,
@@ -141,7 +140,7 @@ async def test_engine_when_idle_for_some_time():
141140

142141
async def test_engine_when_pg_not_reachable(loop):
143142
dsn = DataSourceName(
144-
database="db", user="foo", password="foo", host="localhost", port=123
143+
database="db", user="foo", password="foo", host="127.0.0.1", port=123
145144
)
146145

147146
with pytest.raises(psycopg2.OperationalError):

services/api-server/.env-devel

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LOG_LEVEL=DEBUG
1313
POSTGRES_USER=test
1414
POSTGRES_PASSWORD=test
1515
POSTGRES_DB=test
16-
POSTGRES_HOST=localhost
16+
POSTGRES_HOST=127.0.0.1
1717

1818
# Enables debug
1919
SC_BOOT_MODE=debug-ptvsd

services/api-server/tests/unit/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def environment() -> Dict:
3737
env = {
3838
"WEBSERVER_HOST": "webserver",
3939
"WEBSERVER_SESSION_SECRET_KEY": "REPLACE ME with a key of at least length 32.",
40-
"POSTGRES_HOST": "localhost",
40+
"POSTGRES_HOST": "127.0.0.1",
4141
"POSTGRES_USER": "test",
4242
"POSTGRES_PASSWORD": "test",
4343
"POSTGRES_DB": "test",

services/api-server/tests/unit/test_settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ def test_min_environ_for_settings(project_env_devel_environment, monkeypatch):
1919
assert settings.boot_mode == BootModeEnum.PRODUCTION
2020
assert settings.loglevel == logging.DEBUG
2121

22-
assert settings.postgres.dsn == URL("postgresql://test:test@localhost:5432/test")
22+
assert settings.postgres.dsn == URL("postgresql://test:test@127.0.0.1:5432/test")

services/api-server/tests/utils/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
- POSTGRES_USER=${POSTGRES_USER:-test}
77
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-test}
88
- POSTGRES_DB=${POSTGRES_DB:-test}
9-
- POSTGRES_HOST=${POSTGRES_HOST:-localhost}
9+
- POSTGRES_HOST=${POSTGRES_HOST:-127.0.0.1}
1010
- POSTGRES_PORT=${POSTGRES_PORT:-5432}
1111
ports:
1212
- "5432:5432"

services/api-server/tests/utils/init-pg.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88

99
import aiopg.sa
1010
import faker
11-
import sqlalchemy as sa
12-
import yaml
13-
1411
import simcore_postgres_database.cli as pg_cli
1512
import simcore_service_api_server.db.tables as pg
13+
import sqlalchemy as sa
14+
import yaml
1615

1716
DSN_FORMAT = "postgresql://{user}:{password}@{host}:{port}/{database}"
1817

1918
default_db_settings = dict(
2019
user=os.environ.get("POSTGRES_USER", "test"),
2120
password=os.environ.get("POSTGRES_PASSWORD", "test"),
22-
host=os.environ.get("POSTGRES_HOST", "localhost"),
21+
host=os.environ.get("POSTGRES_HOST", "127.0.0.1"),
2322
port=os.environ.get("POSTGRES_PORT", 5432),
2423
database=os.environ.get("POSTGRES_DB", 5432),
2524
)
@@ -37,7 +36,7 @@ def load_db_config() -> Dict:
3736
return dict(
3837
user=environ["POSTGRES_USER"],
3938
password=environ["POSTGRES_PASSWORD"],
40-
host="localhost",
39+
host="127.0.0.1",
4140
port=5432,
4241
database=environ["POSTGRES_DB"],
4342
)
@@ -64,7 +63,10 @@ def random_user(**overrides):
6463

6564
def random_api_key(**overrides):
6665
data = dict(
67-
user_id=1, display_name=fake.word(), api_key=uuid4(), api_secret=uuid4(),
66+
user_id=1,
67+
display_name=fake.word(),
68+
api_key=uuid4(),
69+
api_secret=uuid4(),
6870
)
6971
data.update(overrides)
7072
return data

services/web/server/tests/unit/with_dbs/config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ db:
1919
database: test
2020
user: admin
2121
password: admin
22-
host: localhost
22+
host: 127.0.0.1
2323
port: 5432
2424
maxsize: 5
2525
minsize: 1

0 commit comments

Comments
 (0)