Skip to content

Fix/jupyter sftp port discovery #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions mig/shared/functionality/reqjupyterservice.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
Expand All @@ -20,7 +20,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Check warning on line 23 in mig/shared/functionality/reqjupyterservice.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
#
# -- END_HEADER ---
#
Expand Down Expand Up @@ -52,10 +52,14 @@
import time
import shutil
import random
import requests
try:
import requests
except ImportError as err:
requests = None

Check failure on line 58 in mig/shared/functionality/reqjupyterservice.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Incompatible types in assignment (expression has type "None", variable has type Module) [assignment]

from mig.shared import returnvalues
from mig.shared.base import client_id_dir, extract_field
from mig.shared.conf import get_configuration_object
from mig.shared.defaults import session_id_bytes
from mig.shared.fileio import make_symlink, pickle, unpickle, write_file, \
delete_symlink, delete_file
Expand All @@ -68,6 +72,18 @@
get_workflow_session_id


def __bail_out_requests(*args, **kwargs):

Check failure on line 75 in mig/shared/functionality/reqjupyterservice.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'kwargs' (100% confidence)

Check failure on line 75 in mig/shared/functionality/reqjupyterservice.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'args' (100% confidence)
"""Helper for dynamic bail out on actual use"""
raise Exception("jupyter functions require requests")


def __require_requests(func):
"""Internal helper to verify requests module availability on use"""
if requests is None:
return __bail_out_requests
return func


def is_active(pickle_state, timeout=7200):
"""
:param pickle_state: expects a pickle object dictionary that
Expand All @@ -77,7 +93,7 @@
default is 2 hours -> 7200 seconds
:return: Boolean
"""
assert isinstance(pickle_state, dict), "pickle_state is a dictionary: %r" % \

Check warning on line 96 in mig/shared/functionality/reqjupyterservice.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
pickle_state
assert 'CREATED_TIMESTAMP' in pickle_state

Expand All @@ -99,7 +115,7 @@
if not isinstance(input_str, basestring) or not input_str:
return None
input_str = input_str.lower()
valid_unix_name = "".join(re.findall('[a-z0-9_.\-]+', input_str))

Check warning on line 118 in mig/shared/functionality/reqjupyterservice.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

invalid escape sequence '\-'
if not valid_unix_name:
return None
return valid_unix_name[:32]
Expand All @@ -118,8 +134,8 @@
if "@" in mount_string and ":" in mount_string:
# Expects that the mount_string is in the format
# @mount_url:mount_path
target_host = mount_string[mount_string.index("@")+1:mount_string.index(":")]

Check warning on line 137 in mig/shared/functionality/reqjupyterservice.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (85 > 80 characters)
target_path = mount_string[mount_string.index(":")+1:]

Check warning on line 138 in mig/shared/functionality/reqjupyterservice.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

trailing whitespace

mount = {
'targetHost': target_host,
Expand Down Expand Up @@ -212,14 +228,14 @@
old_mounts.append(mount)
return latest, old_mounts


@__require_requests

Check warning on line 231 in mig/shared/functionality/reqjupyterservice.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

expected 2 blank lines, found 1
def get_host_from_service(configuration, service, base_url=None):
"""
Returns a URL from one of the services available hosts,
if no active host is found None is returned.
:param configuration: The MiG Configuration object
:param service: A service object that an active hosts should be found from
:param base_url: An optional postfix URL path that will be appended to the selected service host

Check warning on line 238 in mig/shared/functionality/reqjupyterservice.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (100 > 80 characters)
when trying to connect to the service.
:return: url string or None
"""
Expand Down Expand Up @@ -318,7 +334,7 @@
}
return ['', defaults]


@__require_requests

Check warning on line 337 in mig/shared/functionality/reqjupyterservice.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

expected 2 blank lines, found 1
def main(client_id, user_arguments_dict):
"""Main function used by front end"""
(configuration, logger, output_objects, op_name) = \
Expand Down Expand Up @@ -350,12 +366,7 @@
{'object_type': 'error_text', 'text':
'The required sftp service is not enabled on the system'})
return (output_objects, returnvalues.SYSTEM_ERROR)

if configuration.site_enable_sftp:
sftp_port = configuration.user_sftp_port

if configuration.site_enable_sftp_subsys:
sftp_port = configuration.user_sftp_subsys_port
sftp_port = configuration.user_sftp_show_port

requested_service = accepted['service'][-1]
service = {k: v for options in configuration.jupyter_services
Expand All @@ -381,7 +392,7 @@
)
return (output_objects, returnvalues.SYSTEM_ERROR)

host = get_host_from_service(configuration, service, base_url="/%s" % service["service_name"])

Check warning on line 395 in mig/shared/functionality/reqjupyterservice.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (98 > 80 characters)
# Get an active jupyterhost
if not host:
logger.error("No active jupyterhub host could be found")
Expand Down Expand Up @@ -494,7 +505,7 @@
workflow_session_id = get_workflow_session_id(configuration,
client_id)
if not workflow_session_id:
workflow_session_id = create_workflow_session_id(configuration,

Check warning on line 508 in mig/shared/functionality/reqjupyterservice.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (83 > 80 characters)
client_id)
# TODO get these dynamically
workflows_url = configuration.migserver_https_sid_url + \
Expand Down Expand Up @@ -653,7 +664,6 @@


if __name__ == "__main__":
from mig.shared.conf import get_configuration_object
if not os.environ.get('MIG_CONF', ''):
conf_path = os.path.join(os.path.dirname(sys.argv[0]),
'..', '..', 'server', 'MiGserver.conf')
Expand Down