Hi Alex:

On 10/08/2013 05:53 AM, Alex Jia wrote:
Hi Chris,
I want to implement a secret XML parser module under the virttest/libvirt_xml, the secret XML looks like this:

<secret ephemeral='*no*' private='*no*'>
         <description>Super secret name of my first puppy</description>
         <usage type='*volume*'>
            <*volume*>/var/lib/libvirt/images/puppyname.img</volume>
         </usage>
</secret>

or

<secret ephemeral='*no*' private='*yes*'>
         <description>CEPH passphrase example</description>
         <auth type='*ceph*' username='myname'/>
         <usage type='*ceph*'>
            <*name*>ceph_example</name>
         </usage>
</secret>

or

<secret ephemeral='*yes*' private='*yes*'>
<description>Passphrase for the iSCSI example.com server</description>
         <auth type='*chap*' username='myname'/>
         <usage type='*iscsi*'>
            <*target*>libvirtiscsi</target>
         </usage>
</secret>

I saw existing XML modules haven't talked about >=2 attributions in '/' such as "<secret ephemeral='yes' private='yes'>",
The XMLElementDict class in accessors module is designed to accesse
more than one attribute of a tag. And it works even if the tag is "/".
I think you can add a accessor in your SecretXML class for it as below:

```
accessors.XMLElementDict('secret_attributes', self, parent_xpath='/',
tag_name='secret')

```
Then you can access the attributs of <secret> in your test module.
```
secret_xml = SecretXML.new_from_dumpxml(secret_name)
print secret_xml.secret_attributes
```
The result of "print" is {'ephemeral': 'no', 'private': 'no'}

Also, you can use one accessors.XMLAttribute  for each attribute of them.
In this way, you need to add a name in __slots__ for each one, such as secret_ephemeral, secret_private.
Then you can add accessors for them in __init__ method.
```
        accessors.XMLAttribute('secret_ephemeral', self, parent_xpath='/',
tag_name='secret', attribute='ephemeral')
        accessors.XMLAttribute('secret_private', self, parent_xpath='/',
tag_name='secret', attribute='private')
```

Both are possible I think.
in addition, the usage type is a variable and it has
different sub-tag, and some tags are optional such as '<auth xxxxx>', I want to know
how to implement it in autotest?
About the optional tag in secret, AFAIK, there is no problem that you add a accessor for auth
if the auth tag does not exist in you xml file.
But when you attempt to access it with "secret_xml.auth" you will get an error in run-time:
*** LibvirtXMLNotFoundError: LibvirtXMLNotFoundError()

So, I guess you can use only one SecretXML class to cover the two different types. But if you think
we need to treet them differently, we can talk more about it.

Wish they are helpful to you.
Yang.

Thanks in advance,
Alex


_______________________________________________
Virt-test-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virt-test-devel

_______________________________________________
Virt-test-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virt-test-devel

Reply via email to