commit 90a28e7e52523165116a613c0f8eba6a1f127dad
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Wed Aug 22 15:19:15 2012 +0200
Ticket #4: machine_id from int to string
Machine ids in tags <machine id=''> and <command machine_id=''> are no
longer converted to integers and are used as strings.
Introducing these changes requires a number of changes in formatted
strings where integers were required.
Machine id is also used as the first parameter in template functions so
these had to be changed as well.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Common/XmlTemplates.py | 8 ++++----
NetTest/NetTestCommand.py | 2 +-
NetTest/NetTestController.py | 16 ++++++++--------
NetTest/NetTestParse.py | 12 ++++++------
4 files changed, 19 insertions(+), 19 deletions(-)
---
diff --git a/Common/XmlTemplates.py b/Common/XmlTemplates.py
index a3be062..3b6c663 100644
--- a/Common/XmlTemplates.py
+++ b/Common/XmlTemplates.py
@@ -219,7 +219,7 @@ class XmlTemplates:
self._validate_func_params("ip", params, 2, 1)
recipe = self._get_recipe_data("ip")
- m_id = int(params[0])
+ m_id = params[0]
if_id = int(params[1])
ip_id = int(params[2]) if len(params) == 3 else 0
@@ -246,7 +246,7 @@ class XmlTemplates:
def _hwaddr_func(self, params):
self._validate_func_params("hwaddr", params, 2, 0)
recipe = self._get_recipe_data("hwaddr")
- m_id = int(params[0])
+ m_id = params[0]
if_id = int(params[1])
if 'machines' not in recipe or m_id not in recipe['machines']:
@@ -267,7 +267,7 @@ class XmlTemplates:
def _devname_func(self, params):
self._validate_func_params("devname", params, 2, 0)
recipe = self._get_recipe_data("devname")
- m_id = int(params[0])
+ m_id = params[0]
if_id = int(params[1])
if 'machines' not in recipe or m_id not in recipe['machines']:
@@ -295,7 +295,7 @@ class XmlTemplates:
err = "Function %s takes %d arguments, %d passed" \
% (name, mandatory, num_params)
raise XmlTemplateError(err)
- for param in params:
+ for param in params[1:]:
try:
int(param)
except ValueError:
diff --git a/NetTest/NetTestCommand.py b/NetTest/NetTestCommand.py
index ae1297f..5403621 100644
--- a/NetTest/NetTestCommand.py
+++ b/NetTest/NetTestCommand.py
@@ -19,7 +19,7 @@ import pickle, traceback
from Common.ExecCmd import exec_cmd, ExecCmdFail
def str_command(command):
- out = ("type (%s), machine_id (%d), value (%s)"
+ out = ("type (%s), machine_id (%s), value (%s)"
% (command["type"], command["machine_id"], command["value"]))
if "timeout" in command:
out += ", timeout (%d)" % command["timeout"]
diff --git a/NetTest/NetTestController.py b/NetTest/NetTestController.py
index 1f86eba..2ff6a8a 100644
--- a/NetTest/NetTestController.py
+++ b/NetTest/NetTestController.py
@@ -103,7 +103,7 @@ class NetTestController:
if dev["create"] == "libvirt":
if not "virt_domain_ctl" in info:
msg = "Cannot create device. " \
- "Machine '%d' is not virtual." % (machine_id)
+ "Machine '%s' is not virtual." % (machine_id)
raise NetTestError(msg)
if "hwaddr" in dev:
@@ -131,7 +131,7 @@ class NetTestController:
br_name = brctl.get_name()
brctl.init()
- logging.info("Creating netdevice %d (%s) on machine %d",
+ logging.info("Creating netdevice %d (%s) on machine %s",
dev_id, dev["hwaddr"], machine_id)
domain_ctl = info["virt_domain_ctl"]
@@ -142,7 +142,7 @@ class NetTestController:
if not ready:
msg = "Netdevice initialization failed." \
- "Unable to create device %d (%s) on machine %d" \
+ "Unable to create device %d (%s) on machine %s" \
% (dev_id, dev["hwaddr"], machine_id)
raise NetTestError(msg)
@@ -154,11 +154,11 @@ class NetTestController:
if len(phys_devs) == 1:
pass
elif len(phys_devs) < 1:
- msg = "Device %d not found on machine %d" \
+ msg = "Device %d not found on machine %s" \
% (dev_id, machine_id)
raise NetTestError(msg)
elif len(phys_devs) > 1:
- msg = "Multiple netdevices with same address %s on machine %d" \
+ msg = "Multiple netdevices with same address %s on machine %s" \
% (dev["hwaddr"], machine_id)
raise NetTestError(msg)
@@ -196,7 +196,7 @@ class NetTestController:
rpc.deconfigure_interface(netdev_config_id)
def _prepare_slave(self, machine_id):
- logging.info("Preparing machine #%d", machine_id)
+ logging.info("Preparing machine %s", machine_id)
info = self._get_machineinfo(machine_id)
if "libvirt_domain" in info:
@@ -271,7 +271,7 @@ class NetTestController:
if "created_devices" not in info:
continue
for dev_id, dev in reversed(info["created_devices"]):
- logging.info("Removing netdevice %d (%s) from machine %d",
+ logging.info("Removing netdevice %d (%s) from machine %s",
dev_id, dev["hwaddr"], machine_id)
domain_ctl = info["virt_domain_ctl"]
domain_ctl.detach_interface(dev["hwaddr"])
@@ -309,7 +309,7 @@ class NetTestController:
except KeyError:
pass
- if machine_id == 0:
+ if machine_id == "0":
cmd_res = NetTestCommand(command).run()
else:
rpc = self._get_machinerpc(machine_id)
diff --git a/NetTest/NetTestParse.py b/NetTest/NetTestParse.py
index 7af2084..b69eea3 100644
--- a/NetTest/NetTestParse.py
+++ b/NetTest/NetTestParse.py
@@ -86,7 +86,7 @@ class MachineParse(RecipeParser):
raise XmlProcessingError("Unknown machine type")
def parse(self, node):
- self._id = self._get_attribute(node, "id", int)
+ self._id = self._get_attribute(node, "id")
self._machine = {}
self._recipe[self._target][self._id] = self._machine
@@ -361,7 +361,7 @@ class CommandSequenceParse(RecipeParser):
bg_ids[machine_id].remove(bg_id)
else:
logging.error("Found command \"%s\" for bg_id \"%s\" on "
- "machine \"%d\" which was not previously "
+ "machine \"%s\" which was not previously "
"defined", cmd_type, bg_id, machine_id)
err = True
@@ -371,13 +371,13 @@ class CommandSequenceParse(RecipeParser):
bg_ids[machine_id].add(bg_id)
else:
logging.error("Command \"%d\" uses bg_id \"%d\" on machine "
- "\"%d\" which is already used",
+ "\"%s\" which is already used",
i, bg_id, machine_id)
err = True
for machine_id in bg_ids:
for bg_id in bg_ids[machine_id]:
- logging.error("bg_id \"%d\" on machine \"%d\" has no kill/wait "
+ logging.error("bg_id \"%d\" on machine \"%s\" has no kill/wait "
"command to it", bg_id, machine_id)
err = True
if err:
@@ -399,11 +399,11 @@ class CommandParse(RecipeParser):
self._cmd_num = len(recipe["sequences"][self._seq_num]["commands"]) - 1
if self._has_attribute(node, "machine_id"):
- machine_id = self._get_attribute(node, "machine_id", int)
+ machine_id = self._get_attribute(node, "machine_id")
if machine_id and not machine_id in recipe["machines"]:
raise XmlProcessingError("Invalid machine_id", node)
else:
- machine_id = 0 # controller id
+ machine_id = "0" # controller id
command["machine_id"] = machine_id
command["type"] = self._get_attribute(node, "type")