Skip to content

Commit

Permalink
[code] remove usage of socket.getfqdn()
Browse files Browse the repository at this point in the history
getfqdn constrains the deployment of ipol so that only one instance
can be hosted at the same time, which does not make sense for a service.
  • Loading branch information
kidanger committed Nov 19, 2023
1 parent 4f03818 commit 9d85230
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ci_tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class IntegrationTests(unittest.TestCase):
"""

# General
BASE_URL = os.environ.get("IPOL_URL", "http://" + socket.getfqdn())
BASE_URL = os.environ["IPOL_URL"]

# These variables are initialized in the __main__
test_ddl_file = None
Expand Down
4 changes: 2 additions & 2 deletions cp2/ControlPanel/ControlPanel/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

HOST_NAME = os.environ.get("IPOL_HOST", socket.getfqdn())
IPOL_URL = os.environ.get("IPOL_URL", "http://" + socket.getfqdn())
HOST_NAME = os.environ["IPOL_HOST"]
IPOL_URL = os.environ["IPOL_URL"]
ALLOWED_HOSTS = []

ACCOUNT_EMAIL_VERIFICATION = "none"
Expand Down
4 changes: 1 addition & 3 deletions cp2/ControlPanel/ControlPanel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

def api_post(resource, method, **kwargs):
try:
host = os.environ.get(
"IPOL_URL", f"http://{socket.gethostbyname(socket.getfqdn())}"
)
host = os.environ["IPOL_URL"]
if method == "get":
response = requests.get(f"{host}{resource}", **kwargs)
return response.json(), response.status_code
Expand Down
2 changes: 1 addition & 1 deletion ipol_demo/modules/archive/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ArchiveTests(unittest.TestCase):
ArchiveTests
"""

BASE_URL = os.environ.get("IPOL_URL", "http://" + socket.getfqdn())
BASE_URL = os.environ["IPOL_URL"]
module = "archive"

# Blob info
Expand Down
2 changes: 1 addition & 1 deletion ipol_demo/modules/blobs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BlobsTests(unittest.TestCase):
BlobsTests
"""

BASE_URL = os.environ.get("IPOL_URL", "http://" + socket.getfqdn())
BASE_URL = os.environ.get("IPOL_URL")
module = "blobs"

# Blob info
Expand Down
2 changes: 1 addition & 1 deletion ipol_demo/modules/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Settings(BaseSettings):
)
authorized_patterns: str = f"{config_common_dir}/authorized_patterns.conf"

base_url: str = os.environ.get("IPOL_URL", "http://" + socket.getfqdn())
base_url: str = os.environ["IPOL_URL"]

project_folder = os.path.expanduser("~") + "/ipolDevel"
blobs_folder = os.path.expanduser("~") + "/ipolDevel/ipol_demo/modules/blobs"
Expand Down
6 changes: 3 additions & 3 deletions ipol_demo/modules/core/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self):
os.path.expanduser("~") + "/ipolDevel/ipol_demo/modules/config_common"
)

self.base_url: str = os.environ.get("IPOL_URL", "http://" + socket.getfqdn())
self.base_url: str = os.environ["IPOL_URL"]

self.project_folder = os.path.expanduser("~") + "/ipolDevel"
self.blobs_folder = (
Expand All @@ -106,7 +106,7 @@ def __init__(self):
os.makedirs(self.dl_extras_dir, exist_ok=True)
os.makedirs(self.demo_extras_main_dir, exist_ok=True)

base_url = os.environ.get("IPOL_URL", "http://" + socket.getfqdn())
base_url = os.environ["IPOL_URL"]
demorunners_path = (
os.path.expanduser("~")
+ "/ipolDevel/ipol_demo/modules/config_common/demorunners.xml"
Expand Down Expand Up @@ -1377,7 +1377,7 @@ def post(api_url, method=None, **kwargs):
"""
General purpose function to make http requests.
"""
base_url = os.environ.get("IPOL_URL", "http://" + socket.getfqdn())
base_url = os.environ["IPOL_URL"]
if method == "get":
response = requests.get(f"{base_url}/{api_url}")
return response.json(), response.status_code
Expand Down
2 changes: 1 addition & 1 deletion ipol_demo/modules/core/core/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ async def run(
and "archive" in ddl
and (origin != "blobset" or ddl["archive"].get("archive_always"))
):
base_url = os.environ.get("IPOL_URL", "http://" + socket.getfqdn())
base_url = os.environ["IPOL_URL"]
try:
response, status_code = send_to_archive(
demo_id,
Expand Down
2 changes: 1 addition & 1 deletion ipol_demo/modules/demorunner/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class DemorunnerTests(unittest.TestCase):

# Demo Runners
demorunners = {}
base_url = os.environ.get("IPOL_URL", "http://" + socket.getfqdn())
base_url = os.environ["IPOL_URL"]

#####################
# Tests #
Expand Down
1 change: 1 addition & 0 deletions tools/demo2template/demo2template.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class Error(Exception):
origin_host = "ipolcore.ipol.im"

# Host destination of the demo
assert False, "this requires to be updated with correct urls"
destination_host = socket.getfqdn()
if (destination_host != "integration.ipol.im" and destination_host != "ipolcore.ipol.im"):
destination_host = "127.0.0.1"
Expand Down
1 change: 1 addition & 0 deletions tools/demo_copy/demo_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ def __init__(self, message):

print('Source: ', origin_host)
# Host destination of the demo
assert False, "this requires to be updated with correct urls"
destination_host = socket.getfqdn()
if (destination_host != "integration.ipol.im" and destination_host != "ipolcore.ipol.im"):
destination_host = "127.0.0.1"
Expand Down
1 change: 1 addition & 0 deletions tools/migrations/archive_db_migration_include_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def insert_experiments_ordered_in_database(database_file, exp):
#-----------------------------------------------------------------------
if __name__ == '__main__':

assert False, "this requires to be updated with correct urls"
server = socket.getfqdn()
os.system("clear")
try:
Expand Down

0 comments on commit 9d85230

Please sign in to comment.