Skip to content

Commit 815bcb6

Browse files
committed
feat: 配置平台(CMDB) 相关插件支持 云区域:IP #7432
1 parent bf4e0fa commit 815bcb6

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

pipeline_plugins/components/collections/sites/open/cc/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ def cc_get_host_id_by_innerip(executor, bk_biz_id, ip_list, supplier_account):
121121
hosts = []
122122
c_hosts = []
123123
for host in host_list:
124-
if {host["bk_host_innerip"]: host["bk_cloud_id"]} in hosts:
124+
if {host["bk_host_innerip"]: host.get("bk_cloud_id", "")} in hosts:
125125
c_hosts.append(host["bk_host_innerip"])
126126
else:
127-
hosts.append({host["bk_host_innerip"]: host["bk_cloud_id"]})
127+
hosts.append({host["bk_host_innerip"]: host.get("bk_cloud_id", "")})
128128
if len(c_hosts) > 0:
129129
message = _(f"IP [{', '.join(c_hosts)}] 在本业务下重复: 请检查配置, 修复后重新执行 | cc_get_host_id_by_innerip")
130130
logger.error(message)

pipeline_plugins/tests/components/collections/sites/open/cc/base/test_cc_get_host_id_by_innerip.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
specific language governing permissions and limitations under the License.
1212
"""
1313

14-
from mock import MagicMock, patch
15-
1614
from django.test import TestCase
15+
from mock import MagicMock, patch
1716

1817
from pipeline_plugins.components.collections.sites.open.cc.base import cc_get_host_id_by_innerip
1918

@@ -33,7 +32,11 @@ def test__get_business_host_return_empty(self):
3332
data = cc_get_host_id_by_innerip(self.executor, self.bk_biz_id, self.ip_list, self.supplier_account)
3433

3534
mock_cmdb.get_business_host.assert_called_once_with(
36-
self.executor, self.bk_biz_id, self.supplier_account, ["bk_host_id", "bk_host_innerip"], self.ip_list
35+
self.executor,
36+
self.bk_biz_id,
37+
self.supplier_account,
38+
["bk_host_id", "bk_host_innerip", "bk_cloud_id"],
39+
self.ip_list,
3740
)
3841
self.assertFalse(data["result"])
3942
self.assertEqual(
@@ -55,7 +58,11 @@ def test__return_host_list_gt_ip_list(self):
5558
data = cc_get_host_id_by_innerip(self.executor, self.bk_biz_id, self.ip_list, self.supplier_account)
5659

5760
mock_cmdb.get_business_host.assert_called_once_with(
58-
self.executor, self.bk_biz_id, self.supplier_account, ["bk_host_id", "bk_host_innerip"], self.ip_list
61+
self.executor,
62+
self.bk_biz_id,
63+
self.supplier_account,
64+
["bk_host_id", "bk_host_innerip", "bk_cloud_id"],
65+
self.ip_list,
5966
)
6067
self.assertFalse(data["result"])
6168
self.assertEqual(data["message"], "IP [1.1.1.1, 2.2.2.2] 在本业务下重复: 请检查配置, 修复后重新执行 | cc_get_host_id_by_innerip")
@@ -69,7 +76,11 @@ def test__return_host_list_lt_ip_list(self):
6976
data = cc_get_host_id_by_innerip(self.executor, self.bk_biz_id, self.ip_list, self.supplier_account)
7077

7178
mock_cmdb.get_business_host.assert_called_once_with(
72-
self.executor, self.bk_biz_id, self.supplier_account, ["bk_host_id", "bk_host_innerip"], self.ip_list
79+
self.executor,
80+
self.bk_biz_id,
81+
self.supplier_account,
82+
["bk_host_id", "bk_host_innerip", "bk_cloud_id"],
83+
self.ip_list,
7384
)
7485
self.assertFalse(data["result"])
7586
self.assertEqual(data["message"], "IP [3.3.3.3] 在本业务下不存在: 请检查配置, 修复后重新执行 | cc_get_host_id_by_innerip")
@@ -87,7 +98,11 @@ def test__normal(self):
8798
data = cc_get_host_id_by_innerip(self.executor, self.bk_biz_id, self.ip_list, self.supplier_account)
8899

89100
mock_cmdb.get_business_host.assert_called_once_with(
90-
self.executor, self.bk_biz_id, self.supplier_account, ["bk_host_id", "bk_host_innerip"], self.ip_list
101+
self.executor,
102+
self.bk_biz_id,
103+
self.supplier_account,
104+
["bk_host_id", "bk_host_innerip", "bk_cloud_id"],
105+
self.ip_list,
91106
)
92107
self.assertTrue(data["result"])
93108
self.assertEqual(data["data"], ["1", "2", "3"])

0 commit comments

Comments
 (0)