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

overlord/ifacestate: setup security backends phased by backends first #6128

Merged
merged 9 commits into from Nov 15, 2018
54 changes: 54 additions & 0 deletions tests/regression/lp-1802581/mock-gpio.py
@@ -0,0 +1,54 @@
#!/usr/bin/python3

import os
import selectors
import sys


def data_to_gpio(data):
return "gpio"+data.decode().strip()


def export_ready(fd, mask):
data = os.read(fd, 128)
# allow quit
if data == b'quit\n':
return False
with open(data_to_gpio(data), "w"):
pass
return True


def unexport_ready(fd, mask):
os.remove(data_to_gpio(os.read(fd, 128)))
return True


def dispatch(sel):
for key, mask in sel.select():
callback = key.data
if not callback(key.fileobj, mask):
return False
return True


if __name__ == "__main__":
os.chdir(sys.argv[1])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move this to main. Doing it like this makes sel, efd and ufd globals that can silently be picked up from typos elsewhere in the code.


# fake gpio export/unexport files
os.mkfifo("export")
os.mkfifo("unexport")

# ensure that we create the right
sel = selectors.DefaultSelector()
efd = os.open("export", os.O_RDWR | os.O_NONBLOCK)
ufd = os.open("unexport", os.O_RDWR | os.O_NONBLOCK)
sel.register(efd, selectors.EVENT_READ, export_ready)
sel.register(ufd, selectors.EVENT_READ, unexport_ready)
while True:
if not dispatch(sel):
break

# cleanup
os.close(efd)
os.close(ufd)
38 changes: 38 additions & 0 deletions tests/regression/lp-1802581/task.yaml
@@ -0,0 +1,38 @@
summary: Regression test for 1802581
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray space

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please cherry pick the documentation of the issue from the snap attached to the bug report?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the bugreport seems to be a private one.


systems: [ubuntu-core-16-64]

environment:
GPIO_MOCK_DIR: /home/test/gpio-mock

prepare: |
echo "Mock gpio"
mkdir -p "$GPIO_MOCK_DIR"
systemd-run --unit mock-gpio -- "$(pwd)/mock-gpio.py" "$GPIO_MOCK_DIR"
# shellcheck source=tests/lib/systemd.sh
. "$TESTSLIB/systemd.sh"
wait_for_service mock-gpio
mount --bind "$GPIO_MOCK_DIR" /sys/class/gpio
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the monkey patching of the Linux kernel :D


restore: |
systemctl stop mock-gpio || true
umount /sys/class/gpio || true
rm -rf "$GPIO_MOCK_DIR"

execute: |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test!

echo "Install a snap that uses the gpio consumer"
#shellcheck source=tests/lib/snaps.sh
. "$TESTSLIB"/snaps.sh
install_local gpio-consumer

echo "And connect the gpio pin"
snap connect gpio-consumer:gpio :gpio-pin
snap interfaces | MATCH ":gpio-pin.*gpio-consumer:gpio"

# LP-1802581
echo "Now disable and enable the snap to ensure lp: #1802581 is fixed"
snap disable gpio-consumer
snap enable gpio-consumer

echo "Check that the connection is still here after enable"
snap interfaces | MATCH ":gpio-pin.*gpio-consumer:gpio"