Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated testbeds, CI_Automation and TestSuites #420

Merged
merged 3 commits into from
Jun 21, 2024
Merged
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
6 changes: 4 additions & 2 deletions CI_Automation/CloneTestingRepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def clone(self):
Utilities.updateStage(self.ciVars.overallSummaryFile, stage='cloneTestRepo',
status='running', result='None', threadLock=self.lock)

self.log.info(f'clone: testIdTestingBranch: {self.testIdTestingBranch}')

# Create the TestBranch folder to hold all testId testing repos
if os.path.exists(self.testBranchFolder) is False:
Utilities.runLinuxCmd(f'mkdir -p {self.testBranchFolder}')
Expand All @@ -41,7 +43,7 @@ def clone(self):
Utilities.runLinuxCmd(f'chmod 770 {self.testIdTestingBranch}')

if self.ciVars.localTestBranch:
Utilities.runLinuxCmd(f'cp -r {self.ciVars.localTestBranch} {self.testIdTestingBranch}', logObj=self.log)
Utilities.runLinuxCmd(f'cp -r {self.ciVars.localTestBranch}/* {self.testIdTestingBranch}', logObj=self.log)
else:
if self.branchName:
cmd = f'git clone --branch {self.branchName} {self.repo} {self.testIdTestingBranch}'
Expand All @@ -62,7 +64,7 @@ def clone(self):
self.log.info('Verify if cloned repo test branch has files in it')
output = Utilities.runLinuxCmd('ls', cwd=self.testIdTestingBranch, logObj=self.log)
if len(output) > 0:
self.log.info('Verified cloned files!')
self.log.info('Verified cloned files')
verified = True
Utilities.updateStage(self.ciVars.overallSummaryFile, stage='cloneTestRepo',
status='completed', result='passed', threadLock=self.lock)
Expand Down
15 changes: 12 additions & 3 deletions CI_Automation/DentCiArgParse.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def __init__(self, ciVars: object) -> None:
def parse(self):
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('-testName', nargs='+', default=None, help='Give a test name to identify your test ID.')
parser.add_argument('-builds', nargs='+', default=None, help='Both ARM and AMD full path URLs for the builds')
parser.add_argument('-builds', nargs='+', default=None, help='Get from Dent website. Both ARM and AMD full path URLs for the builds')
parser.add_argument('-localBuilds', nargs='+', default=None, help='Local path to builds. Both ARM and AMD full path URLs for the builds')
parser.add_argument('-testSuites', nargs='+', default=None, help='The test suite to run')
parser.add_argument('-repo', nargs='+', default=None, help='The repo to clone for testing')
parser.add_argument('-localBranch', nargs='+', default=None, help='Test with a local branch that is already cloned. Provide the path.')
Expand Down Expand Up @@ -73,6 +74,11 @@ def parse(self):
else:
self.ciVars.builds = args.builds

if args.localBuilds is None:
self.ciVars.localBuilds = []
else:
self.ciVars.localBuilds = args.localBuilds

if args.repo is None:
# Default pulling the main branch
self.ciVars.repo = self.ciVars.gitCloneDefaultRepo
Expand All @@ -92,8 +98,12 @@ def parse(self):
localBranch = args.localBranch[0]

self.ciVars.localTestBranch = localBranch
self.ciVars.repo = localBranch
else:
Utilities.sysExit(self.ciVars, f'No such local test branch: {args.localBranch[0]}')
print(f'No such local test branch: {args.localBranch[0]}')
sys.exit(f'No such local test branch: {args.localBranch[0]}')
else:
self.ciVars.localTestBranch = None

if args.tftp is False and args.http is False:
# Default to use http
Expand All @@ -116,7 +126,6 @@ def parse(self):

if args.disableDownloadNewBuilds:
self.ciVars.downloadNewBuilds = False
self.ciVars.builds = []
else:
if args.builds:
self.ciVars.builds = args.builds
Expand Down
191 changes: 125 additions & 66 deletions CI_Automation/DeployDent.py

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions CI_Automation/DeployIxNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
echo 'start the vm'
virsh autostart IxNetwork-930
virsh start IxNetwork-930

Debug:
virsh console IxNetwork-9.30
"""
import os
import time
Expand Down Expand Up @@ -81,11 +84,11 @@ def __init__(self, ixNetworkVMFolder: str, logObj: object) -> None:
def isIxNetworkVMExists(self) -> bool:
vmExists = False

# Attempt to verify up to 5 times. Sometimes, this command
# Attempt to verify up to 5 times. Sometimes this command
# is either delayed or doesn't show anything
for counter in range(0, 5):
output = Utilities.runLinuxCmd('virsh list', logObj=self.log)
self.log.info(f'isNetworkVMExists: output {counter}/5: {output}')
self.log.info(f'isNetworkVMExists: Verifying {counter}/5x: {output}')

if output:
for line in output:
Expand Down
2 changes: 1 addition & 1 deletion CI_Automation/DeployTestContainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def removeAndBuild(self) -> str:
if self.isDockerImagesExists():
Utilities.updateStage(self.overallSummaryFile, stage=stage,
status='completed', result='passed', threadLock=self.lock)
self.sessionLog.info(f'dentContainerTag: {self.dentContainerTag}')
self.sessionLog.info(f'dentContainerTag: {self.ciVars.dockerImageTag}')
return True
else:
errorMsg = 'Dent test docker images not found'
Expand Down
26 changes: 25 additions & 1 deletion CI_Automation/DownloadBuilds.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init__(self, ciVars: object):
self.log = ciVars.sessionLog

# Every test has its down testId folder to store the builds download
# /DentBuildReleases/06-11-2024-19-34-49-119160_devMode
Utilities.runLinuxCmd(f'mkdir -p {self.downloadToServerFolder}', logObj=self.log)

'''
def getPullRequestList(self):
"""
Expand Down Expand Up @@ -217,6 +217,24 @@ def downloadBuilds(self, scrapedBuildList: bool = False):
else:
return False

def copyLocalBuildsToHttpServerTestIdFolder(self):
print('\ncopyLocalBuildsToHttpServerTestIdFolder')
for srcBuild in self.ciVars.localBuilds:
buildName = srcBuild.split('/')[-1]
downloadToDestPath = f'{self.downloadToServerFolder}/{buildName}'

doOnce = True
if doOnce:
# buildName: DENTOS-HEAD_ONL-OS10_2023-09-20.1438-a00d7f6_ARM64_INSTALLED_INSTALLER
matchReg = search(r'DENTOS.*_([0-9]+-[0-9]+-[0-9]+)\.([0-9]+)-.*', buildName)
if matchReg:
data = Utilities.readJson(self.ciVars.overallSummaryFile)
data.update({'buildDate': matchReg.group(1), 'buildNumber': matchReg.group(2)})
Utilities.writeToJson(jsonFile=self.ciVars.overallSummaryFile, data=data, mode='w', threadLock=self.ciVars.lock)
doOnce = False

Utilities.runLinuxCmd(f'cp {srcBuild} {downloadToDestPath}', logObj=self.log)


def downloadBuilds(ciVars: object) -> bool:
"""
Expand All @@ -228,6 +246,12 @@ def downloadBuilds(ciVars: object) -> bool:
downloadBuildsObj = DownloadBuilds(ciVars)
srcBuildList = ciVars.builds

if ciVars.localBuilds:
downloadBuildsObj.copyLocalBuildsToHttpServerTestIdFolder()
Utilities.updateStage(ciVars.overallSummaryFile, stage='downloadNewBuilds',
status='completed', result='passed', threadLock=ciVars.lock)
return True

if ciVars.builds == []:
# User did not provide builds. Scrape for the latest builds from the main branch in github
srcBuildList = downloadBuildsObj.scrapeForLatestBuild(globalSettings.downloadBuildUrlPrefixPath)
Expand Down
39 changes: 31 additions & 8 deletions CI_Automation/TestMgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def __init__(self, ciVars: object = None):
# Testbed reservation
self.testbedMgmtFolder = globalSettings.testbedMgmtFolder
self.testbedWaitingFolder = globalSettings.testbedMgmtWaitingFolder
# Test session folder: /home/dent/testing
# Test session folder: /home/dent/DentCiMgmt/TestResults/06-14-2024-16-18-45-420609
self.testSessionFolder = ciVars.testSessionFolder
# testIdTestingBranch: /path/DentCiMgmt/TestBranches/06-14-2024-16-18-45-420609_devMode
self.testIdTestingBranch = ciVars.testIdTestingBranch
# The Linux host logged in user running the test
self.user = ciVars.user
Expand All @@ -71,9 +72,10 @@ def __init__(self, ciVars: object = None):
self.overallSummaryFile = ciVars.overallSummaryFile
self.reportFile = ciVars.reportFile
self.abortTestOnError = ciVars.abortTestOnError
self.overallTestResult = 'Passed'
self.overallTestResult = 'None'
self.testIdTestbeds = []
self.setTestcases()
self.isThereAnyResultInReport = None

self.log.info(f'RunTest: testSuites={self.testSuites}')
self.log.info(f'RunTest: logDir={self.testSessionFolder}')
Expand Down Expand Up @@ -166,11 +168,13 @@ def report(self) -> str:
But within each suite group has many testcases with results.
"""
testResult = None

# /path/DentCiMgmt/tools/test_utils.py
result = Utilities.runLinuxCmd(f'{sys.executable} {globalSettings.dentToolsPath}/test_utils.py csv -d {self.testSessionFolder}',
logObj=self.log)

if result:
report = ''
testResult = 'passed'
# ['Name,Group,Subgroup,Status,Message', 'test_clean_config,basic_triggers,test_clean_config,pass,""']
for index, line in enumerate(result):
if not line:
Expand All @@ -185,6 +189,7 @@ def report(self) -> str:
if len(line) != 5:
continue

self.isThereAnyResultInReport = True
status = line[3]
# pass | failure
if status != 'pass':
Expand All @@ -193,6 +198,13 @@ def report(self) -> str:

report += f'{line[0]:25} {line[1]:20} {line[2]:20} {line[3]:20} {line[4]:30}\n'

if self.isThereAnyResultInReport and testResult is None:
testResult = 'passed'
if self.isThereAnyResultInReport and testResult == 'failed':
testResult = 'failed'
if self.isThereAnyResultInReport is None and testResult is None:
testResult = 'none'

self.log.info(f'{report}', noTimestamp=True)
Utilities.writeToFile(report, filename=self.reportFile, mode='w', printToStdout=False)

Expand Down Expand Up @@ -269,23 +281,34 @@ def runTestSuite(self) -> None:
testDeltaTime = str((stopTime - startTime))
if aborted:
status = 'aborted'
self.overallTestResult = 'unknown'
self.overallTestResult = 'Aborted'
else:
status = 'completed'

testResult = self.report()
if status == 'completed':
if self.isThereAnyResultInReport and self.overallTestResult not in ['Aborted', 'Failed']:
self.overallTestResult = 'Passed'

if self.isThereAnyResultInReport and self.overallTestResult in ['Aborted', 'Failed']:
self.overallTestResult = 'Failed'

if self.isThereAnyResultInReport is None:
self.overallTestResult = 'Failed'
errorMsg = 'There were no test case results hmtl files found in the test branch folder. No result.'

self.report()
Utilities.updateTestMgmtData(self.overallSummaryFile,
{'status': status,
'stopTime': stopTime.strftime('%m-%d-%Y %H:%M:%S:%f'),
'testDuration': testDeltaTime,
'error': errorMsg,
'aborted': aborted,
'result': testResult
'result': self.overallTestResult
},
threadLock=self.lock)

Utilities.updateStage(self.overallSummaryFile, stage='runTest', status=status,
result=testResult, error=None, threadLock=self.lock)
result=self.overallTestResult, error=None, threadLock=self.lock)

if aborted and self.abortTestOnError:
self.killTest(status='AbortTestOnError')
Expand Down Expand Up @@ -389,7 +412,7 @@ def runSuiteGroup(self, suiteGroup: dict) -> None:
Utilities.updateStage(self.overallSummaryFile, stage='runTest', status='error',
result='None', error=errorMsg, threadLock=self.lock)
self.log.error(errorMsg)
self.overallTestResult = 'unknown'
self.overallTestResult = 'Aborted'
print(f'runSuiteGroup error: {errorMsg}')

finally:
Expand Down
6 changes: 6 additions & 0 deletions CI_Automation/TestSuites/basic_agg1_testbed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
suiteGroups:
runInSeries:
- name: suite_group_clean_config_agg1
config: ./DentOsTestbed/configuration/testbed_config/basic_agg1/testbed.json
suiteGroups:
- suite_group_clean_config
6 changes: 6 additions & 0 deletions CI_Automation/TestSuites/basic_infra1_testbed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
suiteGroups:
runInSeries:
- name: suite_group_clean_config_infra1
config: ./DentOsTestbed/configuration/testbed_config/basic_infra1/testbed.json
suiteGroups:
- suite_group_clean_config
11 changes: 11 additions & 0 deletions CI_Automation/TestSuites/cleanConfig_sit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
suiteGroups:
runInSeries:
- name: suite_group_clean_config
config: ./DentOsTestbed/configuration/testbed_config/sit_vm/testbed.json
suiteGroups:
- suite_group_clean_config

#- name: suite_group_functional
# config: ./DentOsTestbed/configuration/testbed_config/sit/testbed.json
# suiteGroups:
# - suite_group_functional
6 changes: 6 additions & 0 deletions CI_Automation/TestSuites/hw/sit/basic_agg1_testbed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
suiteGroups:
runInSeries:
- name: suite_group_clean_config_agg1
config: ./DentOsTestbed/configuration/testbed_config/hw/sit/basic_agg1/testbed.json
suiteGroups:
- suite_group_clean_config
6 changes: 6 additions & 0 deletions CI_Automation/TestSuites/hw/sit/basic_infra1_testbed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
suiteGroups:
runInSeries:
- name: suite_group_clean_config_infra1
config: ./DentOsTestbed/configuration/testbed_config/hw/sit/basic_infra1/testbed.json
suiteGroups:
- suite_group_clean_config
6 changes: 6 additions & 0 deletions CI_Automation/TestSuites/hw/sit/cleanConfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
suiteGroups:
runInSeries:
- name: suite_group_clean_config
config: ./DentOsTestbed/configuration/testbed_config/hw/sit/testbed.json
suiteGroups:
- suite_group_clean_config
Loading
Loading