Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion azure/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions azure/logging_install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions azure/logging_install/build.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion azure/logging_install/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[pytest]
pythonpath=src
pythonpath = src ../shared/src
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions azure/logging_install/src/azure_logging_install/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions azure/logging_install/src/azure_logging_install/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down
11 changes: 6 additions & 5 deletions azure/logging_install/src/azure_logging_install/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion azure/logging_install/tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions azure/logging_install/tests/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion azure/logging_install/tests/test_existing_lfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions azure/logging_install/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions azure/logging_install/tests/test_resource_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
13 changes: 7 additions & 6 deletions azure/logging_install/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
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,
InputParamValidationError,
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,
Expand Down
2 changes: 2 additions & 0 deletions azure/shared/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
pythonpath=src
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
RefreshTokenError,
ResourceNotFoundError,
)
from .logging import log
from .logs import log


AUTH_FAILED_ERROR = "AuthorizationFailed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"""
Expand Down
9 changes: 9 additions & 0 deletions azure/shared/tests/test_data.py
Original file line number Diff line number Diff line change
@@ -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"