Use archiveArtifact() for CN undeploy
This commit is contained in:
@@ -29,6 +29,7 @@ import yaml
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
import cls_cmd
|
import cls_cmd
|
||||||
|
from cls_ci_helper import archiveArtifact
|
||||||
|
|
||||||
def listify(s):
|
def listify(s):
|
||||||
if s is None:
|
if s is None:
|
||||||
@@ -114,8 +115,7 @@ class CoreNetwork:
|
|||||||
logging.info(f'deployed core network {self}, pingable IP address {ip}')
|
logging.info(f'deployed core network {self}, pingable IP address {ip}')
|
||||||
return True, output
|
return True, output
|
||||||
|
|
||||||
def _collect_logs(self, log_dir):
|
def _collect_logs(self, ctx):
|
||||||
logging.info(f'collecting logs into (local) {log_dir}')
|
|
||||||
remote_dir = "/tmp/cn-undeploy-logs"
|
remote_dir = "/tmp/cn-undeploy-logs"
|
||||||
with cls_cmd.getConnection(self._host) as c:
|
with cls_cmd.getConnection(self._host) as c:
|
||||||
# create a directory for log collection
|
# create a directory for log collection
|
||||||
@@ -134,18 +134,17 @@ class CoreNetwork:
|
|||||||
logging.error("cannot enumerate log files")
|
logging.error("cannot enumerate log files")
|
||||||
return []
|
return []
|
||||||
log_files = []
|
log_files = []
|
||||||
# copy them to the executor one by one, and store in log_dir
|
# copy them to the executor one by one
|
||||||
for f in ret.stdout.split("\n"):
|
for f in ret.stdout.split("\n"):
|
||||||
l = f.replace(remote_dir, log_dir)
|
name = archiveArtifact(c, ctx, f)
|
||||||
c.copyin(f, l)
|
log_files.append(name)
|
||||||
log_files.append(l)
|
|
||||||
c.run(f'rm -rf {remote_dir}')
|
c.run(f'rm -rf {remote_dir}')
|
||||||
return log_files
|
return log_files
|
||||||
|
|
||||||
def undeploy(self, log_dir=None):
|
def undeploy(self, ctx=None):
|
||||||
log_files = []
|
log_files = []
|
||||||
if log_dir is not None:
|
if ctx is not None:
|
||||||
log_files = self._collect_logs(log_dir)
|
log_files = self._collect_logs(ctx)
|
||||||
else:
|
else:
|
||||||
logging.warning("no directory for log collection specified, cannot retrieve core network logs")
|
logging.warning("no directory for log collection specified, cannot retrieve core network logs")
|
||||||
logging.info(f'undeploy core network {self}')
|
logging.info(f'undeploy core network {self}')
|
||||||
|
|||||||
@@ -844,7 +844,7 @@ class OaiCiTest():
|
|||||||
HTML.CreateHtmlTestRowQueue(f'N/A', 'OK', messages)
|
HTML.CreateHtmlTestRowQueue(f'N/A', 'OK', messages)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def DeployCoreNetwork(cn_id, HTML):
|
def DeployCoreNetwork(cn_id, ctx, HTML):
|
||||||
core_name = cn_id.strip()
|
core_name = cn_id.strip()
|
||||||
cn = cls_corenetwork.CoreNetwork(core_name)
|
cn = cls_corenetwork.CoreNetwork(core_name)
|
||||||
success, output = cn.deploy()
|
success, output = cn.deploy()
|
||||||
@@ -858,18 +858,12 @@ class OaiCiTest():
|
|||||||
HTML.CreateHtmlTestRowQueue(core_name, 'KO', [msg])
|
HTML.CreateHtmlTestRowQueue(core_name, 'KO', [msg])
|
||||||
return success
|
return success
|
||||||
|
|
||||||
def UndeployCoreNetwork(cn_id, HTML):
|
def UndeployCoreNetwork(cn_id, ctx, HTML):
|
||||||
# Ping, Iperf, DeployObject put logs into a path based on YAML. We
|
|
||||||
# can't do this here (because there is no yaml), so hardcode a path for
|
|
||||||
# "cn_logs" for the moment
|
|
||||||
logPath = f'{os.getcwd()}/../cmake_targets/log/cn_logs'
|
|
||||||
with cls_cmd.getConnection('localhost') as local:
|
|
||||||
local.run(f'mkdir -p {logPath}', silent=True)
|
|
||||||
core_name = cn_id.strip()
|
core_name = cn_id.strip()
|
||||||
cn = cls_corenetwork.CoreNetwork(core_name)
|
cn = cls_corenetwork.CoreNetwork(core_name)
|
||||||
logs, output = cn.undeploy(log_dir=logPath)
|
logs, output = cn.undeploy(ctx=ctx)
|
||||||
logging.info(f"undeployed core network {core_name}, logs {logs}, output:\n{output}")
|
logging.info(f"undeployed core network {core_name}, logs {logs}, output:\n{output}")
|
||||||
message = "Log files: " + ", ".join([os.path.basename(l) for l in logs])
|
message = "Log files:\n" + "\n".join([os.path.basename(l) for l in logs])
|
||||||
HTML.CreateHtmlTestRowQueue(core_name, 'OK', [message])
|
HTML.CreateHtmlTestRowQueue(core_name, 'OK', [message])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -302,7 +302,7 @@ def ExecuteActionWithParam(action, ctx):
|
|||||||
elif action == 'DeployCoreNetwork' or action == 'UndeployCoreNetwork':
|
elif action == 'DeployCoreNetwork' or action == 'UndeployCoreNetwork':
|
||||||
cn_id = test.findtext('cn_id')
|
cn_id = test.findtext('cn_id')
|
||||||
core_op = getattr(cls_oaicitest.OaiCiTest, action)
|
core_op = getattr(cls_oaicitest.OaiCiTest, action)
|
||||||
success = core_op(cn_id, HTML)
|
success = core_op(cn_id, ctx, HTML)
|
||||||
|
|
||||||
elif action == 'Deploy_Object' or action == 'Undeploy_Object' or action == "Create_Workspace":
|
elif action == 'Deploy_Object' or action == 'Undeploy_Object' or action == "Create_Workspace":
|
||||||
eNB_instance=test.findtext('eNB_instance')
|
eNB_instance=test.findtext('eNB_instance')
|
||||||
|
|||||||
@@ -6,14 +6,22 @@ logging.basicConfig(
|
|||||||
format="[%(asctime)s] %(levelname)8s: %(message)s"
|
format="[%(asctime)s] %(levelname)8s: %(message)s"
|
||||||
)
|
)
|
||||||
import os
|
import os
|
||||||
|
import tempfile
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
sys.path.append('./') # to find OAI imports below
|
sys.path.append('./') # to find OAI imports below
|
||||||
import cls_corenetwork
|
import cls_corenetwork
|
||||||
|
from cls_ci_helper import TestCaseCtx
|
||||||
import cls_cmd
|
import cls_cmd
|
||||||
|
|
||||||
class TestCoreNetwork(unittest.TestCase):
|
class TestCoreNetwork(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.ctx = TestCaseCtx.Default(tempfile.mkdtemp())
|
||||||
|
def tearDown(self):
|
||||||
|
with cls_cmd.LocalCmd() as c:
|
||||||
|
c.run(f'rm -rf {self.ctx.logPath}')
|
||||||
|
|
||||||
def test_simple_core(self):
|
def test_simple_core(self):
|
||||||
c = cls_corenetwork.CoreNetwork("test", filename="tests/config/test_core_infra.yaml")
|
c = cls_corenetwork.CoreNetwork("test", filename="tests/config/test_core_infra.yaml")
|
||||||
success, output = c.deploy()
|
success, output = c.deploy()
|
||||||
@@ -22,14 +30,14 @@ class TestCoreNetwork(unittest.TestCase):
|
|||||||
# should not have it set in config
|
# should not have it set in config
|
||||||
self.assertTrue(c.runIperf3Server())
|
self.assertTrue(c.runIperf3Server())
|
||||||
self.assertEqual(c.getIP(), "127.0.0.1")
|
self.assertEqual(c.getIP(), "127.0.0.1")
|
||||||
log_files, output = c.undeploy(log_dir="/tmp")
|
log_files, output = c.undeploy(self.ctx)
|
||||||
self.assertEqual(output, "undeploy")
|
self.assertEqual(output, "undeploy")
|
||||||
with cls_cmd.LocalCmd() as cmd:
|
with cls_cmd.LocalCmd() as cmd:
|
||||||
# there must be one log file for this (test) core
|
# there must be one log file for this (test) core
|
||||||
self.assertEqual(len(log_files), 1)
|
self.assertEqual(len(log_files), 1)
|
||||||
# test core writes to %%log_dir%%/logs, which expands to /tmp/logs
|
# undeploy uses archiveArtifact(), which writes to {prefix}-logs
|
||||||
l = log_files[0]
|
l = log_files[0]
|
||||||
self.assertEqual(l, "/tmp/logs")
|
self.assertEqual(l, f"{self.ctx.baseFilename()}-logs")
|
||||||
ret = cmd.run(f"cat {l}")
|
ret = cmd.run(f"cat {l}")
|
||||||
self.assertEqual(ret.returncode, 0) # command must succeed
|
self.assertEqual(ret.returncode, 0) # command must succeed
|
||||||
self.assertEqual(ret.stdout, "logs") # output should be "logs"
|
self.assertEqual(ret.stdout, "logs") # output should be "logs"
|
||||||
@@ -39,14 +47,14 @@ class TestCoreNetwork(unittest.TestCase):
|
|||||||
success, _ = c.deploy()
|
success, _ = c.deploy()
|
||||||
self.assertTrue(success)
|
self.assertTrue(success)
|
||||||
self.assertFalse(c.runIperf3Server())
|
self.assertFalse(c.runIperf3Server())
|
||||||
c.undeploy(log_dir="/tmp")
|
c.undeploy(None)
|
||||||
|
|
||||||
def test_core_fail(self):
|
def test_core_fail(self):
|
||||||
c = cls_corenetwork.CoreNetwork("test_fail", filename="tests/config/test_core_infra.yaml")
|
c = cls_corenetwork.CoreNetwork("test_fail", filename="tests/config/test_core_infra.yaml")
|
||||||
success, _ = c.deploy()
|
success, _ = c.deploy()
|
||||||
self.assertFalse(success)
|
self.assertFalse(success)
|
||||||
# undeployment should still work
|
# undeployment should still work
|
||||||
c.undeploy(log_dir="/tmp")
|
c.undeploy(None)
|
||||||
|
|
||||||
def test_core_script(self):
|
def test_core_script(self):
|
||||||
c = cls_corenetwork.CoreNetwork("test_script", filename="tests/config/test_core_infra.yaml")
|
c = cls_corenetwork.CoreNetwork("test_script", filename="tests/config/test_core_infra.yaml")
|
||||||
|
|||||||
Reference in New Issue
Block a user