Skip to content

Commit ebf1e5d

Browse files
committed
Azure: fix bug preventing pushing preview offers live
This commit fixes a bug which did prevent `AzureService` to push live offers which were in the `preview` state with the SAS URI already attached. It basically adds a new condition on step 5 of `publish` to check whether the offer state is preview. Refers to SPSTRAT-583 Signed-off-by: Jonathan Gangi <jgangi@redhat.com>
1 parent 3edd8d6 commit ebf1e5d

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

cloudpub/ms_azure/service.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -669,15 +669,24 @@ def publish(self, metadata: AzurePublishingMetadata) -> None:
669669

670670
# 5. Proceed to publishing if it was requested.
671671
# Note: The publishing will only occur if it made changes in disk_version.
672-
if disk_version and not metadata.keepdraft:
673-
log.info(
674-
"Publishing the new changes for \"%s\" on plan \"%s\"", product_name, plan_name
675-
)
676-
logdiff(self.diff_offer(product))
677-
self.ensure_can_publish(product.id)
672+
if not metadata.keepdraft:
673+
# Get the submission state
674+
submission: ProductSubmission = cast(
675+
List[ProductSubmission],
676+
self.filter_product_resources(product=product, resource="submission"),
677+
)[0]
678+
679+
# We should only publish if there are new changes OR
680+
# the existing offer was already in preview
681+
if disk_version or self._is_submission_in_preview(submission):
682+
log.info(
683+
"Publishing the new changes for \"%s\" on plan \"%s\"", product_name, plan_name
684+
)
685+
logdiff(self.diff_offer(product))
686+
self.ensure_can_publish(product.id)
678687

679-
self._publish_preview(product, product_name)
680-
self._publish_live(product, product_name)
688+
self._publish_preview(product, product_name)
689+
self._publish_live(product, product_name)
681690

682691
log.info(
683692
"Finished publishing the image \"%s\" to \"%s\"",

tests/ms_azure/test_service.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,7 @@ def test_publish_nodiskversion(
10931093

10941094
@pytest.mark.parametrize("keepdraft", [True, False], ids=["nochannel", "push"])
10951095
@mock.patch("cloudpub.ms_azure.AzureService.configure")
1096+
@mock.patch("cloudpub.ms_azure.AzureService._is_submission_in_preview")
10961097
@mock.patch("cloudpub.ms_azure.AzureService.submit_to_status")
10971098
@mock.patch("cloudpub.ms_azure.service.update_skus")
10981099
@mock.patch("cloudpub.ms_azure.utils.prepare_vm_images")
@@ -1109,6 +1110,7 @@ def test_publish_saspresent(
11091110
mock_prep_img: mock.MagicMock,
11101111
mock_upd_sku: mock.MagicMock,
11111112
mock_submit: mock.MagicMock,
1113+
mock_is_preview: mock.MagicMock,
11121114
mock_configure: mock.MagicMock,
11131115
keepdraft: bool,
11141116
product_obj: Product,
@@ -1127,12 +1129,17 @@ def test_publish_saspresent(
11271129
mock_is_sas.return_value = True
11281130
mock_disk_scratch.return_value = disk_version_obj
11291131
mock_upd_sku.return_value = technical_config_obj
1132+
mock_is_preview.return_value = False
11301133

11311134
azure_service.publish(metadata_azure_obj)
11321135

11331136
mock_getprpl_name.assert_called_once_with("example-product", "plan-1")
1134-
mock_filter.assert_called_once_with(
1135-
product=product_obj, resource="virtual-machine-plan-technical-configuration"
1137+
mock_filter.assert_has_calls(
1138+
[
1139+
mock.call(
1140+
product=product_obj, resource="virtual-machine-plan-technical-configuration"
1141+
)
1142+
]
11361143
)
11371144
mock_is_sas.assert_called_once_with(
11381145
technical_config_obj,
@@ -1362,6 +1369,7 @@ def test_publish_live_x64_only(
13621369
mock_filter.side_effect = [
13631370
[technical_config_obj],
13641371
[submission_obj],
1372+
[submission_obj],
13651373
]
13661374
mock_getsubst.side_effect = ["preview", "live"]
13671375
mock_res_preview = mock.MagicMock()
@@ -1454,6 +1462,7 @@ def test_publish_live_arm64_only(
14541462
mock_filter.side_effect = [
14551463
[technical_config_obj],
14561464
[submission_obj],
1465+
[submission_obj],
14571466
]
14581467
mock_getsubst.side_effect = ["preview", "live"]
14591468
mock_res_preview = mock.MagicMock()

0 commit comments

Comments
 (0)