Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added tests/common/tgen/__init__.py
Empty file.
82 changes: 82 additions & 0 deletions tests/common/tgen/ixia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Ixia file to update ixia related variables

# import pytest

class IXIA(object):
"""
IXIA Class to get ixia related variables
"""
def __init__(self,testbed,duthost):
"""
Args:
testbed (pytest fixture): The testbed fixture.
duthost (pytest fixture): The duthost fixture.

"""

self.testbed = testbed
self.duthost = duthost

@property
def api_serv_ip(self):
"""
In an Ixia testbed, there is no PTF docker.
Hence, we use ptf_ip field to store Ixia API server.
This fixture returns the IP address of the Ixia API server.

Args:
testbed (pytest fixture): The testbed fixture.

Returns:
Ixia API server IP
"""
return self.testbed['ptf_ip']


@property
def api_serv_user(self):
"""
Return the username of Ixia API server.

Returns:
Ixia API server username.
"""
return self.duthost.host.options['variable_manager']. \
_hostvars[self.duthost.hostname]['secret_group_vars']['ixia_api_server']['user']


@property
def api_serv_passwd(self):
"""
Return the password of Ixia API server.

Returns:
Ixia API server password.
"""
return self.duthost.host.options['variable_manager']. \
_hostvars[self.duthost.hostname]['secret_group_vars']['ixia_api_server']['password']


@property
def api_serv_port(self):
"""
This fixture returns the TCP port for REST API of the ixia API server.

Returns:
Ixia API server REST port.
"""
return self.duthost.host.options['variable_manager']. \
_hostvars[self.duthost.hostname]['secret_group_vars']['ixia_api_server']['rest_port']


@property
def api_serv_session_id(self):
"""
Ixia API server can spawn multiple session on the same REST port.
Optional for LINUX, required for windows return the session ID.

Returns:
Ixia API server session id.
"""
return self.duthost.host.options['variable_manager']. \
_hostvars[self.duthost.hostname]['secret_group_vars']['ixia_api_server']['session_id']
27 changes: 27 additions & 0 deletions tests/common/tgen/tgen_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## tgn fixtures file where multiple vendors can define as per Open TGEN approach
import pytest

@pytest.fixture(scope='module')
def api(fanout_graph_facts,
tbinfo,
duthost):
"""
Common api fixture for tgen of any platform.

Support is available for IXIA currently, please update for other traffic generators
"""
# This is a dynamic approach for getting the tgen platform

if 'ixia-sonic' in fanout_graph_facts.keys():
from ixnetwork_open_traffic_generator.ixnetworkapi import IxNetworkApi
from ixia import IXIA
ixia = IXIA(tbinfo,duthost)
ixnetwork_api = IxNetworkApi(address=ixia.api_serv_ip,
port=ixia.api_serv_port,
username=ixia.api_serv_user,
password=ixia.api_serv_passwd)
yield ixnetwork_api
if ixnetwork_api.assistant is not None:
ixnetwork_api.assistant.Session.remove()
else:
pytest.fail("The test supports only for IXIA TGEN, please add for other vendors")
Loading