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
Changes from 1 commit
61727a4
b59f5a4
6127cb0
dd08e0e
9588c9f
bd190c2
071616a
b6b1626
71b219f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) | ||
|
||
# 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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
summary: Regression test for 1802581 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stray space There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" |
There was a problem hiding this comment.
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 makessel
,efd
andufd
globals that can silently be picked up from typos elsewhere in the code.