[PATCH] bug fix: from persistent xml get user and group

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> define domain just edit the persistent xml. So we should get user and group from persistent xml instead of live xml when domain is living. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model/vms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 90e9537..2b9bf56 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -258,9 +258,11 @@ class VMModel(object): old_xml = new_xml = dom.XMLDesc(0) + meta_xml = (dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) + if dom.isPersistent() else old_xml) metadata_xpath = "/domain/metadata/kimchi/access/%s" - users = xpath_get_text(old_xml, metadata_xpath % "user") - groups = xpath_get_text(old_xml, metadata_xpath % "group") + users = xpath_get_text(meta_xml, metadata_xpath % "user") + groups = xpath_get_text(meta_xml, metadata_xpath % "group") for key, val in params.items(): if key == 'users': -- 1.9.0

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
define domain just edit the persistent xml. So we should get user and group from persistent xml instead of live xml when domain is living.
On 04/21/2014 02:22 PM, shaohef@linux.vnet.ibm.com wrote: libvirt also support virDomain.metadata and virDomain.setMetadata two api. we can use virDomain.setMetadata set set the user and group by both live xml and persistent xml.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model/vms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 90e9537..2b9bf56 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -258,9 +258,11 @@ class VMModel(object):
old_xml = new_xml = dom.XMLDesc(0)
+ meta_xml = (dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) + if dom.isPersistent() else old_xml) metadata_xpath = "/domain/metadata/kimchi/access/%s" - users = xpath_get_text(old_xml, metadata_xpath % "user") - groups = xpath_get_text(old_xml, metadata_xpath % "group") + users = xpath_get_text(meta_xml, metadata_xpath % "user") + groups = xpath_get_text(meta_xml, metadata_xpath % "group")
for key, val in params.items(): if key == 'users':
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
define domain just edit the persistent xml. So we should get user and group from persistent xml instead of live xml when domain is living. Sheldon found this bug: when we set kimchi metadata when vm is running, we cannot read corresponding info,
On 2014年04月21日 14:22, shaohef@linux.vnet.ibm.com wrote: the root cause is what we set is in persistent configuration, but what we read from is the live xml. His patch fix this inconsistency by just manipulating(read/write) the persistent one.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model/vms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 90e9537..2b9bf56 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -258,9 +258,11 @@ class VMModel(object):
old_xml = new_xml = dom.XMLDesc(0)
+ meta_xml = (dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) + if dom.isPersistent() else old_xml) metadata_xpath = "/domain/metadata/kimchi/access/%s" - users = xpath_get_text(old_xml, metadata_xpath % "user") - groups = xpath_get_text(old_xml, metadata_xpath % "group") + users = xpath_get_text(meta_xml, metadata_xpath % "user") + groups = xpath_get_text(meta_xml, metadata_xpath % "group")
for key, val in params.items(): if key == 'users':

On 04/21/2014 03:58 AM, Royce Lv wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
define domain just edit the persistent xml. So we should get user and group from persistent xml instead of live xml when domain is living. Sheldon found this bug: when we set kimchi metadata when vm is running, we cannot read corresponding info,
On 2014年04月21日 14:22, shaohef@linux.vnet.ibm.com wrote: the root cause is what we set is in persistent configuration, but what we read from is the live xml. His patch fix this inconsistency by just manipulating(read/write) the persistent one.
Royce, I made some tests and even with this patch when I updated users/groups in a running VM the changes only take effect in next boot
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model/vms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 90e9537..2b9bf56 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -258,9 +258,11 @@ class VMModel(object):
old_xml = new_xml = dom.XMLDesc(0)
+ meta_xml = (dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) + if dom.isPersistent() else old_xml) metadata_xpath = "/domain/metadata/kimchi/access/%s" - users = xpath_get_text(old_xml, metadata_xpath % "user") - groups = xpath_get_text(old_xml, metadata_xpath % "group") + users = xpath_get_text(meta_xml, metadata_xpath % "user") + groups = xpath_get_text(meta_xml, metadata_xpath % "group")
for key, val in params.items(): if key == 'users':
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel

On 04/22/2014 01:39 PM, Aline Manera wrote:
On 04/21/2014 03:58 AM, Royce Lv wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
define domain just edit the persistent xml. So we should get user and group from persistent xml instead of live xml when domain is living. Sheldon found this bug: when we set kimchi metadata when vm is running, we cannot read corresponding info,
On 2014年04月21日 14:22, shaohef@linux.vnet.ibm.com wrote: the root cause is what we set is in persistent configuration, but what we read from is the live xml. His patch fix this inconsistency by just manipulating(read/write) the persistent one.
Royce, I made some tests and even with this patch when I updated users/groups in a running VM the changes only take effect in next boot
I found the problem. To fix it we also need to do: + xml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) in lookup() I will adjust that before applying
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model/vms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 90e9537..2b9bf56 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -258,9 +258,11 @@ class VMModel(object):
old_xml = new_xml = dom.XMLDesc(0)
+ meta_xml = (dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) + if dom.isPersistent() else old_xml) metadata_xpath = "/domain/metadata/kimchi/access/%s" - users = xpath_get_text(old_xml, metadata_xpath % "user") - groups = xpath_get_text(old_xml, metadata_xpath % "group") + users = xpath_get_text(meta_xml, metadata_xpath % "user") + groups = xpath_get_text(meta_xml, metadata_xpath % "group")
for key, val in params.items(): if key == 'users':
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel

On 04/22/2014 01:42 PM, Aline Manera wrote:
On 04/22/2014 01:39 PM, Aline Manera wrote:
On 04/21/2014 03:58 AM, Royce Lv wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
define domain just edit the persistent xml. So we should get user and group from persistent xml instead of live xml when domain is living. Sheldon found this bug: when we set kimchi metadata when vm is running, we cannot read corresponding info,
On 2014年04月21日 14:22, shaohef@linux.vnet.ibm.com wrote: the root cause is what we set is in persistent configuration, but what we read from is the live xml. His patch fix this inconsistency by just manipulating(read/write) the persistent one.
Royce, I made some tests and even with this patch when I updated users/groups in a running VM the changes only take effect in next boot
I found the problem. To fix it we also need to do:
+ xml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE)
in lookup()
I will adjust that before applying
Sheldon, as you will need to update this patch according to my comments, could you also update lookup()?
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model/vms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 90e9537..2b9bf56 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -258,9 +258,11 @@ class VMModel(object):
old_xml = new_xml = dom.XMLDesc(0)
+ meta_xml = (dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) + if dom.isPersistent() else old_xml) metadata_xpath = "/domain/metadata/kimchi/access/%s" - users = xpath_get_text(old_xml, metadata_xpath % "user") - groups = xpath_get_text(old_xml, metadata_xpath % "group") + users = xpath_get_text(meta_xml, metadata_xpath % "user") + groups = xpath_get_text(meta_xml, metadata_xpath % "group")
for key, val in params.items(): if key == 'users':
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel

On 04/21/2014 02:22 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
define domain just edit the persistent xml. So we should get user and group from persistent xml instead of live xml when domain is living.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model/vms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 90e9537..2b9bf56 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -258,9 +258,11 @@ class VMModel(object):
old_xml = new_xml = dom.XMLDesc(0)
meta_xml = (dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) if dom.isUpdated else old_xml)?
+ meta_xml = (dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) + if dom.isPersistent() else old_xml) metadata_xpath = "/domain/metadata/kimchi/access/%s" - users = xpath_get_text(old_xml, metadata_xpath % "user") - groups = xpath_get_text(old_xml, metadata_xpath % "group") + users = xpath_get_text(meta_xml, metadata_xpath % "user") + groups = xpath_get_text(meta_xml, metadata_xpath % "group")
for key, val in params.items(): if key == 'users':
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

On 04/21/2014 03:22 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
define domain just edit the persistent xml. So we should get user and group from persistent xml instead of live xml when domain is living.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model/vms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 90e9537..2b9bf56 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -258,9 +258,11 @@ class VMModel(object):
old_xml = new_xml = dom.XMLDesc(0)
+ meta_xml = (dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) + if dom.isPersistent() else old_xml)
From libvirt doc (http://libvirt.org/html/libvirt-libvirt.html#virDomainGetXMLDesc): "If @flags includes VIR_DOMAIN_XML_INACTIVE <http://libvirt.org/html/libvirt-libvirt.html#VIR_DOMAIN_XML_INACTIVE>, then the XML represents the configuration that will be used on the next boot of a persistent domain; otherwise, the configuration represents the currently running domain" So you don't need to add the 'if' statement there (if dom.isPersistent()) And call direclty: meta_xml = (dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE)
metadata_xpath = "/domain/metadata/kimchi/access/%s" - users = xpath_get_text(old_xml, metadata_xpath % "user") - groups = xpath_get_text(old_xml, metadata_xpath % "group") + users = xpath_get_text(meta_xml, metadata_xpath % "user") + groups = xpath_get_text(meta_xml, metadata_xpath % "group")
for key, val in params.items(): if key == 'users':

On 04/23/2014 12:50 AM, Aline Manera wrote:
On 04/21/2014 03:22 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng<shaohef@linux.vnet.ibm.com>
define domain just edit the persistent xml. So we should get user and group from persistent xml instead of live xml when domain is living.
Signed-off-by: ShaoHe Feng<shaohef@linux.vnet.ibm.com> Signed-off-by: Royce Lv<lvroyce@linux.vnet.ibm.com> --- src/kimchi/model/vms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 90e9537..2b9bf56 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -258,9 +258,11 @@ class VMModel(object):
old_xml = new_xml = dom.XMLDesc(0)
+ meta_xml = (dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) + if dom.isPersistent() else old_xml)
From libvirt doc (http://libvirt.org/html/libvirt-libvirt.html#virDomainGetXMLDesc):
"If @flags includes VIR_DOMAIN_XML_INACTIVE <http://libvirt.org/html/libvirt-libvirt.html#VIR_DOMAIN_XML_INACTIVE>, then the XML represents the configuration that will be used on the next boot of a persistent domain; otherwise, the configuration represents the currently running domain"
So you don't need to add the 'if' statement there (if dom.isPersistent())
And call direclty:
meta_xml = (dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) Actually libvirt support to create a dom without define it.
some other tools may keep the vm configure by itself, and just let libvirt create it. So no configure xml and dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) will raise an error.
metadata_xpath = "/domain/metadata/kimchi/access/%s" - users = xpath_get_text(old_xml, metadata_xpath % "user") - groups = xpath_get_text(old_xml, metadata_xpath % "group") + users = xpath_get_text(meta_xml, metadata_xpath % "user") + groups = xpath_get_text(meta_xml, metadata_xpath % "group")
for key, val in params.items(): if key == 'users':
-- Thanks and best regards! Sheldon Feng(???)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center
participants (4)
-
Aline Manera
-
Royce Lv
-
shaohef@linux.vnet.ibm.com
-
Sheldon