def test_add_app_exists(self, mock_labbook): """Test adding an app that already exists (update it)""" bam = BundledAppManager(mock_labbook[2]) assert os.path.exists(bam.bundled_app_file) is False result = bam.add_bundled_app(8050, 'dash 1', 'a demo dash app', 'python app.py') assert os.path.exists(bam.bundled_app_file) is True assert 'dash 1' in result assert result['dash 1']['port'] == 8050 assert result['dash 1']['description'] == 'a demo dash app' assert result['dash 1']['command'] == 'python app.py' result2 = bam.add_bundled_app(9000, 'dash 1', 'updated demo dash app', 'python app.py') assert 'dash 1' in result assert result2['dash 1']['port'] == 9000 assert result2['dash 1']['description'] == 'updated demo dash app' assert result2['dash 1']['command'] == 'python app.py' loaded_apps = bam.get_bundled_apps() assert result2 != result assert result2 == loaded_apps
def _start_dev_tool(cls, labbook: LabBook, username: str, dev_tool: str, container_override_id: str = None): router = ProxyRouter.get_proxy(labbook.client_config.config['proxy']) bam = BundledAppManager(labbook) bundled_apps = bam.get_bundled_apps() bundled_app_names = [x for x in bundled_apps] if dev_tool == "rstudio": suffix = cls._start_rstudio(labbook, router, username) elif dev_tool in ["jupyterlab", "notebook"]: # Note that starting the dev tool is identical whether we're targeting jupyterlab or notebook suffix = cls._start_jupyter_tool(labbook, router, username, container_override_id) elif dev_tool in bundled_app_names: app_data = bundled_apps[dev_tool] app_data['name'] = dev_tool suffix = cls._start_bundled_app(labbook, router, username, app_data, container_override_id) else: raise GigantumException(f"'{dev_tool}' not currently supported as a Dev Tool") # Don't include the port in the path if running on 80 apparent_proxy_port = labbook.client_config.config['proxy']["apparent_proxy_port"] if apparent_proxy_port == 80: path = suffix else: path = f':{apparent_proxy_port}{suffix}' return path
def test_remove_app(self, mock_labbook): """Test removing a bundled app""" bam = BundledAppManager(mock_labbook[2]) assert os.path.exists(bam.bundled_app_file) is False bam.add_bundled_app(8050, 'dash 1', 'a demo dash app 1', 'python app1.py') bam.add_bundled_app(9000, 'dash 2', 'a demo dash app 2', 'python app2.py') bam.add_bundled_app(9001, 'dash 3', 'a demo dash app 3', 'python app3.py') apps = bam.get_bundled_apps() assert os.path.exists(bam.bundled_app_file) is True assert 'dash 1' in apps assert apps['dash 1']['port'] == 8050 assert apps['dash 1']['description'] == 'a demo dash app 1' assert apps['dash 1']['command'] == 'python app1.py' assert 'dash 2' in apps assert apps['dash 2']['port'] == 9000 assert apps['dash 2']['description'] == 'a demo dash app 2' assert apps['dash 2']['command'] == 'python app2.py' assert 'dash 3' in apps assert apps['dash 3']['port'] == 9001 assert apps['dash 3']['description'] == 'a demo dash app 3' assert apps['dash 3']['command'] == 'python app3.py' bam.remove_bundled_app('dash 2') apps = bam.get_bundled_apps() assert 'dash 1' in apps assert 'dash 2' not in apps assert 'dash 3' in apps bam.remove_bundled_app('dash 3') apps = bam.get_bundled_apps() assert 'dash 1' in apps assert 'dash 2' not in apps assert 'dash 3' not in apps bam.remove_bundled_app('dash 1') apps = bam.get_bundled_apps() assert len(apps.keys()) == 0 assert isinstance(apps, OrderedDict)
def helper_resolve_bundled_apps(self, labbook): """Helper to get list of BundledApp objects""" bam = BundledAppManager(labbook) apps = bam.get_bundled_apps() return [ BundledApp(name=self.name, owner=self.owner, app_name=x) for x in apps ]
def _load_app_data(self): lb = InventoryManager().load_labbook(get_logged_in_username(), self.owner, self.name) bam = BundledAppManager(lb) apps = bam.get_bundled_apps() self.description = apps[self.app_name].get('description') self.port = apps[self.app_name].get('port') self.command = apps[self.app_name].get('command')
def test_start_bundled_app(self, build_lb_image_for_jupyterlab): test_file_path = os.path.join('/mnt', 'share', 'test.txt') try: lb = build_lb_image_for_jupyterlab[0] assert os.path.exists(test_file_path) is False bam = BundledAppManager(lb) bam.add_bundled_app(9002, 'my app', 'tester', f"echo 'teststr' >> {test_file_path}") apps = bam.get_bundled_apps() start_bundled_app(lb, 'unittester', apps['my app']['command']) time.sleep(3) assert os.path.exists(test_file_path) is True except: raise finally: if os.path.exists(test_file_path): os.remove(test_file_path)