Skip to content

Commit

Permalink
Add image_stream_template (#67)
Browse files Browse the repository at this point in the history
Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
  • Loading branch information
phracek authored Jun 17, 2024
1 parent 31f8a85 commit 24a3f5a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
55 changes: 52 additions & 3 deletions container_ci_suite/openshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,10 @@ def is_pod_finished(self, pod_suffix_name: str = "deploy") -> bool:
return True
return False

def run_command_in_pod(self, pod_name, command: str = ""):
def run_command_in_pod(self, pod_name, command: str = "") -> str:
output = OpenShiftAPI.run_oc_command(f"exec {pod_name} -- \"{command}\"")
print(output)
return output

def oc_get_services(self, service_name):
output = OpenShiftAPI.run_oc_command(f"get svc/{service_name}", json_output=True, namespace=self.namespace)
Expand Down Expand Up @@ -458,8 +459,8 @@ def command_app_run(self, cmd: str, return_output: bool = True) -> str:
print(f"cmd_image_run output: {cmd_out}")
return cmd_out

def create_deploy_command_app(self) -> bool:
cmd_file = utils.save_command_yaml(image_name="registry.access.redhat.com/ubi8/ubi")
def create_deploy_command_app(self, image_name: str = "registry.access.redhat.com/ubi8/ubi") -> bool:
cmd_file = utils.save_command_yaml(image_name=image_name)
self.run_oc_command(f"create -f {cmd_file}")
if not self.is_pod_running(pod_name_prefix="command-app"):
print("create_deploy_command_app: command-app pod is not running after time.")
Expand Down Expand Up @@ -504,9 +505,38 @@ def deploy_s2i_app(self, image_name: str, app: str, context: str, service_name:
time.sleep(5)
if Path(app).is_dir():
output = self.start_build(service_name=service_name, app_name=app)
print(f"Output from start build: {output}")

return True

def deploy_image_stream_template(
self, imagestream_file: str, template_file: str, app_name: str, openshift_args=None
) -> bool:
local_is_file = utils.download_template(template_name=imagestream_file)
local_template = utils.download_template(template_name=template_file)
json_output = self.import_is(local_is_file, name="", skip_check=True)
if not json_output:
print("deploy_image_stream_template: import_is failed")
return False
if openshift_args is None:
openshift_args = ""
else:
openshift_args = self.get_openshift_args(oc_args=openshift_args)
print(f"========\n"
f"Creating a new-app with name {app_name} in "
f"namespace {self.namespace} with args {openshift_args}\n"
f"========")
oc_cmd = f"new-app -f {local_template} --name={app_name} -p NAMESPACE={self.namespace} {openshift_args}"
print(f"Deploy template by command: oc {oc_cmd}")
try:
output = self.run_oc_command(f"{oc_cmd}", json_output=False)
print(output)
except subprocess.CalledProcessError:
return False
# Let's wait couple seconds to deployment can start
time.sleep(3)
return True

def deploy_imagestream_s2i(
self, imagestream_file: str, image_name: str, app: str, context: str
) -> bool:
Expand Down Expand Up @@ -572,6 +602,25 @@ def deploy_template(
time.sleep(3)
return True

def check_command_internal(
self,
image_name: str,
service_name: str,
cmd: str,
expected_output: str,
timeout: int = 120
) -> bool:
if not self.create_deploy_command_app(image_name=image_name):
return False
ip_address = self.get_service_ip(service_name=service_name)
cmd = cmd.replace("<IP>", ip_address)
for count in range(timeout):
output = self.command_app_run(cmd=cmd, return_output=True)
if expected_output in output:
return True
time.sleep(3)
return False

def check_response_inside_cluster(
self, cmd_to_run: str = None, name_in_template: str = "",
expected_output: str = "",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_requirements():
description='A python3 container CI tool for testing images.',
long_description=long_description,
long_description_content_type='text/markdown',
version="0.1.2",
version="0.2.0",
keywords='tool,containers,images,tests',
packages=find_packages(exclude=["tests"]),
url="https://github.com/sclorg/container-ci-suite",
Expand Down

0 comments on commit 24a3f5a

Please sign in to comment.