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
diff --git a/tools/net-convert.py b/tools/net-convert.py
index 68559cb..d1a4a64 100755
--- a/tools/net-convert.py
+++ b/tools/net-convert.py
@@ -4,11 +4,13 @@
4import argparse4import argparse
5import json5import json
6import os6import os
7import sys
7import yaml8import yaml
89
9from cloudinit.sources.helpers import openstack10from cloudinit.sources.helpers import openstack
1011
11from cloudinit.net import eni12from cloudinit.net import eni
13from cloudinit import log
12from cloudinit.net import netplan14from cloudinit.net import netplan
13from cloudinit.net import network_state15from cloudinit.net import network_state
14from cloudinit.net import sysconfig16from cloudinit.net import sysconfig
@@ -29,14 +31,23 @@ def main():
29 metavar="name,mac",31 metavar="name,mac",
30 action='append',32 action='append',
31 help="interface name to mac mapping")33 help="interface name to mac mapping")
34 parser.add_argument("--debug", action='store_true',
35 help='enable debug logging to stderr.')
32 parser.add_argument("--output-kind", "-ok",36 parser.add_argument("--output-kind", "-ok",
33 choices=['eni', 'netplan', 'sysconfig'],37 choices=['eni', 'netplan', 'sysconfig'],
34 required=True)38 required=True)
35 args = parser.parse_args()39 args = parser.parse_args()
3640
41 if not args.directory.endswith("/"):
42 args.directory += "/"
43
37 if not os.path.isdir(args.directory):44 if not os.path.isdir(args.directory):
38 os.makedirs(args.directory)45 os.makedirs(args.directory)
3946
47 if args.debug:
48 log.setupBasicLogging(level=log.DEBUG)
49 else:
50 log.setupBasicLogging(level=log.WARN)
40 if args.mac:51 if args.mac:
41 known_macs = {}52 known_macs = {}
42 for item in args.mac:53 for item in args.mac:
@@ -53,8 +64,10 @@ def main():
53 pre_ns = yaml.load(net_data)64 pre_ns = yaml.load(net_data)
54 if 'network' in pre_ns:65 if 'network' in pre_ns:
55 pre_ns = pre_ns.get('network')66 pre_ns = pre_ns.get('network')
56 print("Input YAML")67 if args.debug:
57 print(yaml.dump(pre_ns, default_flow_style=False, indent=4))68 sys.stderr.write('\n'.join(
69 ["Input YAML",
70 yaml.dump(pre_ns, default_flow_style=False, indent=4), ""]))
58 ns = network_state.parse_net_config_data(pre_ns)71 ns = network_state.parse_net_config_data(pre_ns)
59 else:72 else:
60 pre_ns = openstack.convert_net_json(73 pre_ns = openstack.convert_net_json(
@@ -65,8 +78,10 @@ def main():
65 raise RuntimeError("No valid network_state object created from"78 raise RuntimeError("No valid network_state object created from"
66 "input data")79 "input data")
6780
68 print("\nInternal State")81 if args.debug:
69 print(yaml.dump(ns, default_flow_style=False, indent=4))82 sys.stderr.write('\n'.join([
83 "", "Internal State",
84 yaml.dump(ns, default_flow_style=False, indent=4), ""]))
70 if args.output_kind == "eni":85 if args.output_kind == "eni":
71 r_cls = eni.Renderer86 r_cls = eni.Renderer
72 elif args.output_kind == "netplan":87 elif args.output_kind == "netplan":
@@ -75,6 +90,11 @@ def main():
75 r_cls = sysconfig.Renderer90 r_cls = sysconfig.Renderer
7691
77 r = r_cls()92 r = r_cls()
93 sys.stderr.write(''.join([
94 "Read input format '%s' from '%s'.\n" % (
95 args.kind, args.network_data.name),
96 "Wrote output format '%s' to '%s'\n" % (
97 args.output_kind, args.directory)]) + "\n")
78 r.render_network_state(network_state=ns, target=args.directory)98 r.render_network_state(network_state=ns, target=args.directory)
7999
80100

Subscribers

People subscribed via source and target branches