WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] Re: [resend] [PATCH] [XS-TEST] Support for Xen-API authentic

To: Ewan Mellor <ewan@xxxxxxxxxxxxx>
Subject: [Xen-devel] Re: [resend] [PATCH] [XS-TEST] Support for Xen-API authenticated session
From: Stefan Berger <stefanb@xxxxxxxxxx>
Date: Tue, 26 Dec 2006 08:41:30 -0500
Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Tue, 26 Dec 2006 05:41:13 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <20061223124504.GE28890@xxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx

Ewan Mellor <ewan@xxxxxxxxxxxxx> wrote on 12/23/2006 07:45:04 AM:

> On Thu, Dec 21, 2006 at 03:38:21PM -0500, Stefan Berger wrote:
>
> > I am adding a tool 'xapi-setup.py' to the xm-test suite for being able
> > to setup authentication credentials needed for automatically running
> > Xen-API - related tests. The username and password information is stored
> > in cleartext in lib/XmTestLib/xapi_auth.py.
> > In the one test using the Xen-API I add another check for availability
> > of the python PAM module. The test is skipped if the module is not
> > available on the system.
> >
> > Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxx>
>
> Ah, sorry, I'd forgotten about this one.
>
> There is now a configuration file for xm (see
> tools/examples/xm-config.xml) so would it make sense to pull the
> username and password from there?  If you look at xen/xm/main.py,


I had not seen this file, but it seems not to be copied into /etc/xen/ by default. Would it be ok for now if I adapted the XML format and have xapi.py try to get username/password from the xm-config.xml file first and if it does not exist read the file created by the tool that I add to the xm test suite (xapi-setup.py) ?

  Stefan

> there's code for parsing the config file, and also for using the XenAPI
> session manager and server proxy -- you ought to be able to import that
> code now rather than using ServerProxy, and then there will be less for
> xapi.py to do, because it will be sharing with xm.
>
> Cheers,
>
> Ewan.
>
> > Index: root/xen-unstable.hg/tools/xm-test/lib/XmTestLib/xapi.py
> > ===================================================================
> > --- root.orig/xen-unstable.hg/tools/xm-test/lib/XmTestLib/xapi.py
> > +++ root/xen-unstable.hg/tools/xm-test/lib/XmTestLib/xapi.py
> > @@ -24,9 +24,6 @@ from xen.util.xmlrpclib2 import ServerPr
> >  from types import DictType
> >  
> >  
> > -XAPI_DEFAULT_LOGIN = " "
> > -XAPI_DEFAULT_PASSWORD = " "
> > -
> >  class XenAPIError(Exception):
> >      pass
> >  
> > @@ -58,8 +55,12 @@ def _connect(*args):
> >      global _server, _session, _initialised
> >      if not _initialised:
> >          _server = ServerProxy('httpu:///var/run/xend/xen-api.sock')
> > -        login = XAPI_DEFAULT_LOGIN
> > -        password = XAPI_DEFAULT_PASSWORD
> > +        try:
> > +            from XmTestLib import xapi_auth
> > +        except:
> > +            FAIL("Missing Xen-API credentials. Run xapi-setup.py!")
> > +        login = xapi_auth.XAPI_DEFAULT_LOGIN
> > +        password = xapi_auth.XAPI_DEFAULT_PASSWORD
> >          creds = (login, password)
> >          _session = execute(_server.session.login_with_password, *creds)
> >          _initialised = True
> > Index: root/xen-unstable.hg/tools/xm-test/tests/vtpm/09_vtpm-xapi.py
> > ===================================================================
> > --- root.orig/xen-unstable.hg/tools/xm-test/tests/vtpm/09_vtpm-xapi.py
> > +++ root/xen-unstable.hg/tools/xm-test/tests/vtpm/09_vtpm-xapi.py
> > @@ -68,6 +68,10 @@ def do_test():
> >      domain.destroy()
> >  
> >  
> > +try:
> > +    import PAM
> > +except ImportError:
> > +    SKIP("Skipping test. Python-PAM module not found.")
> >  
> >  try:
> >      do_test()
> > Index: root/xen-unstable.hg/tools/xm-test/xapi-setup.py
> > ===================================================================
> > --- /dev/null
> > +++ root/xen-unstable.hg/tools/xm-test/xapi-setup.py
> > @@ -0,0 +1,41 @@
> > +#!/usr/bin/python
> > +import sys as sys
> > +import getpass as getpass
> > +
> > +XAPI_AUTH_FILE = "xapi_auth.py"
> > +XAPI_AUTH_PATH = "./lib/XmTestLib/"
> > +XAPI_FILE = XAPI_AUTH_PATH + XAPI_AUTH_FILE
> > +
> > +def usage():
> > +    print "Usage: xapi-setup.py [<username>] [<password>]\n\n" \
> > +          "Tool to setup the xm-test suite for being able to use
> the Xen-API\n" \
> > +          "with authenticated sessions. Username and password are
> stored in\n" \
> > +          "cleartext in %s.\n" % XAPI_FILE
> > +
> > +def main():
> > +    if (len(sys.argv) >= 2) and sys.argv[1] == "-?":
> > +        usage()
> > +        sys.exit(0)
> > +    print "Enter username and password for usage with Xen-API:\n"
> > +    if (len(sys.argv) >=2  ):
> > +        username = sys.argv[1]
> > +        print "Login: %s" % username
> > +    else:
> > +        username = rawinput("Login: ")
> > +    if (len(sys.argv) >= 3 ):
> > +        password = sys.argv[2]
> > +        print "Password: <given>"
> > +    else:
> > +        password = getpass.getpass()
> > +    f = open(XAPI_FILE, "w")
> > +    if f:
> > +        f.write("# File was created by xapi-setup.py.\n"
> > +                "XAPI_DEFAULT_LOGIN = \"%s\"\n"
> > +                "XAPI_DEFAULT_PASSWORD = \"%s\"\n"
> > +                % (username, password))
> > +        f.close()
> > +    else:
> > +        print("Could not open file %s for writing." % XAPI_FILE)
> > +
> > +if __name__ == "__main__":
> > +    sys.exit(main())
>
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel