-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A top level API for loading and deleting test configuration. Needed s…
…ome modifications in model spec.
- Loading branch information
1 parent
e9fbfd3
commit b6c612c
Showing
9 changed files
with
96 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import cyperf | ||
import urllib3 | ||
import requests | ||
from cyperf.rest import ApiException | ||
from pprint import pprint | ||
|
||
import time | ||
|
||
class TestConfig(object): | ||
def __init__(self, configFile, agentMapping, objectiveType, objectiveValue, verifyRules): | ||
self.file = configFile | ||
self.agents = agentMapping | ||
self.objective = { | ||
'type' : objectiveType, | ||
'value' : objectiveValue | ||
} | ||
self.statRules = [] | ||
|
||
class TestRunner(object): | ||
WAP_CLIENT_ID = 'clt-wap' | ||
|
||
def __init__(self, controller, username, password): | ||
self.host = f'https://{controller}' | ||
self.username = username | ||
self.password = password | ||
|
||
self.configuration = cyperf.Configuration(host = self.host) | ||
self.configuration.access_token = self.__authorize__() | ||
self.configuration.verify_ssl = False | ||
self.apiClient = cyperf.ApiClient(self.configuration) | ||
|
||
def __authorize__(self): | ||
session = requests.Session() | ||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | ||
session.verify = False | ||
|
||
url = f'{self.host}/auth/realms/keysight/protocol/openid-connect/token' | ||
headers = {"content-type" : "application/x-www-form-urlencoded"} | ||
payload = {"username" : self.username, | ||
"password" : self.password, | ||
"grant_type" : "password", | ||
"client_id" : TestRunner.WAP_CLIENT_ID} | ||
response = session.post(url, headers = headers, data = payload, verify = False) | ||
if response.headers.get('content-type') == 'application/json': | ||
return response.json()['access_token'] | ||
else: | ||
raise Exception(f'Cannot generate access token for {self.host}') | ||
|
||
def Authorize(self): | ||
self.configuration.access_token = self.__authorize__() | ||
|
||
def LoadConfigs(self, configFiles): | ||
apiInstance = cyperf.ConfigurationsApi(self.apiClient) | ||
results = [] | ||
for cFile in configFiles: | ||
response = apiInstance.api_v2_configs_operations_import_post (cFile) | ||
while 'IN_PROGRESS' == response.state: | ||
response = apiInstance.api_v2_configs_operations_import_id_get(response.id) | ||
if 'SUCCESS' == response.state: | ||
results += response.result | ||
|
||
return [cyperf.AppsecConfig.from_dict(e['configData']) for e in results] | ||
|
||
def DeleteConfig(self, configs): | ||
apiInstance = cyperf.ConfigurationsApi(self.apiClient) | ||
for config in configs: | ||
apiInstance.api_v2_configs_config_id_delete (config.id) | ||
|
||
def Run(self, config): | ||
pprint (f"Loading configuration {config.file} ...") | ||
configs = self.LoadConfigs ([config.file]) | ||
pprint (f"Loaded configuration {config.file} ...") | ||
time.sleep(10) | ||
pprint (f"Deleting configuration {config.file} ...") | ||
self.DeleteConfig (configs) | ||
pprint (f"Deleted configuration {config.file} ...") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,10 @@ | ||
import cyperf | ||
import urllib3 | ||
import requests | ||
from cyperf.rest import ApiException | ||
from pprint import pprint | ||
from cyperf.utils.test import TestRunner, TestConfig | ||
|
||
class TestConfig(object): | ||
def __init__(self, configFile, agentMapping, objectiveType, objectiveValue, verifyRules): | ||
self.config = configFile | ||
self.agents = agentMapping | ||
self.objective = { | ||
'type' : objectiveType, | ||
'value' : objectiveValue | ||
} | ||
self.statRules = [] | ||
|
||
class TestRunner(object): | ||
WAP_CLIENT_ID = 'clt-wap' | ||
|
||
def __init__(self, controller, username, password): | ||
self.host = f'https://{controller}' | ||
self.username = username | ||
self.password = password | ||
|
||
self.configuration = cyperf.Configuration(host = self.host) | ||
self.configuration.access_token = self.__authorize__() | ||
self.apiClient = cyperf.ApiClient(configuration) | ||
|
||
def __authorize__(self): | ||
session = requests.Session() | ||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | ||
session.verify = False | ||
|
||
url = f'{self.host}/auth/realms/keysight/protocol/openid-connect/token' | ||
headers = {"content-type" : "application/x-www-form-urlencoded"} | ||
payload = {"username" : self.username, | ||
"password" : self.password, | ||
"grant_type" : "password", | ||
"client_id" : TestRunner.WAP_CLIENT_ID} | ||
response = session.post(url, headers = headers, data = payload, verify = False) | ||
if response.headers.get('content-type') == 'application/json': | ||
return response.json()['access_token'] | ||
else: | ||
raise Exception(f'Cannot generate access token for {self.host}') | ||
|
||
def authorize(self): | ||
self.configuration.access_token = self.__authorize__() | ||
|
||
def run(self, config): | ||
pass | ||
tests = [ | ||
TestConfig ('samples/configs/Msoft_tput_smartNIC_passthru.zip', {'IP Network Segment 1': ['10.36.75.235'], 'IP Network Segment 2': ['10.36.75.246']}, 'Throughput', 12500000000, None) | ||
] | ||
|
||
runner = TestRunner ('10.36.75.241', 'admin', 'CyPerf&Keysight#1') | ||
print(runner.configuration.access_token) | ||
|
||
for config in tests: | ||
runner.Run (config) |