Skip to content
Open
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
8 changes: 4 additions & 4 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import logging
import os
import platform
import re
import sqlite3
import sys
import yaml
Expand All @@ -17,7 +16,6 @@
from lib import networks
from lib import packages
from lib import processor
from lib import statistics
from lib import tables

def generate(database, manifest_file, seatmap_file,
Expand All @@ -27,7 +25,7 @@ def generate(database, manifest_file, seatmap_file,
# Create fresh database file
logging.debug('Checking if database file %s exists', database)
has_previous_db = False
previous_statistics = None
before = {}
if os.path.isfile(database):
logging.debug(
'Found existing database file %s, gathering stats before deleting',
Expand Down Expand Up @@ -87,6 +85,7 @@ def generate(database, manifest_file, seatmap_file,

# Parse ipplan
logging.debug('Parsing lines in %s', ipplan)
lines = []
try:
with open(ipplan, 'r') as f:
lines = f.readlines()
Expand All @@ -110,7 +109,7 @@ def generate(database, manifest_file, seatmap_file,
logging.debug('Parsing manifest file as JSON')
try:
with open(manifest_file, 'r') as f:
manifest = yaml.safe_load(f.read())
manifest = json.load(f)
except Exception as e:
logging.error(
'Could not parse manifest file %s as JSON: %s',
Expand Down Expand Up @@ -149,6 +148,7 @@ def generate(database, manifest_file, seatmap_file,
sys.exit(9)
logging.debug('Found seatmap file \'%s\'', seatmap_file)
logging.debug('Parsing seatmap file as JSON')
seatmap = {}
try:
with open(seatmap_file, 'r') as f:
seatmap = json.loads(f.read())
Expand Down
8 changes: 0 additions & 8 deletions lib/diff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import re
import sys


Expand Down Expand Up @@ -61,10 +60,6 @@ def _print(color, msg, output):


def compare_states(before, after, logging, output=sys.stdout, limit=10000):
# Did we detect _any_ changes?
changed = False

# Any new tables?
tables_before = set(before['tables'])
tables_after = set(after['tables'])
dropped_tables = tables_before - tables_after
Expand All @@ -73,12 +68,10 @@ def compare_states(before, after, logging, output=sys.stdout, limit=10000):
output.write('Dropped %d table(s):' % (len(dropped_tables)))
for dropped_table in dropped_tables:
_print(bcolors.FAIL, dropped_table, output)
changed = True
if len(new_tables) > 0:
output.write('Added %d table(s):' % (len(new_tables)))
for added_table in new_tables:
_print(bcolors.OKGREEN, added_table, output)
changed = True

# We can only do diff magic on tables that were in both databases
tables = tables_after.intersection(tables_before)
Expand All @@ -93,7 +86,6 @@ def compare_states(before, after, logging, output=sys.stdout, limit=10000):
delta_count = count_after - count_before
if delta_count != 0:
logging.info('%s %d' % (table, delta_count))
changed = True
removed_objects = objects_before - objects_after
added_objects = objects_after - objects_before
if len(removed_objects) > 0:
Expand Down
6 changes: 3 additions & 3 deletions lib/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def prefetch_node_and_services(self):

self.node_services = dict()
self.service_nodes = dict()
for access, access_key in access_to_sql_map.iteritems():
for access, access_key in access_to_sql_map.items():
# TODO(bluecmd): These are deprecated in favor of packages
# We should emit warnings in the presubmit hook to make sure
# people are not using these
Expand All @@ -90,14 +90,14 @@ def prefetch_node_and_services(self):
for node, service in explicit:
self.register_service(access, node, service)

for node, packset in self.nodes.iteritems():
for node, packset in self.nodes.items():
for package_name in packset:
package = self.packages[package_name] or {}
for service in set(package.get(access, [])):
self.register_service(access, node, service)

# Prune redundant flows (hosts that share the network flows)
for node, services in self.node_services[access].iteritems():
for node in self.node_services[access].iteritems():
if node not in self.netmap:
continue
parent = self.node_services[access].get(self.netmap[node])
Expand Down
Loading