Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integration: add basic test cases #44

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions Dockerfile.dapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
FROM registry.suse.com/bci/bci-base:15.4

ARG DAPPER_HOST_ARCH=amd64
ARG http_proxy
ARG https_proxy
ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH}
ENV PROTOBUF_VER=3.18.0

# Setup environment
ENV PATH /go/bin:$PATH
ENV DAPPER_DOCKER_SOCKET true
ENV DAPPER_ENV TAG REPO
ENV DAPPER_OUTPUT bin coverage.out
ENV DAPPER_RUN_ARGS --privileged --tmpfs /go/src/github.com/longhorn/longhorn-engine/integration/.venv:exec --tmpfs /go/src/github.com/longhorn/longhorn-engine/integration/.tox:exec -v /dev:/host/dev -v /proc:/host/proc
ENV DAPPER_SOURCE /go/src/github.com/longhorn/longhorn-engine
WORKDIR ${DAPPER_SOURCE}

RUN zypper -n addrepo --refresh https://download.opensuse.org/repositories/system:/snappy/SLE_15/system:snappy.repo && \
zypper -n addrepo --refresh https://download.opensuse.org/repositories/network:/utilities/SLE_15_SP4/network:utilities.repo && \
zypper -n addrepo --refresh https://download.opensuse.org/repositories/devel:libraries:c_c++/15.4/devel:libraries:c_c++.repo && \
zypper -n addrepo --refresh https://download.opensuse.org/repositories/devel:languages:python:Factory/15.4/devel:languages:python:Factory.repo && \
zypper -n addrepo --refresh https://download.opensuse.org/repositories/devel:languages:python:backports/SLE_15/devel:languages:python:backports.repo && \
zypper --gpg-auto-import-keys ref

RUN zypper -n install cmake wget curl git less file gcc \
libkmod-devel libnl3-devel linux-glibc-devel pkg-config psmisc tox qemu-tools fuse python3 python3-devel \
bash-completion librdmacm1 librdmacm-utils libibverbs xsltproc docbook-xsl-stylesheets \
perl-Config-General libaio-devel glibc-devel-static glibc-devel sg3_utils iptables libltdl7 \
python3-pip uuid-runtime libdevmapper1_03 iproute2 jq unzip \
rpm-build rdma-core-devel gcc-c++ docker util-linux-systemd grep nvme-cli && \
rm -rf rm -rf /var/cache/zypp/*

# needed for ${!var} substitution
RUN rm -f /bin/sh && ln -s /bin/bash /bin/sh

RUN if [ ${ARCH} == "s390x" ]; then \
ln -s /usr/bin/gcc /usr/bin/s390x-linux-gnu-gcc;\
fi

# Install Go & tools
ENV GOLANG_ARCH_amd64=amd64 GOLANG_ARCH_arm64=arm64 GOLANG_ARCH_s390x=s390x GOLANG_ARCH=GOLANG_ARCH_${ARCH} \
GOPATH=/go PATH=/go/bin:/usr/local/go/bin:${PATH} SHELL=/bin/bash
RUN wget -O - https://storage.googleapis.com/golang/go1.20.3.linux-${!GOLANG_ARCH}.tar.gz | tar -xzf - -C /usr/local && \
go install golang.org/x/lint/golint@latest

# GRPC dependencies
# GRPC health probe
ENV GRPC_HEALTH_PROBE_amd64=https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.3.2/grpc_health_probe-linux-amd64 \
GRPC_HEALTH_PROBE_arm64=https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.3.2/grpc_health_probe-linux-arm64 \
GRPC_HEALTH_PROBE_s390x=https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.3.2/grpc_health_probe-linux-s390x \
GRPC_HEALTH_PROBE=GRPC_HEALTH_PROBE_${ARCH}

RUN wget ${!GRPC_HEALTH_PROBE} -O /usr/local/bin/grpc_health_probe && \
chmod +x /usr/local/bin/grpc_health_probe

# protoc
ENV PROTOC_amd64=https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VER}/protoc-${PROTOBUF_VER}-linux-x86_64.zip \
PROTOC_arm64=https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VER}/protoc-${PROTOBUF_VER}-linux-aarch_64.zip \
PROTOC_s390x=https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VER}/protoc-${PROTOBUF_VER}-linux-s390_64.zip \
PROTOC=PROTOC_${ARCH}

RUN cd /usr/src && \
wget ${!PROTOC} -O protoc_${ARCH}.zip && \
unzip protoc_${ARCH}.zip -d /usr/local/

# protoc-gen-go
RUN cd /go/src/github.com/ && \
mkdir golang/ && \
cd golang && \
git clone https://github.com/golang/protobuf.git && \
cd protobuf && \
git checkout v1.3.2 && \
cd protoc-gen-go && \
go build && \
cp protoc-gen-go /usr/local/bin

# python grpc-tools
RUN if [ "${ARCH}" == "s390x" ]; then \
zypper -n in libopenssl-devel && \
GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=True pip3 install grpcio==1.25.0 grpcio_tools==1.25.0 protobuf==${PROTOBUF_VER}; \
else \
pip3 install grpcio==1.25.0 grpcio_tools==1.25.0 protobuf==${PROTOBUF_VER}; \
fi

# buf
ENV GO111MODULE=on
RUN go install github.com/bufbuild/buf/cmd/[email protected]

# Build cache for tox
RUN mkdir integration/
COPY integration/setup.py integration/tox.ini integration/requirements.txt integration/
RUN cd integration && \
if [ "${ARCH}" == "s390x" ]; then \
GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=True tox --notest;\
else \
tox --notest; \
fi

# Install libqcow to resolve error:
# vendor/github.com/longhorn/longhorn-engine/pkg/qcow/libqcow.go:6:11: fatal error: libqcow.h: No such file or directory
RUN wget -O - https://s3-us-west-1.amazonaws.com/rancher-longhorn/libqcow-alpha-20181117.tar.gz | tar xvzf - -C /usr/src
RUN cd /usr/src/libqcow-20181117 && \
./configure
RUN cd /usr/src/libqcow-20181117 && \
make -j$(nproc) && \
make install
RUN ldconfig

# Build SPDK
ENV SPDK_DIR /usr/src/spdk
RUN if [ ${ARCH} == "amd64" ]; then \
git clone https://github.com/longhorn/spdk.git ${SPDK_DIR} --recursive && \
cd ${SPDK_DIR} && \
git checkout 980f535d3876a5a6665486ad0cfaac5d584034aa && \
git submodule update --init && \
./scripts/pkgdep.sh && \
./configure --target-arch=nehalem --disable-tests --disable-unit-tests --disable-examples && \
make -j$(nproc) && \
make install && \
rm -rf ${SPDK_DIR}; \
fi

# Build longhorn-instance-manager for integration testing
RUN cd /go/src/github.com/longhorn && \
git clone https://github.com/derekbit/longhorn-instance-manager.git && \
cd longhorn-instance-manager && \
git checkout 1f6d365948ee53293c2719f95572cb4f4ad3b4cf && \
go build -o ./longhorn-instance-manager && \
cp -r integration/rpc/ ${DAPPER_SOURCE}/integration/rpc/ && \
cp longhorn-instance-manager /usr/local/bin

VOLUME /tmp
ENV TMPDIR /tmp
ENTRYPOINT ["./scripts/entry"]
CMD ["ci"]
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
TARGETS := $(shell ls scripts)

.dapper:
@echo Downloading dapper
@curl -sL https://releases.rancher.com/dapper/latest/dapper-`uname -s`-`uname -m` > .dapper.tmp
@@chmod +x .dapper.tmp
@./.dapper.tmp -v
@mv .dapper.tmp .dapper

$(TARGETS): .dapper
./.dapper $@

trash: .dapper
./.dapper -m bind trash

trash-keep: .dapper
./.dapper -m bind trash -k

deps: trash

.DEFAULT_GOAL := ci

.PHONY: $(TARGETS)
4 changes: 3 additions & 1 deletion generate_grpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ fi
# proto lint check
#buf check lint

protoc -I proto/spdkrpc/ -I proto/vendor/protobuf/src/ proto/spdkrpc/spdk.proto --go_out=plugins=grpc:proto/spdkrpc/
mkdir -p integration/rpc/spdk
protoc -I proto/spdkrpc/ -I proto/vendor/protobuf/src/ proto/spdkrpc/spdk.proto --go_out=plugins=grpc:proto/spdkrpc/
python3 -m grpc_tools.protoc -I proto/spdkrpc/ -I proto/vendor/protobuf/src/ --python_out=integration/rpc/spdk --grpc_python_out=integration/rpc/spdk proto/spdkrpc/spdk.proto
13 changes: 13 additions & 0 deletions integration/common/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os

INSTANCE_MANAGER_PROCESS_MANAGER = "localhost:8500"
INSTANCE_MANAGER_DISK = "localhost:8502"
INSTANCE_MANAGER_INSTANCE = "localhost:8503"
INSTANCE_MANAGER_SPDK = "localhost:8504"

DISK_TYPE = "block"
DISK_NAME = "test-disk"
DISK_PATH = "/dev/im-disk"
DISK_BLOCK_SIZE = 4096

POD_IP = "127.0.0.1"
13 changes: 13 additions & 0 deletions integration/common/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import socket

def get_pod_ip():
hostname = socket.gethostname()
addr_info = socket.getaddrinfo(hostname, None)

pod_ip = ""
for addr in addr_info:
if addr[0] == socket.AF_INET and addr[4][0] != "127.0.0.1":
pod_ip = addr[4][0]
break

return pod_ip
Empty file added integration/core/__init__.py
Empty file.
56 changes: 56 additions & 0 deletions integration/core/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import pytest


from rpc.imrpc.process_manager_client import ProcessManagerClient
from rpc.instance.instance_client import InstanceClient
from rpc.spdk.spdk_client import SPDKClient
from rpc.disk.disk_client import DiskClient

from common.constants import (
DISK_TYPE,
DISK_NAME,
DISK_PATH,
DISK_BLOCK_SIZE,
INSTANCE_MANAGER_PROCESS_MANAGER,
INSTANCE_MANAGER_INSTANCE,
INSTANCE_MANAGER_SPDK,
INSTANCE_MANAGER_DISK,
)

def delete_disk():
try:
disk_client = DiskClient(INSTANCE_MANAGER_DISK)
disk_client.disk_delete(DISK_TYPE, DISK_NAME, DISK_PATH)
except Exception as e:
raise e


@pytest.fixture
def grpc_instance_client(request, address=INSTANCE_MANAGER_INSTANCE):
try:
disk_client = DiskClient(INSTANCE_MANAGER_DISK)
disk_client.disk_create(DISK_TYPE, DISK_NAME, DISK_PATH,
DISK_BLOCK_SIZE)
except Exception as e:
raise e

request.addfinalizer(lambda: delete_disk())
return InstanceClient(address)


@pytest.fixture
def grpc_process_manager_client(request, address=INSTANCE_MANAGER_PROCESS_MANAGER):
c = ProcessManagerClient(address)
return c


@pytest.fixture
def grpc_disk_client(request, address=INSTANCE_MANAGER_DISK):
c = DiskClient(address)
return c


@pytest.fixture
def grpc_spdk_client(request, address=INSTANCE_MANAGER_SPDK):
c = SPDKClient(address)
return c
31 changes: 31 additions & 0 deletions integration/core/test_disk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import grpc
import pytest

from rpc.disk.disk_client import DiskClient


def test_disk_create_and_delete(grpc_disk_client):
disk_type = "block"
disk_name = "test-disk"
disk_path = "/dev/im-disk"
block_size = 4096

disk = grpc_disk_client.disk_create(disk_type, disk_name, disk_path,
block_size)
assert disk.type == disk_type
assert disk_path == disk.path
assert block_size == disk.block_size

disk = grpc_disk_client.disk_get(disk_type, disk_name, disk_path)
assert disk.type == disk_type
assert disk_path == disk.path
assert block_size == disk.block_size

grpc_disk_client.disk_delete(disk_type, disk_name, disk.uuid)

try:
disk = grpc_disk_client.disk_get(disk_type, disk_name, disk_path)
except Exception as e:
if "NotFound" not in str(e):
raise e
Loading