Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional debugging #22

Merged
merged 3 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packetnetworking/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def run(self, rootfs_path):
builder.build()
return builder.run(rootfs_path)

def as_dict(self):
return {"metadata": self.metadata, "network": self.network.as_dict()}


class NetworkData(object):
def __init__(self, default_resolvers=None, default_private_subnets=None):
Expand Down Expand Up @@ -117,3 +120,13 @@ def build_addresses(self):

def build_resolvers(self):
self.resolvers = utils.resolvers(self.resolvers)

def as_dict(self):
return {
"bonding": self.bonding,
"interfaces": self.interfaces,
"bonds": self.bonds,
"addresses": self.addresses,
"resolvers": self.resolvers,
"private_subnets": self.private_subnets,
}
11 changes: 10 additions & 1 deletion packetnetworking/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
+ "(otherwise uses ones from /etc/resolv.conf)"
),
)
@click.option("-n", "--max-attempts", default=10, help="retry up to N times on failure")
@click.option(
"-n",
"--max-attempts",
default=10,
help="Retry up to N times on failure when downloading metadata from a url",
)
@click.option("-v", "--verbose", count=True, help="Provide more detailed output")
@click.option("-q", "--quiet", is_flag=True, help="Silences all output")
def cli(
Expand Down Expand Up @@ -91,6 +96,10 @@ def cli(
)
break
except Exception as exc:
# If a metadata file has been passed, retrying won't result in a
# different outcome.
if metadata_file:
raise
if attempt == max_attempts:
raise
attempt += 1
Expand Down
37 changes: 27 additions & 10 deletions packetnetworking/distros/distro_builder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import sys
import logging
import json
from textwrap import dedent

from jinja2 import Template, StrictUndefined
from jinja2.exceptions import UndefinedError

from ..utils import Tasks, package_dir

Expand Down Expand Up @@ -107,6 +109,7 @@ def all_tasks(self):
tasks.update(builder.tasks)
return tasks

# pylama:ignore=C901
def render(self):
"""
Render compiles each task template into the final content.
Expand Down Expand Up @@ -139,21 +142,35 @@ def render(self):
if fmt:
template = template.format(**fmt)

template = Template(
dedent(template),
template = dedent(template)
tmpl = Template(
template,
keep_trailing_newline=True,
lstrip_blocks=True,
trim_blocks=True,
undefined=StrictUndefined,
)
if file_mode or mode:
rendered_tasks[path] = {
"file_mode": file_mode,
"mode": mode,
"content": template.render(self.context()),
}
else:
rendered_tasks[path] = template.render(self.context())
try:
if file_mode or mode:
rendered_tasks[path] = {
"file_mode": file_mode,
"mode": mode,
"content": tmpl.render(self.context()),
}
else:
rendered_tasks[path] = tmpl.render(self.context())
except UndefinedError:
# having to use print as log.* isn't printing out the json
print(
"==== METADATA ====\n"
+ json.dumps(self.metadata.as_dict(), indent=2),
file=sys.stderr,
)
log.error(
"An exception occured while processing task "
+ "'{}' with template:\n{}".format(path, template)
)
raise
return rendered_tasks

def run(self, rootfs_path):
Expand Down