Skip to content

Commit ab8921b

Browse files
committed
fix: fix create unified cost error when workspace_id is None
Signed-off-by: ImMin5 <[email protected]>
1 parent 97a9b07 commit ab8921b

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

src/spaceone/cost_analysis/manager/identity_manager.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from typing import Union
23

34
from spaceone.core import cache
45
from spaceone.core import config
@@ -76,7 +77,9 @@ def check_workspace(self, workspace_id: str, domain_id: str) -> None:
7677
@cache.cacheable(
7778
key="cost-analysis:workspace-name:{domain_id}:{workspace_id}:name", expire=300
7879
)
79-
def get_workspace(self, workspace_id: str, domain_id: str) -> str:
80+
def get_workspace(self, workspace_id: Union[str, None], domain_id: str) -> str:
81+
if not workspace_id:
82+
return workspace_id
8083
try:
8184
workspace_info = self.identity_conn.dispatch(
8285
"Workspace.get",

src/spaceone/cost_analysis/manager/unified_cost_manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self, *args, **kwargs):
1717
def create_unified_cost(self, params: dict) -> UnifiedCost:
1818
def _rollback(vo: UnifiedCost):
1919
_LOGGER.info(
20-
f"[create_unified_cost._rollback] Delete unified_cost : {vo.unified_cost_id}, {vo.unified_cost_id} "
20+
f"[create_unified_cost._rollback] Delete unified_cost : {vo.unified_cost_id}, {vo.to_dict()} "
2121
)
2222
vo.delete()
2323

src/spaceone/cost_analysis/model/unified_cost/database.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class UnifiedCost(MongoModel):
2525
service_account_name = StringField(max_length=255)
2626
data_source_name = StringField(max_length=255)
2727
project_name = StringField(max_length=255)
28-
workspace_name = StringField(max_length=255)
28+
workspace_name = StringField(max_length=255, default=None, null=True)
2929
service_account_id = StringField(max_length=40)
3030
data_source_id = StringField(max_length=40)
3131
project_id = StringField(max_length=40, default=None, null=True)

src/spaceone/cost_analysis/service/unified_cost_service.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,15 @@ def create_unified_cost_with_workspace(
327327
exchange_date: datetime,
328328
aggregation_date: datetime,
329329
is_confirmed: bool = False,
330-
):
330+
) -> None:
331+
if workspace_id:
332+
return
333+
331334
identity_mgr = IdentityManager(token=config.get_global("TOKEN"))
332-
workspace_name = identity_mgr.get_workspace(workspace_id, domain_id)
333335
workspace_ids = [workspace_id]
334336

337+
workspace_name = identity_mgr.get_workspace(workspace_id, domain_id)
338+
335339
v_workspace_ids = self._get_virtual_workspace_ids_from_ds_account(
336340
domain_id, workspace_id
337341
)
@@ -421,11 +425,12 @@ def create_unified_cost_with_workspace(
421425
aggregated_unified_cost_data["domain_id"] = domain_id
422426

423427
# set workspace name
424-
aggregated_unified_cost_data["workspace_id"] = workspace_id
425-
aggregated_unified_cost_data["workspace_name"] = workspace_name
428+
if workspace_id:
429+
aggregated_unified_cost_data["workspace_id"] = workspace_id
430+
aggregated_unified_cost_data["workspace_name"] = workspace_name
426431

427432
# set project name
428-
project_id = aggregated_unified_cost_data.get("project_id")
433+
project_id = aggregated_unified_cost_data.get("project_id", None)
429434
aggregated_unified_cost_data["project_name"] = project_name_map.get(
430435
project_id, project_id
431436
)

0 commit comments

Comments
 (0)