This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/test/clients/client.py
2019-02-20 16:07:05 -05:00

119 lines
4.6 KiB
Python

from abc import ABCMeta, abstractmethod
from collections import namedtuple
from six import add_metaclass
Command = namedtuple('Command', ['command'])
# NOTE: FileCopy is done via `scp`, instead of `ssh` which is how Command is run.
FileCopy = namedtuple('FileCopy', ['source', 'destination'])
@add_metaclass(ABCMeta)
class Client(object):
""" Client defines the interface for all clients being tested. """
@abstractmethod
def setup_client(self, registry_host):
""" Returns the commands necessary to setup the client inside the VM.
"""
@abstractmethod
def populate_test_image(self, registry_host, namespace, name):
""" Returns the commands necessary to populate the test image. """
@abstractmethod
def print_version(self):
""" Returns the commands necessary to print the version of the client. """
@abstractmethod
def login(self, registry_host, username, password):
""" Returns the commands necessary to login. """
@abstractmethod
def push(self, registry_host, namespace, name):
""" Returns the commands necessary to test pushing. """
@abstractmethod
def pre_pull_cleanup(self, registry_host, namespace, name):
""" Returns the commands necessary to cleanup before pulling. """
@abstractmethod
def pull(self, registry_host, namespace, name):
""" Returns the commands necessary to test pulling. """
@abstractmethod
def verify(self, registry_host, namespace, name):
""" Returns the commands necessary to verify the pulled image. """
class DockerClient(Client):
def __init__(self, requires_v1=False):
self.requires_v1 = requires_v1
def setup_client(self, registry_host):
cp_command = ('sudo cp /home/core/50-insecure-registry.conf ' +
'/etc/systemd/system/docker.service.d/50-insecure-registry.conf')
yield Command('sudo mkdir -p /etc/systemd/system/docker.service.d/')
yield FileCopy('50-insecure-registry.conf', '/home/core')
yield FileCopy('Dockerfile.test', '/home/core/Dockerfile')
yield Command(cp_command)
yield Command('sudo systemctl daemon-reload')
def populate_test_image(self, registry_host, namespace, name):
if self.requires_v1:
# These versions of Docker don't support the new TLS cert on quay.io, so we need to pull
# from v1.quay.io and then retag so the build works.
yield Command('docker pull v1.quay.io/quay/busybox')
yield Command('docker tag v1.quay.io/quay/busybox quay.io/quay/busybox')
yield Command('docker build -t %s/%s/%s .' % (registry_host, namespace, name))
def print_version(self):
yield Command('docker version')
def login(self, registry_host, username, password):
yield Command('docker login --username=%s --password=%s %s' %
(username, password, registry_host))
def push(self, registry_host, namespace, name):
yield Command('docker push %s/%s/%s' % (registry_host, namespace, name))
def pre_pull_cleanup(self, registry_host, namespace, name):
prefix = 'v1.' if self.requires_v1 else ''
yield Command('docker rmi -f %s/%s/%s' % (registry_host, namespace, name))
yield Command('docker rmi -f %squay.io/quay/busybox' % prefix)
def pull(self, registry_host, namespace, name):
yield Command('docker pull %s/%s/%s' % (registry_host, namespace, name))
def verify(self, registry_host, namespace, name):
yield Command('docker run %s/%s/%s echo testfile' % (registry_host, namespace, name))
class PodmanClient(Client):
def setup_client(self, registry_host):
yield FileCopy('Dockerfile.test', '/home/vagrant/Dockerfile')
def populate_test_image(self, registry_host, namespace, name):
yield Command('sudo podman build -t %s/%s/%s /home/vagrant/' % (registry_host, namespace, name))
def print_version(self):
yield Command('sudo podman version')
def login(self, registry_host, username, password):
yield Command('sudo podman login --tls-verify=false --username=%s --password=%s %s' %
(username, password, registry_host))
def push(self, registry_host, namespace, name):
yield Command('sudo podman push --tls-verify=false %s/%s/%s' % (registry_host, namespace, name))
def pre_pull_cleanup(self, registry_host, namespace, name):
yield Command('sudo podman rmi -f %s/%s/%s' % (registry_host, namespace, name))
yield Command('sudo podman rmi -f quay.io/quay/busybox')
def pull(self, registry_host, namespace, name):
yield Command('sudo podman pull --tls-verify=false %s/%s/%s' % (registry_host, namespace, name))
def verify(self, registry_host, namespace, name):
yield Command('sudo podman run %s/%s/%s echo testfile' % (registry_host, namespace, name))