Matteo Scandolo | 9c675d0 | 2019-02-12 10:05:35 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
Andy Bavier | e443214 | 2019-02-07 15:11:25 -0700 | [diff] [blame] | 3 | # Copyright 2019-present Open Networking Foundation |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
Andy Bavier | e443214 | 2019-02-07 15:11:25 -0700 | [diff] [blame] | 17 | from pyparsing import Combine, Group, Optional, ParseException, Regex, Word, ZeroOrMore, alphas, nums |
| 18 | import fileinput |
| 19 | import pprint |
| 20 | |
| 21 | Written = {} |
| 22 | |
| 23 | Date = Combine(Word(nums)+"-"+Word(nums)+"-"+Word(nums)) |
| 24 | Time = Combine(Word(nums)+":"+Word(nums)+":"+Word(nums)+"."+Word(nums)) |
| 25 | Msg = Regex("is new|no changes|updated") |
| 26 | QuotedWord = "'"+Word(alphas+"_")+"'"+Optional(", ") |
| 27 | Array = "["+ZeroOrMore(QuotedWord)+"]" |
| 28 | Key = Word(alphas+"_") |
| 29 | Value = Array | Word(alphas+"_-/.") |
| 30 | KeyValue = Combine(Key("key")+"="+Value("value")) |
| 31 | Logmsg = Date+"T"+Time+"Z [debug ] save(): "+Msg+KeyValue*(2,3) |
| 32 | |
| 33 | entries = {} |
| 34 | |
| 35 | def add_syncstep(model, field, syncstep): |
| 36 | if model not in entries: |
| 37 | entries[model] = {} |
| 38 | if field in entries[model]: |
| 39 | if syncstep not in entries[model][field]: |
| 40 | entries[model][field].append(syncstep) |
| 41 | else: |
| 42 | entries[model][field] = [syncstep] |
| 43 | |
| 44 | |
| 45 | for line in fileinput.input(): |
| 46 | entry = {} |
| 47 | try: |
| 48 | logline = Logmsg.parseString(line) |
| 49 | #print logline |
| 50 | entry["status"] = logline[4] |
| 51 | for field in range(5, len(logline)): |
| 52 | key, value = logline[field].split("=") |
| 53 | if key == "changed_fields": |
| 54 | entry[key] = eval(value) |
| 55 | else: |
| 56 | entry[key] = value |
| 57 | |
| 58 | if entry["syncstep"] == "None": |
| 59 | continue |
| 60 | |
| 61 | if "changed_fields" in entry: |
| 62 | for field in entry["changed_fields"]: |
| 63 | add_syncstep(entry["classname"], field, entry["syncstep"]) |
| 64 | else: |
| 65 | if entry["status"] == "no changes": |
| 66 | add_syncstep(entry["classname"], "all", entry["syncstep"]) |
| 67 | |
| 68 | |
| 69 | except ParseException, err: |
| 70 | print err.line |
| 71 | print " "*(err.column-1) + "^" |
| 72 | print err |
| 73 | |
| 74 | pp = pprint.PrettyPrinter() |
| 75 | |
| 76 | for obj in entries: |
| 77 | all_syncstep = [] |
| 78 | print "\nInspecting model: ", obj |
| 79 | entry = entries[obj] |
| 80 | if "all" in entry: |
| 81 | print " [WARNING] Object being saved with no changes" |
| 82 | all_syncstep = entry["all"] |
| 83 | for path in all_syncstep: |
| 84 | print " ", path |
| 85 | for field in entry: |
| 86 | if field == "all": |
| 87 | continue |
| 88 | syncstep = list(set(entry[field] + all_syncstep)) |
| 89 | if len(syncstep) > 1: |
| 90 | print " [WARNING] Field saved from multiple tasks: ", field |
| 91 | for path in syncstep: |
| 92 | print " ", path |