Closed marcowenwolf closed 4 years ago
Hi @marcowenwolf,
Here's an example on how to use multiple sessions within the same script: https://github.com/nuagenetworks/vspk-examples/blob/master/python/multi-vsd_list_enterprises_domains_vms_structure_acls.py This example uses different VSDs, but it is the same process for a single VSD environment, but have multiple users.
You need to use the python with
statement (https://docs.python.org/3/reference/compound_stmts.html#the-with-statement) for this functionality.
I hope that helps.
Hallo Phillipe,
Thanks for the quick response. The 'with' suggestion works as a charm. So it looks like you can pass on the session object correctly, but using the session.user object causes issues re-using fetchers in case of multiple VSD sessions. For me it makes sense to use session object to pass on with 'with' statement.
class VSDLib:
def start_vsd_session(self, url, username='csproot', password='csproot', enterprise='csp'):
logger.debug('> VSDLib: Start VSD Session using url: {}'.format(url))
nc = vsdk.NUVSDSession(username=username, password=password, enterprise=enterprise, api_url=url)
session = nc.start()
logger.debug('< VSDLib: Started VSD Session: {}'.format(session))
return session
def get_first_child(self, obj, attr, fltr=''):
"""Get the first child of a given kind
Arguments:
- obj -- the parent object
- attr -- the attribute name of the child type list
- fltr -- search filter
Returns:
- child object or None
Examples:
| ${r} = | Get First Child | obj=root | attr=enterprises | fltr=name is "sdnlight-t1" |
"""
with obj:
logger.debug('< get_first_child: {}, {}, {}'.format(obj, attr, fltr))
fetcher = obj.user.__dict__[attr]
child = fetcher.get_first(filter=fltr)
logger.debug('< Child: {}'.format(child))
return child
Problem description
Test automation requires the capability to define VSD session per enterprise to provide access to enterprises during test runs. It should be possible to perform CRUD actions on multiple enterprises over time.
Reproduction
This result into a None object for first child. It looks like the HTTP header is garbeld with nume2 headers. This is clearly visible using robot framework output:
See log.html session1: Return: <vspk.v6.nume.NUMe object at 0x7f0a64646208> session2: Return: <vspk.v6.nume.NUMe object at 0x7f0a67fb4fd0>
Next the call to session1 to get enterprise by name from NUME object 0x7f0a64646208 (loggin session to se1-c1-v1 enterprise). From below excerpt you can see that the http header uses the wrong X-Nuage-Organization': 'se1-c5-v1' header. If the second session is not started, this test is successful.
Attached:
test_vsd.py.txt log.html.txt bug.robot.txt
Run Python script: