summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-07-08 06:28:12 +0000
committerDevaev Maxim <[email protected]>2018-07-08 06:28:12 +0000
commit41ce7ff2862816a7d97792851e00a6daf400905e (patch)
tree32ba8222b98f8a37310d20c581685db8e102c8fb
parentb1d72e86637b233d26e7b68724251d98030d6052 (diff)
test environment for docker
-rw-r--r--kvmd/Makefile38
-rw-r--r--kvmd/kvmd/application.py2
-rw-r--r--kvmd/kvmd/msd.py26
-rw-r--r--kvmd/testenv/Dockerfile43
-rw-r--r--kvmd/testenv/kvmd.yaml73
-rw-r--r--kvmd/testenv/requirements.txt (renamed from kvmd/dev_requirements.txt)0
-rw-r--r--kvmd/tox.ini8
7 files changed, 172 insertions, 18 deletions
diff --git a/kvmd/Makefile b/kvmd/Makefile
index 5a9737ef..d9e6d8fb 100644
--- a/kvmd/Makefile
+++ b/kvmd/Makefile
@@ -1,8 +1,37 @@
+TESTENV_IMAGE ?= kvmd-testenv
+TESTENV_VIDEO ?= /dev/video0
+TESTENV_LOOP ?= /dev/loop7
+TESTENV_CMD ?= /bin/bash -c " \
+ ln -s $(TESTENV_VIDEO) /dev/kvmd-streamer \
+ && (losetup -d /dev/kvmd-msd || true) \
+ && losetup /dev/kvmd-msd /root/loop.img \
+ && python -m kvmd -c testenv/kvmd.yaml \
+ "
+
+
+# =====
all:
cat Makefile
-bencoder:
- python3 setup.py build_ext --inplace
+
+run:
+ docker build --rm --tag $(TESTENV_IMAGE) -f testenv/Dockerfile .
+ - docker run --rm \
+ --volume `pwd`/kvmd:/kvmd:ro \
+ --volume `pwd`/web:/web:ro \
+ --volume `pwd`/testenv:/testenv:ro \
+ --device $(TESTENV_LOOP):/dev/kvmd-msd \
+ --device $(TESTENV_VIDEO):$(TESTENV_VIDEO) \
+ --publish 8080:8080/tcp \
+ --publish 8081:8081/tcp \
+ --publish 8082:8082/tcp \
+ -it $(TESTENV_IMAGE) $(TESTENV_CMD)
+ - docker run --rm --device=$(TESTENV_LOOP):/dev/kvmd-msd -it $(TESTENV_IMAGE) losetup -d /dev/kvmd-msd
+
+
+shell:
+ make run TESTENV_CMD=/bin/bash
+
release:
make clean
@@ -13,19 +42,24 @@ release:
make push
make clean
+
tox:
tox
+
bump:
bumpversion minor
+
push:
git push
git push --tags
+
clean:
rm -rf build site dist pkg src *.egg-info kvmd-*.tar.gz
find -name __pycache__ | xargs rm -rf
+
clean-all: clean
rm -rf .tox .mypy_cache
diff --git a/kvmd/kvmd/application.py b/kvmd/kvmd/application.py
index bdadf443..a78c1047 100644
--- a/kvmd/kvmd/application.py
+++ b/kvmd/kvmd/application.py
@@ -10,7 +10,7 @@ import yaml
# =====
def init() -> Dict:
parser = argparse.ArgumentParser()
- parser.add_argument("-c", "--config", default="kvmd.yaml", metavar="<path>")
+ parser.add_argument("-c", "--config", required=True, metavar="<path>")
options = parser.parse_args()
with open(options.config) as config_file:
diff --git a/kvmd/kvmd/msd.py b/kvmd/kvmd/msd.py
index 4a6b2554..84cd7477 100644
--- a/kvmd/kvmd/msd.py
+++ b/kvmd/kvmd/msd.py
@@ -50,11 +50,12 @@ class IsBusyError(MassStorageError):
class MassStorageDeviceInfo(NamedTuple):
path: str
+ real: str
size: int
- manufacturer: str
- product: str
- serial: str
image_name: str
+ manufacturer: str = ""
+ product: str = ""
+ serial: str = ""
_DISK_META_SIZE = 4096
@@ -101,15 +102,15 @@ def explore_device(path: str) -> Optional[MassStorageDeviceInfo]:
# udevadm info -a -p $(udevadm info -q path -n /dev/sda)
ctx = pyudev.Context()
- block_device = pyudev.Devices.from_device_file(ctx, path)
+ device = pyudev.Devices.from_device_file(ctx, path)
+ if device.subsystem != "block":
+ return None
try:
- size = block_device.attributes.asint("size") * 512
+ size = device.attributes.asint("size") * 512
except KeyError:
return None
- usb_device = block_device.find_parent("usb", "usb_device")
- if not usb_device:
- return None
+ usb_device = device.find_parent("usb", "usb_device")
with open(path, "rb") as device_file:
device_file.seek(size - _DISK_META_SIZE)
@@ -117,11 +118,14 @@ def explore_device(path: str) -> Optional[MassStorageDeviceInfo]:
return MassStorageDeviceInfo(
path=path,
+ real=(os.readlink(path) if os.path.islink(path) else ""),
size=size,
- manufacturer=usb_device.attributes.asstring("manufacturer").strip(),
- product=usb_device.attributes.asstring("product").strip(),
- serial=usb_device.attributes.asstring("serial").strip(),
image_name=disk_meta["image_name"],
+ **{
+ attr: usb_device.attributes.asstring(attr).strip()
+ for attr in ["manufacturer", "product", "serial"]
+ if usb_device
+ },
)
diff --git a/kvmd/testenv/Dockerfile b/kvmd/testenv/Dockerfile
new file mode 100644
index 00000000..12744df3
--- /dev/null
+++ b/kvmd/testenv/Dockerfile
@@ -0,0 +1,43 @@
+FROM base/archlinux
+
+RUN pacman -Syu --noconfirm \
+ && pacman -S --noconfirm \
+ git \
+ patch \
+ make \
+ fakeroot \
+ binutils \
+ expac \
+ jshon \
+ sudo \
+ && pacman -Sc --noconfirm
+
+RUN useradd -r -d / packer \
+ && cd /tmp \
+ && sudo -u packer git clone https://aur.archlinux.org/packer-color.git \
+ && cd packer-color \
+ && sudo -u packer makepkg \
+ && pacman --noconfirm -U packer-color-*.pkg.tar.xz \
+ && ln -s /usr/bin/packer-color /usr/local/bin/packer \
+ && cp /usr/bin/packer-color /usr/local/bin/user-packer \
+ && sed -i -e "s|makepkg \$MAKEPKGOPTS |chown -R packer:packer \$dir; makepkg \$MAKEPKGOPTS |g" \
+ /usr/local/bin/user-packer \
+ && sed -i -e "s|makepkg \$MAKEPKGOPTS --asroot -f|sudo -u packer makepkg \$MAKEPKGOPTS -f|g" \
+ /usr/local/bin/user-packer \
+ && cd - \
+ && rm -rf /tmp/packer-color
+
+RUN pacman -Syy \
+ && user-packer -S --noconfirm \
+ python \
+ python-pip \
+ nginx \
+ mjpg-streamer-pikvm \
+ && pacman -Sc --noconfirm
+
+COPY testenv/requirements.txt requirements.txt
+RUN pip install -r requirements.txt
+
+RUN dd if=/dev/zero of=/root/loop.img bs=1024 count=1048576
+
+CMD /bin/bash
diff --git a/kvmd/testenv/kvmd.yaml b/kvmd/testenv/kvmd.yaml
new file mode 100644
index 00000000..1956fe16
--- /dev/null
+++ b/kvmd/testenv/kvmd.yaml
@@ -0,0 +1,73 @@
+kvmd:
+ server:
+ host: 0.0.0.0
+ port: 8081
+ heartbeat: 3.0
+
+ keyboard:
+ pinout:
+ clock: 17
+ data: 4
+
+ pulse: 0.0002
+
+ atx:
+ pinout:
+ power_led: 16
+ hdd_led: 12
+ power_switch: 26
+ reset_switch: 20
+
+ click_delay: 0.1
+ long_click_delay: 5.5
+
+ state_poll: 0.1
+
+ msd:
+ device: "/dev/kvmd-msd"
+ init_delay: 2.0
+ write_meta: true
+ chunk_size: 8192
+
+ streamer:
+ pinout:
+ cap: 21
+ conv: 25
+
+ sync_delay: 1.0
+ init_delay: 1.0
+ shutdown_delay: 10.0
+
+ size:
+ width: 720
+ height: 576
+
+ cmd:
+ - "/usr/bin/mjpg_streamer"
+ - "-i"
+ - "input_uvc.so -d /dev/kvmd-streamer -e 2 -y -n -r {width}x{height}"
+ - "-o"
+ - "output_http.so -l 0.0.0.0 -p 8082"
+
+logging:
+ version: 1
+ disable_existing_loggers: false
+
+ formatters:
+ console:
+ (): logging.Formatter
+ style: "{"
+ datefmt: "%H:%M:%S"
+ format: "[{asctime}] {name:20.20} {levelname:>7} --- {message}"
+
+ handlers:
+ console:
+ level: DEBUG
+ class: logging.StreamHandler
+ stream: ext://sys.stdout
+ formatter: console
+
+ root:
+ level: INFO
+ handlers:
+ - console
diff --git a/kvmd/dev_requirements.txt b/kvmd/testenv/requirements.txt
index d054c0ee..d054c0ee 100644
--- a/kvmd/dev_requirements.txt
+++ b/kvmd/testenv/requirements.txt
diff --git a/kvmd/tox.ini b/kvmd/tox.ini
index d627345f..18c839f2 100644
--- a/kvmd/tox.ini
+++ b/kvmd/tox.ini
@@ -10,25 +10,25 @@ commands = flake8 kvmd
deps =
flake8
flake8-double-quotes
- -rdev_requirements.txt
+ -rtestenv/requirements.txt
[testenv:pylint]
commands = pylint --output-format=colorized --reports=no kvmd
deps =
pylint
- -rdev_requirements.txt
+ -rtestenv/requirements.txt
[testenv:mypy]
commands = mypy kvmd
deps =
mypy
- -rdev_requirements.txt
+ -rtestenv/requirements.txt
[testenv:vulture]
commands = vulture kvmd
deps =
vulture
- -rdev_requirements.txt
+ -rtestenv/requirements.txt
[flake8]
max-line-length = 160