Skip to content

Commit 7971816

Browse files
committed
Azure: log the target name from get_product_plan_by_name
This commit changes `get_product_plan_by_name` to return the target of the product and plan whenever these are found. It also changes the `publish` method to log the target from `get_product_plan_by_name`. Refers to SPSTRAT-583 Signed-off-by: Jonathan Gangi <[email protected]>
1 parent 8b856cb commit 7971816

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

cloudpub/ms_azure/service.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,15 @@ def get_plan_by_name(self, product: Product, plan_name: str) -> PlanSummary:
378378

379379
def get_product_plan_by_name(
380380
self, product_name: str, plan_name: str
381-
) -> Tuple[Product, PlanSummary]:
381+
) -> Tuple[Product, PlanSummary, str]:
382382
"""Return a tuple with the desired Product and Plan after iterating over all targets.
383383
384384
Args:
385385
product_name (str): The name of the product to search for
386386
plan_name (str): The name of the plan to search for
387387
388388
Returns:
389-
Tuple[Product, PlanSummary]: The Product and PlanSummary when fonud
389+
Tuple[Product, PlanSummary, str]: The Product, PlanSummary and target when fonud
390390
Raises:
391391
NotFoundError whenever all targets are exhausted and no information was found
392392
"""
@@ -396,7 +396,7 @@ def get_product_plan_by_name(
396396
try:
397397
product = self.get_product_by_name(product_name, first_target=tgt)
398398
plan = self.get_plan_by_name(product, plan_name)
399-
return product, plan
399+
return product, plan, tgt
400400
except NotFoundError:
401401
continue
402402
self._raise_error(
@@ -605,16 +605,17 @@ def publish(self, metadata: AzurePublishingMetadata) -> None:
605605
# "product-name/plan-name"
606606
product_name = metadata.destination.split("/")[0]
607607
plan_name = metadata.destination.split("/")[-1]
608-
product, plan = self.get_product_plan_by_name(product_name, plan_name)
608+
product, plan, tgt = self.get_product_plan_by_name(product_name, plan_name)
609609
log.info(
610-
"Preparing to associate the image \"%s\" with the plan \"%s\" from product \"%s\"",
610+
"Preparing to associate the image \"%s\" with the plan \"%s\" from product \"%s\" on \"%s\"", # noqa: E501
611611
metadata.image_path,
612612
plan_name,
613613
product_name,
614+
tgt,
614615
)
615616

616617
# 2. Retrieve the VM Technical configuration for the given plan
617-
log.info("Retrieving the technical config for \"%s\".", metadata.destination)
618+
log.info("Retrieving the technical config for \"%s\" on \"%s\".", metadata.destination, tgt)
618619
tech_config = self.get_plan_tech_config(product, plan)
619620

620621
# 3. Prepare the Disk Version
@@ -627,8 +628,9 @@ def publish(self, metadata: AzurePublishingMetadata) -> None:
627628
disk_version = None # just to make mypy happy
628629
if metadata.overwrite is True:
629630
log.warning(
630-
"Overwriting the plan \"%s\" with the given image: \"%s\".",
631+
"Overwriting the plan \"%s\" on \"%s\" with the given image: \"%s\".",
631632
plan_name,
633+
tgt,
632634
metadata.image_path,
633635
)
634636
disk_version = create_disk_version_from_scratch(metadata, source)
@@ -639,18 +641,20 @@ def publish(self, metadata: AzurePublishingMetadata) -> None:
639641
# Here we can have the metadata.disk_version set or empty.
640642
# When set we want to get the existing disk_version which matches its value.
641643
log.info(
642-
"Scanning the disk versions from \"%s\" for the image \"%s\"",
644+
"Scanning the disk versions from \"%s\" on \"%s\" for the image \"%s\"",
643645
metadata.destination,
646+
tgt,
644647
metadata.image_path,
645648
)
646649
disk_version = seek_disk_version(tech_config, metadata.disk_version)
647650

648651
# Check the images of the selected DiskVersion if it exists
649652
if disk_version:
650653
log.info(
651-
"DiskVersion \"%s\" exists in \"%s\" for the image \"%s\".",
654+
"DiskVersion \"%s\" exists in \"%s\" on \"%s\" for the image \"%s\".",
652655
disk_version.version_number,
653656
metadata.destination,
657+
tgt,
654658
metadata.image_path,
655659
)
656660
disk_version = set_new_sas_disk_version(disk_version, metadata, source)
@@ -661,21 +665,26 @@ def publish(self, metadata: AzurePublishingMetadata) -> None:
661665
tech_config.disk_versions.append(disk_version)
662666
else:
663667
log.info(
664-
"The destination \"%s\" already contains the SAS URI: \"%s\".",
668+
"The destination \"%s\" on \"%s\" already contains the SAS URI: \"%s\".",
665669
metadata.destination,
670+
tgt,
666671
metadata.image_path,
667672
)
668673

669674
# 4. With the updated disk_version we should adjust the SKUs and submit the changes
670675
if disk_version:
671-
log.info("Updating SKUs for \"%s\".", metadata.destination)
676+
log.info("Updating SKUs for \"%s\" on \"%s\".", metadata.destination, tgt)
672677
tech_config.skus = update_skus(
673678
disk_versions=tech_config.disk_versions,
674679
generation=metadata.generation,
675680
plan_name=plan_name,
676681
old_skus=tech_config.skus,
677682
)
678-
log.info("Updating the technical configuration for \"%s\".", metadata.destination)
683+
log.info(
684+
"Updating the technical configuration for \"%s\" on \"%s\".",
685+
metadata.destination,
686+
tgt,
687+
)
679688
self.configure(resource=tech_config)
680689

681690
# 5. Proceed to publishing if it was requested.

tests/ms_azure/test_service.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,11 @@ def test_get_product_plan_by_name_success_first_attempt(
463463
mock_getpr.return_value = product_obj
464464
mock_getpl.return_value = plan_summary_obj
465465

466-
product, plan = azure_service.get_product_plan_by_name("product", "plan")
466+
product, plan, tgt = azure_service.get_product_plan_by_name("product", "plan")
467467

468468
assert product == product_obj
469469
assert plan == plan_summary_obj
470+
assert tgt == "preview"
470471
mock_getpr.assert_called_once_with("product", first_target="preview")
471472
mock_getpl.assert_called_once_with(product_obj, "plan")
472473

@@ -484,10 +485,11 @@ def test_get_product_plan_by_name_success_next_attempt(
484485
mock_getpr.return_value = product_obj
485486
mock_getpl.side_effect = [NotFoundError("Not found"), plan_summary_obj]
486487

487-
product, plan = azure_service.get_product_plan_by_name("product", "plan")
488+
product, plan, tgt = azure_service.get_product_plan_by_name("product", "plan")
488489

489490
assert product == product_obj
490491
assert plan == plan_summary_obj
492+
assert tgt == "draft"
491493
mock_getpr.assert_has_calls(
492494
[
493495
mock.call("product", first_target="preview"),
@@ -994,7 +996,7 @@ def test_publish_overwrite(
994996
metadata_azure_obj.overwrite = True
995997
metadata_azure_obj.keepdraft = True
996998
metadata_azure_obj.destination = "example-product/plan-1"
997-
mock_getprpl_name.return_value = product_obj, plan_summary_obj
999+
mock_getprpl_name.return_value = product_obj, plan_summary_obj, "preview"
9981000
mock_filter.return_value = [technical_config_obj]
9991001
mock_disk_scratch.return_value = disk_version_obj
10001002
mock_upd_sku.return_value = technical_config_obj
@@ -1053,7 +1055,7 @@ def test_publish_nodiskversion(
10531055
metadata_azure_obj.keepdraft = True
10541056
metadata_azure_obj.disk_version = "1.0.0"
10551057
metadata_azure_obj.destination = "example-product/plan-1"
1056-
mock_getprpl_name.return_value = product_obj, plan_summary_obj
1058+
mock_getprpl_name.return_value = product_obj, plan_summary_obj, "preview"
10571059
technical_config_obj.disk_versions = []
10581060
mock_filter.return_value = [technical_config_obj]
10591061
mock_is_sas.return_value = False
@@ -1124,7 +1126,7 @@ def test_publish_saspresent(
11241126
metadata_azure_obj.keepdraft = keepdraft
11251127
metadata_azure_obj.destination = "example-product/plan-1"
11261128
metadata_azure_obj.disk_version = "2.0.0"
1127-
mock_getprpl_name.return_value = product_obj, plan_summary_obj
1129+
mock_getprpl_name.return_value = product_obj, plan_summary_obj, "preview"
11281130
mock_filter.return_value = [technical_config_obj]
11291131
mock_is_sas.return_value = True
11301132
mock_disk_scratch.return_value = disk_version_obj
@@ -1181,7 +1183,7 @@ def test_publish_novmimages(
11811183
metadata_azure_obj.destination = "example-product/plan-1"
11821184
metadata_azure_obj.disk_version = "2.0.0"
11831185
technical_config_obj.disk_versions[0].vm_images = []
1184-
mock_getprpl_name.return_value = product_obj, plan_summary_obj
1186+
mock_getprpl_name.return_value = product_obj, plan_summary_obj, "preview"
11851187
mock_filter.return_value = [technical_config_obj]
11861188
mock_is_sas.return_value = False
11871189
mock_disk_scratch.return_value = disk_version_obj
@@ -1248,7 +1250,7 @@ def test_publish_disk_has_images(
12481250
metadata_azure_obj.support_legacy = True
12491251
metadata_azure_obj.destination = "example-product/plan-1"
12501252
metadata_azure_obj.disk_version = "2.0.0"
1251-
mock_getprpl_name.return_value = product_obj, plan_summary_obj
1253+
mock_getprpl_name.return_value = product_obj, plan_summary_obj, "preview"
12521254
mock_filter.return_value = [technical_config_obj]
12531255
mock_is_sas.return_value = False
12541256
expected_source = VMImageSource(
@@ -1365,7 +1367,7 @@ def test_publish_live_x64_only(
13651367
metadata_azure_obj.support_legacy = True
13661368
metadata_azure_obj.destination = "example-product/plan-1"
13671369
metadata_azure_obj.disk_version = "2.0.0"
1368-
mock_getprpl_name.return_value = product_obj, plan_summary_obj
1370+
mock_getprpl_name.return_value = product_obj, plan_summary_obj, "preview"
13691371
mock_filter.side_effect = [
13701372
[technical_config_obj],
13711373
[submission_obj],
@@ -1458,7 +1460,7 @@ def test_publish_live_arm64_only(
14581460
metadata_azure_obj.disk_version = "2.1.0"
14591461
metadata_azure_obj.architecture = "aarch64"
14601462
technical_config_obj.disk_versions = [disk_version_arm64_obj]
1461-
mock_getprpl_name.return_value = product_obj, plan_summary_obj
1463+
mock_getprpl_name.return_value = product_obj, plan_summary_obj, "preview"
14621464
mock_filter.side_effect = [
14631465
[technical_config_obj],
14641466
[submission_obj],
@@ -1583,15 +1585,18 @@ def test_publish_live_when_state_is_preview(
15831585
in caplog.text
15841586
)
15851587
assert (
1586-
'Preparing to associate the image "https://uri.test.com" with the plan "plan-1" from product "example-product"' # noqa: E501
1588+
'Preparing to associate the image "https://uri.test.com" with the plan "plan-1" from product "example-product" on "preview"' # noqa: E501
1589+
in caplog.text
1590+
)
1591+
assert (
1592+
'Retrieving the technical config for "example-product/plan-1" on "preview".'
15871593
in caplog.text
15881594
)
1589-
assert 'Retrieving the technical config for "example-product/plan-1".' in caplog.text
15901595
assert (
15911596
'Creating the VMImageResource with SAS for image: "https://uri.test.com"' in caplog.text
15921597
)
15931598
assert (
1594-
'The destination "example-product/plan-1" already contains the SAS URI: "https://uri.test.com".' # noqa: E501
1599+
'The destination "example-product/plan-1" on "preview" already contains the SAS URI: "https://uri.test.com".' # noqa: E501
15951600
in caplog.text
15961601
)
15971602
assert 'Publishing the new changes for "example-product" on plan "plan-1"' in caplog.text
@@ -1623,11 +1628,12 @@ def test_publish_live_when_state_is_preview(
16231628

16241629
# Absent messages
16251630
assert (
1626-
'Scanning the disk versions from "example-product/plan-1" for the image "https://uri.test.com"' # noqa: E501
1631+
'Scanning the disk versions from "example-product/plan-1" on "preview" for the image "https://uri.test.com"' # noqa: E501
16271632
not in caplog.text
16281633
)
16291634
assert 'The DiskVersion doesn\'t exist, creating one from scratch.' not in caplog.text
1630-
assert 'Updating SKUs for "example-product/plan-1".' not in caplog.text
1635+
assert 'Updating SKUs for "example-product/plan-1" on "preview".' not in caplog.text
16311636
assert (
1632-
'Updating the technical configuration for "example-product/plan-1".' not in caplog.text
1637+
'Updating the technical configuration for "example-product/plan-1" on "preview".'
1638+
not in caplog.text
16331639
)

0 commit comments

Comments
 (0)