[OpenStack-Infra] client manager setup in tempest

Matthew Treinish mtreinish at kortar.org
Sun Aug 9 23:50:10 UTC 2015


Just for future reference most of the ML tempest discussions happen on the
openstack-dev list with a [QA] or a [tempest] tag.

On Thu, Aug 06, 2015 at 08:35:40PM -0400, John Warren wrote:
> 
> Could somebody explain to me how this code in tempest/test.py can possibly
> work:
> 
>     @classmethod
>     def setup_credentials(cls):
>         """Allocate credentials and the client managers from them.
>         A test class that requires network resources must override
>         setup_credentials and defined the required resources before super
>         is invoked.
>         """
>         for credentials_type in cls.credentials:
>             # This may raise an exception in case credentials are not
> available
>             # In that case we want to let the exception through and the test
>             # fail accordingly
>             if isinstance(credentials_type, six.string_types):
>                 manager = cls.get_client_manager(
>                     credential_type=credentials_type)
>                 setattr(cls, 'os_%s' % credentials_type, manager)
>                 # Setup some common aliases
>                 # TODO(andreaf) The aliases below are a temporary hack
>                 # to avoid changing too much code in one patch. They should
>                 # be removed eventually
>                 if credentials_type == 'primary':
>                     cls.os = cls.manager = cls.os_primary
>                 if credentials_type == 'admin':
>                     cls.os_adm = cls.admin_manager = cls.os_admin
>                 if credentials_type == 'alt':
>                     cls.alt_manager = cls.os_alt
>             elif isinstance(credentials_type, list):
>                 manager = cls.get_client_manager(roles=credentials_type[1:],
>                                                  force_new=True)
>                 setattr(cls, 'os_roles_%s' % credentials_type[0], manager)
> 
> I'm wondering about the following line:
> 
> cls.os_adm = cls.admin_manager = cls.os_admin
> 
> From inside the root directory I do a grep search:
> 
> $ grep -Hr os_admin tempest
> Binary file tempest/test.pyc matches
> tempest/test.py:                    cls.os_adm = cls.admin_manager =
> cls.os_admin
> tempest/api/baremetal/admin/base.py:        cls.client =
> cls.os_admin.baremetal_client
> Binary file tempest/api/baremetal/admin/base.pyc matches
> 
> This indicates to me that "os_admin" isn't being assigned a value anywhere.
> Therefore, I would expect an AttributeError (class BaseTestCase has no
> attribute 'os_admin'), yet this class method seems to work.  What am I
> missing?

So a grep actually won't help here, because that attribute, and all of the other
manager object class attributes, get set dynamically by setup_credentials(). If
you look at:

http://git.openstack.org/cgit/openstack/tempest/tree/tempest/test.py#n352

that setattr() call is setting the attribute for each manager on the test class.

The way this method is intended to be used is that each test class defines as an
attribute the list of isolated credential types which are required for the tests
in the class. setup_credentials(), which gets called as part of setUpClass, will
then take that list, allocate the credentials (either using tenant isolation or
the locking test accounts mechanism) and use that to init a client manager
object. That then gets set to as an attribute on the class so that tests can
get to the manager objects for each set of credentials.

The line you pointed out is only there because before we had a common
implementation for creating client manager objects each test class would do it
slightly differently. So the class attributes that tests were expecting vary
slightly. (hence the todo comment saying we need to change all the tests to
remove the aliases) That's actually a quick low hanging fruit kinda thing for
someone to pick up, to just go through all the tests and unify the use of the
manager object attrs so we can remove this alias.


-Matt Treinish
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.openstack.org/pipermail/openstack-infra/attachments/20150809/2555fc7b/attachment.pgp>


More information about the OpenStack-Infra mailing list