@@ -868,7 +868,10 @@ def test_publish_preview_success_on_retry(
868868 azure_service ._publish_preview (product_obj , "test-product" )
869869
870870 mock_subst .assert_has_calls (
871- [mock .call (product_id = product_obj .id , status = "preview" ) for _ in range (3 )]
871+ [
872+ mock .call (product_id = product_obj .id , status = "preview" , resources = None )
873+ for _ in range (3 )
874+ ]
872875 )
873876 mock_getsubst .assert_has_calls (
874877 [mock .call (product_obj .id , state = "preview" ) for _ in range (3 )]
@@ -900,7 +903,7 @@ def test_publish_preview_fail_on_retry(
900903 # Remove the retry sleep
901904 azure_service ._publish_preview .retry .sleep = mock .Mock () # type: ignore
902905 expected_err = (
903- f"Failed to submit the product { product_obj .id } to preview. "
906+ f"Failed to submit the product test-product \\ ( { product_obj .id } \\ ) to preview. "
904907 "Status: failed Errors: failure1\n failure2"
905908 )
906909
@@ -960,7 +963,7 @@ def test_publish_live_fail_on_retry(
960963 # Remove the retry sleep
961964 azure_service ._publish_live .retry .sleep = mock .Mock () # type: ignore
962965 expected_err = (
963- f"Failed to submit the product { product_obj .id } to live. "
966+ f"Failed to submit the product test-product \\ ( { product_obj .id } \\ ) to live. "
964967 "Status: failed Errors: failure1\n failure2"
965968 )
966969
@@ -1417,7 +1420,7 @@ def test_publish_live_x64_only(
14171420 mock_diff_offer .assert_called_once_with (product_obj )
14181421 mock_configure .assert_called_once_with (resources = [technical_config_obj ])
14191422 submit_calls = [
1420- mock .call (product_id = product_obj .id , status = "preview" ),
1423+ mock .call (product_id = product_obj .id , status = "preview" , resources = None ),
14211424 mock .call (product_id = product_obj .id , status = "live" ),
14221425 ]
14231426 mock_submit .assert_has_calls (submit_calls )
@@ -1509,7 +1512,7 @@ def test_publish_live_arm64_only(
15091512 mock_diff_offer .assert_called_once_with (product_obj )
15101513 mock_configure .assert_called_once_with (resources = [technical_config_obj ])
15111514 submit_calls = [
1512- mock .call (product_id = product_obj .id , status = "preview" ),
1515+ mock .call (product_id = product_obj .id , status = "preview" , resources = None ),
15131516 mock .call (product_id = product_obj .id , status = "live" ),
15141517 ]
15151518 mock_submit .assert_has_calls (submit_calls )
@@ -1637,3 +1640,105 @@ def test_publish_live_when_state_is_preview(
16371640 'Updating the technical configuration for "example-product/plan-1" on "preview".'
16381641 not in caplog .text
16391642 )
1643+
1644+ @mock .patch ("cloudpub.ms_azure.AzureService.configure" )
1645+ def test_publish_live_modular_push (
1646+ self ,
1647+ mock_configure : mock .MagicMock ,
1648+ token : Dict [str , Any ],
1649+ auth_dict : Dict [str , Any ],
1650+ configure_success_response : Dict [str , Any ],
1651+ product : Dict [str , Any ],
1652+ products_list : Dict [str , Any ],
1653+ product_summary : Dict [str , Any ],
1654+ technical_config : Dict [str , Any ],
1655+ submission : Dict [str , Any ],
1656+ product_summary_obj : ProductSummary ,
1657+ plan_summary_obj : PlanSummary ,
1658+ metadata_azure_obj : mock .MagicMock ,
1659+ gen2_image : Dict [str , Any ],
1660+ caplog : pytest .LogCaptureFixture ,
1661+ ) -> None :
1662+ """Ensure a modular publish works as intended."""
1663+ # Prepare testing data
1664+ metadata_azure_obj .keepdraft = False
1665+ metadata_azure_obj .destination = "example-product/plan-1"
1666+ metadata_azure_obj .modular_push = True
1667+
1668+ # Set the complementary submission states
1669+ submission_preview = deepcopy (submission )
1670+ submission_preview .update ({"target" : {"targetType" : "preview" }})
1671+ submission_live = deepcopy (submission )
1672+ submission_live .update ({"target" : {"targetType" : "live" }})
1673+ mock_configure .return_value = ConfigureStatus .from_json (configure_success_response )
1674+
1675+ # Expected results
1676+ new_dv = {
1677+ "version_number" : metadata_azure_obj .disk_version ,
1678+ "vm_images" : [
1679+ {
1680+ "imageType" : "x64Gen2" ,
1681+ "source" : {
1682+ "sourceType" : "sasUri" ,
1683+ "osDisk" : {"uri" : "https://foo.com/bar/image.vhd" },
1684+ "dataDisks" : [],
1685+ },
1686+ }
1687+ ],
1688+ "lifecycle_state" : "generallyAvailable" ,
1689+ }
1690+ dvs = technical_config ["vmImageVersions" ] + [new_dv ]
1691+ new_tc = deepcopy (technical_config )
1692+ new_tc ["vmImageVersions" ] = dvs
1693+ expected_tc = VMIPlanTechConfig .from_json (new_tc )
1694+ expected_modular_resources = [
1695+ product_summary_obj ,
1696+ plan_summary_obj ,
1697+ expected_tc ,
1698+ ProductSubmission .from_json (submission_preview ),
1699+ ]
1700+
1701+ # Constants
1702+ login_url = "https://login.microsoftonline.com/foo/oauth2/token"
1703+ base_url = "https://graph.microsoft.com/rp/product-ingestion"
1704+ product_id = str (product_summary ['id' ]).split ("/" )[- 1 ]
1705+
1706+ # Test
1707+ with caplog .at_level (logging .INFO ):
1708+ with requests_mock .Mocker () as m :
1709+ m .post (login_url , json = token )
1710+ m .get (f"{ base_url } /product" , json = products_list )
1711+ m .get (f"{ base_url } /resource-tree/product/{ product_id } " , json = product )
1712+ m .get (
1713+ f"{ base_url } /submission/{ product_id } " ,
1714+ [
1715+ {"json" : {"value" : [submission ]}}, # ensure_can_publish call "preview"
1716+ {"json" : {"value" : [submission ]}}, # ensure_can_publish call "live"
1717+ {"json" : {"value" : [submission ]}}, # push_preview: call submit_status
1718+ {"json" : {"value" : [submission_preview ]}}, # push_preview: check result
1719+ {"json" : {"value" : [submission_preview ]}}, # push_live: call submit_status
1720+ {"json" : {"value" : [submission_live ]}}, # push_live: check result
1721+ ],
1722+ )
1723+ azure_svc = AzureService (auth_dict )
1724+ azure_svc .publish (metadata = metadata_azure_obj )
1725+
1726+ # Present messages
1727+ assert "The DiskVersion doesn't exist, creating one from scratch." in caplog .text
1728+ assert (
1729+ "Found the following offer diff before publishing:\n "
1730+ "Item root['resources'][1]['vmImageVersions'][1] added to iterable."
1731+ ) in caplog .text
1732+ assert (
1733+ 'Updating the technical configuration for "example-product/plan-1" on "preview".'
1734+ in caplog .text
1735+ )
1736+ assert (
1737+ 'Performing a modular push to "preview" for "ffffffff-ffff-ffff-ffff-ffffffffffff"'
1738+ in caplog .text
1739+ )
1740+
1741+ # Configure request
1742+ mock_configure .assert_has_calls (
1743+ [mock .call (resources = [expected_tc ]), mock .call (resources = expected_modular_resources )]
1744+ )
0 commit comments