Skip to content

Commit

Permalink
Add support for testing with docker
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed Oct 16, 2024
1 parent 60c37b4 commit f912a7a
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 13 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ jobs:
sudo systemctl restart docker.service
df -h
- name: Docker info
run: docker info
- name: Print disk space after cleanup
shell: bash
Expand All @@ -50,6 +48,11 @@ jobs:
run: |
pip install tqdm --break-system-packages
make bats-nocontainer
- name: bats-docker
run: |
docker info
pip install tqdm --break-system-packages
make bats-docker
macos:
runs-on: macos-14
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ bats:
bats-nocontainer:
_RAMALAMA_TEST_OPTS=--nocontainer RAMALAMA=$(CURDIR)/bin/ramalama bats -T test/system/

.PHONY: bats-docker
bats-docker:
_RAMALAMA_TEST_OPTS=--engine=docker RAMALAMA=$(CURDIR)/bin/ramalama bats -T test/system/

.PHONY: ci
ci:
test/ci.sh
Expand Down
16 changes: 13 additions & 3 deletions ramalama/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,21 @@ def _stop_container(args, name):
raise IndexError("no container manager (Podman, Docker) found")

conman_args = [conman, "stop", "-t=0"]
ignore_stderr=False
if args.ignore:
conman_args += ["--ignore", str(args.ignore)]
if conman == "podman":
conman_args += ["--ignore", str(args.ignore)]
else:
ignore_stderr=True

conman_args += [name]
run_cmd(conman_args)
try:
run_cmd(conman_args, ignore_stderr=ignore_stderr)
except subprocess.CalledProcessError:
if args.ignore and conman == "docker":
return
else:
raise


def stop_container(args):
Expand All @@ -507,7 +518,6 @@ def stop_container(args):

if args.NAME:
raise IndexError("specifying --all and container name, %s, not allowed" % args.NAME)
args.noheading = True
args.ignore = True
args.format = "{{ .Names }}"
for i in _list_containers(args):
Expand Down
8 changes: 6 additions & 2 deletions ramalama/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def exec_cmd(args, stderr=True):
raise


def run_cmd(args, cwd=None):
def run_cmd(args, cwd=None, ignore_stderr=False):
"""
Run the given command arguments.
Expand All @@ -65,7 +65,11 @@ def run_cmd(args, cwd=None):
if x:
print(*args)

return subprocess.run(args, check=True, cwd=cwd, stdout=subprocess.PIPE)
stderr=None
if ignore_stderr:
stderr=subprocess.PIPE

return subprocess.run(args, check=True, cwd=cwd, stdout=subprocess.PIPE, stderr=stderr)


def find_working_directory():
Expand Down
4 changes: 3 additions & 1 deletion test/system/030-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ load helpers
model=m_$(safename)
image=m_$(safename)

verify_begin="podman run --rm -i --label RAMALAMA --security-opt=label=disable -e RAMALAMA_TRANSPORT --name"
run_ramalama info
conman=$(jq .Engine <<< $output | tr -d '"' )
verify_begin="${conman} run --rm -i --label RAMALAMA --security-opt=label=disable -e RAMALAMA_TRANSPORT --name"

run_ramalama --dryrun run ${model}
is "$output" "${verify_begin} ramalama_.*" "dryrun correct"
Expand Down
9 changes: 6 additions & 3 deletions test/system/040-serve.bats
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ verify_begin=".*run --rm -i --label RAMALAMA --security-opt=label=disable -e RAM

run_ramalama serve --name ${container1} --detach ${model}
cid="$output"
run -0 podman inspect $cid
run_ramalama info
conmon=$(jq .Engine <<< $output)

run -0 ${conman} inspect1 $cid

run_ramalama ps
is "$output" ".*${container1}" "list correct for for container1"
Expand Down Expand Up @@ -100,8 +103,8 @@ verify_begin=".*run --rm -i --label RAMALAMA --security-opt=label=disable -e RAM
run_ramalama 22 stop
is "$output" "Error: must specify a container name" "name required"

run_ramalama 125 stop ${name}
is "$output" "Error: no container with name or ID \"${name}\" found: no such container.*" "missing container"
run_ramalama ? stop ${name}
is "$output" "Error.*such container.*" "missing container"

run_ramalama stop --ignore ${name}
is "$output" "" "ignore missing"
Expand Down
2 changes: 1 addition & 1 deletion test/system/060-info.bats
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ load helpers
Image | "quay.io/ramalama/ramalama:latest"
Runtime | "llama.cpp"
Version | "${version}"
Store | "${HOME}/.local/share/ramalama"
Store | \\\("${HOME}/.local/share/ramalama"\\\|"/var/lib/ramalama"\\\)
"

defer-assertion-failures
Expand Down
2 changes: 1 addition & 1 deletion test/system/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ function skip_if_nocontainer() {
}

function skip_if_darwin() {
[ "$(uname)" == "darwin" ] || skip "Not supported on darwin"
[ "$(uname)" != "darwin" ] || skip "Not supported on darwin"
}

# END miscellaneous tools
Expand Down

0 comments on commit f912a7a

Please sign in to comment.