summaryrefslogtreecommitdiff
path: root/doc/ext
diff options
context:
space:
mode:
authorBalazs Gibizer <balazs.gibizer@ericsson.com>2017-04-03 18:05:07 +0200
committerBalazs Gibizer <balazs.gibizer@ericsson.com>2017-11-03 11:36:57 +0100
commit5a5155ea4e4e3ade01e89a8c221ccd73fe1827b9 (patch)
tree54980853b3dad058ebae4273f5dd51703b70821c /doc/ext
parent47bdd101375487d1c67dd3fdc295a87f56ec012a (diff)
downloadnova-5a5155ea4e4e3ade01e89a8c221ccd73fe1827b9.tar.gz
Factor out duplicated notification sample data
Versioned notifications are functionally tested against stored sample data. Also most of the instance notitication shares payload structure. Today we store a separate sample for every instance notification. These samples store similar, mostly redundant data. When a new field is added to the InstancePayload then every instance notification related sample file needs to be modified. This leads to big and redundant changes like I18af99479562e2fe5e74e6e1252b804b074fee58. To remove the redundancy this patch proposes to use json references in the sample files instead of copy pasting the same notification sample fragment to every sample. As a first step this patch introduces a small json ref resolver. Then subsequent patches will replace the duplicated sample data with references to common sample fragments. This proposed resolver supports resolving the refs recursively so a referenced json fragment can reference further fragments. However the current implementation does not handle reference loops. The resolver also supports overriding parts of the referenced json fragment to support content customization needed in the next patch. Change-Id: Ic3ab7d60e4ac12b767fe70bef97b327545a86e74
Diffstat (limited to 'doc/ext')
-rw-r--r--doc/ext/versioned_notifications.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/doc/ext/versioned_notifications.py b/doc/ext/versioned_notifications.py
index ae457544a3..dee53445a1 100644
--- a/doc/ext/versioned_notifications.py
+++ b/doc/ext/versioned_notifications.py
@@ -19,15 +19,18 @@ It is used via a single directive in the .rst file
.. versioned_notifications::
"""
+import os
from docutils import nodes
from docutils.parsers import rst
import importlib
+from oslo_serialization import jsonutils
import pkgutil
-import nova.notifications.objects
from nova.notifications.objects import base as notification
from nova.objects import base
+from nova.tests import json_ref
+import nova.utils
class VersionedNotificationDirective(rst.Directive):
@@ -125,9 +128,17 @@ jQuery(document).ready(function(){
col = nodes.entry()
row.append(col)
- with open(self.SAMPLE_ROOT + sample_file, 'r') as f:
+ with open(os.path.join(self.SAMPLE_ROOT, sample_file), 'r') as f:
sample_content = f.read()
+ sample_obj = jsonutils.loads(sample_content)
+ sample_obj = json_ref.resolve_refs(
+ sample_obj,
+ base_path=os.path.abspath(self.SAMPLE_ROOT))
+ sample_content = jsonutils.dumps(sample_obj,
+ sort_keys=True, indent=4,
+ separators=(',', ': '))
+
event_type = sample_file[0: -5]
html_str = self.TOGGLE_SCRIPT % ((event_type, ) * 3)
html_str += ("<input type='button' id='%s-hideshow' "