Updates from Production Scripts
Made a bunch of tweaks when using these tests to run production scripts for initial setup, this brings over a bunch of those changes
This commit is contained in:
parent
becc3630c2
commit
d646c3c00f
@ -235,6 +235,7 @@ class BillingProfileCLINBudget(AliasModel):
|
|||||||
class BillingProfileCSPPayload(BaseCSPPayload):
|
class BillingProfileCSPPayload(BaseCSPPayload):
|
||||||
tenant_id: str
|
tenant_id: str
|
||||||
billing_profile_display_name: str
|
billing_profile_display_name: str
|
||||||
|
billing_account_name: str
|
||||||
enabled_azure_plans: Optional[List[str]]
|
enabled_azure_plans: Optional[List[str]]
|
||||||
address: BillingProfileAddress
|
address: BillingProfileAddress
|
||||||
|
|
||||||
@ -321,7 +322,7 @@ class TaskOrderBillingCSPPayload(BaseCSPPayload):
|
|||||||
|
|
||||||
|
|
||||||
class EnableTaskOrderBillingCSPResult(AliasModel):
|
class EnableTaskOrderBillingCSPResult(AliasModel):
|
||||||
task_order_billing_validation_url: str
|
task_order_billing_validate_url: str
|
||||||
retry_after: int
|
retry_after: int
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@ -331,8 +332,8 @@ class EnableTaskOrderBillingCSPResult(AliasModel):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class TaskOrderBillingCSPResult(BaseCSPPayload):
|
class VerifyTaskOrderBillingCSPPayload(BaseCSPPayload):
|
||||||
task_order_billing_validation_url: str
|
task_order_billing_validate_url: str
|
||||||
|
|
||||||
|
|
||||||
class BillingProfileEnabledPlanDetails(AliasModel):
|
class BillingProfileEnabledPlanDetails(AliasModel):
|
||||||
@ -754,7 +755,7 @@ class AzureSDKProvider(object):
|
|||||||
import azure.graphrbac as graphrbac
|
import azure.graphrbac as graphrbac
|
||||||
import azure.common.credentials as credentials
|
import azure.common.credentials as credentials
|
||||||
import azure.identity as identity
|
import azure.identity as identity
|
||||||
from azure.keyvault import secrets import secrets
|
from azure.keyvault import secrets
|
||||||
|
|
||||||
from msrestazure.azure_cloud import AZURE_PUBLIC_CLOUD
|
from msrestazure.azure_cloud import AZURE_PUBLIC_CLOUD
|
||||||
import adal
|
import adal
|
||||||
@ -896,11 +897,8 @@ class AzureCloudProvider(CloudProviderInterface):
|
|||||||
headers=create_tenant_headers,
|
headers=create_tenant_headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
print("create tenant result")
|
|
||||||
print(result.json())
|
|
||||||
|
|
||||||
if result.status_code == 200:
|
if result.status_code == 200:
|
||||||
return self._ok(TenantCSPResult(**result.json()))
|
return self._ok(TenantCSPResult(**result.json(), tenant_admin_password=payload.password, tenant_admin_username=payload.user_id))
|
||||||
else:
|
else:
|
||||||
return self._error(result.json())
|
return self._error(result.json())
|
||||||
|
|
||||||
@ -917,9 +915,7 @@ class AzureCloudProvider(CloudProviderInterface):
|
|||||||
"Authorization": f"Bearer {sp_token}",
|
"Authorization": f"Bearer {sp_token}",
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: unsure if this is a static value or needs to be constructed/configurable
|
billing_account_create_url = f"https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{payload.billing_account_name}/billingProfiles?api-version=2019-10-01-preview"
|
||||||
BILLING_ACCOUT_NAME = "7c89b735-b22b-55c0-ab5a-c624843e8bf6:de4416ce-acc6-44b1-8122-c87c4e903c91_2019-05-31"
|
|
||||||
billing_account_create_url = f"https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{BILLING_ACCOUT_NAME}/billingProfiles?api-version=2019-10-01-preview"
|
|
||||||
|
|
||||||
result = self.sdk.requests.post(
|
result = self.sdk.requests.post(
|
||||||
billing_account_create_url,
|
billing_account_create_url,
|
||||||
@ -1022,9 +1018,7 @@ class AzureCloudProvider(CloudProviderInterface):
|
|||||||
"Authorization": f"Bearer {sp_token}",
|
"Authorization": f"Bearer {sp_token}",
|
||||||
}
|
}
|
||||||
|
|
||||||
result = self.sdk.requests.get(
|
result = self.sdk.requests.get(payload.task_order_billing_validate_url, headers=auth_header)
|
||||||
payload.task_order_billing_validation_url, headers=auth_header
|
|
||||||
)
|
|
||||||
|
|
||||||
if result.status_code == 202:
|
if result.status_code == 202:
|
||||||
# 202 has location/retry after headers
|
# 202 has location/retry after headers
|
||||||
|
@ -5,31 +5,30 @@ from uuid import uuid4
|
|||||||
|
|
||||||
from atst.domain.csp.cloud import (
|
from atst.domain.csp.cloud import (
|
||||||
AzureCloudProvider,
|
AzureCloudProvider,
|
||||||
TenantCSPResult,
|
|
||||||
TenantCSPPayload,
|
|
||||||
BillingProfileCSPPayload,
|
|
||||||
BillingProfileAddress,
|
|
||||||
BillingProfileCreateCSPResult,
|
BillingProfileCreateCSPResult,
|
||||||
BillingProfileVerifyCSPPayload,
|
BillingProfileCSPPayload,
|
||||||
BillingProfileCSPResult,
|
BillingProfileCSPResult,
|
||||||
BillingRoleAssignmentCSPPayload,
|
BillingProfileTenantAccessCSPPayload,
|
||||||
BillingRoleAssignmentCSPResult,
|
BillingProfileTenantAccessCSPResult,
|
||||||
EnableTaskOrderBillingCSPPayload,
|
BillingProfileVerifyCSPPayload,
|
||||||
VerifyTaskOrderBillingCSPPayload,
|
|
||||||
BillingProfileEnabledCSPResult,
|
|
||||||
ReportCLINCSPPayload,
|
ReportCLINCSPPayload,
|
||||||
ReportCLINCSPResult,
|
ReportCLINCSPResult,
|
||||||
|
TaskOrderBillingCSPPayload,
|
||||||
|
TenantCSPPayload,
|
||||||
|
TenantCSPResult,
|
||||||
|
VerifyTaskOrderBillingCSPPayload,
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests.mock_azure import mock_azure, AUTH_CREDENTIALS
|
from tests.mock_azure import mock_azure, AUTH_CREDENTIALS
|
||||||
from tests.factories import EnvironmentFactory, ApplicationFactory
|
from tests.factories import EnvironmentFactory, ApplicationFactory
|
||||||
|
|
||||||
|
|
||||||
# TODO: Directly test create subscription, provide all args √
|
creds = {
|
||||||
# TODO: Test create environment (create management group with parent)
|
"home_tenant_id": "",
|
||||||
# TODO: Test create application (create manageemnt group with parent)
|
"client_id": "",
|
||||||
# Create reusable mock for mocking the management group calls for multiple services
|
"secret_key": "",
|
||||||
#
|
}
|
||||||
|
BILLING_ACCOUNT_NAME = "52865e4c-52e8-5a6c-da6b-c58f0814f06f:7ea5de9d-b8ce-4901-b1c5-d864320c7b03_2019-05-31"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip("Skipping legacy azure integration tests")
|
@pytest.mark.skip("Skipping legacy azure integration tests")
|
||||||
@ -153,7 +152,7 @@ def test_create_tenant(mock_azure: AzureCloudProvider):
|
|||||||
mock_azure.sdk.requests.post.return_value = mock_result
|
mock_azure.sdk.requests.post.return_value = mock_result
|
||||||
payload = TenantCSPPayload(
|
payload = TenantCSPPayload(
|
||||||
**dict(
|
**dict(
|
||||||
creds={"username": "mock-cloud", "password": "shh"},
|
creds=creds,
|
||||||
user_id="admin",
|
user_id="admin",
|
||||||
password="JediJan13$coot",
|
password="JediJan13$coot",
|
||||||
domain_name="jediccpospawnedtenant2",
|
domain_name="jediccpospawnedtenant2",
|
||||||
@ -192,7 +191,8 @@ def test_create_billing_profile(mock_azure: AzureCloudProvider):
|
|||||||
),
|
),
|
||||||
creds={"username": "mock-cloud", "password": "shh"},
|
creds={"username": "mock-cloud", "password": "shh"},
|
||||||
tenant_id="60ff9d34-82bf-4f21-b565-308ef0533435",
|
tenant_id="60ff9d34-82bf-4f21-b565-308ef0533435",
|
||||||
display_name="Test Billing Profile",
|
billing_profile_display_name="Test Billing Profile",
|
||||||
|
billing_account_name=BILLING_ACCOUNT_NAME,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
result = mock_azure.create_billing_profile(payload)
|
result = mock_azure.create_billing_profile(payload)
|
||||||
@ -250,10 +250,10 @@ def test_validate_billing_profile_creation(mock_azure: AzureCloudProvider):
|
|||||||
)
|
)
|
||||||
|
|
||||||
result = mock_azure.validate_billing_profile_created(payload)
|
result = mock_azure.validate_billing_profile_created(payload)
|
||||||
body: BillingProfileCreateCSPResult = result.get("body")
|
body: BillingProfileCSPResult = result.get("body")
|
||||||
assert body.billing_profile_name == "KQWI-W2SU-BG7-TGB"
|
assert body.billing_profile_name == "KQWI-W2SU-BG7-TGB"
|
||||||
assert (
|
assert (
|
||||||
body.billing_profile_properties.display_name
|
body.billing_profile_properties.billing_profile_display_name
|
||||||
== "First Portfolio Billing Profile"
|
== "First Portfolio Billing Profile"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ def test_create_billing_profile_tenant_access(mock_azure: AzureCloudProvider):
|
|||||||
|
|
||||||
mock_azure.sdk.requests.post.return_value = mock_result
|
mock_azure.sdk.requests.post.return_value = mock_result
|
||||||
|
|
||||||
payload = BillingRoleAssignmentCSPPayload(
|
payload = BillingProfileTenantAccessCSPPayload(
|
||||||
**dict(
|
**dict(
|
||||||
creds={
|
creds={
|
||||||
"username": "username",
|
"username": "username",
|
||||||
@ -296,7 +296,7 @@ def test_create_billing_profile_tenant_access(mock_azure: AzureCloudProvider):
|
|||||||
)
|
)
|
||||||
|
|
||||||
result = mock_azure.create_billing_profile_tenant_access(payload)
|
result = mock_azure.create_billing_profile_tenant_access(payload)
|
||||||
body: BillingRoleAssignmentCSPResult = result.get("body")
|
body: BillingProfileTenantAccessCSPResult = result.get("body")
|
||||||
assert (
|
assert (
|
||||||
body.billing_role_assignment_name
|
body.billing_role_assignment_name
|
||||||
== "40000000-aaaa-bbbb-cccc-100000000000_0a5f4926-e3ee-4f47-a6e3-8b0a30a40e3d"
|
== "40000000-aaaa-bbbb-cccc-100000000000_0a5f4926-e3ee-4f47-a6e3-8b0a30a40e3d"
|
||||||
@ -317,7 +317,7 @@ def test_create_task_order_billing(mock_azure: AzureCloudProvider):
|
|||||||
|
|
||||||
mock_azure.sdk.requests.patch.return_value = mock_result
|
mock_azure.sdk.requests.patch.return_value = mock_result
|
||||||
|
|
||||||
payload = EnableTaskOrderBillingCSPPayload(
|
payload = TaskOrderBillingCSPPayload(
|
||||||
**dict(
|
**dict(
|
||||||
creds={
|
creds={
|
||||||
"username": "username",
|
"username": "username",
|
||||||
@ -388,7 +388,7 @@ def test_validate_task_order_billing_enabled(mock_azure):
|
|||||||
"password": "password",
|
"password": "password",
|
||||||
"tenant_id": "tenant_id",
|
"tenant_id": "tenant_id",
|
||||||
},
|
},
|
||||||
task_order_billing_validation_url="https://management.azure.com/providers/Microsoft.Billing/billingAccounts/7c89b735-b22b-55c0-ab5a-c624843e8bf6:de4416ce-acc6-44b1-8122-c87c4e903c91_2019-05-31/operationResults/createBillingProfile_478d5706-71f9-4a8b-8d4e-2cbaca27a668?api-version=2019-10-01-preview",
|
task_order_billing_validate_url="https://management.azure.com/providers/Microsoft.Billing/billingAccounts/7c89b735-b22b-55c0-ab5a-c624843e8bf6:de4416ce-acc6-44b1-8122-c87c4e903c91_2019-05-31/operationResults/createBillingProfile_478d5706-71f9-4a8b-8d4e-2cbaca27a668?api-version=2019-10-01-preview",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user