PermissionError: Unable to create paho python mqtt client instance in snap

Its now connected:

Interface      Plug                       Slot            Notes
home           olibox-core:home           :home           -
mount-observe  olibox-core:mount-observe  :mount-observe  manual
network        olibox-core:network        :network        -
network-bind   olibox-core:network-bind   :network-bind   -
ssh-keys       olibox-core:ssh-keys       -               -

but still there is same error.

you mean it still complains about /proc/*/mounts ?
you are jumping back and forth between topics here, this is very hard to follow … could you work on one thing at a time ?

I’m sorry.
from apparmor, add 'home' to 'plugs'
and from console, cp: cannot open './ca-certificates.crt' for reading: Permission denied

no

home is already added, but I think I can not connect to home manually.

@ogra the adjust program to not access '@{PROC}/@{pid}/mounts' arises when I run the snap out of current project directory. This can be fixed by manually connecting to the mount-observe interface.
after fixing this, I run the snap and got the cp: cannot open './ca-certificates.crt' for reading: Permission denied.

However, if I run the snap in the current project directory that contains the .crt file, then it works. But in the apparmor, it says adjust program to read necessary files from $SNAP, $SNAP_DATA, $SNAP_COMMON, $SNAP_USER_DATA or $SNAP_USER_COMMON.
so now I need a way to place the .crt to a location from where it should be available at the time of snap run as suggessted by @lucyllewy.
can you please guide where should I place the file?
thanks

I add following lines in parts in .yaml file:

  olibox-core-data:
    plugin: dump
    source: .

and updated the copy command in script as:

cp $SNAP/ca-certificates.crt $SNAP_USER_DATA/ca-certificates.crt

it seems working, I’m not sure is this is a correct approach to copy the files from project home directory to $SNAP_USER_DATA.

I’m trying to install snap on Raspbian. The snap is created with the following architectures specified in yaml file:

architectures: 
  - build-on: [ amd64, armhf ]
    run-on: [amd64, armhf]

When I tried to install the snap, I got the following warning:

sudo snap install olibox-core

error: cannot perform the following tasks:
- Mount snap "olibox-core" (2) (cannot find required base "core18")

I could fix the the warning as:

sudo snap install core
core 16-2.43.3 from 'canonical' installed

I reboot the Raspbian and tried to install the snap, the result is:
Screenshot%20from%202020-02-20%2010-08-21

can you please help me out what I’m doing wrong/missing here?
@ogra
thanks

versions:
snap 2.43.3
snapd 2.43.2
series 16
raspbian 9
kernel 4.19.66-v7+

the result of echo $PATH is:
Screenshot%20from%202020-02-20%2010-50-11

I could fix the /snap/bin was not found in your $PATH.... warning as described here:

but the 2nd error still exists:
Screenshot%20from%202020-02-20%2012-15-43

any thoughts about this, please?
thanks

the first lines seem to come from some hacks that raspbian does to /etc/ld.so.preload (forcing to preload that library even though snaps can simply not access it due to confinement) … you can ignore them, they should be harmless…

the python error looks like some error in your code trying to create a directory somewhere …

I’m just creating following files through script:

[ -e "$SNAP_USER_DATA/config.toml" ] || touch $SNAP_USER_DATA/config.toml

[ -e "$SNAP_USER_DATA/energy-data.json" ] || echo "{}" >> $SNAP_USER_DATA/energy-data.json

[ -e "$SNAP_USER_DATA/power-data.json" ] || echo "{}" >> $SNAP_USER_DATA/power-data.json

cp $SNAP/ca-certificates.crt $SNAP_USER_DATA/ca-certificates.crt

one more thing, the snap can be installed on ubunut 19.10 and can be run without errors.
These errors arise only on Raspbian.

your error is a python error, not a shell one … so it must be something in your python code obviously …

well, i cant help here, never using raspbian … my pi’s only run ubuntu core across the board.

I mean inside my python code I’m not creating any file. Just writing to the files created by script.

That’s likely not what you want. You need to ideally build on the target architecture. The block above tells snapcraft that it can build on either amd64 or armhf and that the resulting snap binaries will be runnable on both amd64 and armhf.

That means if you build on amd64 snapcraft will set that the snap can run on armhf (in addition to amd64) even though the binaries are only amd64.

Conversely if you build on armhf snapcraft will set that the snap can run on amd64 (in addition to armhf) even though the binaries are only armhf.

Neither of those are true.

Updated the .yaml file as:

architectures: 
  - build-on: armhf 
    run-on: armhf

but still getting the same error. :frowning_face: @lucyllewy any thoughts, please? thanks

it looks to me like it’s trying to parse python3 (an ELF binary) with an interpreter of some kind, possibly python3 recursively, which obviously isn’t going to work because it’s supposed to execute directly.

Do you perchance have python3 specified twice in your command line?

I’m sorry, I could not fully get your point.
these are the contents of .yaml file:

name: olibox-core
base: core18
version: '0.1dev'
summary: Core functionality for Oli box
description: |
    Olibox_core module provides the basic functionality 
    to wrtie data from IR sensor and REST API to json files
    and publish this data to mqtt broker.
    This utility is particularly useful for Oli box.
grade: devel
confinement: strict
architectures: 
  - build-on: armhf 
    run-on: armhf

parts:
  olibox-core:
    #source: https://github.com/olisystems/olibox_core.git
    source: .
    plugin: python
    requirements: ['requirements.txt']

  olibox-core-data:
    plugin: dump
    source: .

  launcher:
      plugin: nil
      source: .
      override-build: |
        mkdir -p $SNAPCRAFT_PART_INSTALL/bin
        cp -av mylauncher.sh $SNAPCRAFT_PART_INSTALL/bin/
apps:
  olibox-core:
    command: mylauncher.sh olibox-core
    plugs: [network, network-bind, ssh-keys, home, mount-observe]

and I’m calling my snap just using olibox-core.

I’m using plugin here and here in launcher:

do I need the same here?

@lucyllewy
I checked the architecture of the host system using uname -m and it is armv71.
should I use armv71 in architectures inside yaml?

I’m releasing the snap to snap store using the command ``
and the result is:

Revision 4 of 'olibox-core' created.
Track    Arch    Channel    Version    Revision
latest   amd64   stable     -          -
                 candidate  -          -
                 beta       0.1dev     4
                 edge       ^          ^

I’m wondering why it shows amd64 under Arch? I am expecting to see armhf as I only specified this in architectures.
is this an issue that causes the aforementioned errors or it is just because I’m creating the snap on ubuntu?

@lucyllewy
@ogra

I could not make it work for Raspbian and switched to Ubuntu core now but still getting the same error.
I have created a very simple test case, can you guys please be kind enough to have look at this issue:


thanks