Skip to content

Commit bf61854

Browse files
committed
Adds staged file structure for cloud images.
1 parent 2f9a778 commit bf61854

File tree

10 files changed

+343
-1
lines changed

10 files changed

+343
-1
lines changed

docs/sources/staged.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Here is a brief overview of the structure of a staging directory:
5555
root/destination/MODULEMD/*
5656
root/destination/RPMS/*.rpm
5757
root/destination/AWS_IMAGES/*
58+
root/destination/CLOUD_IMAGES/*
5859
root/destination/RAW/*
5960

6061
The staging directory consists of:
@@ -196,6 +197,19 @@ Files in this directory must have metadata included in ``staged.yaml``.
196197

197198
Will yield instances of :class:`~pushsource.AmiPushItem`.
198199

200+
root/destination/CLOUD_IMAGES/\*
201+
..............................
202+
203+
The ``CLOUD_IMAGES`` should contain the VMI(s) plus a ``resources.yaml``.
204+
205+
The ``resources.yaml`` contains all the information needed for the
206+
images in that folder.
207+
208+
Files in this directory should not include the ``staged.yaml``.
209+
210+
Will yield instances of either :class:`~pushsource.AmiPushItem` or
211+
:class:`~pushsource.VHDPushItem`.
212+
199213
root/destination/RAW/\*
200214
.......................
201215

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import logging
2+
import yaml
3+
import os
4+
5+
from .staged_base import StagedBaseMixin, handles_type
6+
from ...model import VHDPushItem, AmiPushItem, AmiRelease, BootMode, KojiBuildInfo
7+
8+
LOG = logging.getLogger("pushsource")
9+
10+
11+
class StagedCloudMixin(StagedBaseMixin):
12+
def __build_ami_push_item(self, resources, src, origin, name):
13+
build_resources = resources.get("build")
14+
build_info = KojiBuildInfo(
15+
name=build_resources.get("name"),
16+
version=build_resources.get("version"),
17+
release=build_resources.get("respin")
18+
)
19+
image_kwargs = {
20+
"name": name,
21+
"src": src,
22+
"build_info": build_info,
23+
"origin": origin,
24+
}
25+
26+
image_kwargs.update(
27+
{
28+
"boot_mode": (
29+
BootMode(resources.get("boot_mode"))
30+
if resources.get("boot_mode")
31+
else None
32+
)
33+
}
34+
)
35+
36+
release_required = ["product", "date", "arch", "respin"]
37+
if all(x in build_resources for x in release_required):
38+
release_attrs = [
39+
"product",
40+
"date",
41+
"arch",
42+
"respin",
43+
"version",
44+
"base_product",
45+
"base_version",
46+
"variant",
47+
"type",
48+
]
49+
release_kwargs = {}
50+
for key in release_attrs:
51+
release_kwargs[key] = build_resources.get(key)
52+
53+
image_kwargs["release"] = AmiRelease(**release_kwargs)
54+
55+
image_attrs = [
56+
"dest",
57+
"type",
58+
"region",
59+
"virtualization",
60+
"volume",
61+
"root_device",
62+
"description",
63+
"sriov_net_support",
64+
"ena_support",
65+
"uefi_support",
66+
"public_image",
67+
"release_notes",
68+
"usage_instructions",
69+
"recommended_instance_type",
70+
"marketplace_entity_type",
71+
"image_id",
72+
"scanning_port",
73+
"user_name",
74+
"version_title",
75+
"security_groups",
76+
"access_endpoint_url",
77+
]
78+
79+
for key in image_attrs:
80+
if key in resources:
81+
image_kwargs[key] = resources.get(key)
82+
83+
return AmiPushItem(**image_kwargs)
84+
85+
def __build_azure_push_item(self, resources, src, origin, name):
86+
build_resources = resources.get("build")
87+
build_info = KojiBuildInfo(
88+
name=build_resources.get("name"),
89+
version=build_resources.get("version"),
90+
release=build_resources.get("respin")
91+
)
92+
image_kwargs = {
93+
"name": name,
94+
"src": src,
95+
"build_info": build_info,
96+
"origin": origin,
97+
}
98+
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+
107+
out = []
108+
image_type = raw.get("type")
109+
images_info = raw.get("images")
110+
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")))
123+
124+
return out

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from .staged_utils import StagingMetadata, StagingLeafDir
1818
from .staged_ami import StagedAmiMixin
19+
from .staged_cloud import StagedCloudMixin
1920
from .staged_files import StagedFilesMixin
2021
from .staged_errata import StagedErrataMixin
2122
from .staged_compsxml import StagedCompsXmlMixin
@@ -33,6 +34,7 @@
3334
class StagedSource(
3435
Source,
3536
StagedAmiMixin,
37+
StagedCloudMixin,
3638
StagedFilesMixin,
3739
StagedErrataMixin,
3840
StagedCompsXmlMixin,
@@ -179,7 +181,11 @@ def _push_items_for_topdir(self, topdir):
179181
)
180182
for f in completed_fs:
181183
for pushitem in f.result():
182-
yield pushitem
184+
if isinstance(pushitem, list):
185+
for p in pushitem:
186+
yield p
187+
else:
188+
yield pushitem
183189

184190

185191
Source.register_backend("staged", StagedSource)
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# A pushsource library testcase.
2+
#
3+
# This file was generated from a template.
4+
# To regenerate, run test_baseline.py with PUSHSOURCE_UPDATE_BASELINE=1.
5+
6+
# URL of Source to test.
7+
url: "staged:{{ src_dir }}/tests/staged/data/simple_cloud"
8+
9+
# Push items generated from above.
10+
items:
11+
- AmiPushItem:
12+
access_endpoint_url: null
13+
billing_codes: null
14+
boot_mode: hybrid
15+
build: null
16+
build_info:
17+
id: null
18+
name: rhel-ec2
19+
release: '1'
20+
version: '9.4'
21+
description: build1 sample
22+
dest: []
23+
ena_support: null
24+
image_id: null
25+
marketplace_entity_type: null
26+
marketplace_name: null
27+
marketplace_title_template: null
28+
md5sum: null
29+
name: something1.raw.xz
30+
origin: {{ src_dir }}/tests/staged/data/simple_cloud
31+
public_image: null
32+
recommended_instance_type: null
33+
region: null
34+
release: null
35+
release_notes: null
36+
root_device: null
37+
scanning_port: null
38+
security_groups: []
39+
sha256sum: null
40+
signing_key: null
41+
src: {{ src_dir }}/tests/staged/data/simple_cloud/build1/CLOUD_IMAGES/something1.raw.xz
42+
sriov_net_support: null
43+
state: PENDING
44+
type: AMI
45+
uefi_support: null
46+
usage_instructions: null
47+
user_name: null
48+
version_title: null
49+
virtualization: null
50+
volume: null
51+
- AmiPushItem:
52+
access_endpoint_url: null
53+
billing_codes: null
54+
boot_mode: hybrid
55+
build: null
56+
build_info:
57+
id: null
58+
name: rhel-ec2
59+
release: '1'
60+
version: '9.4'
61+
description: build1 sample
62+
dest: []
63+
ena_support: null
64+
image_id: null
65+
marketplace_entity_type: null
66+
marketplace_name: null
67+
marketplace_title_template: null
68+
md5sum: null
69+
name: something2.raw.xz
70+
origin: {{ src_dir }}/tests/staged/data/simple_cloud
71+
public_image: null
72+
recommended_instance_type: null
73+
region: null
74+
release: null
75+
release_notes: null
76+
root_device: null
77+
scanning_port: null
78+
security_groups: []
79+
sha256sum: null
80+
signing_key: null
81+
src: {{ src_dir }}/tests/staged/data/simple_cloud/build1/CLOUD_IMAGES/something2.raw.xz
82+
sriov_net_support: null
83+
state: PENDING
84+
type: AMI
85+
uefi_support: null
86+
usage_instructions: null
87+
user_name: null
88+
version_title: null
89+
virtualization: null
90+
volume: null
91+
- AmiPushItem:
92+
access_endpoint_url: null
93+
billing_codes: null
94+
boot_mode: hybrid
95+
build: null
96+
build_info:
97+
id: null
98+
name: rhel-ec2
99+
release: '1'
100+
version: '9.4'
101+
description: build2 sample
102+
dest: []
103+
ena_support: null
104+
image_id: null
105+
marketplace_entity_type: null
106+
marketplace_name: null
107+
marketplace_title_template: null
108+
md5sum: null
109+
name: something1.raw.xz
110+
origin: {{ src_dir }}/tests/staged/data/simple_cloud
111+
public_image: null
112+
recommended_instance_type: null
113+
region: null
114+
release: null
115+
release_notes: null
116+
root_device: null
117+
scanning_port: null
118+
security_groups: []
119+
sha256sum: null
120+
signing_key: null
121+
src: {{ src_dir }}/tests/staged/data/simple_cloud/build2/CLOUD_IMAGES/something1.raw.xz
122+
sriov_net_support: null
123+
state: PENDING
124+
type: AMI
125+
uefi_support: null
126+
usage_instructions: null
127+
user_name: null
128+
version_title: null
129+
virtualization: null
130+
volume: null
131+
- AmiPushItem:
132+
access_endpoint_url: null
133+
billing_codes: null
134+
boot_mode: hybrid
135+
build: null
136+
build_info:
137+
id: null
138+
name: rhel-ec2
139+
release: '1'
140+
version: '9.4'
141+
description: build2 sample
142+
dest: []
143+
ena_support: null
144+
image_id: null
145+
marketplace_entity_type: null
146+
marketplace_name: null
147+
marketplace_title_template: null
148+
md5sum: null
149+
name: something2.raw.xz
150+
origin: {{ src_dir }}/tests/staged/data/simple_cloud
151+
public_image: null
152+
recommended_instance_type: null
153+
region: null
154+
release: null
155+
release_notes: null
156+
root_device: null
157+
scanning_port: null
158+
security_groups: []
159+
sha256sum: null
160+
signing_key: null
161+
src: {{ src_dir }}/tests/staged/data/simple_cloud/build2/CLOUD_IMAGES/something2.raw.xz
162+
sriov_net_support: null
163+
state: PENDING
164+
type: AMI
165+
uefi_support: null
166+
usage_instructions: null
167+
user_name: null
168+
version_title: null
169+
virtualization: null
170+
volume: null
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
api: v1
2+
resource: CloudImage
3+
images:
4+
- path: something1.raw.xz
5+
architecture: x86_64
6+
- path: something2.raw.xz
7+
architecture: arm64
8+
build:
9+
name: rhel-ec2
10+
version: "9.4"
11+
respin: "1"
12+
description: "build1 sample"
13+
boot_mode: hybrid
14+
type: AMI

tests/staged/data/simple_cloud/build1/CLOUD_IMAGES/sample1.raw.xz

Whitespace-only changes.

tests/staged/data/simple_cloud/build1/CLOUD_IMAGES/sample2.raw.xz

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
api: v1
2+
resource: CloudImage
3+
images:
4+
- path: something1.raw.xz
5+
architecture: x86_64
6+
- path: something2.raw.xz
7+
architecture: arm64
8+
build:
9+
name: rhel-ec2
10+
version: "9.4"
11+
respin: "1"
12+
description: "build2 sample"
13+
boot_mode: hybrid
14+
type: AMI

tests/staged/data/simple_cloud/build2/CLOUD_IMAGES/sample1.raw.xz

Whitespace-only changes.

tests/staged/data/simple_cloud/build2/CLOUD_IMAGES/sample2.raw.xz

Whitespace-only changes.

0 commit comments

Comments
 (0)