Commit dee9ce26 authored by Robert Schmidt's avatar Robert Schmidt

CI: Pull_Image_from_Registry(): harmonize code

- pass parameter directly instead of indirectly via class
- call it simply "images", to harmonize with clean-function later
- harmonize to svr_id as in the previous commit
- rewrite function to use with-statement with cls_cmd
- optionally pass a tag to use (which will be used in a test, and can be
  used to pull flexric)
- Introduce Pull_Image() which does the actual pulling, can pull from
  any registry, and will be reused in the case of pulling from cluster.
parent a48728ba
......@@ -335,7 +335,6 @@ class Containerize():
self.imageToCopy = ''
self.testSvrId = ''
self.imageToPull = []
#checkers from xml
self.ran_checkers={}
......@@ -772,45 +771,44 @@ class Containerize():
HTML.CreateHtmlTestRow('N/A', 'OK', CONST.ALL_PROCESSES_OK)
return True
def Pull_Image_from_Local_Registry(self, HTML):
lIpAddr, lSourcePath = self.GetCredentials(self.testSvrId)
logging.debug('\u001B[1m Pulling image(s) on server: ' + lIpAddr + '\u001B[0m')
myCmd = cls_cmd.getConnection(lIpAddr)
imagePrefix = 'porcepix.sboai.cs.eurecom.fr'
response = myCmd.run(f'docker login -u oaicicd -p oaicicd {imagePrefix}')
if response.returncode != 0:
msg = 'Could not log into local registry'
logging.error(msg)
myCmd.close()
HTML.CreateHtmlTestRow(msg, 'KO', CONST.ALL_PROCESSES_OK)
return False
def Pull_Image(cmd, images, tag, registry, username, password):
if username is not None and password is not None:
logging.info(f"logging into registry {username}@{registry}")
response = cmd.run(f'docker login -u {username} -p {password} {registry}', silent=True, reportNonZero=False)
if response.returncode != 0:
msg = f'Could not log into registry {username}@{registry}'
logging.error(msg)
return False, msg
pulled_images = []
for image in self.imageToPull:
tagToUse = CreateTag(self.ranCommitID, self.ranBranch, self.ranAllowMerge)
imageTag = f"{image}:{tagToUse}"
cmd = f'docker pull {imagePrefix}/{imageTag}'
response = myCmd.run(cmd, timeout=120)
for image in images:
imageTag = f"{image}:{tag}"
response = cmd.run(f'docker pull {registry}/{imageTag}')
if response.returncode != 0:
logging.debug(response)
msg = f'Could not pull {image} from local registry : {imageTag}'
msg = f'Could not pull {image} from local registry: {imageTag}'
logging.error(msg)
myCmd.close()
HTML.CreateHtmlTestRow('msg', 'KO', CONST.ALL_PROCESSES_OK)
return False
myCmd.run(f'docker tag {imagePrefix}/{imageTag} oai-ci/{imageTag}')
myCmd.run(f'docker rmi {imagePrefix}/{imageTag}')
return False, msg
cmd.run(f'docker tag {registry}/{imageTag} oai-ci/{imageTag}')
cmd.run(f'docker rmi {registry}/{imageTag}')
pulled_images += [f"oai-ci/{imageTag}"]
response = myCmd.run(f'docker logout {imagePrefix}')
if response.returncode != 0:
msg = 'Could not log off from local registry'
logging.error(msg)
myCmd.close()
HTML.CreateHtmlTestRow(msg, 'KO', CONST.ALL_PROCESSES_OK)
return False
myCmd.close()
if username is not None and password is not None:
response = cmd.run(f'docker logout {registry}')
# we have the images, if logout fails it's no problem
msg = "Pulled Images:\n" + '\n'.join(pulled_images)
HTML.CreateHtmlTestRowQueue('N/A', 'OK', [msg])
return True
return True, msg
def Pull_Image_from_Registry(self, HTML, svr_id, images, tag=None, registry="porcepix.sboai.cs.eurecom.fr", username="oaicicd", password="oaicicd"):
lIpAddr, lSourcePath = self.GetCredentials(svr_id)
logging.debug('\u001B[1m Pulling image(s) on server: ' + lIpAddr + '\u001B[0m')
if not tag:
tag = CreateTag(self.ranCommitID, self.ranBranch, self.ranAllowMerge)
with cls_cmd.getConnection(lIpAddr) as cmd:
success, msg = Containerize.Pull_Image(cmd, images, tag, registry, username, password)
param = f"on node {lIpAddr}"
if success:
HTML.CreateHtmlTestRowQueue(param, 'OK', [msg])
else:
HTML.CreateHtmlTestRowQueue(param, 'KO', [msg])
return success
def Clean_Test_Server_Images(self, HTML):
lIpAddr, lSourcePath = self.GetCredentials(self.testSvrId)
......
......@@ -374,14 +374,9 @@ def ExecuteActionWithParam(action):
success = CONTAINERS.Push_Image_to_Local_Registry(HTML, svr_id)
elif action == 'Pull_Local_Registry':
string_field = test.findtext('test_svr_id')
if (string_field is not None):
CONTAINERS.testSvrId = string_field
CONTAINERS.imageToPull.clear()
string_field = test.findtext('images_to_pull')
if (string_field is not None):
CONTAINERS.imageToPull = string_field.split()
success = CONTAINERS.Pull_Image_from_Local_Registry(HTML)
svr_id = test.findtext('svr_id')
images = test.findtext('images').split()
success = CONTAINERS.Pull_Image_from_Registry(HTML, svr_id, images)
elif action == 'Clean_Test_Server_Images':
string_field = test.findtext('test_svr_id')
......
......@@ -44,8 +44,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb oai-lte-ue</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb oai-lte-ue</images>
</testCase>
<testCase id="800813">
<class>Create_Workspace</class>
......
......@@ -52,8 +52,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb-asan oai-lte-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb-asan oai-lte-ue-asan</images>
</testCase>
<testCase id="000011">
......
......@@ -43,8 +43,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb-asan oai-lte-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb-asan oai-lte-ue-asan</images>
</testCase>
<testCase id="800813">
<class>Create_Workspace</class>
......
......@@ -47,8 +47,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb-asan oai-lte-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb-asan oai-lte-ue-asan</images>
</testCase>
<testCase id="800813">
<class>Create_Workspace</class>
......
......@@ -47,8 +47,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb-asan oai-lte-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb-asan oai-lte-ue-asan</images>
</testCase>
<testCase id="800813">
<class>Create_Workspace</class>
......
......@@ -40,8 +40,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb-asan oai-lte-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb-asan oai-lte-ue-asan</images>
</testCase>
<testCase id="800813">
<class>Create_Workspace</class>
......
......@@ -40,8 +40,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb-asan oai-lte-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb-asan oai-lte-ue-asan</images>
</testCase>
<testCase id="800813">
<class>Create_Workspace</class>
......
......@@ -47,8 +47,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb oai-lte-ue</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb oai-lte-ue</images>
</testCase>
<testCase id="800813">
<class>Create_Workspace</class>
......
......@@ -40,8 +40,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb oai-nr-cuup oai-nr-ue</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb oai-nr-cuup oai-nr-ue</images>
</testCase>
<testCase id="800813">
<class>Create_Workspace</class>
......
......@@ -47,8 +47,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb-asan oai-nr-cuup-asan oai-nr-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb-asan oai-nr-cuup-asan oai-nr-ue-asan</images>
</testCase>
<testCase id="800813">
<class>Create_Workspace</class>
......
......@@ -42,8 +42,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb-asan oai-nr-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb-asan oai-nr-ue-asan</images>
</testCase>
<testCase id="800813">
<class>Create_Workspace</class>
......
......@@ -57,8 +57,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb-asan oai-nr-ue</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb-asan oai-nr-ue</images>
</testCase>
<testCase id="800813">
<class>Create_Workspace</class>
......
......@@ -42,8 +42,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb-asan oai-nr-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb-asan oai-nr-ue-asan</images>
</testCase>
<testCase id="800813">
<class>Create_Workspace</class>
......
......@@ -42,8 +42,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb-asan oai-nr-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb-asan oai-nr-ue-asan</images>
</testCase>
<testCase id="800813">
<class>Create_Workspace</class>
......
......@@ -42,8 +42,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb-asan oai-nr-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb-asan oai-nr-ue-asan</images>
</testCase>
<testCase id="004000">
......
......@@ -39,8 +39,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb-asan oai-nr-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb-asan oai-nr-ue-asan</images>
</testCase>
<testCase id="800813">
......
......@@ -41,8 +41,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb-asan oai-nr-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb-asan oai-nr-ue-asan</images>
</testCase>
<testCase id="800813">
......
......@@ -39,8 +39,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-nr-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-nr-ue-asan</images>
</testCase>
<testCase id="800813">
......
......@@ -41,8 +41,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb-asan oai-nr-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb-asan oai-nr-ue-asan</images>
</testCase>
<testCase id="004000">
......
......@@ -42,8 +42,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb-asan oai-nr-ue-asan</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb-asan oai-nr-ue-asan</images>
</testCase>
<testCase id="800813">
<class>Create_Workspace</class>
......
......@@ -43,8 +43,8 @@ Replaces xml_files/enb_usrp210_band7_test_05mhz_tm1.xml
<testCase id="111110">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="100000">
......
......@@ -42,8 +42,8 @@
<testCase id="111110">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="100000">
......
......@@ -42,8 +42,8 @@ Replaces xml_files/enb_usrp210_band7_test_05mhz_tm1_rrc_inactivity_no_flexran.xm
<testCase id="111110">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="100000">
<class>Custom_Command</class>
......
......@@ -44,8 +44,8 @@ Replaces xml_files/enb_usrp210_band7_test_10mhz_tm1.xml
<testCase id="111110">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="100000">
<class>Custom_Command</class>
......
......@@ -43,8 +43,8 @@ Replaces xml_files/enb_usrp210_band7_test_10mhz_tm1.xml
<testCase id="111110">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="100000">
<class>Custom_Command</class>
......
......@@ -49,14 +49,14 @@
<testCase id="111110">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>1</test_svr_id>
<images_to_pull>oai-lte-ue</images_to_pull>
<svr_id>1</svr_id>
<images>oai-lte-ue</images>
</testCase>
<testCase id="100000">
<class>Custom_Command</class>
......
......@@ -43,8 +43,8 @@ Replaces xml_files/enb_usrp210_band7_test_10mhz_tm1.xml
<testCase id="111110">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="100000">
<class>Custom_Command</class>
......
......@@ -43,8 +43,8 @@ Replaces xml_files/enb_usrp210_band40_test_05mhz_tm1.xml
<testCase id="111110">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="100000">
......
......@@ -41,8 +41,8 @@
<testCase id="111110">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="100000">
......
......@@ -41,8 +41,8 @@ Replaces xml_files/enb_usrp210_band40_test_05mhz_tm2.xml
<testCase id="111110">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="100000">
<class>Custom_Command</class>
......
......@@ -42,8 +42,8 @@ Replaces xml_files/enb_usrp210_band40_test_10mhz_tm1.xml
<testCase id="111110">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="100000">
<class>Custom_Command</class>
......
......@@ -42,8 +42,8 @@ Replaces xml_files/enb_usrp210_band40_test_20mhz_tm1.xml
<testCase id="111110">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="100000">
<class>Custom_Command</class>
......
......@@ -42,8 +42,8 @@ Replaces xml_files/enb_usrp210_band40_test_20mhz_tm1_default_scheduler.xml
<testCase id="111110">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="100000">
......
......@@ -48,8 +48,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="100000">
......
......@@ -48,8 +48,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="100000">
......
......@@ -57,15 +57,15 @@
<testCase id="111110">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-enb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-enb</images>
</testCase>
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>1</test_svr_id>
<images_to_pull>oai-gnb</images_to_pull>
<svr_id>1</svr_id>
<images>oai-gnb</images>
</testCase>
<testCase id = "100000">
......
......@@ -43,8 +43,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb-aerial</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb-aerial</images>
</testCase>
<testCase id="800813">
......
......@@ -59,8 +59,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb</images>
</testCase>
<testCase id="100000">
......
......@@ -56,8 +56,8 @@
<testCase id="333333">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb oai-nr-cuup</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb oai-nr-cuup</images>
</testCase>
<testCase id="310000">
......
......@@ -64,8 +64,8 @@
<testCase id="111111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb</images>
</testCase>
<testCase id="110000">
......
......@@ -53,8 +53,8 @@
<testCase id="311111">
<class>Pull_Local_Registry</class>
<desc>Pull Images from Local Registry</desc>
<test_svr_id>0</test_svr_id>
<images_to_pull>oai-gnb</images_to_pull>
<svr_id>0</svr_id>
<images>oai-gnb</images>
</testCase>
<testCase id="300000">
......
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