Skip to content

Commit 3c1a735

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 a065198 commit 3c1a735

File tree

5 files changed

+58
-53
lines changed

5 files changed

+58
-53
lines changed

docs/sources/staged.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,15 @@ Will yield instances of :class:`~pushsource.AmiPushItem`.
200200
root/destination/CLOUD_IMAGES/\*
201201
................................
202202

203-
The ``CLOUD_IMAGES`` directory should contain the VMI(s) plus a ``resources.yaml``.
203+
Each directory within ``CLOUD_IMAGES`` should contain one or more VMI(s) plus a
204+
``resources.yaml`` .
204205

205206
The ``resources.yaml`` contains all the information needed for the
206207
images in that folder.
207208

208209
:ref:`cloud_schema` provides a complete reference of the fields which can be set by this
209210
file.
210211

211-
A blank ``staged.yaml`` must be included in the root directory.
212-
213212
Will yield instances of either :class:`~pushsource.AmiPushItem` or
214213
:class:`~pushsource.VHDPushItem`.
215214

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ class TypeHandler(object):
1010
# Decorator for handling specific file directories (e.g. "FILES", "ISOS" etc)
1111
HANDLERS = {}
1212

13-
def __init__(self, type_name):
13+
def __init__(self, type_name, accepts = lambda entry: entry.is_file()):
1414
self.type_name = type_name
15+
self.accepts = accepts
1516

1617
def __call__(self, fn):
17-
TypeHandler.HANDLERS[self.type_name] = fn
18+
TypeHandler.HANDLERS[self.type_name] = (fn, self.accepts)
1819
return fn
1920

2021

@@ -29,19 +30,18 @@ def __init__(self, *args, **kwargs):
2930
super(StagedBaseMixin, self).__init__(*args, **kwargs)
3031
self._FILE_TYPES = self._FILE_TYPES.copy()
3132
for typename in TypeHandler.HANDLERS:
32-
fn = TypeHandler.HANDLERS[typename]
33+
fn, accepts = TypeHandler.HANDLERS[typename]
3334
bound_fn = partial(fn, self)
3435
self._FILE_TYPES[typename] = partial(
35-
self.__mixin_push_items, delegate=bound_fn
36-
)
36+
self.__mixin_push_items, delegate=bound_fn, accepts=accepts)
3737

38-
def __mixin_push_items(self, leafdir, metadata, delegate):
38+
def __mixin_push_items(self, leafdir, metadata, delegate, accepts):
3939
out = []
4040

4141
LOG.debug("Looking for files in %s", leafdir)
4242

4343
for entry in scandir(leafdir.path):
44-
if entry.is_file():
44+
if accepts(entry):
4545
item = delegate(leafdir, metadata, entry)
4646
if item:
4747
out.append(item)

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

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99

1010

1111
class StagedCloudMixin(StagedBaseMixin):
12-
def __build_ami_push_item(self, resources, src, origin, name):
12+
def __build_ami_push_item(self, resources, origin, name, dest):
1313
build_resources = resources.get("build")
14-
release_resources = resources.get("release", {})
14+
release_resources = resources.get("release") or {}
15+
src = os.path.join(origin, name)
1516
build_info = KojiBuildInfo(
1617
name=build_resources.get("name"),
1718
version=build_resources.get("version"),
@@ -22,6 +23,7 @@ def __build_ami_push_item(self, resources, src, origin, name):
2223
"src": src,
2324
"build_info": build_info,
2425
"origin": origin,
26+
"dest": [dest],
2527
}
2628

2729
image_kwargs.update(
@@ -54,7 +56,6 @@ def __build_ami_push_item(self, resources, src, origin, name):
5456
image_kwargs["release"] = AmiRelease(**release_kwargs)
5557

5658
image_attrs = [
57-
"dest",
5859
"type",
5960
"region",
6061
"virtualization",
@@ -83,8 +84,9 @@ def __build_ami_push_item(self, resources, src, origin, name):
8384

8485
return AmiPushItem(**image_kwargs)
8586

86-
def __build_azure_push_item(self, resources, src, origin, name):
87+
def __build_azure_push_item(self, resources, origin, name, dest):
8788
build_resources = resources.get("build")
89+
src = os.path.join(origin, name)
8890
build_info = KojiBuildInfo(
8991
name=build_resources.get("name"),
9092
version=build_resources.get("version"),
@@ -96,46 +98,45 @@ def __build_azure_push_item(self, resources, src, origin, name):
9698
"description": resources.get("description"),
9799
"build_info": build_info,
98100
"origin": origin,
101+
"dest": [dest],
99102
}
100103
return VHDPushItem(**image_kwargs)
101-
102-
def __process_builds(self, build_dirs):
103-
out = []
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", [])
116104

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-
)
105+
def __process_builds(self, current_dir, leafdir):
106+
yaml_path = os.path.join(current_dir, "resources.yaml")
107+
try:
108+
with open(yaml_path, "rt") as fh:
109+
raw = yaml.safe_load(fh)
110+
except FileNotFoundError:
111+
LOG.warning("No resources.yaml file found at %s (ignored)", yaml_path)
112+
return
113+
if not raw:
114+
LOG.warning("Resources.yaml file at %s is empty (ignored)", yaml_path)
115+
return
116+
image_type = raw.get("type") or ""
117+
images_info = raw.get("images") or []
118+
out = []
119+
for image in images_info:
120+
if "/" in image.get("path"):
121+
LOG.warning("Unexpected '/' in %s (ignored)", image.get("path"))
122+
return
123+
if image_type == "AMI":
124+
out.append(
125+
self.__build_ami_push_item(
126+
raw, current_dir, image.get("path"), leafdir.dest
127127
)
128-
elif image_type == "VHD":
129-
out.append(
130-
self.__build_azure_push_item(
131-
raw, image_relative_path, bd, image.get("path")
132-
)
128+
)
129+
elif image_type == "VHD":
130+
out.append(
131+
self.__build_azure_push_item(
132+
raw, current_dir, image.get("path"), leafdir.dest
133133
)
134+
)
134135
return out
135136

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)
137+
@handles_type("CLOUD_IMAGES",
138+
accepts=lambda entry: entry.is_dir() and os.path.exists(os.path.join(entry.path, "resources.yaml")))
139+
def __cloud_push_item(self, leafdir, metadata, entry):
140+
out = self.__process_builds(entry.path, leafdir)
140141

141142
return out

tests/baseline/cases/staged-simple-cloud.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ items:
1919
release: '1'
2020
version: '9.4'
2121
description: build2 sample
22-
dest: []
22+
dest:
23+
- starmap
2324
ena_support: null
2425
image_id: null
2526
marketplace_entity_type: null
@@ -59,7 +60,8 @@ items:
5960
release: '1'
6061
version: '9.4'
6162
description: build2 sample
62-
dest: []
63+
dest:
64+
- starmap
6365
ena_support: null
6466
image_id: null
6567
marketplace_entity_type: null
@@ -99,7 +101,8 @@ items:
99101
release: '1'
100102
version: '9.4'
101103
description: build3 sample
102-
dest: []
104+
dest:
105+
- starmap
103106
ena_support: null
104107
image_id: null
105108
marketplace_entity_type: null
@@ -146,7 +149,8 @@ items:
146149
release: '1'
147150
version: '9.4'
148151
description: build1 sample
149-
dest: []
152+
dest:
153+
- starmap
150154
disk_version: null
151155
generation: V2
152156
legacy_sku_id: null
@@ -173,7 +177,8 @@ items:
173177
release: '1'
174178
version: '9.4'
175179
description: build1 sample
176-
dest: []
180+
dest:
181+
- starmap
177182
disk_version: null
178183
generation: V2
179184
legacy_sku_id: null

tests/staged/data/simple_cloud/starmap/CLOUD_IMAGES/staged.yaml

Whitespace-only changes.

0 commit comments

Comments
 (0)