Commit ea123a2a authored by Bipin Adhikari's avatar Bipin Adhikari Committed by Raphael Defosseux

Use new SSH class for Deploy_Object

parent ee4b1938
......@@ -67,7 +67,7 @@ def CreateWorkspace(sshSession, sourcePath, ranRepository, ranCommitID, ranTarge
sshSession.command(f'rm -rf {sourcePath}', '\$', 10)
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
if ranTargetBranch == 'null':
ranTargetBranch = 'develop'
......@@ -884,26 +884,23 @@ class Containerize():
logging.debug('\u001B[1m Deploying OAI Object on server: ' + lIpAddr + '\u001B[0m')
self.deployKind[self.eNB_instance] = True
mySSH = SSH.SSHConnection()
mySSH.open(lIpAddr, lUserName, lPassWord)
mySSH = cls_cmd.getConnection(lIpAddr)
CreateWorkspace(mySSH, lSourcePath, self.ranRepository, self.ranCommitID, self.ranTargetBranch, self.ranAllowMerge)
mySSH.command('cd ' + lSourcePath + '/' + self.yamlPath[self.eNB_instance], '\$', 5)
mySSH.command('cp docker-compose.y*ml ci-docker-compose.yml', '\$', 5)
mySSH.cd(lSourcePath + '/' + self.yamlPath[self.eNB_instance])
mySSH.run('cp docker-compose.y*ml ci-docker-compose.yml', 5)
for image in IMAGES:
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
svcName = self.services[self.eNB_instance]
if svcName == '':
logging.warning('no service name given: starting all services in ci-docker-compose.yml!')
mySSH.command(f'docker compose --file ci-docker-compose.yml up -d -- {svcName}', '\$', 30)
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)
# 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())
unhealthyNb = 0
healthyNb = 0
......@@ -916,7 +913,7 @@ class Containerize():
time.sleep(5)
cnt = 0
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')
healthyNb = mySSH.getBefore().count('healthy') - unhealthyNb
startingNb = mySSH.getBefore().count('starting')
......@@ -926,13 +923,13 @@ class Containerize():
time.sleep(10)
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'):
if stdoutLine.count('ImageUsed: oai-ci'):
usedImage = stdoutLine.replace('ImageUsed: oai-ci', 'oai-ci').strip()
logging.debug('Used image is ' + 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'):
if re.search('Size = [0-9]', stdoutLine) is not None:
imageInfo += stdoutLine.strip() + '\n'
......@@ -951,7 +948,7 @@ class Containerize():
if healthyNb == 1:
cnt = 0
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())
if result is None:
time.sleep(6)
......@@ -964,8 +961,9 @@ class Containerize():
# 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
logfilename = f'{lSourcePath}/cmake_targets/log/{self.eNB_logFile[self.eNB_instance]}'
mySSH.command(f'docker logs {containerName} > {logfilename}', '\$', 30)
mySSH.copyin(lIpAddr, lUserName, lPassWord, logfilename, '.')
mySSH.run(f'docker logs {containerName} > {logfilename}', 30)
mySSH.copyin(logfilename, '.',True)
mySSH.close()
message = ''
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment