Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ more_executors>=2.11.4
pushcollector>=1.3.0
pushsource>=2.50.0
strenum>=0.4.15
starmap-client>=2.2.1
cloudpub>=1.3.3
starmap-client>=2.3.0
cloudpub>=1.4.0
1 change: 1 addition & 0 deletions src/pubtools/_marketplacesvm/cloud_providers/ms_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def _publish(
"destination": destination,
"keepdraft": nochannel,
"overwrite": overwrite,
"check_base_sas_only": kwargs.get("check_base_sas_only", False),
}
metadata = AzurePublishMetadata(**publish_metadata_kwargs)
res = self.publish_svc.publish(metadata)
Expand Down
1 change: 1 addition & 0 deletions src/pubtools/_marketplacesvm/tasks/push/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def _publish(
restrict_version=dest.restrict_version,
restrict_major=dest.restrict_major,
restrict_minor=dest.restrict_minor,
check_base_sas_only=dest.vhd_check_base_sas_only,
)

# Once we process all destinations we set back the list of destinations
Expand Down
66 changes: 66 additions & 0 deletions tests/cloud_providers/test_provider_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ def azure_push_item(vmi_release: VMIRelease) -> VHDPushItem:
return VHDPushItem(**params)


@pytest.fixture
def fake_core_product() -> Product:
params = {
"$schema": "https://schema.mp.microsoft.com/schema/resource-tree/2022-03-01-preview2",
"root": "product/foobar",
"target": {"targetType": "draft"},
"resources": [
{
"$schema": "https://schema.mp.microsoft.com/schema/product/2022-03-01-preview3",
"id": "product/foobar",
"identity": {"externalId": "FooBar"},
"type": "coreVirtualMachine",
"alias": "Foo Bar",
},
],
}
return Product.from_json(params)


@pytest.mark.parametrize("marketplace_account", ["azure-na", "azure-emea"])
def test_get_provider(marketplace_account: str, fake_credentials: AzureCredentials) -> None:
conn_str = (
Expand Down Expand Up @@ -226,6 +245,7 @@ def test_publish(
"destination": azure_push_item.dest[0],
"keepdraft": False,
"overwrite": False,
"check_base_sas_only": False,
}
meta_obj = MagicMock(**metadata)
mock_metadata.return_value = meta_obj
Expand All @@ -244,6 +264,52 @@ def test_publish(
mock_ensure_offer_writable.assert_called_once()


@patch("pubtools._marketplacesvm.cloud_providers.ms_azure.AzurePublishMetadata")
def test_publish_core_vms(
mock_metadata: MagicMock,
azure_push_item: VHDPushItem,
fake_core_product: Product,
fake_azure_provider: AzureProvider,
monkeypatch: pytest.MonkeyPatch,
) -> None:
# Generate data for the test
azure_push_item = evolve(azure_push_item, disk_version=None)
fake_azure_provider.publish_svc.get_product_by_name.return_value = fake_core_product
fake_azure_provider.publish_svc.filter_product_resources.return_value = (
fake_core_product.resources
)
mock_metadata.side_effect = lambda **x: x
dv = "7.0.202301010000"
mock_generate_dv = MagicMock()
mock_generate_dv.return_value = dv
expected_metadata = {
'disk_version': dv,
"sku_id": azure_push_item.sku_id,
"generation": azure_push_item.generation or "V2",
"support_legacy": azure_push_item.support_legacy or False,
"recommended_sizes": azure_push_item.recommended_sizes or [],
"legacy_sku_id": azure_push_item.legacy_sku_id,
"image_path": azure_push_item.sas_uri,
"architecture": azure_push_item.release.arch,
"destination": azure_push_item.dest[0],
'keepdraft': False,
'overwrite': False,
"check_base_sas_only": True,
}
mock_ensure_offer_writable = MagicMock()

monkeypatch.setattr(fake_azure_provider, '_generate_disk_version', mock_generate_dv)
monkeypatch.setattr(fake_azure_provider, 'ensure_offer_is_writable', mock_ensure_offer_writable)

# Run the test
fake_azure_provider.publish(
azure_push_item, nochannel=False, overwrite=False, check_base_sas_only=True
)
fake_azure_provider.publish_svc.publish.assert_called_once_with(expected_metadata)
fake_azure_provider.upload_svc.publish.assert_not_called()
mock_ensure_offer_writable.assert_called_once()


@patch("pubtools._marketplacesvm.cloud_providers.ms_azure.AzurePublishMetadata")
def test_publish_allow_draft_from_env(
mock_metadata: MagicMock,
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[ INFO] Loading items from koji:https://fakekoji.com?vmi_build=ami_build
[ INFO] Retrieving the mappings for ami_pushitem from https://starmap-example.com
[ INFO] starmap query returned for ami_pushitem : {"name": "test-build", "version": "7.0", "query_response": {"meta": null, "name": "sample-product", "billing_code_config": {}, "cloud": "aws", "workflow": "stratosphere", "mappings": {"aws-na": {"meta": {}, "destinations": [{"meta": {"tag1": "aws-na-value1", "tag2": "aws-na-value2"}, "id": null, "architecture": "x86_64", "destination": "ffffffff-ffff-ffff-ffff-ffffffffffff", "overwrite": true, "restrict_version": false, "restrict_major": null, "restrict_minor": null, "ami_version_template": "{major}.{minor}.0", "provider": null, "tags": {"key1": "value1", "key2": "value2"}}], "provider": null}, "aws-emea": {"meta": {}, "destinations": [{"meta": {"tag1": "aws-emea-value1", "tag2": "aws-emea-value2"}, "id": null, "architecture": "x86_64", "destination": "00000000-0000-0000-0000-000000000000", "overwrite": true, "restrict_version": false, "restrict_major": null, "restrict_minor": null, "ami_version_template": null, "provider": null, "tags": {"key3": "value3", "key4": "value4"}}], "provider": null}}}}
[ INFO] starmap query returned for ami_pushitem : {"name": "test-build", "version": "7.0", "query_response": {"meta": null, "name": "sample-product", "billing_code_config": {}, "cloud": "aws", "workflow": "stratosphere", "mappings": {"aws-na": {"meta": {}, "destinations": [{"meta": {"tag1": "aws-na-value1", "tag2": "aws-na-value2"}, "id": null, "architecture": "x86_64", "destination": "ffffffff-ffff-ffff-ffff-ffffffffffff", "overwrite": true, "restrict_version": false, "restrict_major": null, "restrict_minor": null, "ami_version_template": "{major}.{minor}.0", "provider": null, "tags": {"key1": "value1", "key2": "value2"}, "vhd_check_base_sas_only": null}], "provider": null}, "aws-emea": {"meta": {}, "destinations": [{"meta": {"tag1": "aws-emea-value1", "tag2": "aws-emea-value2"}, "id": null, "architecture": "x86_64", "destination": "00000000-0000-0000-0000-000000000000", "overwrite": true, "restrict_version": false, "restrict_major": null, "restrict_minor": null, "ami_version_template": null, "provider": null, "tags": {"key3": "value3", "key4": "value4"}, "vhd_check_base_sas_only": null}], "provider": null}}}}
[ WARNING] Missing information for the attribute ami_pushitem.description, leaving it unset.
[ WARNING] Missing information for the attribute ami_pushitem.boot_mode, leaving it unset.
[ WARNING] Missing information for the attribute ami_pushitem.region, leaving it unset.
Expand Down
Loading