Skip to content

Commit 2990f2b

Browse files
Starting syslog and generating locales in IDE
1 parent 2090d79 commit 2990f2b

File tree

6 files changed

+56
-30
lines changed

6 files changed

+56
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ __pycache__
2222
/djl-serving/
2323
/src_diff/
2424
/tests/geckodriver.log
25+
/tests/.sm-ssh-owner

.gitlab-ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ run_tests:
2929
- tests/htmlcov/
3030
- tests/coverage.xml
3131
- tests/.coverage
32+
- tests/output/
3233
- bandit.txt
3334
- flake8.txt
3435

@@ -40,4 +41,5 @@ profile_tests:
4041
artifacts:
4142
when: always
4243
paths:
43-
- tests/prof/
44+
- tests/prof/
45+

sagemaker_ssh_helper/sm-helper-functions

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,28 @@ function _assert_is_ssh_ide_inside_studio() {
186186
exit 2
187187
fi
188188
}
189+
190+
function _locale_gen() {
191+
if _is_centos; then
192+
:
193+
else
194+
# Generating UTF-8 locales only for Debian
195+
locale-gen
196+
fi
197+
}
198+
199+
function _start_syslogd() {
200+
if _is_centos; then
201+
/usr/sbin/rsyslogd
202+
else
203+
service rsyslog start || (echo "ERROR: Failed to start syslogd service")
204+
fi
205+
}
206+
207+
function _start_sshd() {
208+
if _is_centos; then
209+
/usr/sbin/sshd
210+
else
211+
service ssh start || (echo "ERROR: Failed to start sshd service" && exit 255)
212+
fi
213+
}

sagemaker_ssh_helper/sm-setup-ssh

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,9 @@ if [[ "$1" == "start-ssh" ]]; then
102102
# Dump container bootstrap environment (PID 1) - can be different from above, useful for debugging
103103
ps wwwe -p 1 | tail -1
104104

105-
if _is_centos; then
106-
:
107-
else
108-
# Generating UTF-8 locales for Debian
109-
locale-gen
110-
fi
111-
112-
# Start SSH server
113-
if _is_centos; then
114-
# NOTE: systemctl will not work in CentOS SageMaker container (e.g. Spark processing) because lack of
115-
# privileges to access DBUS, so we run sshd manually. This command doesn't work:
116-
# systemctl start sshd
117-
/usr/sbin/rsyslogd
118-
/usr/sbin/sshd
119-
else
120-
service rsyslog start || (echo "ERROR: Failed to start syslogd service")
121-
service ssh start || (echo "ERROR: Failed to start ssh service" && exit 255)
122-
fi
105+
_locale_gen
106+
_start_syslogd
107+
_start_sshd
123108

124109
sm-init-ssm
125110

sagemaker_ssh_helper/sm-ssh-ide

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,14 @@ elif [[ "$1" == "start" ]]; then
177177
echo "sm-ssh-ide: Saving env variables for remote SSH interpreter"
178178
sm-save-env
179179

180+
echo "sm-ssh-ide: Generating UTF-8 locales"
181+
_locale_gen
182+
183+
echo "sm-ssh-ide: Starting Syslog service"
184+
_start_syslogd
185+
180186
echo "sm-ssh-ide: Starting SSH service"
181-
if _is_centos; then
182-
/usr/sbin/sshd
183-
else
184-
service ssh start || (echo "sm-ssh-ide: ERROR: Failed to start ssh service" && exit 255)
185-
fi
187+
_start_sshd
186188

187189
if [[ "$OPTIONS" != "--ssh-only" ]]; then
188190

tests/test_ide.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def test_sagemaker_studio(instances, request):
9595

9696
ide = SSHIDE(request.config.getini('sagemaker_studio_domain'), user)
9797

98+
# TODO:
99+
# os.env["LOCAL_USER_ID"] -> ./.sm-ssh-owner
100+
# ide.upload_UI("./.sm-ssh-owner", "/.sm-ssh-owner") - cannot upload dot file in UI?
101+
98102
ide.create_ssh_kernel_app(
99103
app_name,
100104
image_name_or_arn=image_name,
@@ -296,8 +300,14 @@ def test_studio_notebook_in_firefox(request):
296300
logging.info(f"Found SageMaker Studio kernel menu item: {kernel_menu_item}")
297301
kernel_menu_item.click()
298302

299-
# TODO: File -> Open from Path -> /sagemaker-ssh-helper/SageMaker_SSH_IDE.ipynb
300-
# TODO: File -> Save Notebook As... -> /SageMaker_SSH_IDE-DS2-CPU.ipynb
303+
# TODO: ide.upload_ssh("../SageMaker_SSH_IDE.ipynb", "/root/SageMaker_SSH_IDE-DS2-CPU.ipynb")
304+
# TODO: ide.upload_UI("../SageMaker_SSH_IDE.ipynb", "/SageMaker_SSH_IDE-DS2-CPU.ipynb")
305+
# TODO: ide.upload_UI("../", "/sagemaker-ssh-helper", exclude=["*"], include=["setup.py", "sagemaker_ssh_helper/"])
306+
# TODO: File -> Reload notebook from Disk
307+
# TODO: ide.add_new_cell([
308+
# "%%sh"
309+
# "pip3 install -U ./sagemaker-ssh-helper/"
310+
# ])
301311

302312
logging.info("Restarting kernel and running all cells")
303313
restart_menu_xpath = "//div[@class='lm-Menu-itemLabel p-Menu-itemLabel' " \
@@ -321,10 +331,6 @@ def test_studio_notebook_in_firefox(request):
321331

322332
time.sleep(120) # Give time to restart
323333

324-
# TODO: save notebook and download for comparison
325-
# TODO: ide.download("/root/SageMaker_SSH_IDE-DS2-CPU.ipynb",
326-
# "/tmp/SageMaker_SSH_IDE-DS2-CPU.ipynb")
327-
328334
studio_ids = ide.get_kernel_instance_ids("sagemaker-data-science-ml-m5-large-6590da95dc67eec021b14bedc036",
329335
timeout_in_sec=300)
330336
studio_id = studio_ids[0]
@@ -334,6 +340,11 @@ def test_studio_notebook_in_firefox(request):
334340
services_running = ssm_proxy.run_command_with_output("sm-ssh-ide status")
335341
services_running = services_running.decode('latin1')
336342

343+
# TODO: File -> Save Notebook
344+
# TODO: ide.download_ssh("/root/SageMaker_SSH_IDE-DS2-CPU.ipynb",
345+
# "./output/SageMaker_SSH_IDE-DS2-CPU.ipynb")
346+
# See: https://github.com/aws-samples/sagemaker-ssh-helper/issues/18
347+
337348
assert "127.0.0.1:8889" in services_running
338349
assert "127.0.0.1:5901" in services_running
339350

0 commit comments

Comments
 (0)