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

Introduce initial logging infrastructure #182

Closed
wants to merge 2 commits into from

Conversation

marc0der
Copy link
Contributor

@marc0der marc0der commented Feb 21, 2021

This PR is part of #156 and performs the following:

  • Install python-systemd at system level (not installed by pip, as the systemd package is borked)
  • Set up and configure logger and journald logging handler
  • Introduce first snippets of logging when turbo mode is set, or can't be set

@AdnanHodzic
Copy link
Owner

I apologize for such delayed review, as always great stuff, but there's one problem with it.

It doesn't seem like it'll work as a snap, once snap is built with these changes and installed it'll fail due to following reason:

Traceback (most recent call last):
  File "/snap/auto-cpufreq/x1/bin/auto-cpufreq", line 14, in <module>
    from auto_cpufreq.core import *
  File "/snap/auto-cpufreq/x1/lib/python3.8/site-packages/auto_cpufreq/core.py", line 21, in <module>
    from systemd.journal import JournalHandler
ModuleNotFoundError: No module named 'systemd'

I tried building it by placing python3-systemd to python/build/stage-packages as part of snap/snapcraft.yaml but problem persists. Of course, this seems to be due to the fact that within Snap container systemd won't be available in traditional sense, so we need to figure out how we are going to work around this.

@marc0der
Copy link
Contributor Author

Thanks, @AdnanHodzic, my bad for not testing this well enough. Let me see if I can find a workaround for this problem.

@AdnanHodzic
Copy link
Owner

Thanks, @AdnanHodzic, my bad for not testing this well enough. Let me see if I can find a workaround for this problem.

No worries, let me know if I can help with anything.

@marc0der
Copy link
Contributor Author

marc0der commented Mar 7, 2021

I had a look into this and it doesn't seem to be related to systemd not being present in the snap itself. The problem seems to be that the python3-systemd module is not available to python, hence the error message while importing:

from systemd.journal import JournalHandler

ModuleNotFoundError: No module named 'systemd'

Looking at the snapcraft.yaml, I see that the PYTHONPATH is set to:

$SNAP/usr/lib/python3/site-packages:$SNAP/usr/lib/python3/dist-packages:$PYTHONPATH

Assuming that $SNAP is set to /snap, I'm not seeing any such thing as /snap/usr/lib/python3 on my system. Am I missing something?

@AdnanHodzic
Copy link
Owner

I had a look into this and it doesn't seem to be related to systemd not being present in the snap itself. The problem seems to be that the python3-systemd module is not available to python, hence the error message while importing:

from systemd.journal import JournalHandler

ModuleNotFoundError: No module named 'systemd'

It will be installed if I place python3-systemd to one of the stages in snapcraft,yaml.

Looking at the snapcraft.yaml, I see that the PYTHONPATH is set to:

$SNAP/usr/lib/python3/site-packages:$SNAP/usr/lib/python3/dist-packages:$PYTHONPATH

Assuming that $SNAP is set to /snap, I'm not seeing any such thing as /snap/usr/lib/python3 on my system. Am I missing something?

When running echo $SNAP inside a snap I get:

/snap/auto-cpufreq/x1

and inside that location I see the following:

drwxr-xr-x 11 root root  267 Mar  9 20:19 .
drwxr-xr-x  3 root root 4096 Mar  9 20:19 ..
-rwxrwxr-x  1 root root  815 Feb 14 10:50 auto-cpufreq-install.sh
-rwxrwxr-x  1 root root  725 Feb 14 10:50 auto-cpufreq-remove.sh
-rw-rw-r--  1 root root  242 Mar  9 20:03 auto-cpufreq.service
drwxr-xr-x  2 root root  540 Mar  9 20:18 bin
drwxr-xr-x  3 root root   53 Mar  9 20:18 etc
drwxr-xr-x  2 root root    3 Mar  9 20:18 include
drwxr-xr-x  4 root root   56 Mar  9 20:18 lib
drwxr-xr-x  2 root root   43 Mar  9 20:18 lib64
drwxr-xr-x  2 root root   32 Mar  9 20:19 meta
-rw-r--r--  1 root root   69 Mar  9 20:18 pyvenv.cfg
drwxr-xr-x  3 root root   36 Mar  9 20:18 share
drwxr-xr-x  3 root root   36 Mar  9 20:19 snap
drwxr-xr-x  6 root root   86 Mar  9 20:18 usr

I also see /usr/lib/python3 location inside of Snap environment with following contents:

dist-packages

@marc0der
Copy link
Contributor Author

marc0der commented Mar 10, 2021

@AdnanHodzic So we might have a problem here with snaps:

I resorted to installing python3-systemd using the package manager because the pip installation of systemd that provides the python bindings seemed to be borked when I tried it. Installing it with pacman, apt, zypper etc solved the problem for me with a standard install using the installer script.

I can't find any docs in the repo for building the snap package. Would you be able to share the commands you run to build it so I can try to get it working on my side?

@AdnanHodzic
Copy link
Owner

@marc0der

I resorted to installing python3-systemd using the package manager because the pip installation of systemd that provides the python bindings seemed to be borked when I tried it. Installing it with pacman, apt, zypper etc solved the problem for me with a standard install using the installer script.

It might be worth looking at http://forum.snapcraft.io/ for help. In past I asked questions regarding Snap's and they were incredibly attentive and helpful. Only mention of python3-systemd I can find is this one few years ago, so it might be worth starting a new thread.

I can't find any docs in the repo for building the snap package. Would you be able to share the commands you run to build it so I can try to get it working on my side?

In auto-cpufreq source root dir, run following to build a snap:

snapcraft clean
snapcraft

After it's done result will be i.e: auto-cpufreq_1.6.2_amd64.snap

Install it by running:

sudo snap install auto-cpufreq_1.6.2_amd64.snap --devmode

--devmode will give you full rights in what is normally a confined environment.

Regardless, after that auto-cpufreq will be installed and usable, to run shell inside snap environemnt run:

snap run --shell auto-cpufreq

I guess this will be enough to get you going so you can explore around it. In meantime if you get stuck with anything or have any questions please let me know.

@marc0der
Copy link
Contributor Author

Great, thanks for your help @AdnanHodzic

* Provide dependency on python-systemd
* Introduce journal logger
* Add first log case: set turbo mode
@AdnanHodzic
Copy link
Owner

Closed due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants