Use new SSH class for Deploy_Object
This commit is contained in:
committed by
Raphael Defosseux
parent
ee4b193877
commit
ea123a2ac0
@@ -67,7 +67,7 @@ def CreateWorkspace(sshSession, sourcePath, ranRepository, ranCommitID, ranTarge
|
|||||||
|
|
||||||
sshSession.command(f'rm -rf {sourcePath}', '\$', 10)
|
sshSession.command(f'rm -rf {sourcePath}', '\$', 10)
|
||||||
sshSession.command('mkdir -p ' + sourcePath, '\$', 5)
|
sshSession.command('mkdir -p ' + sourcePath, '\$', 5)
|
||||||
sshSession.command('cd ' + sourcePath, '\$', 5)
|
(sshSession.cd(sourcePath) if isinstance(sshSession, cls_cmd.Cmd) else sshSession.command('cd ' + sourcePath, '\$', 5))
|
||||||
# Recent version of git (>2.20?) should handle missing .git extension # without problems
|
# Recent version of git (>2.20?) should handle missing .git extension # without problems
|
||||||
if ranTargetBranch == 'null':
|
if ranTargetBranch == 'null':
|
||||||
ranTargetBranch = 'develop'
|
ranTargetBranch = 'develop'
|
||||||
@@ -884,26 +884,23 @@ class Containerize():
|
|||||||
logging.debug('\u001B[1m Deploying OAI Object on server: ' + lIpAddr + '\u001B[0m')
|
logging.debug('\u001B[1m Deploying OAI Object on server: ' + lIpAddr + '\u001B[0m')
|
||||||
self.deployKind[self.eNB_instance] = True
|
self.deployKind[self.eNB_instance] = True
|
||||||
|
|
||||||
mySSH = SSH.SSHConnection()
|
mySSH = cls_cmd.getConnection(lIpAddr)
|
||||||
mySSH.open(lIpAddr, lUserName, lPassWord)
|
|
||||||
|
|
||||||
CreateWorkspace(mySSH, lSourcePath, self.ranRepository, self.ranCommitID, self.ranTargetBranch, self.ranAllowMerge)
|
CreateWorkspace(mySSH, lSourcePath, self.ranRepository, self.ranCommitID, self.ranTargetBranch, self.ranAllowMerge)
|
||||||
|
|
||||||
mySSH.command('cd ' + lSourcePath + '/' + self.yamlPath[self.eNB_instance], '\$', 5)
|
mySSH.cd(lSourcePath + '/' + self.yamlPath[self.eNB_instance])
|
||||||
mySSH.command('cp docker-compose.y*ml ci-docker-compose.yml', '\$', 5)
|
mySSH.run('cp docker-compose.y*ml ci-docker-compose.yml', 5)
|
||||||
for image in IMAGES:
|
for image in IMAGES:
|
||||||
imageTag = ImageTagToUse(image, self.ranCommitID, self.ranBranch, self.ranAllowMerge)
|
imageTag = ImageTagToUse(image, self.ranCommitID, self.ranBranch, self.ranAllowMerge)
|
||||||
mySSH.command(f'sed -i -e "s#image: {image}:latest#image: oai-ci/{imageTag}#" ci-docker-compose.yml', '\$', 2)
|
mySSH.run(f'sed -i -e "s#image: {image}:latest#image: oai-ci/{imageTag}#" ci-docker-compose.yml', 2)
|
||||||
|
|
||||||
# Currently support only one
|
# Currently support only one
|
||||||
svcName = self.services[self.eNB_instance]
|
svcName = self.services[self.eNB_instance]
|
||||||
if svcName == '':
|
if svcName == '':
|
||||||
logging.warning('no service name given: starting all services in ci-docker-compose.yml!')
|
logging.warning('no service name giv en: starting all services in ci-docker-compose.yml!')
|
||||||
|
mySSH.run(f'docker compose --file ci-docker-compose.yml up -d -- {svcName}', 30)
|
||||||
mySSH.command(f'docker compose --file ci-docker-compose.yml up -d -- {svcName}', '\$', 30)
|
|
||||||
|
|
||||||
# Checking Status
|
# Checking Status
|
||||||
mySSH.command(f'docker compose --file ci-docker-compose.yml config {svcName}', '\$', 5)
|
mySSH.run(f'docker compose --file ci-docker-compose.yml config {svcName}')
|
||||||
result = re.search('container_name: (?P<container_name>[a-zA-Z0-9\-\_]+)', mySSH.getBefore())
|
result = re.search('container_name: (?P<container_name>[a-zA-Z0-9\-\_]+)', mySSH.getBefore())
|
||||||
unhealthyNb = 0
|
unhealthyNb = 0
|
||||||
healthyNb = 0
|
healthyNb = 0
|
||||||
@@ -916,7 +913,7 @@ class Containerize():
|
|||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
cnt = 0
|
cnt = 0
|
||||||
while (cnt < 3):
|
while (cnt < 3):
|
||||||
mySSH.command('docker inspect --format="{{.State.Health.Status}}" ' + containerName, '\$', 5)
|
mySSH.run('docker inspect --format="{{.State.Health.Status}}" ' + containerName, 5)
|
||||||
unhealthyNb = mySSH.getBefore().count('unhealthy')
|
unhealthyNb = mySSH.getBefore().count('unhealthy')
|
||||||
healthyNb = mySSH.getBefore().count('healthy') - unhealthyNb
|
healthyNb = mySSH.getBefore().count('healthy') - unhealthyNb
|
||||||
startingNb = mySSH.getBefore().count('starting')
|
startingNb = mySSH.getBefore().count('starting')
|
||||||
@@ -926,13 +923,13 @@ class Containerize():
|
|||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
cnt += 1
|
cnt += 1
|
||||||
|
|
||||||
mySSH.command('docker inspect --format="ImageUsed: {{.Config.Image}}" ' + containerName, '\$', 5)
|
mySSH.run('docker inspect --format="ImageUsed: {{.Config.Image}}" ' + containerName)
|
||||||
for stdoutLine in mySSH.getBefore().split('\n'):
|
for stdoutLine in mySSH.getBefore().split('\n'):
|
||||||
if stdoutLine.count('ImageUsed: oai-ci'):
|
if stdoutLine.count('ImageUsed: oai-ci'):
|
||||||
usedImage = stdoutLine.replace('ImageUsed: oai-ci', 'oai-ci').strip()
|
usedImage = stdoutLine.replace('ImageUsed: oai-ci', 'oai-ci').strip()
|
||||||
logging.debug('Used image is ' + usedImage)
|
logging.debug('Used image is ' + usedImage)
|
||||||
if usedImage != '':
|
if usedImage != '':
|
||||||
mySSH.command('docker image inspect --format "* Size = {{.Size}} bytes\n* Creation = {{.Created}}\n* Id = {{.Id}}" ' + usedImage, '\$', 5, silent=True)
|
mySSH.run('docker image inspect --format "* Size = {{.Size}} bytes\n* Creation = {{.Created}}\n* Id = {{.Id}}" ' + usedImage, 5, silent=True)
|
||||||
for stdoutLine in mySSH.getBefore().split('\n'):
|
for stdoutLine in mySSH.getBefore().split('\n'):
|
||||||
if re.search('Size = [0-9]', stdoutLine) is not None:
|
if re.search('Size = [0-9]', stdoutLine) is not None:
|
||||||
imageInfo += stdoutLine.strip() + '\n'
|
imageInfo += stdoutLine.strip() + '\n'
|
||||||
@@ -951,7 +948,7 @@ class Containerize():
|
|||||||
if healthyNb == 1:
|
if healthyNb == 1:
|
||||||
cnt = 0
|
cnt = 0
|
||||||
while (cnt < 20):
|
while (cnt < 20):
|
||||||
mySSH.command('docker logs ' + containerName + ' | egrep --text --color=never -i "wait|sync|Starting|ready"', '\$', 30)
|
mySSH.run(f'docker logs {containerName} | egrep --text --color=never -i "wait|sync|Starting|ready"')
|
||||||
result = re.search('got sync|Starting E1AP at CU UP|Starting F1AP at CU|Got sync|Waiting for RUs to be configured|cuPHYController initialized|Received CONFIG.response, gNB is ready', mySSH.getBefore())
|
result = re.search('got sync|Starting E1AP at CU UP|Starting F1AP at CU|Got sync|Waiting for RUs to be configured|cuPHYController initialized|Received CONFIG.response, gNB is ready', mySSH.getBefore())
|
||||||
if result is None:
|
if result is None:
|
||||||
time.sleep(6)
|
time.sleep(6)
|
||||||
@@ -964,8 +961,9 @@ class Containerize():
|
|||||||
# containers are unhealthy, so we won't start. However, logs are stored at the end
|
# containers are unhealthy, so we won't start. However, logs are stored at the end
|
||||||
# in UndeployObject so we here store the logs of the unhealthy container to report it
|
# in UndeployObject so we here store the logs of the unhealthy container to report it
|
||||||
logfilename = f'{lSourcePath}/cmake_targets/log/{self.eNB_logFile[self.eNB_instance]}'
|
logfilename = f'{lSourcePath}/cmake_targets/log/{self.eNB_logFile[self.eNB_instance]}'
|
||||||
mySSH.command(f'docker logs {containerName} > {logfilename}', '\$', 30)
|
mySSH.run(f'docker logs {containerName} > {logfilename}', 30)
|
||||||
mySSH.copyin(lIpAddr, lUserName, lPassWord, logfilename, '.')
|
mySSH.copyin(logfilename, '.',True)
|
||||||
|
|
||||||
mySSH.close()
|
mySSH.close()
|
||||||
|
|
||||||
message = ''
|
message = ''
|
||||||
|
|||||||
Reference in New Issue
Block a user