awspub 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- awspub/__init__.py +3 -0
- awspub/api.py +165 -0
- awspub/cli/__init__.py +146 -0
- awspub/configmodels.py +157 -0
- awspub/context.py +108 -0
- awspub/exceptions.py +16 -0
- awspub/image.py +593 -0
- awspub/image_marketplace.py +120 -0
- awspub/s3.py +262 -0
- awspub/snapshot.py +241 -0
- awspub/tests/__init__.py +0 -0
- awspub/tests/fixtures/config-invalid-s3-extra.yaml +12 -0
- awspub/tests/fixtures/config-minimal.yaml +12 -0
- awspub/tests/fixtures/config-valid-nonawspub.yaml +13 -0
- awspub/tests/fixtures/config1.vmdk +0 -0
- awspub/tests/fixtures/config1.yaml +118 -0
- awspub/tests/fixtures/config2-mapping.yaml +2 -0
- awspub/tests/fixtures/config2.yaml +48 -0
- awspub/tests/fixtures/config3-duplicate-keys.yaml +18 -0
- awspub/tests/test_api.py +86 -0
- awspub/tests/test_cli.py +0 -0
- awspub/tests/test_context.py +88 -0
- awspub/tests/test_image.py +433 -0
- awspub/tests/test_image_marketplace.py +44 -0
- awspub/tests/test_s3.py +74 -0
- awspub/tests/test_snapshot.py +122 -0
- awspub-0.0.1.dist-info/LICENSE +675 -0
- awspub-0.0.1.dist-info/METADATA +700 -0
- awspub-0.0.1.dist-info/RECORD +31 -0
- awspub-0.0.1.dist-info/WHEEL +4 -0
- awspub-0.0.1.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,118 @@
|
|
1
|
+
awspub:
|
2
|
+
s3:
|
3
|
+
bucket_name: "bucket1"
|
4
|
+
|
5
|
+
source:
|
6
|
+
# config1.vmdk generated with
|
7
|
+
# dd if=/dev/zero of=config1.raw bs=1K count=1
|
8
|
+
# qemu-img convert -f raw -O vmdk -o subformat=streamOptimized config1.raw config1.vmdk
|
9
|
+
path: "config1.vmdk"
|
10
|
+
architecture: "x86_64"
|
11
|
+
|
12
|
+
images:
|
13
|
+
"test-image-1":
|
14
|
+
description: |
|
15
|
+
A test image
|
16
|
+
boot_mode: "uefi"
|
17
|
+
regions:
|
18
|
+
- region1
|
19
|
+
- region2
|
20
|
+
temporary: true
|
21
|
+
groups:
|
22
|
+
- group1
|
23
|
+
- group2
|
24
|
+
"test-image-2":
|
25
|
+
description: |
|
26
|
+
A test image with a separate snapshot
|
27
|
+
boot_mode: "uefi"
|
28
|
+
separate_snapshot: true
|
29
|
+
groups:
|
30
|
+
- group1
|
31
|
+
"test-image-3":
|
32
|
+
description: |
|
33
|
+
A test image with a separate snapshot and a billing code
|
34
|
+
boot_mode: "uefi"
|
35
|
+
separate_snapshot: true
|
36
|
+
billing_products:
|
37
|
+
- billingcode
|
38
|
+
"test-image-4":
|
39
|
+
description: |
|
40
|
+
A test image without a separate snapshot but a billing product
|
41
|
+
boot_mode: "uefi-preferred"
|
42
|
+
billing_products:
|
43
|
+
- billingcode
|
44
|
+
"test-image-5":
|
45
|
+
description: |
|
46
|
+
A test image without a separate snapshot but multiple billing products
|
47
|
+
boot_mode: "uefi-preferred"
|
48
|
+
billing_products:
|
49
|
+
- billingcode1
|
50
|
+
- billingcode2
|
51
|
+
"test-image-6":
|
52
|
+
description: |
|
53
|
+
A test image without a separate snapshot but multiple billing products
|
54
|
+
boot_mode: "uefi-preferred"
|
55
|
+
regions:
|
56
|
+
- "eu-central-1"
|
57
|
+
public: true
|
58
|
+
tags:
|
59
|
+
key1: value1
|
60
|
+
"test-image-7":
|
61
|
+
description: |
|
62
|
+
A test image without a separate snapshot but multiple billing products
|
63
|
+
boot_mode: "uefi-preferred"
|
64
|
+
regions:
|
65
|
+
- "eu-central-1"
|
66
|
+
public: true
|
67
|
+
temporary: true
|
68
|
+
tags:
|
69
|
+
key2: name
|
70
|
+
name: "not-foobar"
|
71
|
+
"test-image-8":
|
72
|
+
description: |
|
73
|
+
A test image without a separate snapshot but multiple billing products
|
74
|
+
boot_mode: "uefi-preferred"
|
75
|
+
regions:
|
76
|
+
- "eu-central-1"
|
77
|
+
- "us-east-1"
|
78
|
+
public: true
|
79
|
+
tags:
|
80
|
+
key1: value1
|
81
|
+
marketplace:
|
82
|
+
entity_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
83
|
+
access_role_arn: "arn:aws:iam::xxxxxxxxxxxx:role/AWSMarketplaceAccess"
|
84
|
+
version_title: "1.0.0"
|
85
|
+
release_notes: "N/A"
|
86
|
+
user_name: "ubuntu"
|
87
|
+
scanning_port: 22
|
88
|
+
os_name: "UBUNTU"
|
89
|
+
os_version: "22.04"
|
90
|
+
usage_instructions: |
|
91
|
+
You can use me
|
92
|
+
recommended_instance_type: "m5.large"
|
93
|
+
security_groups:
|
94
|
+
-
|
95
|
+
from_port: 22
|
96
|
+
ip_protocol: "tcp"
|
97
|
+
ip_ranges:
|
98
|
+
- "0.0.0.0/0"
|
99
|
+
to_port: 22
|
100
|
+
ssm_parameter:
|
101
|
+
-
|
102
|
+
name: /test/image
|
103
|
+
-
|
104
|
+
name: /test/another-image
|
105
|
+
"test-image-9":
|
106
|
+
boot_mode: "uefi"
|
107
|
+
description: |
|
108
|
+
A test image without a separate snapshot but multiple billing products
|
109
|
+
regions:
|
110
|
+
- "eu-central-1"
|
111
|
+
- "us-east-1"
|
112
|
+
ssm_parameter:
|
113
|
+
-
|
114
|
+
name: /awspub-test/param2
|
115
|
+
allow_overwrite: true
|
116
|
+
|
117
|
+
tags:
|
118
|
+
name: "foobar"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
awspub:
|
2
|
+
s3:
|
3
|
+
bucket_name: "bucket1"
|
4
|
+
|
5
|
+
source:
|
6
|
+
# config1.vmdk generated with
|
7
|
+
# dd if=/dev/zero of=config1.raw bs=1K count=1
|
8
|
+
# qemu-img convert -f raw -O vmdk -o subformat=streamOptimized config1.raw config1.vmdk
|
9
|
+
path: "config1.vmdk"
|
10
|
+
architecture: "x86_64"
|
11
|
+
|
12
|
+
images:
|
13
|
+
"test-image-$key1":
|
14
|
+
description: |
|
15
|
+
A test image
|
16
|
+
boot_mode: "uefi"
|
17
|
+
regions:
|
18
|
+
- region1
|
19
|
+
- region2
|
20
|
+
temporary: true
|
21
|
+
"test-image-$key2":
|
22
|
+
description: |
|
23
|
+
A test image with a separate snapshot
|
24
|
+
boot_mode: "uefi"
|
25
|
+
separate_snapshot: true
|
26
|
+
"test-image-3":
|
27
|
+
description: |
|
28
|
+
A test image with a separate snapshot and a billing code
|
29
|
+
boot_mode: "uefi"
|
30
|
+
separate_snapshot: true
|
31
|
+
billing_products:
|
32
|
+
- billingcode
|
33
|
+
"test-image-4":
|
34
|
+
description: |
|
35
|
+
A test image without a separate snapshot but a billing product
|
36
|
+
boot_mode: "uefi-preferred"
|
37
|
+
billing_products:
|
38
|
+
- billingcode
|
39
|
+
"test-image-5":
|
40
|
+
description: |
|
41
|
+
A test image without a separate snapshot but multiple billing products
|
42
|
+
boot_mode: "uefi-preferred"
|
43
|
+
billing_products:
|
44
|
+
- billingcode1
|
45
|
+
- billingcode2
|
46
|
+
|
47
|
+
tags:
|
48
|
+
name: "foobar"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
awspub:
|
2
|
+
s3:
|
3
|
+
bucket_name: "bucket1"
|
4
|
+
|
5
|
+
source:
|
6
|
+
path: "config1.vmdk"
|
7
|
+
architecture: "x86_64"
|
8
|
+
|
9
|
+
images:
|
10
|
+
"test-image-1":
|
11
|
+
description: |
|
12
|
+
A test image
|
13
|
+
boot_mode: "uefi"
|
14
|
+
# second image with the same key
|
15
|
+
"test-image-1":
|
16
|
+
description: |
|
17
|
+
A test image
|
18
|
+
boot_mode: "uefi"
|
awspub/tests/test_api.py
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
import pathlib
|
2
|
+
|
3
|
+
import pytest
|
4
|
+
|
5
|
+
from awspub import api, context, image
|
6
|
+
|
7
|
+
curdir = pathlib.Path(__file__).parent.resolve()
|
8
|
+
|
9
|
+
|
10
|
+
@pytest.mark.parametrize(
|
11
|
+
"group,expected_image_names",
|
12
|
+
[
|
13
|
+
# without any group, all images should be processed
|
14
|
+
(
|
15
|
+
None,
|
16
|
+
[
|
17
|
+
"test-image-1",
|
18
|
+
"test-image-2",
|
19
|
+
"test-image-3",
|
20
|
+
"test-image-4",
|
21
|
+
"test-image-5",
|
22
|
+
"test-image-6",
|
23
|
+
"test-image-7",
|
24
|
+
"test-image-8",
|
25
|
+
"test-image-9",
|
26
|
+
],
|
27
|
+
),
|
28
|
+
# with a group that no image as, no image should be processed
|
29
|
+
(
|
30
|
+
"group-not-used",
|
31
|
+
[],
|
32
|
+
),
|
33
|
+
# with a group that an image has
|
34
|
+
(
|
35
|
+
"group2",
|
36
|
+
["test-image-1"],
|
37
|
+
),
|
38
|
+
# with a group that multiple images have
|
39
|
+
(
|
40
|
+
"group1",
|
41
|
+
["test-image-1", "test-image-2"],
|
42
|
+
),
|
43
|
+
],
|
44
|
+
)
|
45
|
+
def test_api__images_filtered(group, expected_image_names):
|
46
|
+
"""
|
47
|
+
Test the _images_filtered() function
|
48
|
+
"""
|
49
|
+
ctx = context.Context(curdir / "fixtures/config1.yaml", None)
|
50
|
+
|
51
|
+
image_names = [i[0] for i in api._images_filtered(ctx, group)]
|
52
|
+
assert image_names == expected_image_names
|
53
|
+
|
54
|
+
|
55
|
+
@pytest.mark.parametrize(
|
56
|
+
"group,expected",
|
57
|
+
[
|
58
|
+
# without any group, all images should be processed
|
59
|
+
(
|
60
|
+
None,
|
61
|
+
(
|
62
|
+
{"test-image-1": {"eu-central-1": "ami-123", "eu-central-2": "ami-456"}},
|
63
|
+
{
|
64
|
+
"group1": {"test-image-1": {"eu-central-1": "ami-123", "eu-central-2": "ami-456"}},
|
65
|
+
"group2": {"test-image-1": {"eu-central-1": "ami-123", "eu-central-2": "ami-456"}},
|
66
|
+
},
|
67
|
+
),
|
68
|
+
),
|
69
|
+
# with a group that no image as, image should be there but nothing in the group
|
70
|
+
("group-not-used", ({"test-image-1": {"eu-central-1": "ami-123", "eu-central-2": "ami-456"}}, {})),
|
71
|
+
],
|
72
|
+
)
|
73
|
+
def test_api__images_grouped(group, expected):
|
74
|
+
"""
|
75
|
+
Test the _images_grouped() function
|
76
|
+
"""
|
77
|
+
ctx = context.Context(curdir / "fixtures/config1.yaml", None)
|
78
|
+
images = [
|
79
|
+
(
|
80
|
+
"test-image-1",
|
81
|
+
image.Image(ctx, "test-image-1"),
|
82
|
+
{"eu-central-1": image._ImageInfo("ami-123", None), "eu-central-2": image._ImageInfo("ami-456", None)},
|
83
|
+
)
|
84
|
+
]
|
85
|
+
grouped = api._images_grouped(images, group)
|
86
|
+
assert grouped == expected
|
awspub/tests/test_cli.py
ADDED
File without changes
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import glob
|
2
|
+
import os
|
3
|
+
import pathlib
|
4
|
+
|
5
|
+
import pytest
|
6
|
+
from pydantic import ValidationError
|
7
|
+
from ruamel.yaml.constructor import DuplicateKeyError
|
8
|
+
|
9
|
+
from awspub import context
|
10
|
+
|
11
|
+
curdir = pathlib.Path(__file__).parent.resolve()
|
12
|
+
|
13
|
+
|
14
|
+
def test_context_create():
|
15
|
+
"""
|
16
|
+
Create a Context object from a given configuration
|
17
|
+
"""
|
18
|
+
ctx = context.Context(curdir / "fixtures/config1.yaml", None)
|
19
|
+
assert ctx.conf["source"]["path"] == curdir / "fixtures/config1.vmdk"
|
20
|
+
assert ctx.source_sha256 == "6252475408b9f9ee64452b611d706a078831a99b123db69d144d878a0488a0a8"
|
21
|
+
assert ctx.conf["source"]["architecture"] == "x86_64"
|
22
|
+
assert ctx.conf["s3"]["bucket_name"] == "bucket1"
|
23
|
+
|
24
|
+
|
25
|
+
def test_context_create_minimal():
|
26
|
+
"""
|
27
|
+
Create a Context object from a given minimal configuration
|
28
|
+
"""
|
29
|
+
ctx = context.Context(curdir / "fixtures/config-minimal.yaml", None)
|
30
|
+
assert ctx.conf["source"]["path"] == curdir / "fixtures/config1.vmdk"
|
31
|
+
assert ctx.source_sha256 == "6252475408b9f9ee64452b611d706a078831a99b123db69d144d878a0488a0a8"
|
32
|
+
assert ctx.conf["source"]["architecture"] == "x86_64"
|
33
|
+
assert ctx.conf["s3"]["bucket_name"] == "bucket1"
|
34
|
+
|
35
|
+
|
36
|
+
def test_context_create_with_mapping():
|
37
|
+
"""
|
38
|
+
Create a Context object from a given configuration
|
39
|
+
"""
|
40
|
+
ctx = context.Context(curdir / "fixtures/config2.yaml", curdir / "fixtures/config2-mapping.yaml")
|
41
|
+
assert ctx.conf["source"]["path"] == curdir / "fixtures/config1.vmdk"
|
42
|
+
assert ctx.source_sha256 == "6252475408b9f9ee64452b611d706a078831a99b123db69d144d878a0488a0a8"
|
43
|
+
assert ctx.conf["images"].get("test-image-value1")
|
44
|
+
assert ctx.conf["images"].get("test-image-value$2")
|
45
|
+
|
46
|
+
|
47
|
+
def test_context_with_docs_config_samples():
|
48
|
+
"""
|
49
|
+
Create a Context object with the sample config files used for documentation
|
50
|
+
"""
|
51
|
+
config_samples_dir = curdir.parents[1] / "docs" / "config-samples"
|
52
|
+
for f in glob.glob(f"{config_samples_dir}/*.yaml"):
|
53
|
+
mapping_file = f + ".mapping"
|
54
|
+
if os.path.exists(mapping_file):
|
55
|
+
mapping = mapping_file
|
56
|
+
else:
|
57
|
+
mapping = None
|
58
|
+
context.Context(os.path.join(config_samples_dir, f), mapping)
|
59
|
+
|
60
|
+
|
61
|
+
def test_context_with_duplicate_image_name():
|
62
|
+
"""
|
63
|
+
Create a context with a configuration file that contains a duplicate image name key
|
64
|
+
"""
|
65
|
+
with pytest.raises(DuplicateKeyError):
|
66
|
+
context.Context(curdir / "fixtures/config3-duplicate-keys.yaml", None)
|
67
|
+
|
68
|
+
|
69
|
+
@pytest.mark.parametrize(
|
70
|
+
"config_file",
|
71
|
+
["fixtures/config-minimal.yaml", "fixtures/config-valid-nonawspub.yaml"],
|
72
|
+
)
|
73
|
+
def test_valid_configuration(config_file):
|
74
|
+
"""
|
75
|
+
Test with a valid configuration file (no extra fields)
|
76
|
+
"""
|
77
|
+
ctx = context.Context(curdir / config_file, None)
|
78
|
+
assert ctx.conf is not None
|
79
|
+
assert ctx.conf["s3"]["bucket_name"] == "bucket1"
|
80
|
+
assert ctx.conf["source"]["architecture"] == "x86_64"
|
81
|
+
|
82
|
+
|
83
|
+
def test_invalid_configuration_extra_field():
|
84
|
+
"""
|
85
|
+
Test with an invalid configuration file that includes an extra field
|
86
|
+
"""
|
87
|
+
with pytest.raises(ValidationError):
|
88
|
+
context.Context(curdir / "fixtures/config-invalid-s3-extra.yaml", None)
|