Merge ~smoser/cloud-init:cleanup/net-convert-add-debug into cloud-init:master

Proposed by Scott Moser
Status: Merged
Approved by: Scott Moser
Approved revision: 9bc7bc6e5ed1bc716fbfde963fa2b12603359486
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~smoser/cloud-init:cleanup/net-convert-add-debug
Merge into: cloud-init:master
Diff against target: 78 lines (+24/-4)
1 file modified
tools/net-convert.py (+24/-4)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Ryan Harper Approve
Review via email: mp+349484@code.launchpad.net

Commit message

tools: add '--debug' to tools/net-convert.py

In order to see some of the WARNING messages added by bug 1774666
I wanted logging output of tools/net-convert. This does:

a.) add '--debug' and make it print the network state and read yaml only
    if --debug is provided.
b.) set up basic logging so warnings goes to console by default and
    debug goes to console if --debug is provided.

Description of the change

see commit message

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:89df355378d78072e9576810d531c14b7efebdc2
https://jenkins.ubuntu.com/server/job/cloud-init-ci/164/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/164/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

Thanks. I sort of got used to the noisy output, but better to have it via --debug.

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
https://jenkins.ubuntu.com/server/job/cloud-init-autoland-test/7/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:9bc7bc6e5ed1bc716fbfde963fa2b12603359486
https://jenkins.ubuntu.com/server/job/cloud-init-ci/166/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/166/rebuild

review: Approve (continuous-integration)

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/tools/net-convert.py b/tools/net-convert.py
2index 68559cb..d1a4a64 100755
3--- a/tools/net-convert.py
4+++ b/tools/net-convert.py
5@@ -4,11 +4,13 @@
6 import argparse
7 import json
8 import os
9+import sys
10 import yaml
11
12 from cloudinit.sources.helpers import openstack
13
14 from cloudinit.net import eni
15+from cloudinit import log
16 from cloudinit.net import netplan
17 from cloudinit.net import network_state
18 from cloudinit.net import sysconfig
19@@ -29,14 +31,23 @@ def main():
20 metavar="name,mac",
21 action='append',
22 help="interface name to mac mapping")
23+ parser.add_argument("--debug", action='store_true',
24+ help='enable debug logging to stderr.')
25 parser.add_argument("--output-kind", "-ok",
26 choices=['eni', 'netplan', 'sysconfig'],
27 required=True)
28 args = parser.parse_args()
29
30+ if not args.directory.endswith("/"):
31+ args.directory += "/"
32+
33 if not os.path.isdir(args.directory):
34 os.makedirs(args.directory)
35
36+ if args.debug:
37+ log.setupBasicLogging(level=log.DEBUG)
38+ else:
39+ log.setupBasicLogging(level=log.WARN)
40 if args.mac:
41 known_macs = {}
42 for item in args.mac:
43@@ -53,8 +64,10 @@ def main():
44 pre_ns = yaml.load(net_data)
45 if 'network' in pre_ns:
46 pre_ns = pre_ns.get('network')
47- print("Input YAML")
48- print(yaml.dump(pre_ns, default_flow_style=False, indent=4))
49+ if args.debug:
50+ sys.stderr.write('\n'.join(
51+ ["Input YAML",
52+ yaml.dump(pre_ns, default_flow_style=False, indent=4), ""]))
53 ns = network_state.parse_net_config_data(pre_ns)
54 else:
55 pre_ns = openstack.convert_net_json(
56@@ -65,8 +78,10 @@ def main():
57 raise RuntimeError("No valid network_state object created from"
58 "input data")
59
60- print("\nInternal State")
61- print(yaml.dump(ns, default_flow_style=False, indent=4))
62+ if args.debug:
63+ sys.stderr.write('\n'.join([
64+ "", "Internal State",
65+ yaml.dump(ns, default_flow_style=False, indent=4), ""]))
66 if args.output_kind == "eni":
67 r_cls = eni.Renderer
68 elif args.output_kind == "netplan":
69@@ -75,6 +90,11 @@ def main():
70 r_cls = sysconfig.Renderer
71
72 r = r_cls()
73+ sys.stderr.write(''.join([
74+ "Read input format '%s' from '%s'.\n" % (
75+ args.kind, args.network_data.name),
76+ "Wrote output format '%s' to '%s'\n" % (
77+ args.output_kind, args.directory)]) + "\n")
78 r.render_network_state(network_state=ns, target=args.directory)
79
80

Subscribers

People subscribed via source and target branches