Merge ~bladernr/plainbox-provider-checkbox:1662724-fix-no-ip-traceback into plainbox-provider-checkbox:master

Proposed by Jeff Lane 
Status: Merged
Approved by: Pierre Equoy
Approved revision: ebb1f2b354f1ea4124e62a037fa7cfaa489111b0
Merged at revision: 573fff67d94422a8b158859f4943881a0a7a2750
Proposed branch: ~bladernr/plainbox-provider-checkbox:1662724-fix-no-ip-traceback
Merge into: plainbox-provider-checkbox:master
Diff against target: 61 lines (+16/-7)
1 file modified
bin/network (+16/-7)
Reviewer Review Type Date Requested Status
Pierre Equoy Approve
Review via email: mp+318157@code.launchpad.net

Description of the change

Fixes bug where a traceback is thrown if the network device under test has no IP address. Now when that happens, error messages are generated and the script aborts and exits with a 1.

To post a comment you must log in.
Revision history for this message
Pierre Equoy (pieq) wrote :

Testing on my device.

Before this MP:

% ./network test -i eno1
ERROR:root:No IP address for eno1
ERROR:root:No netmask for eno1
Traceback (most recent call last):
  File "./network", line 727, in <module>
    sys.exit(main())
  File "./network", line 723, in main
    return args.func(args)
  File "./network", line 457, in interface_test
    test_targets_list = make_target_list(args.interface, test_targets, True)
  File "./network", line 421, in make_target_list
    False)
  File "/usr/lib/python3.5/ipaddress.py", line 1525, in __init__
    self.network_address = IPv4Address(self._ip_int_from_string(addr[0]))
  File "/usr/lib/python3.5/ipaddress.py", line 1118, in _ip_int_from_string
    raise AddressValueError("Expected 4 octets in %r" % ip_str)
ipaddress.AddressValueError: Expected 4 octets in '1'

After:

% ./network test -i eno1
ERROR:root:No IP address for eno1
ERROR:root:No netmask for eno1
ERROR:root:Device eno1: Invalid IP Address
ERROR:root: Expected 4 octets in 'None'
ERROR:root:Aborting test now

Much more elegant! Both return 1 so this shouldn't change the outcome of the jobs in the test plans, only the ugly traceback shown in the logs :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/network b/bin/network
2index 88fd931..8291674 100755
3--- a/bin/network
4+++ b/bin/network
5@@ -260,7 +260,7 @@ class Interface(socket.socket):
6 nic_data = fcntl.ioctl(self.fileno(), 0x8915, freq)
7 except IOError:
8 logging.error("No IP address for %s", self.interface)
9- return 1
10+ return None
11 return socket.inet_ntoa(nic_data[20:24])
12
13 @property
14@@ -271,7 +271,7 @@ class Interface(socket.socket):
15 mask_data = fcntl.ioctl(self.fileno(), 0x891b, freq)
16 except IOError:
17 logging.error("No netmask for %s", self.interface)
18- return 1
19+ return None
20 return socket.inet_ntoa(mask_data[20:24])
21
22 @property
23@@ -433,9 +433,15 @@ def make_target_list(iface, test_targets, log_warnings):
24 List form of input string, minus invalid values
25 """
26 test_targets_list = test_targets.split(",")
27- net = ipaddress.IPv4Network("{}/{}".format(Interface(iface).ipaddress,
28- Interface(iface).netmask),
29- False)
30+ try:
31+ net = ipaddress.IPv4Network("{}/{}".format(Interface(iface).ipaddress,
32+ Interface(iface).netmask),
33+ False)
34+ except ipaddress.AddressValueError as e:
35+ logging.error("Device {}: Invalid IP Address".format(iface))
36+ logging.error(" {}".format(e))
37+ logging.error("Aborting test now")
38+ sys.exit(1)
39 first_addr = net.network_address + 1
40 last_addr = first_addr + net.num_addresses - 2
41 return_list = list(test_targets_list)
42@@ -471,7 +477,8 @@ def interface_test(args):
43 if (args.test_type.lower() == "iperf" or
44 args.test_type.lower() == "stress"):
45 test_targets = test_parameters["test_target_iperf"]
46- test_targets_list = make_target_list(args.interface, test_targets, True)
47+ test_targets_list = make_target_list(args.interface, test_targets,
48+ True)
49
50 # Validate that we got reasonable values
51 if not test_targets_list or "example.com" in test_targets:
52@@ -535,7 +542,9 @@ def interface_test(args):
53 if not test_targets_list:
54 logging.info(" Exhausted test target list; trying again "
55 .center(60, "="))
56- test_targets_list = make_target_list(args.interface, test_targets, False)
57+ test_targets_list = make_target_list(args.interface,
58+ test_targets,
59+ False)
60 time.sleep(30)
61 first_loop = False
62

Subscribers

People subscribed via source and target branches