22import json
33import logging
44import os
5+ from enum import IntEnum
56from typing import Any , Dict , Iterator , List , Optional , Tuple , Union , cast
67
78from deepdiff import DeepDiff
7172]
7273
7374
75+ class SasFoundStatus (IntEnum ):
76+ """Represent the submission target level of SAS found in a given product."""
77+
78+ missing = 0
79+ draft = 1
80+ preview = 2
81+ live = 3
82+
83+
7484class AzureService (BaseService [AzurePublishingMetadata ]):
7585 """Service provider for Microsoft Azure using the Product Ingestion API."""
7686
@@ -570,7 +580,7 @@ def compute_targets(self, product_id: str) -> List[str]:
570580 """List all the possible publishing targets order to seek data from Azure.
571581
572582 It also returns the ordered list of targets with the following precedence:
573- ``preview `` -> ``live `` -> ``draft``
583+ ``live `` -> ``preview `` -> ``draft``
574584
575585 Args:
576586 product_id (str)
@@ -579,7 +589,7 @@ def compute_targets(self, product_id: str) -> List[str]:
579589 Returns:
580590 List[Str]: The ordered list with targets to lookup.
581591 """
582- all_targets = ["preview " , "live " , "draft" ]
592+ all_targets = ["live " , "preview " , "draft" ]
583593 computed_targets = []
584594
585595 # We cannot simply return all targets above because the existing product might
@@ -622,7 +632,7 @@ def _publish_preview(
622632 self , product : Product , product_name : str , resources : Optional [List [AzureResource ]] = None
623633 ) -> None :
624634 """
625- Submit the product to 'preview' if it's not already in this state .
635+ Submit the product to 'preview' after going through Azure Marketplace Validatoin .
626636
627637 This is required to execute the validation pipeline on Azure side.
628638
@@ -634,19 +644,6 @@ def _publish_preview(
634644 resources:
635645 Additional resources for modular push.
636646 """
637- # We just want to set the ProductSubmission to 'preview' if it's not in this status.
638- #
639- # The `preview` stage runs the Azure pipeline which takes up to 4 days.
640- # Meanwhile the `submit_for_status` will be blocked querying the `job_status`until
641- # all the Azure verification pipeline finishes.
642- submission : ProductSubmission = cast (
643- List [ProductSubmission ],
644- self .filter_product_resources (product = product , resource = "submission" ),
645- )[0 ]
646- if self ._is_submission_in_preview (submission ):
647- log .info ("The product \" %s\" is already set to preview" , product_name )
648- return
649-
650647 res = self .submit_to_status (product_id = product .id , status = 'preview' , resources = resources )
651648
652649 if res .job_result != 'succeeded' or not self .get_submission_state (
@@ -817,7 +814,7 @@ def publish(self, metadata: AzurePublishingMetadata) -> None:
817814 product_name = metadata .destination .split ("/" )[0 ]
818815 plan_name = metadata .destination .split ("/" )[- 1 ]
819816 product_id = self .get_productid (product_name )
820- disk_version = None
817+ sas_in_target = SasFoundStatus . missing
821818 log .info (
822819 "Preparing to associate the image \" %s\" with the plan \" %s\" from product \" %s\" " ,
823820 metadata .image_path ,
@@ -838,7 +835,6 @@ def publish(self, metadata: AzurePublishingMetadata) -> None:
838835 target = "draft" # It's expected to exist for whenever product.
839836 res = self ._overwrite_disk_version (metadata , product_name , plan_name , source , target )
840837 tech_config = res ["tech_config" ]
841- disk_version = tech_config .disk_versions [0 ] # only 1 as it was overwritten
842838 else :
843839 # Otherwise we need to check whether SAS isn't already present
844840 # in any of the targets "preview", "live" or "draft" and if not attach and publish it.
@@ -849,6 +845,7 @@ def publish(self, metadata: AzurePublishingMetadata) -> None:
849845 tech_config = res ["tech_config" ]
850846 # We don't want to seek for SAS anymore as it was already found
851847 if res ["sas_found" ]:
848+ sas_in_target = SasFoundStatus [target ]
852849 break
853850 else :
854851 # At this point there's no SAS URI in any target so we can safely add it
@@ -862,10 +859,10 @@ def publish(self, metadata: AzurePublishingMetadata) -> None:
862859 metadata .image_path ,
863860 )
864861 dv = seek_disk_version (tech_config , metadata .disk_version )
865- disk_version = self ._create_or_update_disk_version (res , source , dv )
862+ self ._create_or_update_disk_version (res , source , dv )
866863
867864 # 4. With the updated disk_version we should adjust the SKUs and submit the changes
868- if disk_version :
865+ if sas_in_target == SasFoundStatus . missing :
869866 log .info ("Updating SKUs for \" %s\" on \" %s\" ." , metadata .destination , target )
870867 tech_config .skus = update_skus (
871868 disk_versions = tech_config .disk_versions ,
@@ -892,7 +889,7 @@ def publish(self, metadata: AzurePublishingMetadata) -> None:
892889
893890 # We should only publish if there are new changes OR
894891 # the existing offer was already in preview
895- if disk_version or self ._is_submission_in_preview (submission ):
892+ if sas_in_target <= SasFoundStatus . draft or self ._is_submission_in_preview (submission ):
896893 log .info (
897894 "Publishing the new changes for \" %s\" on plan \" %s\" " , product_name , plan_name
898895 )
@@ -905,8 +902,10 @@ def publish(self, metadata: AzurePublishingMetadata) -> None:
905902 modular_resources = None
906903 if metadata .modular_push :
907904 modular_resources = self .get_modular_resources_to_publish (product , tech_config )
908- self ._publish_preview (product , product_name , resources = modular_resources )
909- self ._publish_live (product , product_name )
905+ if sas_in_target < SasFoundStatus .preview :
906+ self ._publish_preview (product , product_name , resources = modular_resources )
907+ if sas_in_target < SasFoundStatus .live :
908+ self ._publish_live (product , product_name )
910909
911910 log .info (
912911 "Finished publishing the image \" %s\" to \" %s\" " ,
0 commit comments