def test_commands(tmp_path): tmpdir = os.path.join(tmp_path, "repo") repo = "https://github.com/singularityhub/singularity-compose-examples" # Clone the example run_command(["git", "clone", repo, tmpdir]) # Test the simple apache example workdir = os.path.join(tmpdir, "apache-simple") os.chdir(workdir) # Check for required files assert "singularity-compose.yml" in os.listdir() print("Creating project...") # Loading project validates config project = Project() print("Testing build") assert "httpd.sif" not in os.listdir("httpd") project.build() assert "httpd.sif" in os.listdir("httpd") print("Testing view config") project.view_config() print("Testing up") project.up() assert "etc.hosts" in os.listdir() assert "resolv.conf" in os.listdir() print("Waiting for instance to start") sleep(10) print("Testing logs") project.logs(["httpd"], tail=20) print("Clearing logs") project.clear_logs(["httpd"]) project.logs(["httpd"], tail=20) print("Testing ps") project.ps() print("Testing exec") project.execute("httpd", ["echo", "MarsBar"]) # Ensure running print(requests.get("http://127.0.0.1").status_code) print("Testing down") project.down() print("Testing ip lookup") lookup = project.get_ip_lookup(["httpd"]) assert "httpd" in lookup assert lookup["httpd"] == "10.22.0.2"
def test_commands(tmp_path): tmpdir = os.path.join(tmp_path, 'repo') repo = "https://github.com/singularityhub/singularity-compose-simple" # Clone the example run_command(["git", "clone", repo, tmpdir]) os.chdir(tmpdir) # Check for required files assert 'singularity-compose.yml' in os.listdir() print('Creating project...') # Loading project validates config project = Project() print('Testing build') assert 'app.sif' not in os.listdir('app') project.build() assert 'app.sif' in os.listdir('app') print('Testing view config') project.view_config() print('Testing up') project.up() assert 'etc.hosts' in os.listdir() assert 'resolv.conf' in os.listdir() print('Waiting for instance to start') sleep(10) print('Testing logs') project.logs(['app'], tail=20) print('Clearing logs') project.clear_logs(['app']) project.logs(['app'], tail=20) print('Testing ps') project.ps() print('Testing exec') project.execute('app', ['echo', 'MarsBar']) # Ensure running assert requests.get('http://127.0.0.1/').status_code == 200 assert 'db.sqlite3' in os.listdir('app') print('Testing down') project.down() print('Testing ip lookup') lookup = project.get_ip_lookup(['app']) assert 'app' in lookup assert lookup['app'] == '10.22.0.2'
def main(args, parser, extra): '''Build or rebuild containers Containers are built once and then named as <project>_<service>, e.g. `folder_db`. If a Singularity recipe changes for a container folder, you can run "singularity-compose build" to rebuild it. ''' # Initialize the project project = Project(filename=args.file, name=args.project_name, env_file=args.env_file) # Builds any containers into folders project.build(args.names)
def test_no_circular_dependency(tmp_path): bot.clear() ## Clear previously logged messages depends_on = os.path.join(here, "configs", "depends_on") for filename in os.listdir(depends_on): source = os.path.join(depends_on, filename) dest = os.path.join(tmp_path, filename) print("Copying %s to %s" % (filename, dest)) shutil.copyfile(source, dest) # Test the simple apache example os.chdir(tmp_path) # Check for required files assert "singularity-compose.yml" in os.listdir() print("Creating project...") # Loading project validates config project = Project() print("Testing build") project.build() for image in ["first.sif", "second.sif", "third.sif"]: assert image in os.listdir(tmp_path) print("Testing view config") project.view_config() # Test depends_on DAG order keys = list(project.instances.keys()) assert keys == ["first", "second", "third"] print("Testing up") project.up() print("Waiting for instances to start") sleep(10) print("Bringing down") project.down() log = bot.get_logs() assert log.index("Creating first") < log.index( "Creating second") and log.index("Creating second") < log.index( "Creating third")
def test_command_args(tmp_path): bot.clear() ## Clear previously logged messages cmd_args = os.path.join(here, "configs", "cmd_args") for filename in os.listdir(cmd_args): source = os.path.join(cmd_args, filename) dest = os.path.join(tmp_path, filename) print("Copying %s to %s" % (filename, dest)) shutil.copyfile(source, dest) # Test the simple apache example os.chdir(tmp_path) # Check for required files assert "singularity-compose.yml" in os.listdir() print("Creating project...") # Loading project validates config project = Project() print("Testing build") project.build() assert "echo.sif" in os.listdir(tmp_path) print("Testing view config") project.view_config() print("Testing up") project.up() print("Waiting for instances to start") sleep(10) print("Bringing down") project.down() log = bot.get_logs() assert "echo arg0 arg1 arg2" in log
def test_circular_dependency(tmp_path): depends_on = os.path.join(here, "configs", "wrong_depends_on") for filename in os.listdir(depends_on): source = os.path.join(depends_on, filename) dest = os.path.join(tmp_path, filename) print("Copying %s to %s" % (filename, dest)) shutil.copyfile(source, dest) # Test the simple apache example os.chdir(tmp_path) # Check for required files assert "singularity-compose.yml" in os.listdir() print("Creating project...") # Loading project validates config project = Project() print("Testing build") project.build() for image in ["first.sif", "second.sif", "third.sif"]: assert image in os.listdir(tmp_path) print("Testing view config") project.view_config() try: print("Testing up") project.up() raise Exception("Up should have failed") except SystemExit: print("Up failed as expected") finally: print("Bringing down") project.down()