The name RecipeParser is ambiguous, because the class is used as base
for both recipe parsers and also slave machine config files.
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
---
lnst/Common/XmlProcessing.py | 28 ++++++++++++----------
lnst/Controller/NetTestController.py | 2 +-
lnst/Controller/NetTestParse.py | 42 +++++++++++++++++-----------------
3 files changed, 37 insertions(+), 35 deletions(-)
diff --git a/lnst/Common/XmlProcessing.py b/lnst/Common/XmlProcessing.py
index 80e9aca..83bd630 100644
--- a/lnst/Common/XmlProcessing.py
+++ b/lnst/Common/XmlProcessing.py
@@ -205,39 +205,41 @@ class XmlParser(object):
return res
-class RecipeParser(XmlParser):
+class LnstParser(XmlParser):
""" Enhanced XmlParser
This class enhances XmlParser with advanced features that are
- used in parsing XML recipe files. All recipe (sub)parsers should
+ used in parsing LNST XML files. All (sub)parsers should
use this as their base class.
"""
- _recipe = None
+ _data = None
_template_proc = None
_include_root = None
_events_enabled = None
_event_handlers = None
def __init__(self, parent=None):
- super(RecipeParser, self).__init__()
+ super(LnstParser, self).__init__()
if parent:
- self._recipe = parent._recipe
+ self._data = parent._data
self._template_proc = parent._template_proc
self._include_root = parent._include_root
self._events_enabled = parent._events_enabled
self._event_handlers = parent._event_handlers
else:
- self._recipe = {}
+ self._data = {}
self._template_proc = XmlTemplates()
self._include_root = os.getcwd()
self._events_enabled = True
self._event_handlers = {}
- def set_recipe(self, recipe):
- self._recipe = recipe
- self._template_proc.set_machines(recipe["machines"])
+ def set_target(self, data_dict):
+ self._data = data_dict
+ # TODO: This should be removed and done differently after we
+ # figure out the new design of template functions
+ self._template_proc.set_machines(data_dict["machines"])
def set_definitions(self, defs):
self._template_proc.set_definitions(defs)
@@ -276,7 +278,7 @@ class RecipeParser(XmlParser):
if new_ns_level:
self._template_proc.add_namespace_level()
- parent = super(RecipeParser, self)
+ parent = super(LnstParser, self)
result = parent._process_child_nodes(node, scheme, params,
default_handler)
@@ -324,14 +326,14 @@ class RecipeParser(XmlParser):
if not node.hasAttribute(name):
node.setAttribute(name, value)
- parent = super(RecipeParser, self)
+ parent = super(LnstParser, self)
parent._process_node(node, handler, params)
if old_include_root:
self._include_root = old_include_root
def _get_attribute(self, node, attr_name, conversion_cb=None):
- parent = super(RecipeParser, self)
+ parent = super(LnstParser, self)
raw_attr_val = parent._get_attribute(node, attr_name)
try:
@@ -342,7 +344,7 @@ class RecipeParser(XmlParser):
return self._convert_string(node, attr_val, conversion_cb)
def _get_text_content(self, node, conversion_cb=None):
- parent = super(RecipeParser, self)
+ parent = super(LnstParser, self)
raw_content = parent._get_text_content(node)
try:
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index ffa2bf8..94ed7f5 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -65,7 +65,7 @@ class NetTestController:
mac_pool_range[1])
ntparse = NetTestParse(recipe_path)
- ntparse.set_recipe(self._recipe)
+ ntparse.set_target(self._recipe)
ntparse.register_event_handler("provisioning_requirements_ready",
self._prepare_provisioning)
diff --git a/lnst/Controller/NetTestParse.py b/lnst/Controller/NetTestParse.py
index caa15a0..ed4a72e 100644
--- a/lnst/Controller/NetTestParse.py
+++ b/lnst/Controller/NetTestParse.py
@@ -13,14 +13,14 @@ jpirko(a)redhat.com (Jiri Pirko)
import logging
import os
import re
-from lnst.Common.XmlProcessing import RecipeParser
+from lnst.Common.XmlProcessing import LnstParser
from lnst.Common.XmlProcessing import XmlDomTreeInit
from lnst.Common.XmlProcessing import XmlProcessingError
from lnst.Common.NetUtils import normalize_hwaddr
from lnst.Common.Utils import bool_it
from lnst.Common.RecipePath import RecipePath
-class NetTestParse(RecipeParser):
+class NetTestParse(LnstParser):
def __init__(self, recipe_filepath):
super(NetTestParse, self).__init__()
@@ -42,7 +42,7 @@ class NetTestParse(RecipeParser):
second_pass.parse(xml_dom)
-class FirstPass(RecipeParser):
+class FirstPass(LnstParser):
"""
Purpose of the first pass through the recipe is to detect
machine requirements for provisioning.
@@ -52,7 +52,7 @@ class FirstPass(RecipeParser):
"""
def parse(self, node):
- self._recipe["provisioning"]["setup_requirements"] = {}
+ self._data["provisioning"]["setup_requirements"] = {}
if node.nodeType == node.DOCUMENT_NODE:
scheme = {"lnstrecipe": self._lnstrecipe}
@@ -80,7 +80,7 @@ class FirstPass(RecipeParser):
default_handler=self._ignore_tag)
def _requirements(self, node, params):
- machine_req =
self._recipe["provisioning"]["setup_requirements"]
+ machine_req =
self._data["provisioning"]["setup_requirements"]
m_id = params["id"]
template = {}
template["netdevices"] = {}
@@ -94,10 +94,10 @@ class FirstPass(RecipeParser):
pass
-class SecondPass(RecipeParser):
+class SecondPass(LnstParser):
"""
Second pass makes sure all recognized values from the recipe
- are properly saved into the self._recipe.
+ are properly saved into the self._data.
This is where the real parsing is done.
"""
@@ -134,14 +134,14 @@ class SecondPass(RecipeParser):
subparser.parse(node)
def _command_sequence(self, node, params):
- if not "sequences" in self._recipe:
- self._recipe["sequences"] = []
+ if not "sequences" in self._data:
+ self._data["sequences"] = []
subparser = CommandSequenceParse(self)
subparser.parse(node)
-class MachineParse(RecipeParser):
+class MachineParse(LnstParser):
_target = "machines"
def set_type(self, machine_type):
@@ -155,7 +155,7 @@ class MachineParse(RecipeParser):
def parse(self, node):
self._id = self._get_attribute(node, "id")
- recipe = self._recipe
+ recipe = self._data
self._machine = recipe["machines"][self._id]
self._machine["netconfig"] = {}
@@ -175,7 +175,7 @@ class MachineParse(RecipeParser):
logging.error(XmlProcessingError(str(exc), node))
raise
-class ParamsParse(RecipeParser):
+class ParamsParse(LnstParser):
_params = None
def set_params_dict(self, target):
@@ -195,7 +195,7 @@ class ParamsParse(RecipeParser):
self._params[name] = value
-class RequirementsParse(RecipeParser):
+class RequirementsParse(LnstParser):
_requirements = None
def set_template(self, tmp_dict):
@@ -239,7 +239,7 @@ class RequirementsParse(RecipeParser):
dev["hwaddr"] =
normalize_hwaddr(dev["params"]["hwaddr"])
-class SlaveMachineParse(RecipeParser):
+class SlaveMachineParse(LnstParser):
_machine_id = None
_machine = None
@@ -333,7 +333,7 @@ class SlaveMachineParse(RecipeParser):
logging.error(XmlProcessingError(str(exc), node))
raise
-class NetConfigParse(RecipeParser):
+class NetConfigParse(LnstParser):
_machine_id = None
_machine = None
@@ -467,9 +467,9 @@ class NetConfigParse(RecipeParser):
self._process_child_nodes(node, scheme, params)
-class CommandSequenceParse(RecipeParser):
+class CommandSequenceParse(LnstParser):
def parse(self, node):
- sequences = self._recipe["sequences"]
+ sequences = self._data["sequences"]
sequences.append({})
seq_num = len(sequences) - 1
sequences[seq_num]["commands"] = []
@@ -532,7 +532,7 @@ class CommandSequenceParse(RecipeParser):
raise XmlProcessingError(msg, self._seq_node)
-class CommandParse(RecipeParser):
+class CommandParse(LnstParser):
_seq_num = None
_cmd_num = None
@@ -540,7 +540,7 @@ class CommandParse(RecipeParser):
self._seq_num = num
def parse(self, node):
- recipe = self._recipe
+ recipe = self._data
command = {}
recipe["sequences"][self._seq_num]["commands"].append(command)
self._cmd_num =
len(recipe["sequences"][self._seq_num]["commands"]) - 1
@@ -607,7 +607,7 @@ class CommandParse(RecipeParser):
def _options(self, node, params):
seq = self._seq_num
cmd = self._cmd_num
-
self._recipe["sequences"][seq]["commands"][cmd]["options"] =
{}
+
self._data["sequences"][seq]["commands"][cmd]["options"] =
{}
scheme = {"option": self._option}
self._process_child_nodes(node, scheme)
@@ -615,7 +615,7 @@ class CommandParse(RecipeParser):
def _option(self, node, params):
seq = self._seq_num
cmd = self._cmd_num
- options =
self._recipe["sequences"][seq]["commands"][cmd]["options"]
+ options =
self._data["sequences"][seq]["commands"][cmd]["options"]
name = self._get_attribute(node, "name")
if not name in options:
--
1.7.7.6