forked from sig_core/toolkit
remove final dependencies on results variable
* put logging code into runCmd method to reduce repeated code
This commit is contained in:
parent
361c155481
commit
3cf47dd85c
@ -79,6 +79,7 @@ class ImageBuild:
|
|||||||
revision: Optional[int] = field()
|
revision: Optional[int] = field()
|
||||||
metadata: pathlib.Path = field(init=False)
|
metadata: pathlib.Path = field(init=False)
|
||||||
fedora_release: int = field()
|
fedora_release: int = field()
|
||||||
|
release: int = field(default=0)
|
||||||
|
|
||||||
def __attrs_post_init__(self):
|
def __attrs_post_init__(self):
|
||||||
self.tdl_path = self.render_icicle_template()
|
self.tdl_path = self.render_icicle_template()
|
||||||
@ -122,7 +123,7 @@ class ImageBuild:
|
|||||||
log.exception("Couldn't decode metadata file", e)
|
log.exception("Couldn't decode metadata file", e)
|
||||||
|
|
||||||
def output_name(self):
|
def output_name(self):
|
||||||
return f"Rocky-{self.architecture.version}-{self.type_variant}.{BUILDTIME.strftime('%Y%m%d')}.{results.release if results.release else 0}.{self.architecture.name}"
|
return f"Rocky-{self.architecture.version}-{self.type_variant}.{BUILDTIME.strftime('%Y%m%d')}.{self.release}.{self.architecture.name}"
|
||||||
|
|
||||||
def type_variant_name(self):
|
def type_variant_name(self):
|
||||||
return self.image_type if not self.variant else f"{self.image_type}-{self.variant.capitalize()}"
|
return self.image_type if not self.variant else f"{self.image_type}-{self.variant.capitalize()}"
|
||||||
@ -174,7 +175,7 @@ class ImageBuild:
|
|||||||
iso8601date=BUILDTIME.strftime("%Y%m%d"),
|
iso8601date=BUILDTIME.strftime("%Y%m%d"),
|
||||||
installdir="kickstart" if results.kickstartdir else "os",
|
installdir="kickstart" if results.kickstartdir else "os",
|
||||||
major=self.architecture.version,
|
major=self.architecture.version,
|
||||||
release=results.release if results.release else 0,
|
release=self.release,
|
||||||
size="10G",
|
size="10G",
|
||||||
type=self.image_type,
|
type=self.image_type,
|
||||||
utcnow=BUILDTIME,
|
utcnow=BUILDTIME,
|
||||||
@ -211,15 +212,9 @@ class ImageBuild:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
ret, out, err, uuid = self.runCmd(self.build_command())
|
ret, out, err, uuid = self.runCmd(self.build_command())
|
||||||
if ret > 0:
|
if uuid:
|
||||||
#error in build command
|
self.base_uuid = uuid.rstrip()
|
||||||
log.error("Problem during build.")
|
self.save()
|
||||||
if not uuid:
|
|
||||||
log.error("Build UUID not found in stdout. Dumping stdout and stderr")
|
|
||||||
self.log_subprocess(ret, out, err)
|
|
||||||
return ret
|
|
||||||
self.base_uuid = uuid.rstrip()
|
|
||||||
self.save()
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def package(self) -> int:
|
def package(self) -> int:
|
||||||
@ -231,14 +226,9 @@ class ImageBuild:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
ret, out, err, uuid = self.runCmd(self.package_command())
|
ret, out, err, uuid = self.runCmd(self.package_command())
|
||||||
if ret > 0:
|
if uuid:
|
||||||
log.error("Problem during packaging")
|
self.target_uuid = uuid.rstrip()
|
||||||
if not uuid:
|
self.save()
|
||||||
log.error("Target Image UUID not found in stdout. Dumping stdout and stderr")
|
|
||||||
self.log_subprocess(ret, out, err)
|
|
||||||
return ret
|
|
||||||
self.target_uuid = uuid.rstrip()
|
|
||||||
self.save()
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def stage(self) -> int:
|
def stage(self) -> int:
|
||||||
@ -249,9 +239,6 @@ class ImageBuild:
|
|||||||
returns = []
|
returns = []
|
||||||
for command in self.stage_commands:
|
for command in self.stage_commands:
|
||||||
ret, out, err, _ = self.runCmd(command, search=False)
|
ret, out, err, _ = self.runCmd(command, search=False)
|
||||||
if ret > 0:
|
|
||||||
log.error("Problem during unpack.")
|
|
||||||
self.log_subprocess(ret, out, err)
|
|
||||||
returns.append(ret)
|
returns.append(ret)
|
||||||
|
|
||||||
return all(ret > 0 for ret in returns)
|
return all(ret > 0 for ret in returns)
|
||||||
@ -262,9 +249,6 @@ class ImageBuild:
|
|||||||
raise Exception(stage)
|
raise Exception(stage)
|
||||||
|
|
||||||
ret, out, err, _ = self.runCmd(self.copy_command(), search=False)
|
ret, out, err, _ = self.runCmd(self.copy_command(), search=False)
|
||||||
if ret > 0:
|
|
||||||
#error in build command
|
|
||||||
log.error("Problem during build.")
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def runCmd(self, command: List[Union[str, Callable]], search: bool = True) -> Tuple[int, Union[IO[bytes],None], Union[IO[bytes],None], Union[str,None]]:
|
def runCmd(self, command: List[Union[str, Callable]], search: bool = True) -> Tuple[int, Union[IO[bytes],None], Union[IO[bytes],None], Union[str,None]]:
|
||||||
@ -285,7 +269,15 @@ class ImageBuild:
|
|||||||
if ln.startswith("UUID: "):
|
if ln.startswith("UUID: "):
|
||||||
uuid = ln.split(" ")[-1]
|
uuid = ln.split(" ")[-1]
|
||||||
log.debug(f"found uuid: {uuid}")
|
log.debug(f"found uuid: {uuid}")
|
||||||
return p.wait(), p.stdout, p.stdin, uuid
|
|
||||||
|
res = p.wait(), p.stdout, p.stdin, uuid
|
||||||
|
if res[0] > 0:
|
||||||
|
log.error(f"Problem while executing command: '{prepared}'")
|
||||||
|
if search and not res[3]:
|
||||||
|
log.error("UUID not found in stdout. Dumping stdout and stderr")
|
||||||
|
self.log_subprocess(res)
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
def prepare_command(self, command_list: List[Union[str, Callable]]) -> Tuple[List[str],List[None]]:
|
def prepare_command(self, command_list: List[Union[str, Callable]]) -> Tuple[List[str],List[None]]:
|
||||||
"""
|
"""
|
||||||
@ -300,14 +292,14 @@ class ImageBuild:
|
|||||||
r = []
|
r = []
|
||||||
return r, [r.append(c()) if (callable(c) and c.__name__ == '<lambda>') else r.append(str(c)) for c in command_list]
|
return r, [r.append(c()) if (callable(c) and c.__name__ == '<lambda>') else r.append(str(c)) for c in command_list]
|
||||||
|
|
||||||
def log_subprocess(self, return_code: int, stdout: Union[IO[bytes], None], stderr: Union[IO[bytes], None]):
|
def log_subprocess(self, result: Tuple[int, Union[IO[bytes], None], Union[IO[bytes], None], Union[str, None]]):
|
||||||
def log_lines(title, lines):
|
def log_lines(title, lines):
|
||||||
log.info(f"====={title}=====")
|
log.info(f"====={title}=====")
|
||||||
for _, line in lines:
|
for _, line in lines:
|
||||||
log.info(line.decode())
|
log.info(line.decode())
|
||||||
log.info(f"Command return code: {return_code}")
|
log.info(f"Command return code: {result[0]}")
|
||||||
log_lines("Command STDOUT", enumerate(stdout)) # type: ignore
|
log_lines("Command STDOUT", enumerate(result[1])) # type: ignore
|
||||||
log_lines("Command STDERR", enumerate(stderr)) # type: ignore
|
log_lines("Command STDERR", enumerate(result[2])) # type: ignore
|
||||||
|
|
||||||
def render_kubernetes_job(self):
|
def render_kubernetes_job(self):
|
||||||
commands = [self.build_command(), self.package_command(), self.copy_command()]
|
commands = [self.build_command(), self.package_command(), self.copy_command()]
|
||||||
@ -347,13 +339,14 @@ def run():
|
|||||||
|
|
||||||
for architecture in arches:
|
for architecture in arches:
|
||||||
IB = ImageBuild(
|
IB = ImageBuild(
|
||||||
image_type=results.type,
|
|
||||||
variant=results.variant,
|
|
||||||
architecture=Architecture.New(architecture, major),
|
architecture=Architecture.New(architecture, major),
|
||||||
template=tdl_template,
|
debug=results.debug,
|
||||||
revision=rlvars['revision'],
|
|
||||||
fedora_release=rlvars['fedora_release'],
|
fedora_release=rlvars['fedora_release'],
|
||||||
debug=True
|
image_type=results.type,
|
||||||
|
release=results.release if results.release else 0,
|
||||||
|
revision=rlvars['revision'],
|
||||||
|
template=tdl_template,
|
||||||
|
variant=results.variant,
|
||||||
)
|
)
|
||||||
if results.kube:
|
if results.kube:
|
||||||
IB.job_template = tmplenv.get_template('kube/Job.tmpl')
|
IB.job_template = tmplenv.get_template('kube/Job.tmpl')
|
||||||
@ -364,4 +357,3 @@ def run():
|
|||||||
ret = IB.package()
|
ret = IB.package()
|
||||||
ret = IB.copy()
|
ret = IB.copy()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user