mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
Initial varlink implementation
Signed-off-by: baude <bbaude@redhat.com> Closes: #627 Approved by: mheon
This commit is contained in:
37
test/varlink/run_varlink_tests.sh
Normal file
37
test/varlink/run_varlink_tests.sh
Normal file
@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
if [ ! -n "${PYTHON+ }" ]; then
|
||||
if hash python3 > /dev/null 2>&1 /dev/null; then
|
||||
PYTHON=$(hash -t python3)
|
||||
elif type python3 > /dev/null 2>&1; then
|
||||
PYTHON=$(type python3 | awk '{print $3}')
|
||||
elif hash python2 > /dev/null 2>&1; then
|
||||
PYTHON=$(hash -t python2)
|
||||
elif type python2 > /dev/null 2>&1; then
|
||||
PYTHON=$(type python2 | awk '{print $3}')
|
||||
else
|
||||
PYTHON='/usr/bin/python'
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create temporary directory for storage
|
||||
TMPSTORAGE=`mktemp -d`
|
||||
|
||||
# Need a location to store the podman socket
|
||||
mkdir /run/podman
|
||||
|
||||
# Run podman in background without systemd for test purposes
|
||||
bin/podman --storage-driver=vfs --root=${TMPSTORAGE}/crio --runroot=${TMPSTORAGE}/crio-run varlink unix:/run/podman/io.projectatomic.podman&
|
||||
|
||||
# Record podman's pid to be killed later
|
||||
PODMAN_PID=`echo $!`
|
||||
|
||||
# Run tests
|
||||
${PYTHON} -m unittest discover -s test/varlink/
|
||||
|
||||
# Kill podman
|
||||
kill -9 ${PODMAN_PID}
|
||||
|
||||
# Clean up
|
||||
rm -fr ${TMPSTORAGE}
|
99
test/varlink/test_containers.py
Normal file
99
test/varlink/test_containers.py
Normal file
@ -0,0 +1,99 @@
|
||||
import unittest
|
||||
from varlink import (Client, VarlinkError)
|
||||
|
||||
|
||||
address = "unix:/run/podman/io.projectatomic.podman"
|
||||
client = Client(address=address)
|
||||
|
||||
|
||||
def runErrorTest(tfunc):
|
||||
try:
|
||||
tfunc()
|
||||
except VarlinkError as e:
|
||||
return e.error() == "org.varlink.service.MethodNotImplemented"
|
||||
return False
|
||||
|
||||
|
||||
class ContainersAPI(unittest.TestCase):
|
||||
def test_ListContainers(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.ListContainers))
|
||||
|
||||
def test_CreateContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.CreateContainer))
|
||||
|
||||
def test_InspecContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.InspectContainer))
|
||||
|
||||
def test_ListContainerProcesses(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.ListContainerProcesses))
|
||||
|
||||
def test_GetContainerLogs(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.GetContainerLogs))
|
||||
|
||||
def test_ListContainerChanges(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.ListContainerChanges))
|
||||
|
||||
def test_ExportContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.ExportContainer))
|
||||
|
||||
def test_GetContainerStats(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.GetContainerStats))
|
||||
|
||||
def test_ResizeContainerTty(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.ResizeContainerTty))
|
||||
|
||||
def test_StartContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.StartContainer))
|
||||
|
||||
def test_RestartContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.RestartContainer))
|
||||
|
||||
def test_KillContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.KillContainer))
|
||||
|
||||
def test_UpdateContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.UpdateContainer))
|
||||
|
||||
def test_RenameContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.RenameContainer))
|
||||
|
||||
def test_PauseContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.PauseContainer))
|
||||
|
||||
def test_UnpauseContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.UnpauseContainer))
|
||||
|
||||
def test_AttachToContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.AttachToContainer))
|
||||
|
||||
def test_WaitContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.WaitContainer))
|
||||
|
||||
def test_RemoveContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.RemoveContainer))
|
||||
|
||||
def test_DeleteContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.DeleteContainer))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
71
test/varlink/test_images.py
Normal file
71
test/varlink/test_images.py
Normal file
@ -0,0 +1,71 @@
|
||||
import unittest
|
||||
from varlink import (Client, VarlinkError)
|
||||
|
||||
|
||||
address = "unix:/run/podman/io.projectatomic.podman"
|
||||
client = Client(address=address)
|
||||
|
||||
|
||||
def runErrorTest(tfunc):
|
||||
try:
|
||||
tfunc()
|
||||
except VarlinkError as e:
|
||||
return e.error() == "org.varlink.service.MethodNotImplemented"
|
||||
return False
|
||||
|
||||
|
||||
class ImagesAPI(unittest.TestCase):
|
||||
def test_ListImages(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.ListImages))
|
||||
|
||||
def test_BuildImage(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.BuildImage))
|
||||
|
||||
def test_CreateImage(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.CreateImage))
|
||||
|
||||
def test_InspectImage(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.InspectImage))
|
||||
|
||||
def test_HistoryImage(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.HistoryImage))
|
||||
|
||||
def test_PushImage(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.PushImage))
|
||||
|
||||
def test_TagImage(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.TagImage))
|
||||
|
||||
def test_RemoveImage(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.TagImage))
|
||||
|
||||
def test_SearchImage(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.SearchImage))
|
||||
|
||||
def test_DeleteUnusedImages(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.DeleteUnusedImages))
|
||||
|
||||
def test_CreateFromContainer(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.CreateFromContainer))
|
||||
|
||||
def test_ImportImage(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.ImportImage))
|
||||
|
||||
def test_ExportImage(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
self.assertTrue(runErrorTest(podman.ExportImage))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
21
test/varlink/test_system.py
Normal file
21
test/varlink/test_system.py
Normal file
@ -0,0 +1,21 @@
|
||||
import unittest
|
||||
from varlink import (Client, VarlinkError)
|
||||
|
||||
|
||||
address = "unix:/run/podman/io.projectatomic.podman"
|
||||
client = Client(address=address)
|
||||
|
||||
class SystemAPI(unittest.TestCase):
|
||||
def test_ping(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
response = podman.Ping()
|
||||
self.assertEqual("OK", response["ping"]["message"])
|
||||
|
||||
def test_GetVersion(self):
|
||||
podman = client.open("io.projectatomic.podman")
|
||||
response = podman.GetVersion()
|
||||
for k in ["version", "go_version", "built", "os_arch"]:
|
||||
self.assertTrue(k in response["version"].keys())
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user