'Hacky basic and naive fixture loading based on a python module.
Expects that the various APIs into the various services are already
defined on `self`.'

def load_fixtures(self, fixtures):

    fixtures_to_cleanup = []
    if (hasattr(self, 'identity_api') and hasattr(self, 'assignment_api') and hasattr(self, 'resource_api')):
        for domain in fixtures.DOMAINS:
            rv = self.resource_api.create_domain(domain['id'], domain)
            attrname = ('domain_%s' % domain['id'])
            setattr(self, attrname, rv)
            fixtures_to_cleanup.append(attrname)
        for tenant in fixtures.TENANTS:
            tenant_attr_name = ('tenant_%s' % tenant['name'].lower())
            rv = self.resource_api.create_project(tenant['id'], tenant)
            setattr(self, tenant_attr_name, rv)
            fixtures_to_cleanup.append(tenant_attr_name)
        for role in fixtures.ROLES:
            rv = self.role_api.create_role(role['id'], role)
            attrname = ('role_%s' % role['name'])
            setattr(self, attrname, rv)
            fixtures_to_cleanup.append(attrname)
        for user in fixtures.USERS:
            user_copy = user.copy()
            tenants = user_copy.pop('tenants')
            user_copy = self.identity_api.create_user(user_copy)
            user_copy['password'] = user['password']
            for tenant_id in tenants:
                self.assignment_api.add_user_to_project(tenant_id, user_copy['id'])
            attrname = ('user_%s' % user['name'])
            setattr(self, attrname, user_copy)
            fixtures_to_cleanup.append(attrname)
        for role_assignment in fixtures.ROLE_ASSIGNMENTS:
            role_id = role_assignment['role_id']
            user = role_assignment['user']
            tenant_id = role_assignment['tenant_id']
            user_id = getattr(self, ('user_%s' % user))['id']
            self.assignment_api.add_role_to_user_and_project(user_id, tenant_id, role_id)
        self.addCleanup(self.cleanup_instance(*fixtures_to_cleanup))
