Files
Sergio Cazzolato 9f4dc31742 tests: check files and dirs are cleaned for each test (#10443)
* Check files and dirs are cleaned

This is a new check to make sure all the files/dirs created are deleted
after the test is reset.

In a following PR the code could be moved to a test tool.

* Fix shellcheck

* Added /etc abd making checks for all the classic systems now

* Not adding /etc because until it is analyzed the result

File not deleted /etc/systemd/system/var-lib-snapd-snap-core-11378.mount
File not deleted
/etc/systemd/system/multi-user.target.wants/var-lib-snapd-snap-core-11378.mount
File not deleted /etc/environment
File not deleted
/etc/systemd/system/multi-user.target.wants/var-lib-snapd-snap-core-11378.mount
Dir not deleted /etc/systemd/system/snapd.service.d

* Fix error on arch linux

* Comments for exclude

* Remove /root/snap dir

This is created on tests and then it is not deleted

* Clean some tests which failed

* Check if inotifywait is running

* Add more cleanup

* Update how files and dirs are backed up to avoid creating new files

* Allways create the .fake file

* Reset test user bash_history

* Clean /root/.local /root/.cache

I see these dirs remaining:

Dir not deleted /root/.cache/snapcraft
Dir not deleted /root/.cache/snapcraft/download
Dir not deleted /root/.cache/snapcraft/stage-packages
Dir not deleted /root/.local
Dir not deleted /root/.local/share
Dir not deleted /root/.local/share/snapcraft
Dir not deleted /root/.local/share/snapcraft/projects
Dir not deleted /root/.local/share/snapcraft/projects/snapd

* Moved to fs-state and exclude monitor

* Fix shell check error

* Fixes for the tests/lib/tools/suite/fs-state test

* New option to backup a file and dir with a new empty file/dir

* Fix shift command

* Fix how /snap dir is cleaned

* Try again checking /etc

This will need to skip some changes related to the initial core 11378

* Count the number of times a file/dir is createad and deleted

This is to make more precise the check

* Count deleted files and dirs

* fix shell check

* Fix start-monitor command

* Skip backup files

* Exclude all the directories and files in /var/lib/snapd

* Include in teh exclude section the paths which are included in the state

All the paths which are in sync because they are included in the snpad
state which is automatically restored should be not tracked

* Updating directories included and excluded

* Fix shellcheck

* Adding more details to log

* Update how the created and deleted are counted

* New check using tree

The previous approach was not working at all
The files/dirs could be moved and that was not catched, so to make sure
the process worked it was needed to check all the events, not just
create and delete

* fix shellcheck

* install tree in all the systems

* ignore test.tar file

* Move to the initial step of prepare the start-monitor call

* Fix missing "

* Excluding runtime state dir

* Revert --new for mocking files and creating runtime files with the suite

* Not using tree separators anymore

* Improve the exclussion of files using grep and --noreport

* Skip monitor in case the tree command is not installed

* Clean tests

* Fix shell check

* Fix shellcheck

* fix yaml file

* Fix tests which are leaving data

* More cleanups for tests

* More test fixes

* More fixes for tests and tools

* fix issues

* Fix shellcheck

* Automatic removal for installed packages

* Some other test fixes

* Avoid removing empty packages

* Fix duplicated removal

* update function name on pkgdb

* Manually delete installed packages

* Improve cleanup and fix packages removal

* Moving test to focal

This is because there is a bug in postgres on xenial when removing hte
package

google:ubuntu-16.04-64
.../tests/main/special-home-can-run-classic-snaps# systemctl status
postgresql@9.5-main.service
● postgresql@9.5-main.service
   Loaded: not-found (Reason: No such file or directory)
Active: failed (Result: exit-code) since Tue 2021-08-24 20:40:23 UTC;
57min ago
 Main PID: 26307 (code=exited, status=0/SUCCESS)

Aug 24 20:40:15 aug242031-248411 systemd[1]: Starting PostgreSQL Cluster
9.5-main...
Aug 24 20:40:17 aug242031-248411 systemd[1]: Started PostgreSQL Cluster
9.5-main.
Aug 24 20:40:23 aug242031-248411 systemd[1]: Stopping PostgreSQL Cluster
9.5-main...
Aug 24 20:40:23 aug242031-248411 postgresql@9.5-main[26895]: Can't exec
"": No such file or directory at /usr/bin/pg_ctlcluster line 283.
Aug 24 20:40:23 aug242031-248411 systemd[1]:
postgresql@9.5-main.service: Control process exited, code=exited
status=1
Aug 24 20:40:23 aug242031-248411 systemd[1]: Stopped PostgreSQL Cluster
9.5-main.
Aug 24 20:40:23 aug242031-248411 systemd[1]:
postgresql@9.5-main.service: Unit entered failed state.
Aug 24 20:40:23 aug242031-248411 systemd[1]:
postgresql@9.5-main.service: Failed with result 'exit-code'.

* Move tree to find

* Use test.pkgs instead of pkgdb to list installed and remove pkgs

* fix missing call to cmd_list_installed

* Adding another missing parameter to list-installed

* Fix how diff file is checked

* Fix shellcheck error

* Remove check in case tree is not installed

* fix another shell check not related to this pr

* fix another shellcheck error not related to this pr

* Fix manual merge

* fix shellcheck
2021-08-27 09:19:19 -03:00

51 lines
1.6 KiB
YAML

summary: Ensure that the network-setup-control interface works.
details: |
The network setup control interface allows to access the different netplan
configuration files.
systems: [-ubuntu-core-*]
prepare: |
"$TESTSTOOLS"/snaps-state install-local test-snapd-sh
restore: |
rm -f /etc/network/test001 /etc/netplan/test001
execute: |
dirs="/etc/netplan /etc/network"
echo "The interface is disconnected by default"
snap interfaces -i network-setup-control | MATCH -- '^- +test-snapd-sh:network-setup-control'
echo "When the interface is connected"
snap connect test-snapd-sh:network-setup-control
echo "Then the snap is able to write in the network and netplan directories"
for dir in $dirs; do
if [ -d "$dir" ]; then
test-snapd-sh.with-network-setup-control-plug -c "touch $dir/test001"
fi
done
if [ "$(snap debug confinement)" = partial ] ; then
exit 0
fi
echo "When the plug is disconnected"
snap disconnect test-snapd-sh:network-setup-control
echo "Then the snap is not able to access the networking configuration dirs"
for dir in $dirs; do
if [ -d "$dir" ]; then
if test-snapd-sh.with-network-setup-control-plug -c "touch $dir/test002" 2>call.error; then
echo "Expected permission error calling desktop with disconnected plug"
exit 1
fi
MATCH "Permission denied" < call.error
fi
done
echo "Then the interface can be connected again"
snap connect test-snapd-sh:network-setup-control