deployment.py 3.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
import sys
import logging
logging.basicConfig(
	level=logging.DEBUG,
	stream=sys.stdout,
	format="[%(asctime)s] %(levelname)8s: %(message)s"
)
import os
os.system(f'rm -rf cmake_targets')
os.system(f'mkdir -p cmake_targets/log')
import unittest

sys.path.append('./') # to find OAI imports below
import cls_oai_html
import cls_oaicitest
import cls_containerize
import ran
18
import cls_cmd
19 20

class TestDeploymentMethods(unittest.TestCase):
21 22 23 24 25 26 27 28 29 30 31
	def _pull_image(self, cmd, image):
		ret = cmd.run(f"docker inspect oai-ci/{image}:develop-12345678")
		if ret.returncode == 0: # exists
			return
		ret = cmd.run(f"docker pull oaisoftwarealliance/{image}:develop")
		self.assertEqual(ret.returncode, 0)
		ret = cmd.run(f"docker tag oaisoftwarealliance/{image}:develop oai-ci/{image}:develop-12345678")
		self.assertEqual(ret.returncode, 0)
		ret = cmd.run(f"docker rmi oaisoftwarealliance/{image}:develop")
		self.assertEqual(ret.returncode, 0)

32
	def setUp(self):
33 34 35
		with cls_cmd.getConnection("localhost") as cmd:
			self._pull_image(cmd, "oai-gnb")
			self._pull_image(cmd, "oai-nr-ue")
36 37 38 39 40
		self.html = cls_oai_html.HTMLManagement()
		self.html.testCaseId = "000000"
		self.ci = cls_oaicitest.OaiCiTest()
		self.cont = cls_containerize.Containerize()
		self.ran = ran.RANManagement()
41
		self.cont.yamlPath[0] = ''
42
		self.cont.ranAllowMerge = True
43 44
		self.cont.ranBranch = ''
		self.cont.ranCommitID = ''
45 46 47 48 49 50 51
		self.cont.eNB_serverId[0] = '0'
		self.cont.eNBIPAddress = 'localhost'
		self.cont.eNBUserName = None
		self.cont.eNBPassword = None
		self.cont.eNBSourceCodePath = os.getcwd()

	def test_deploy(self):
52 53 54 55 56 57
		self.cont.yamlPath[0] = 'tests/simple-dep/'
		self.cont.deploymentTag = "noble"
		deploy = self.cont.DeployObject(self.html)
		undeploy = self.cont.UndeployObject(self.html, self.ran)
		self.assertTrue(deploy)
		self.assertTrue(undeploy)
58 59

	def test_deployfails(self):
60
		# fails reliably
61 62
		old = self.cont.yamlPath
		self.cont.yamlPath[0] = 'tests/simple-fail/'
63
		deploy = self.cont.DeployObject(self.html)
64
		self.cont.UndeployObject(self.html, self.ran)
65
		self.assertFalse(deploy)
66 67
		self.cont.yamlPath = old

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
	def test_deploy_ran(self):
		self.cont.yamlPath[0] = 'yaml_files/5g_rfsimulator_tdd_dora'
		self.cont.services[0] = "oai-gnb"
		self.cont.deploymentTag = 'develop-12345678'
		deploy = self.cont.DeployObject(self.html)
		undeploy = self.cont.UndeployObject(self.html, self.ran)
		self.assertTrue(deploy)
		self.assertTrue(undeploy)

	def test_deploy_multiran(self):
		self.cont.yamlPath[0] = 'yaml_files/5g_rfsimulator_tdd_dora'
		self.cont.services[0] = "oai-gnb oai-nr-ue"
		self.cont.deploymentTag = 'develop-12345678'
		deploy = self.cont.DeployObject(self.html)
		undeploy = self.cont.UndeployObject(self.html, self.ran)
		self.assertTrue(deploy)
		self.assertTrue(undeploy)

	def test_deploy_staged(self):
		self.cont.yamlPath[0] = 'yaml_files/5g_rfsimulator_tdd_dora'
		self.cont.services[0] = "oai-gnb"
		self.cont.deploymentTag = 'develop-12345678'
		deploy1 = self.cont.DeployObject(self.html)
		self.cont.services[0] = "oai-nr-ue"
		deploy2 = self.cont.DeployObject(self.html)
		undeploy = self.cont.UndeployObject(self.html, self.ran)
		self.assertTrue(deploy1)
		self.assertTrue(deploy2)
		self.assertTrue(undeploy)

98 99
if __name__ == '__main__':
	unittest.main()