lxc / python3-lxc

Python 3.x binding for liblxc
https://linuxcontainers.org/lxc
GNU Lesser General Public License v2.1
57 stars 38 forks source link

KeyError when getting the number of networks #15

Closed ach5948 closed 3 years ago

ach5948 commented 7 years ago

Required information

Distribution: Debian Distribution version: Stretch lxc-start --version: 2.0.7 uname -a: Linux 4.9.0-3-amd64 lxc/lxc#1 SMP Debian 4.9.30-2+deb9u2 (2017-06-26) x86_64 GNU/Linux This is specifically for the Python API python version: 3.5.3

Issue description

Calling the len() function on an empty ContainerNetworkList causes a KeyError.

Steps to reproduce

  1. create a new lxc container. test = lxc.Container("test")
  2. Call the len() function on the Network list len(test.network)

Information to attach

Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3/dist-packages/lxc/init.py", line 127, in len values = self.container.get_config_item("lxc.network") File "/usr/lib/python3/dist-packages/lxc/init.py", line 296, in get_config_item value = _lxc.Container.get_config_item(self, key) KeyError: 'Invalid configuration key'

Able to fix by changing the len function in the ContainerNetworkList class: wrap the line: values = self.container.get_config_item("lxc.network") in a try except block: try: values = self.container.get_config_item("lxc.network") except KeyError: return 0

anirudh-goyal commented 4 years ago

Hello, could me and my classmates work on this issue please?

chang-andrew commented 4 years ago

Oh oops, I opened a PR and I thought it would show up here but I guess I forgot to mention the issue in the PR itself. https://github.com/lxc/python3-lxc/pull/21.

stgraber commented 3 years ago

Sorry about that, didn't get the notification on this one...