Skip to content

Commit a065198

Browse files
pre-commit-ci[bot]jajreidy
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent bf61854 commit a065198

File tree

18 files changed

+422
-68
lines changed

18 files changed

+422
-68
lines changed

docs/schema/cloud.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.. _cloud_schema:
2+
3+
Schema: cloud
4+
==============
5+
6+
This document shows the schema of cloud build YAML files
7+
supported by this library, in `JSON schema`_ format.
8+
These files may be used within the ``CLOUD_IMAGES`` directory within
9+
a :ref:`staging_structure`.
10+
11+
The latest version of this schema is available in raw form at
12+
https://release-engineering.github.io/pushsource/cloud-schema.yaml.
13+
14+
15+
.. include:: ../../src/pushsource/_impl/schema/cloud-schema.yaml
16+
:code: yaml
17+
18+
19+
.. _JSON schema: https://json-schema.org/

docs/sources/staged.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,17 @@ Files in this directory must have metadata included in ``staged.yaml``.
198198
Will yield instances of :class:`~pushsource.AmiPushItem`.
199199

200200
root/destination/CLOUD_IMAGES/\*
201-
..............................
201+
................................
202202

203-
The ``CLOUD_IMAGES`` should contain the VMI(s) plus a ``resources.yaml``.
203+
The ``CLOUD_IMAGES`` directory should contain the VMI(s) plus a ``resources.yaml``.
204204

205205
The ``resources.yaml`` contains all the information needed for the
206206
images in that folder.
207207

208-
Files in this directory should not include the ``staged.yaml``.
208+
:ref:`cloud_schema` provides a complete reference of the fields which can be set by this
209+
file.
210+
211+
A blank ``staged.yaml`` must be included in the root directory.
209212

210213
Will yield instances of either :class:`~pushsource.AmiPushItem` or
211214
:class:`~pushsource.VHDPushItem`.

src/pushsource/_impl/backend/staged/staged_cloud.py

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
2-
import yaml
32
import os
3+
import yaml
44

55
from .staged_base import StagedBaseMixin, handles_type
66
from ...model import VHDPushItem, AmiPushItem, AmiRelease, BootMode, KojiBuildInfo
@@ -11,10 +11,11 @@
1111
class StagedCloudMixin(StagedBaseMixin):
1212
def __build_ami_push_item(self, resources, src, origin, name):
1313
build_resources = resources.get("build")
14+
release_resources = resources.get("release", {})
1415
build_info = KojiBuildInfo(
1516
name=build_resources.get("name"),
1617
version=build_resources.get("version"),
17-
release=build_resources.get("respin")
18+
release=build_resources.get("respin"),
1819
)
1920
image_kwargs = {
2021
"name": name,
@@ -34,7 +35,7 @@ def __build_ami_push_item(self, resources, src, origin, name):
3435
)
3536

3637
release_required = ["product", "date", "arch", "respin"]
37-
if all(x in build_resources for x in release_required):
38+
if all(x in release_resources.keys() for x in release_required):
3839
release_attrs = [
3940
"product",
4041
"date",
@@ -48,7 +49,7 @@ def __build_ami_push_item(self, resources, src, origin, name):
4849
]
4950
release_kwargs = {}
5051
for key in release_attrs:
51-
release_kwargs[key] = build_resources.get(key)
52+
release_kwargs[key] = release_resources.get(key)
5253

5354
image_kwargs["release"] = AmiRelease(**release_kwargs)
5455

@@ -81,44 +82,60 @@ def __build_ami_push_item(self, resources, src, origin, name):
8182
image_kwargs[key] = resources.get(key)
8283

8384
return AmiPushItem(**image_kwargs)
84-
85+
8586
def __build_azure_push_item(self, resources, src, origin, name):
8687
build_resources = resources.get("build")
8788
build_info = KojiBuildInfo(
8889
name=build_resources.get("name"),
8990
version=build_resources.get("version"),
90-
release=build_resources.get("respin")
91+
release=build_resources.get("respin"),
9192
)
9293
image_kwargs = {
9394
"name": name,
9495
"src": src,
96+
"description": resources.get("description"),
9597
"build_info": build_info,
9698
"origin": origin,
9799
}
98100
return VHDPushItem(**image_kwargs)
99-
100-
@handles_type("CLOUD_IMAGES")
101-
def __cloud_push_item(self, leafdir, metadata, entry):
102-
with open(entry.path, "rt") as fh:
103-
raw = yaml.safe_load(fh)
104-
if not raw:
105-
return
106-
101+
102+
def __process_builds(self, build_dirs):
107103
out = []
108-
image_type = raw.get("type")
109-
images_info = raw.get("images")
104+
for bd in build_dirs:
105+
yaml_path = os.path.join(bd, "resources.yaml")
106+
try:
107+
with open(yaml_path, "rt") as fh:
108+
raw = yaml.safe_load(fh)
109+
except FileNotFoundError as e:
110+
LOG.warning("No resources.yaml file found at %s (ignored)", yaml_path)
111+
continue
112+
if not raw:
113+
continue
114+
image_type = raw.get("type", "")
115+
images_info = raw.get("images", [])
110116

111-
for image in images_info:
112-
image_relative_path = os.path.join(leafdir.path, image.get("path"))
113-
if image_type == "AMI":
114-
out.append(self.__build_ami_push_item(raw,
115-
image_relative_path,
116-
leafdir.topdir,
117-
image.get("path")))
118-
elif image_type == "VHD":
119-
out.append(self.__build_azure_push_item(raw,
120-
image_relative_path,
121-
leafdir.topdir,
122-
image.get("path")))
117+
for image in images_info:
118+
if "/" in image.get("path"):
119+
LOG.warning("Unexpected '/' in %s (ignored)", image_relative_path)
120+
continue
121+
image_relative_path = os.path.join(bd, image.get("path"))
122+
if image_type == "AMI":
123+
out.append(
124+
self.__build_ami_push_item(
125+
raw, image_relative_path, bd, image.get("path")
126+
)
127+
)
128+
elif image_type == "VHD":
129+
out.append(
130+
self.__build_azure_push_item(
131+
raw, image_relative_path, bd, image.get("path")
132+
)
133+
)
134+
return out
135+
136+
@handles_type("CLOUD_IMAGES")
137+
def __cloud_push_item(self, leafdir, _, entry):
138+
builds = [ f.path for f in os.scandir(leafdir.path) if f.is_dir() ]
139+
out = self.__process_builds(builds)
123140

124-
return out
141+
return out

0 commit comments

Comments
 (0)