def test_start_jupyterlab(self, build_lb_image_for_jupyterlab): container_id = build_lb_image_for_jupyterlab[4] docker_image_id = build_lb_image_for_jupyterlab[3] client = build_lb_image_for_jupyterlab[2] ib = build_lb_image_for_jupyterlab[1] lb = build_lb_image_for_jupyterlab[0] ec, stdo = client.containers.get(container_id=container_id).exec_run( 'sh -c "ps aux | grep jupyter | grep -v \' grep \'"', user='******') l = [a for a in stdo.decode().split('\n') if a] assert len(l) == 0 start_jupyter(lb, username='******', check_reachable=not (getpass.getuser() == 'circleci')) ec, stdo = client.containers.get(container_id=container_id).exec_run( 'sh -c "ps aux | grep jupyter-lab | grep -v \' grep \'"', user='******') l = [a for a in stdo.decode().split('\n') if a] assert len(l) == 1 # Now, we test the second path through, start jupyterlab when it's already running. start_jupyter(lb, username='******', check_reachable=not (getpass.getuser() == 'circleci')) # Validate there is only one instance running. ec, stdo = client.containers.get(container_id=container_id).exec_run( 'sh -c "ps aux | grep jupyter-lab | grep -v \' grep \'"', user='******') l = [a for a in stdo.decode().split('\n') if a] assert len(l) == 1
def _start_jupyter_tool(cls, lb: LabBook, pr: ProxyRouter, username: str, container_override_id: str = None): tool_port = 8888 lb_ip = ContainerOperations.get_labbook_ip(lb, username) lb_endpoint = f'http://{lb_ip}:{tool_port}' matched_routes = pr.get_matching_routes(lb_endpoint, 'jupyter') run_start_jupyter = True suffix = None if len(matched_routes) == 1: logger.info( f'Found existing Jupyter instance in route table for {str(lb)}.' ) suffix = matched_routes[0] # wait for jupyter to be up try: check_jupyter_reachable(lb_ip, tool_port, suffix) run_start_jupyter = False except GigantumException: logger.warning( f'Detected stale route. Attempting to restart Jupyter and clean up route table.' ) pr.remove(suffix[1:]) elif len(matched_routes) > 1: raise ValueError( f"Multiple Jupyter instances found in route table for {str(lb)}! Restart container." ) if run_start_jupyter: rt_prefix = unique_id() rt_prefix, _ = pr.add(lb_endpoint, f'jupyter/{rt_prefix}') # Start jupyterlab suffix = start_jupyter(lb, username, tag=container_override_id, proxy_prefix=rt_prefix) # Ensure we start monitor IFF jupyter isn't already running. start_labbook_monitor(lb, username, 'jupyterlab', url=f'{lb_endpoint}/{rt_prefix}', author=get_logged_in_author()) return suffix