diff mbox

[XTF,1/3] xtf-runner: introduce get_xen_version

Message ID 1470841650-30850-2-git-send-email-wei.liu2@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Liu Aug. 10, 2016, 3:07 p.m. UTC
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 xtf-runner | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Andrew Cooper Aug. 11, 2016, 10:10 a.m. UTC | #1
On 10/08/16 16:07, Wei Liu wrote:
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> ---
>  xtf-runner | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/xtf-runner b/xtf-runner
> index c063699..7b69c45 100755
> --- a/xtf-runner
> +++ b/xtf-runner
> @@ -151,6 +151,19 @@ def __repr__(self):
>          return "TestInfo(%s)" % (self.name, )
>  
>  
> +def get_xen_version():
> +    """Get the version string of Xen"""
> +
> +    for line in check_output(['xl', 'info']).splitlines():
> +        if not line.startswith("xen_version"):
> +            continue
> +
> +        version_str = line.split()[2:][0]
> +        break
> +
> +    return version_str

This will hit a name error if xen_version isn't found in the output.

A better option would be to "return line.split()[2:][0]" directly and
raise a RunnerError() at this point.

However, xen_version was introduced by me a while ago, but not so very
long ago, and won't work on older versions of Xen.

I think at this point, it would just be easier to use the python libxc
bindings, so

from xen.lowlevel.xc import xc
libxc = xc()

info = libxc.xeninfo()
return "%s.%s" % (info["xen_major"], info["xen_minor"])

Make sure the import statement is inside the function call to avoid
breaking the usecase of `xtf-runner --list` offhost.

~Andrew

> +
> +
>  def parse_test_instance_string(arg):
>      """Parse a test instance string.
>
Wei Liu Aug. 11, 2016, 10:12 a.m. UTC | #2
On Thu, Aug 11, 2016 at 11:10:41AM +0100, Andrew Cooper wrote:
> On 10/08/16 16:07, Wei Liu wrote:
> > Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> > ---
> >  xtf-runner | 13 +++++++++++++
> >  1 file changed, 13 insertions(+)
> >
> > diff --git a/xtf-runner b/xtf-runner
> > index c063699..7b69c45 100755
> > --- a/xtf-runner
> > +++ b/xtf-runner
> > @@ -151,6 +151,19 @@ def __repr__(self):
> >          return "TestInfo(%s)" % (self.name, )
> >  
> >  
> > +def get_xen_version():
> > +    """Get the version string of Xen"""
> > +
> > +    for line in check_output(['xl', 'info']).splitlines():
> > +        if not line.startswith("xen_version"):
> > +            continue
> > +
> > +        version_str = line.split()[2:][0]
> > +        break
> > +
> > +    return version_str
> 
> This will hit a name error if xen_version isn't found in the output.
> 
> A better option would be to "return line.split()[2:][0]" directly and
> raise a RunnerError() at this point.
> 
> However, xen_version was introduced by me a while ago, but not so very
> long ago, and won't work on older versions of Xen.
> 

Oh, didn't notice that. I thought it was available to all versions of
Xen.

> I think at this point, it would just be easier to use the python libxc
> bindings, so
> 
> from xen.lowlevel.xc import xc
> libxc = xc()
> 
> info = libxc.xeninfo()
> return "%s.%s" % (info["xen_major"], info["xen_minor"])
> 
> Make sure the import statement is inside the function call to avoid
> breaking the usecase of `xtf-runner --list` offhost.
> 

NP.

Wei.

> ~Andrew
> 
> > +
> > +
> >  def parse_test_instance_string(arg):
> >      """Parse a test instance string.
> >  
>
Andrew Cooper Aug. 11, 2016, 10:14 a.m. UTC | #3
On 11/08/16 11:12, Wei Liu wrote:
> On Thu, Aug 11, 2016 at 11:10:41AM +0100, Andrew Cooper wrote:
>> On 10/08/16 16:07, Wei Liu wrote:
>>> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
>>> ---
>>>  xtf-runner | 13 +++++++++++++
>>>  1 file changed, 13 insertions(+)
>>>
>>> diff --git a/xtf-runner b/xtf-runner
>>> index c063699..7b69c45 100755
>>> --- a/xtf-runner
>>> +++ b/xtf-runner
>>> @@ -151,6 +151,19 @@ def __repr__(self):
>>>          return "TestInfo(%s)" % (self.name, )
>>>  
>>>  
>>> +def get_xen_version():
>>> +    """Get the version string of Xen"""
>>> +
>>> +    for line in check_output(['xl', 'info']).splitlines():
>>> +        if not line.startswith("xen_version"):
>>> +            continue
>>> +
>>> +        version_str = line.split()[2:][0]
>>> +        break
>>> +
>>> +    return version_str
>> This will hit a name error if xen_version isn't found in the output.
>>
>> A better option would be to "return line.split()[2:][0]" directly and
>> raise a RunnerError() at this point.
>>
>> However, xen_version was introduced by me a while ago, but not so very
>> long ago, and won't work on older versions of Xen.
>>
> Oh, didn't notice that. I thought it was available to all versions of
> Xen.
>
>> I think at this point, it would just be easier to use the python libxc
>> bindings, so
>>
>> from xen.lowlevel.xc import xc
>> libxc = xc()
>>
>> info = libxc.xeninfo()
>> return "%s.%s" % (info["xen_major"], info["xen_minor"])

Erm - these should be %d not %s.

Sorry for the misinformation.

~Andrew

>>
>> Make sure the import statement is inside the function call to avoid
>> breaking the usecase of `xtf-runner --list` offhost.
>>
> NP.
>
> Wei.
>
>> ~Andrew
>>
>>> +
>>> +
>>>  def parse_test_instance_string(arg):
>>>      """Parse a test instance string.
>>>
diff mbox

Patch

diff --git a/xtf-runner b/xtf-runner
index c063699..7b69c45 100755
--- a/xtf-runner
+++ b/xtf-runner
@@ -151,6 +151,19 @@  def __repr__(self):
         return "TestInfo(%s)" % (self.name, )
 
 
+def get_xen_version():
+    """Get the version string of Xen"""
+
+    for line in check_output(['xl', 'info']).splitlines():
+        if not line.startswith("xen_version"):
+            continue
+
+        version_str = line.split()[2:][0]
+        break
+
+    return version_str
+
+
 def parse_test_instance_string(arg):
     """Parse a test instance string.