Skip to content

Commit 89d3016

Browse files
committed
Merge branch 'ADCM-5586' into 'develop'
ADCM-5586 Replace `add_hostcomponent_map` with `set_hostcomponent` See merge request arenadata/development/adcm!3867
2 parents 94cb163 + 2e22457 commit 89d3016

File tree

13 files changed

+47
-192
lines changed

13 files changed

+47
-192
lines changed

python/adcm/tests/base.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from pathlib import Path
1616
from shutil import rmtree
1717
from tempfile import mkdtemp
18-
from typing import Callable, Iterable, TypedDict
18+
from typing import Callable, Iterable
1919
import random
2020
import string
2121
import tarfile
@@ -77,12 +77,6 @@ class TestUserCreateDTO(UserCreateDTO):
7777
password: str = ""
7878

7979

80-
class HostComponentMapDictType(TypedDict):
81-
host_id: int
82-
service_id: int
83-
component_id: int
84-
85-
8680
class ParallelReadyTestCase:
8781
def __init_subclass__(cls, **kwargs):
8882
super().__init_subclass__(**kwargs)
@@ -492,10 +486,6 @@ def add_services_to_cluster(service_names: list[str], cluster: Cluster) -> Query
492486
)
493487
return bulk_add_services_to_cluster(cluster=cluster, prototypes=service_prototypes)
494488

495-
@staticmethod
496-
def add_hostcomponent_map(cluster: Cluster, hc_map: list[HostComponentMapDictType]) -> list[HostComponent]:
497-
return add_hc(cluster=cluster, hc_in=hc_map)
498-
499489
@staticmethod
500490
def set_hostcomponent(cluster: Cluster, entries: Iterable[tuple[Host, ServiceComponent]]) -> list[HostComponent]:
501491
return add_hc(

python/api_v2/tests/test_audit/test_group_config.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,7 @@ def setUp(self) -> None:
6767
object_type=ContentType.objects.get_for_model(self.provider),
6868
object_id=self.provider.pk,
6969
)
70-
self.add_hostcomponent_map(
71-
cluster=self.cluster_1,
72-
hc_map=[
73-
{
74-
"host_id": self.host_for_service.pk,
75-
"service_id": self.service_1.pk,
76-
"component_id": self.component_1.pk,
77-
}
78-
],
79-
)
70+
self.set_hostcomponent(cluster=self.cluster_1, entries=[(self.host_for_service, self.component_1)])
8071
self.cluster_config_data = {
8172
"config": {
8273
"activatable_group": {"integer": 100},

python/api_v2/tests/test_cluster.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212

13-
from typing import Iterable
1413
from unittest.mock import patch
1514

16-
from cm.api import add_hc
15+
from adcm.tests.base import BusinessLogicMixin
1716
from cm.models import (
1817
Action,
1918
ADCMEntityStatus,
2019
Cluster,
2120
ClusterObject,
2221
Host,
23-
HostComponent,
2422
Prototype,
2523
ServiceComponent,
2624
)
@@ -608,17 +606,7 @@ def test_adcm_5051_post_change_mm_perm_wrong_object_fail(self):
608606
self.assertEqual(response.status_code, HTTP_404_NOT_FOUND)
609607

610608

611-
class TestClusterStatuses(BaseAPITestCase):
612-
@staticmethod
613-
def set_hostcomponent(cluster: Cluster, entries: Iterable[tuple[Host, ServiceComponent]]) -> list[HostComponent]:
614-
return add_hc(
615-
cluster=cluster,
616-
hc_in=[
617-
{"host_id": host.pk, "component_id": component.pk, "service_id": component.service_id}
618-
for host, component in entries
619-
],
620-
)
621-
609+
class TestClusterStatuses(BaseAPITestCase, BusinessLogicMixin):
622610
def setUp(self) -> None:
623611
self.client.login(username="admin", password="admin")
624612

python/api_v2/tests/test_group_config.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,7 @@ def setUp(self) -> None:
7878
self.component_2 = ServiceComponent.objects.get(
7979
cluster=self.cluster_1, service=self.service_1, prototype__name="component_2"
8080
)
81-
self.add_hostcomponent_map(
82-
cluster=self.cluster_1,
83-
hc_map=[
84-
{
85-
"host_id": self.host_for_service.pk,
86-
"service_id": self.service_1.pk,
87-
"component_id": self.component_1.pk,
88-
}
89-
],
90-
)
81+
self.set_hostcomponent(cluster=self.cluster_1, entries=[(self.host_for_service, self.component_1)])
9182

9283

9384
class TestGroupConfigNaming(BaseServiceGroupConfigTestCase):
@@ -630,16 +621,7 @@ def setUp(self) -> None:
630621
bundle=self.provider_bundle, provider=self.provider, fqdn="host_for_component"
631622
)
632623
self.add_host_to_cluster(cluster=self.cluster_1, host=self.host_for_component)
633-
self.add_hostcomponent_map(
634-
cluster=self.cluster_1,
635-
hc_map=[
636-
{
637-
"host_id": self.host_for_component.pk,
638-
"service_id": self.service_1.pk,
639-
"component_id": self.component_1.pk,
640-
}
641-
],
642-
)
624+
self.set_hostcomponent(cluster=self.cluster_1, entries=[(self.host_for_component, self.component_1)])
643625

644626
def test_list_success(self):
645627
response = self.client.v2[self.component_1, CONFIG_GROUPS].get()

python/api_v2/tests/test_host.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -700,29 +700,13 @@ def setUp(self) -> None:
700700
self.component_2 = ServiceComponent.objects.get(
701701
cluster=self.cluster_1, service=self.service_1, prototype__name="component_2"
702702
)
703-
self.add_hostcomponent_map(
703+
self.set_hostcomponent(
704704
cluster=self.cluster_1,
705-
hc_map=[
706-
{
707-
"host_id": self.host_1.pk,
708-
"service_id": self.service_1.pk,
709-
"component_id": self.component_1.pk,
710-
},
711-
{
712-
"host_id": self.host_1.pk,
713-
"service_id": self.service_1.pk,
714-
"component_id": self.component_2.pk,
715-
},
716-
{
717-
"host_id": self.host_2.pk,
718-
"service_id": self.service_1.pk,
719-
"component_id": self.component_1.pk,
720-
},
721-
{
722-
"host_id": self.host_2.pk,
723-
"service_id": self.service_1.pk,
724-
"component_id": self.component_2.pk,
725-
},
705+
entries=[
706+
(self.host_1, self.component_1),
707+
(self.host_1, self.component_2),
708+
(self.host_2, self.component_1),
709+
(self.host_2, self.component_2),
726710
],
727711
)
728712

python/api_v2/tests/test_maintenance_mode.py

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ def test_no_task_run_without_hc_service(self):
7373

7474
def test_task_run_if_hc_exists_service(self):
7575
self.add_host_to_cluster(cluster=self.cluster, host=self.host)
76-
self.add_hostcomponent_map(
77-
cluster=self.cluster,
78-
hc_map=[{"host_id": self.host.pk, "service_id": self.service.pk, "component_id": self.component.pk}],
79-
)
76+
self.set_hostcomponent(cluster=self.cluster, entries=[(self.host, self.component)])
8077

8178
response, run_task_mock = self._do_change_mm_request(obj=self.service)
8279

@@ -100,10 +97,7 @@ def test_no_task_run_without_hc_component(self):
10097

10198
def test_task_run_if_hc_exists_component(self):
10299
self.add_host_to_cluster(cluster=self.cluster, host=self.host)
103-
self.add_hostcomponent_map(
104-
cluster=self.cluster,
105-
hc_map=[{"host_id": self.host.pk, "service_id": self.service.pk, "component_id": self.component.pk}],
106-
)
100+
self.set_hostcomponent(cluster=self.cluster, entries=[(self.host, self.component)])
107101

108102
response, run_task_mock = self._do_change_mm_request(obj=self.component)
109103

@@ -128,10 +122,7 @@ def test_task_run_if_obj_is_host_without_hc(self):
128122

129123
def test_task_run_if_obj_is_host_hc_exists(self):
130124
self.add_host_to_cluster(cluster=self.cluster, host=self.host)
131-
self.add_hostcomponent_map(
132-
cluster=self.cluster,
133-
hc_map=[{"host_id": self.host.pk, "service_id": self.service.pk, "component_id": self.component.pk}],
134-
)
125+
self.set_hostcomponent(cluster=self.cluster, entries=[(self.host, self.component)])
135126

136127
response, run_task_mock = self._do_change_mm_request(obj=self.host)
137128

@@ -144,10 +135,7 @@ def test_task_run_if_obj_is_host_hc_exists(self):
144135

145136
def test_mm_not_changed_on_fail_service(self):
146137
self.add_host_to_cluster(cluster=self.cluster, host=self.host)
147-
self.add_hostcomponent_map(
148-
cluster=self.cluster,
149-
hc_map=[{"host_id": self.host.pk, "service_id": self.service.pk, "component_id": self.component.pk}],
150-
)
138+
self.set_hostcomponent(cluster=self.cluster, entries=[(self.host, self.component)])
151139
initial_object_mm = self.service.maintenance_mode
152140

153141
response, run_task_mock = self._do_change_mm_request(
@@ -167,10 +155,7 @@ def test_mm_not_changed_on_fail_service(self):
167155

168156
def test_mm_not_changed_on_fail_component(self):
169157
self.add_host_to_cluster(cluster=self.cluster, host=self.host)
170-
self.add_hostcomponent_map(
171-
cluster=self.cluster,
172-
hc_map=[{"host_id": self.host.pk, "service_id": self.service.pk, "component_id": self.component.pk}],
173-
)
158+
self.set_hostcomponent(cluster=self.cluster, entries=[(self.host, self.component)])
174159
initial_object_mm = self.component.maintenance_mode
175160

176161
response, run_task_mock = self._do_change_mm_request(
@@ -190,10 +175,7 @@ def test_mm_not_changed_on_fail_component(self):
190175

191176
def test_mm_not_changed_on_fail_host(self):
192177
self.add_host_to_cluster(cluster=self.cluster, host=self.host)
193-
self.add_hostcomponent_map(
194-
cluster=self.cluster,
195-
hc_map=[{"host_id": self.host.pk, "service_id": self.service.pk, "component_id": self.component.pk}],
196-
)
178+
self.set_hostcomponent(cluster=self.cluster, entries=[(self.host, self.component)])
197179
initial_object_mm = self.host.maintenance_mode
198180

199181
response, run_task_mock = self._do_change_mm_request(

python/api_v2/tests/test_mapping.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ def setUp(self) -> None:
5353
cluster=self.cluster_1, service=self.service_1, prototype__name="component_2"
5454
)
5555

56-
self.add_hostcomponent_map(
57-
cluster=self.cluster_1,
58-
hc_map=[{"host_id": self.host_1.pk, "service_id": self.service_1.pk, "component_id": self.component_1.pk}],
59-
)
56+
self.set_hostcomponent(cluster=self.cluster_1, entries=[(self.host_1, self.component_1)])
6057

6158
self.test_user_credentials = {"username": "test_user_username", "password": "test_user_password"}
6259
self.test_user = self.create_user(**self.test_user_credentials)

python/api_v2/tests/test_service.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,7 @@ def setUp(self) -> None:
337337
bundle=self.provider_bundle, provider=self.provider, fqdn="doesntmatter_2", cluster=self.cluster_1
338338
)
339339
component = ServiceComponent.objects.filter(cluster_id=self.cluster_1.pk, service_id=self.service.pk).last()
340-
self.add_hostcomponent_map(
341-
cluster=self.cluster_1,
342-
hc_map=[
343-
{
344-
"host_id": self.host_with_component.pk,
345-
"service_id": self.service.pk,
346-
"component_id": component.pk,
347-
}
348-
],
349-
)
340+
self.set_hostcomponent(cluster=self.cluster_1, entries=[(self.host_with_component, component)])
350341

351342
def test_adcm_5278_cluster_hosts_restriction_by_service_administrator_ownership_success(self):
352343
response_list = self.client.v2[self.cluster_1, "hosts"].get()

python/cm/tests/test_ansible_plugins/test_maintenance_mode.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,7 @@ def setUp(self) -> None:
3232
provider_bundle = self.add_bundle(source_dir=bundles_dir / "provider")
3333
provider = self.add_provider(bundle=provider_bundle, name="test_provider")
3434
self.host = self.add_host(bundle=provider_bundle, provider=provider, fqdn="test_host", cluster=self.cluster)
35-
self.add_hostcomponent_map(
36-
cluster=self.cluster,
37-
hc_map=[
38-
{
39-
"host_id": self.host.pk,
40-
"service_id": self.service.pk,
41-
"component_id": self.component.pk,
42-
}
43-
],
44-
)
35+
self.set_hostcomponent(cluster=self.cluster, entries=[(self.host, self.component)])
4536

4637
def _set_objects_mm(
4738
self,

python/cm/tests/test_inventory/base.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
from jinja2 import Template
2222

2323
from cm.adcm_config.ansible import ansible_decrypt
24-
from cm.api import add_hc
2524
from cm.converters import model_name_to_core_type
2625
from cm.models import (
2726
Action,
2827
ADCMEntity,
2928
ADCMModel,
30-
Cluster,
3129
ClusterObject,
3230
GroupConfig,
3331
Host,
@@ -83,16 +81,6 @@ def check_hosts_topology(self, data: Mapping[str, dict], expected: Mapping[str,
8381
for group_name, host_names in expected.items():
8482
self.assertSetEqual(set(data[group_name]["hosts"].keys()), set(host_names))
8583

86-
@staticmethod
87-
def set_hostcomponent(cluster: Cluster, entries: Iterable[tuple[Host, ServiceComponent]]) -> list[HostComponent]:
88-
return add_hc(
89-
cluster=cluster,
90-
hc_in=[
91-
{"host_id": host.pk, "component_id": component.pk, "service_id": component.service_id}
92-
for host, component in entries
93-
],
94-
)
95-
9684
def check_data_by_template(self, data: Mapping[str, dict], templates_data: TemplatesData) -> None:
9785
for key_chain, template_data in templates_data.items():
9886
template_path, kwargs = template_data
@@ -130,9 +118,9 @@ def add_group_config(parent: ADCMModel, hosts: Iterable[Host]) -> GroupConfig:
130118

131119
@staticmethod
132120
def get_mapping_delta_for_hc_acl(cluster, new_mapping: list[MappingEntry]) -> Delta:
133-
existing_mapping_ids = {
134-
(hc.host.pk, hc.component.pk, hc.service.pk) for hc in HostComponent.objects.filter(cluster=cluster)
135-
}
121+
existing_mapping_ids = set(
122+
HostComponent.objects.values_list("host_id", "component_id", "service_id").filter(cluster=cluster)
123+
)
136124
new_mapping_ids = {(hc["host_id"], hc["component_id"], hc["service_id"]) for hc in new_mapping}
137125

138126
added = {}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy