From d740c223cea8fb300b2356ff33ef60ef39d148d5 Mon Sep 17 00:00:00 2001 From: Ben Johnson-Staub Date: Wed, 8 Oct 2025 16:50:29 -0400 Subject: [PATCH 1/3] Move az_cmd and deps to shared folder --- azure/shared/pytest.ini | 2 ++ .../src/az_shared}/az_cmd.py | 2 +- .../src/az_shared}/errors.py | 0 .../logging.py => shared/src/az_shared/logs.py} | 0 azure/{logging_install => shared}/tests/test_az_cmd.py | 10 +++++----- azure/shared/tests/test_data.py | 9 +++++++++ 6 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 azure/shared/pytest.ini rename azure/{logging_install/src/azure_logging_install => shared/src/az_shared}/az_cmd.py (99%) rename azure/{logging_install/src/azure_logging_install => shared/src/az_shared}/errors.py (100%) rename azure/{logging_install/src/azure_logging_install/logging.py => shared/src/az_shared/logs.py} (100%) rename azure/{logging_install => shared}/tests/test_az_cmd.py (97%) create mode 100644 azure/shared/tests/test_data.py diff --git a/azure/shared/pytest.ini b/azure/shared/pytest.ini new file mode 100644 index 00000000..b6fc30e3 --- /dev/null +++ b/azure/shared/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +pythonpath=src \ No newline at end of file diff --git a/azure/logging_install/src/azure_logging_install/az_cmd.py b/azure/shared/src/az_shared/az_cmd.py similarity index 99% rename from azure/logging_install/src/azure_logging_install/az_cmd.py rename to azure/shared/src/az_shared/az_cmd.py index 4b99485f..41a45e30 100644 --- a/azure/logging_install/src/azure_logging_install/az_cmd.py +++ b/azure/shared/src/az_shared/az_cmd.py @@ -14,7 +14,7 @@ RefreshTokenError, ResourceNotFoundError, ) -from .logging import log +from .logs import log AUTH_FAILED_ERROR = "AuthorizationFailed" diff --git a/azure/logging_install/src/azure_logging_install/errors.py b/azure/shared/src/az_shared/errors.py similarity index 100% rename from azure/logging_install/src/azure_logging_install/errors.py rename to azure/shared/src/az_shared/errors.py diff --git a/azure/logging_install/src/azure_logging_install/logging.py b/azure/shared/src/az_shared/logs.py similarity index 100% rename from azure/logging_install/src/azure_logging_install/logging.py rename to azure/shared/src/az_shared/logs.py diff --git a/azure/logging_install/tests/test_az_cmd.py b/azure/shared/tests/test_az_cmd.py similarity index 97% rename from azure/logging_install/tests/test_az_cmd.py rename to azure/shared/tests/test_az_cmd.py index c82b0e86..63da6607 100644 --- a/azure/logging_install/tests/test_az_cmd.py +++ b/azure/shared/tests/test_az_cmd.py @@ -8,15 +8,15 @@ from unittest.mock import Mock, patch as mock_patch # project -from azure_logging_install import az_cmd -from azure_logging_install.errors import ( +from az_shared import az_cmd +from az_shared.errors import ( AccessError, RateLimitExceededError, RefreshTokenError, ResourceNotFoundError, ) -from tests.test_data import ( +from shared.tests.test_data import ( CONTROL_PLANE_SUBSCRIPTION_ID, CONTROL_PLANE_RESOURCE_GROUP, CONTROL_PLANE_REGION, @@ -29,8 +29,8 @@ class TestAzCmd(TestCase): def setUp(self) -> None: """Set up test fixtures and reset global settings""" - self.subprocess_mock = self.patch("azure_logging_install.az_cmd.subprocess.run") - self.sleep_mock = self.patch("azure_logging_install.az_cmd.sleep") + self.subprocess_mock = self.patch("az_shared.az_cmd.subprocess.run") + self.sleep_mock = self.patch("az_shared.az_cmd.sleep") def patch(self, path: str, **kwargs): """Helper method to patch and auto-cleanup""" diff --git a/azure/shared/tests/test_data.py b/azure/shared/tests/test_data.py new file mode 100644 index 00000000..b2c91b8b --- /dev/null +++ b/azure/shared/tests/test_data.py @@ -0,0 +1,9 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2 License. + +# This product includes software developed at Datadog (https://www.datadoghq.com/) Copyright 2025 Datadog, Inc. + +"""Shared test data constants for azure's shared util tests.""" + +CONTROL_PLANE_SUBSCRIPTION_ID = "cp-sub-id" +CONTROL_PLANE_REGION = "eastus" +CONTROL_PLANE_RESOURCE_GROUP = "test-rg" \ No newline at end of file From 4f74825b5cc427e0c76bcdc4f42794c07fe504d9 Mon Sep 17 00:00:00 2001 From: Ben Johnson-Staub Date: Wed, 8 Oct 2025 16:51:14 -0400 Subject: [PATCH 2/3] Build logging install from shared + logging install folders --- azure/.vscode/settings.json | 3 ++- azure/logging_install/README.md | 12 ++++-------- azure/logging_install/build.sh | 14 ++++++++++++++ azure/logging_install/pytest.ini | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 azure/logging_install/build.sh diff --git a/azure/.vscode/settings.json b/azure/.vscode/settings.json index 33d7c04a..3408e686 100644 --- a/azure/.vscode/settings.json +++ b/azure/.vscode/settings.json @@ -3,7 +3,8 @@ "python.defaultInterpreterPath": "~/.pyenv/versions/3.9.22/azintegrationmanagement/bin/python", "python.analysis.extraPaths": [ "./integration_quickstart/src", - "./logging_install/src" + "./logging_install/src", + "./shared/src" ], "python.analysis.autoSearchPaths": true, "python.terminal.activateEnvironment": true diff --git a/azure/logging_install/README.md b/azure/logging_install/README.md index e7f31e18..10de4c8d 100644 --- a/azure/logging_install/README.md +++ b/azure/logging_install/README.md @@ -12,21 +12,17 @@ During final testing, you should upload the executable into Azure Cloud Shell an See instructions in main `azure` folder ### Testing -Run all tests from the `logging_install` folder: +Run all tests from the `azure` folder: ```bash -python -m pytest tests/ --tb=short +python -m pytest logging_install/tests/ --tb=short ``` ### Build/Ship -Run from the `logging_install` folder: +Run from the `azure` folder: Zip app into a single executable file `dist/azure_logging_install.pyz` ```bash -python -m zipapp src \ - -o dist/azure_logging_install.pyz \ - -p "/usr/bin/env python3" \ - -m "azure_logging_install.main:main" -chmod +x dist/azure_logging_install.pyz +logging_install/build.sh ``` ### Execution diff --git a/azure/logging_install/build.sh b/azure/logging_install/build.sh new file mode 100644 index 00000000..d7d90eb3 --- /dev/null +++ b/azure/logging_install/build.sh @@ -0,0 +1,14 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2 License. + +# This product includes software developed at Datadog (https://www.datadoghq.com/) Copyright 2025 Datadog, Inc. + +rm -rf logging_install/dist/tmp +mkdir -p logging_install/dist/tmp +cp -r shared/src/. logging_install/dist/tmp +cp -r logging_install/src/. logging_install/dist/tmp +python -m zipapp logging_install/dist/tmp \ + -o logging_install/dist/azure_logging_install.pyz \ + -p "/usr/bin/env python3" \ + -m "azure_logging_install.main:main" +chmod +x logging_install/dist/azure_logging_install.pyz +rm -r logging_install/dist/tmp \ No newline at end of file diff --git a/azure/logging_install/pytest.ini b/azure/logging_install/pytest.ini index b6fc30e3..f956a1bc 100644 --- a/azure/logging_install/pytest.ini +++ b/azure/logging_install/pytest.ini @@ -1,2 +1,2 @@ [pytest] -pythonpath=src \ No newline at end of file +pythonpath = src ../shared/src \ No newline at end of file From 7f39ba6c4fae91f520430423f76080ca68996ead Mon Sep 17 00:00:00 2001 From: Ben Johnson-Staub Date: Wed, 8 Oct 2025 16:52:30 -0400 Subject: [PATCH 3/3] Update references in logging install --- .../src/azure_logging_install/configuration.py | 7 ++++--- .../src/azure_logging_install/deploy.py | 5 +++-- .../src/azure_logging_install/existing_lfo.py | 5 +++-- .../src/azure_logging_install/main.py | 7 ++++--- .../src/azure_logging_install/resource_setup.py | 15 ++++++++------- .../src/azure_logging_install/role_setup.py | 8 +++++--- .../src/azure_logging_install/validation.py | 11 ++++++----- azure/logging_install/tests/test_configuration.py | 2 +- azure/logging_install/tests/test_deploy.py | 5 +++-- azure/logging_install/tests/test_existing_lfo.py | 2 +- azure/logging_install/tests/test_main.py | 5 +++-- .../logging_install/tests/test_resource_setup.py | 5 +++-- azure/logging_install/tests/test_validation.py | 13 +++++++------ 13 files changed, 51 insertions(+), 39 deletions(-) diff --git a/azure/logging_install/src/azure_logging_install/configuration.py b/azure/logging_install/src/azure_logging_install/configuration.py index 0bd78639..1a0bb60f 100644 --- a/azure/logging_install/src/azure_logging_install/configuration.py +++ b/azure/logging_install/src/azure_logging_install/configuration.py @@ -6,14 +6,15 @@ import uuid from dataclasses import dataclass -from .az_cmd import AzCmd, execute +from az_shared.az_cmd import AzCmd, execute +from az_shared.errors import FatalError +from az_shared.logs import log + from .constants import ( IMAGE_REGISTRY_URL, NIL_UUID, STORAGE_ACCOUNT_KEY_FULL_PERMISSIONS, ) -from .errors import FatalError -from .logging import log @dataclass diff --git a/azure/logging_install/src/azure_logging_install/deploy.py b/azure/logging_install/src/azure_logging_install/deploy.py index 5523cc57..d08d52a8 100644 --- a/azure/logging_install/src/azure_logging_install/deploy.py +++ b/azure/logging_install/src/azure_logging_install/deploy.py @@ -2,8 +2,9 @@ # This product includes software developed at Datadog (https://www.datadoghq.com/) Copyright 2025 Datadog, Inc. -from .az_cmd import AzCmd, execute, set_subscription -from .logging import log +from az_shared.az_cmd import AzCmd, execute, set_subscription +from az_shared.logs import log + from .configuration import Configuration from .resource_setup import ( create_blob_container, diff --git a/azure/logging_install/src/azure_logging_install/existing_lfo.py b/azure/logging_install/src/azure_logging_install/existing_lfo.py index 662dbfbd..1b1566a6 100644 --- a/azure/logging_install/src/azure_logging_install/existing_lfo.py +++ b/azure/logging_install/src/azure_logging_install/existing_lfo.py @@ -6,9 +6,10 @@ from json import JSONDecodeError, loads from typing import Final, Optional -from .az_cmd import AzCmd, execute +from az_shared.az_cmd import AzCmd, execute +from az_shared.logs import log, log_header + from .configuration import Configuration -from .logging import log, log_header from .resource_setup import set_function_app_env_vars from .role_setup import grant_subscriptions_permissions diff --git a/azure/logging_install/src/azure_logging_install/main.py b/azure/logging_install/src/azure_logging_install/main.py index 533e42d7..37365943 100644 --- a/azure/logging_install/src/azure_logging_install/main.py +++ b/azure/logging_install/src/azure_logging_install/main.py @@ -8,7 +8,10 @@ import logging from logging import basicConfig -from .az_cmd import list_users_subscriptions, set_subscription +from az_shared.az_cmd import list_users_subscriptions, set_subscription +from az_shared.errors import InputParamValidationError +from az_shared.logs import log, log_header + from .configuration import Configuration from .deploy import deploy_control_plane, run_initial_deploy from .resource_setup import create_resource_group @@ -19,9 +22,7 @@ validate_az_cli, validate_singleton_lfo, ) -from .errors import InputParamValidationError from .existing_lfo import update_existing_lfo -from .logging import log, log_header SKIP_SINGLETON_CHECK = False diff --git a/azure/logging_install/src/azure_logging_install/resource_setup.py b/azure/logging_install/src/azure_logging_install/resource_setup.py index 22d108ce..4e760100 100644 --- a/azure/logging_install/src/azure_logging_install/resource_setup.py +++ b/azure/logging_install/src/azure_logging_install/resource_setup.py @@ -8,19 +8,20 @@ import tempfile from time import time, sleep -from .az_cmd import AzCmd, execute +from az_shared.az_cmd import AzCmd, execute +from az_shared.errors import ( + ExistenceCheckError, + FatalError, + ResourceNotFoundError, +) +from az_shared.logs import log + from .configuration import Configuration -from .logging import log from .constants import ( CONTROL_PLANE_CACHE, IMAGE_REGISTRY_URL, LFO_PUBLIC_STORAGE_ACCOUNT_URL, ) -from .errors import ( - ExistenceCheckError, - FatalError, - ResourceNotFoundError, -) # ============================================================================= # Subscription, Resource Group, Storage Account diff --git a/azure/logging_install/src/azure_logging_install/role_setup.py b/azure/logging_install/src/azure_logging_install/role_setup.py index e2eb580a..dea1092f 100644 --- a/azure/logging_install/src/azure_logging_install/role_setup.py +++ b/azure/logging_install/src/azure_logging_install/role_setup.py @@ -6,9 +6,12 @@ import time from typing import Iterable -from .az_cmd import AzCmd, execute, set_subscription +from az_shared.az_cmd import AzCmd, execute, set_subscription +from az_shared.errors import ExistenceCheckError, ResourceNotFoundError, TimeoutError +from az_shared.logs import log + from .configuration import Configuration -from .logging import log + from .constants import ( INITIAL_DEPLOY_IDENTITY_NAME, MONITORING_CONTRIBUTOR_ID, @@ -17,7 +20,6 @@ STORAGE_READER_AND_DATA_ACCESS_ID, WEBSITE_CONTRIBUTOR_ID, ) -from .errors import ExistenceCheckError, ResourceNotFoundError, TimeoutError def create_initial_deploy_identity(control_plane_rg: str, control_plane_region: str): diff --git a/azure/logging_install/src/azure_logging_install/validation.py b/azure/logging_install/src/azure_logging_install/validation.py index 6a827770..2c95665a 100644 --- a/azure/logging_install/src/azure_logging_install/validation.py +++ b/azure/logging_install/src/azure_logging_install/validation.py @@ -8,18 +8,19 @@ import sys from dataclasses import asdict -from .az_cmd import AzCmd, execute, set_subscription -from .configuration import Configuration -from .constants import REQUIRED_RESOURCE_PROVIDERS -from .errors import ( +from az_shared.az_cmd import AzCmd, execute, set_subscription +from az_shared.errors import ( AccessError, DatadogAccessValidationError, ExistenceCheckError, InputParamValidationError, ResourceProviderRegistrationValidationError, ) +from az_shared.logs import log + +from .configuration import Configuration +from .constants import REQUIRED_RESOURCE_PROVIDERS from .existing_lfo import check_existing_lfo, LfoMetadata -from .logging import log def validate_user_parameters(config: Configuration): diff --git a/azure/logging_install/tests/test_configuration.py b/azure/logging_install/tests/test_configuration.py index bcd91f1a..bfc743ac 100644 --- a/azure/logging_install/tests/test_configuration.py +++ b/azure/logging_install/tests/test_configuration.py @@ -10,7 +10,7 @@ # project from azure_logging_install.configuration import Configuration -from tests.test_data import ( +from logging_install.tests.test_data import ( CONTROL_PLANE_REGION, CONTROL_PLANE_SUBSCRIPTION_ID, CONTROL_PLANE_RESOURCE_GROUP, diff --git a/azure/logging_install/tests/test_deploy.py b/azure/logging_install/tests/test_deploy.py index a806ae4c..93aaeaaa 100644 --- a/azure/logging_install/tests/test_deploy.py +++ b/azure/logging_install/tests/test_deploy.py @@ -7,11 +7,12 @@ from unittest.mock import patch as mock_patch, MagicMock # project +from az_shared.errors import FatalError + from azure_logging_install import deploy from azure_logging_install.configuration import Configuration -from azure_logging_install.errors import FatalError -from tests.test_data import ( +from logging_install.tests.test_data import ( CONTROL_PLANE_REGION, CONTROL_PLANE_SUBSCRIPTION_ID, CONTROL_PLANE_RESOURCE_GROUP, diff --git a/azure/logging_install/tests/test_existing_lfo.py b/azure/logging_install/tests/test_existing_lfo.py index d4ec16e5..e22b2470 100644 --- a/azure/logging_install/tests/test_existing_lfo.py +++ b/azure/logging_install/tests/test_existing_lfo.py @@ -19,7 +19,7 @@ ) from azure_logging_install.configuration import Configuration -from tests.test_data import ( +from logging_install.tests.test_data import ( CONTROL_PLANE_REGION, CONTROL_PLANE_SUBSCRIPTION_ID, CONTROL_PLANE_RESOURCE_GROUP, diff --git a/azure/logging_install/tests/test_main.py b/azure/logging_install/tests/test_main.py index 01fa92f1..e48b043c 100644 --- a/azure/logging_install/tests/test_main.py +++ b/azure/logging_install/tests/test_main.py @@ -7,15 +7,16 @@ from unittest.mock import patch as mock_patch, MagicMock # project +from az_shared.errors import FatalError, InputParamValidationError + from azure_logging_install import main -from azure_logging_install.errors import FatalError, InputParamValidationError from azure_logging_install.existing_lfo import ( LfoMetadata, LfoControlPlane, update_existing_lfo, ) -from tests.test_data import ( +from logging_install.tests.test_data import ( CONTROL_PLANE_ID, CONTROL_PLANE_REGION, CONTROL_PLANE_SUBSCRIPTION_ID, diff --git a/azure/logging_install/tests/test_resource_setup.py b/azure/logging_install/tests/test_resource_setup.py index 8eb1ddbc..738d351c 100644 --- a/azure/logging_install/tests/test_resource_setup.py +++ b/azure/logging_install/tests/test_resource_setup.py @@ -7,11 +7,12 @@ from unittest.mock import patch as mock_patch, MagicMock # project +from az_shared.errors import FatalError, ResourceNotFoundError + from azure_logging_install import resource_setup from azure_logging_install.configuration import Configuration -from azure_logging_install.errors import FatalError, ResourceNotFoundError -from tests.test_data import ( +from logging_install.tests.test_data import ( CONTROL_PLANE_REGION, CONTROL_PLANE_RESOURCE_GROUP, ) diff --git a/azure/logging_install/tests/test_validation.py b/azure/logging_install/tests/test_validation.py index 4d6d27a3..27b1db25 100644 --- a/azure/logging_install/tests/test_validation.py +++ b/azure/logging_install/tests/test_validation.py @@ -8,11 +8,7 @@ from unittest.mock import patch as mock_patch, MagicMock # project -from azure_logging_install import validation -from azure_logging_install.existing_lfo import LfoControlPlane -from azure_logging_install.configuration import Configuration -from azure_logging_install.constants import REQUIRED_RESOURCE_PROVIDERS -from azure_logging_install.errors import ( +from az_shared.errors import ( AccessError, DatadogAccessValidationError, ExistenceCheckError, @@ -20,7 +16,12 @@ ResourceProviderRegistrationValidationError, ) -from tests.test_data import ( +from azure_logging_install import validation +from azure_logging_install.existing_lfo import LfoControlPlane +from azure_logging_install.configuration import Configuration +from azure_logging_install.constants import REQUIRED_RESOURCE_PROVIDERS + +from logging_install.tests.test_data import ( CONTROL_PLANE_REGION, CONTROL_PLANE_SUBSCRIPTION_ID, CONTROL_PLANE_SUBSCRIPTION_NAME,