ftao / python-ifcfg

Python cross-platform network interface discovery (ifconfig/ipconfig/ip)
BSD 3-Clause "New" or "Revised" License
55 stars 37 forks source link

Feature/raise on missing utils #45

Closed LoyVanBeek closed 4 years ago

LoyVanBeek commented 4 years ago

Fixes #44 Output in case both ifconfig and ip are missing is this:

root@83317aab73fc:/python-ifcfg/src/ifcfg# python3 cli.py 
Neither `ifconfig` (`ifconfig -a`) nor `ip` (`ip address show`) commands are available, listing network interfaces is likely to fail
/bin/sh: 1: ip: not found

Traceback (most recent call last):
  File "cli.py", line 13, in <module>
    main()
  File "cli.py", line 9, in main
    print(json.dumps(ifcfg.interfaces(), indent=2))
  File "/python-ifcfg/src/ifcfg/__init__.py", line 70, in interfaces
    return Parser(ifconfig=ifconfig).interfaces
  File "/python-ifcfg/src/ifcfg/parser.py", line 30, in __init__
    self.parse(self.ifconfig_data)
  File "/python-ifcfg/src/ifcfg/parser.py", line 57, in parse
    raise ValueError("Non-zero return code, reporting error-code '{}'".format(errors))
ValueError: Non-zero return code, reporting error-code '/bin/sh: 1: ip: not found
'

First is a warning, raised when the module is imported and the exception is raised when getting interfaces()

LoyVanBeek commented 4 years ago

Ack, this build now fails because ip and ifconfig are not available in the Travis runner :laughing:

benjaoming commented 4 years ago

Ack, this build now fails because ip and ifconfig are not available in the Travis runner laughing

Tests mock outputs of ip and ifconfig, except that there is one set of tests that run on the local system. Since Travis doesn't have the commands, it could make sense to just skip them if they're not there.

LoyVanBeek commented 4 years ago

The build is failing in the tests test_cp1252_encoding and test_cp1252_non_utf8_byte because those run on Windows. The command it trying to run, but that fails because the tests are of course not running on Windows.

That is now patched in the tests for weird windows encodings.

codecov-io commented 4 years ago

Codecov Report

Merging #45 into master will decrease coverage by 1.34%. The diff coverage is 42.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #45      +/-   ##
==========================================
- Coverage   84.68%   83.33%   -1.35%     
==========================================
  Files           4        4              
  Lines         235      240       +5     
==========================================
+ Hits          199      200       +1     
- Misses         36       40       +4
Impacted Files Coverage Δ
src/ifcfg/__init__.py 90% <33.33%> (-6.43%) :arrow_down:
src/ifcfg/parser.py 79.19% <50%> (-0.81%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 2d6a87f...4359fd2. Read the comment docs.

benjaoming commented 4 years ago

It's getting more and more messy with the architecture of this project... thinking about how Parser and get_command are developing. But I guess everyone can live with this, as long as IPs and interface names are quickly and correctly detected.

benjaoming commented 4 years ago

Released in 0.20