Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gerd Oberlechner <goberlec@redhat.com>
  • Loading branch information
geoberle committed Mar 4, 2024
1 parent 441a316 commit f5e21ce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion reconcile/ocm_machine_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class NodePool(AbstractPool):
subnet: Optional[str]

def delete(self, ocm: OCM) -> None:
ocm.delete_node_pool(self.cluster, self.dict(by_alias=True))
ocm.delete_node_pool(self.cluster, self.id)

def create(self, ocm: OCM) -> None:
spec = self.dict(by_alias=True)
Expand Down
28 changes: 11 additions & 17 deletions reconcile/test/test_ocm_machine_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ def default_hypershift_worker_machine_pool() -> dict:
"id": "workers",
"instance_type": "m5.xlarge",
"replicas": 2,
"subnet": "subnet-1",
}


Expand All @@ -943,7 +944,7 @@ def expected_node_pool_create_payload() -> dict:
"id": "workers",
"labels": None,
"replicas": 2,
"subnet": None,
"subnet": "subnet-1",
"taints": [],
}

Expand All @@ -970,6 +971,7 @@ def existing_updated_hypershift_node_pools() -> list[dict]:
"id": "workers",
"aws_node_pool": {"instance_type": "m5.xlarge"},
"replicas": 3,
"subnet": "subnet-1",
}
]

Expand Down Expand Up @@ -1020,34 +1022,21 @@ def existing_multiple_hypershift_node_pools() -> list[dict]:
"id": "workers",
"aws_node_pool": {"instance_type": "m5.xlarge"},
"replicas": 3,
"subnet": "subnet-1"
},
{
"id": "new-workers",
"aws_node_pool": {"instance_type": "m5.xlarge"},
"replicas": 3,
"subnet": "subnet-2"
},
]


@pytest.fixture
def expected_hypershift_node_pool_delete_payload() -> dict:
return {
"autoscaling": None,
"cluster": "hypershift-cluster",
"id": "new-workers",
"aws_node_pool": {"instance_type": "m5.xlarge"},
"labels": None,
"replicas": 3,
"subnet": None,
"taints": None,
}


def test_run_delete_node_pool(
mocker: MockerFixture,
hypershift_cluster: ClusterV1,
existing_multiple_hypershift_node_pools: list[dict],
expected_hypershift_node_pool_delete_payload: dict,
) -> None:
mocks = setup_mocks(
mocker,
Expand All @@ -1059,7 +1048,7 @@ def test_run_delete_node_pool(

mocks["OCM"].delete_node_pool.assert_called_once_with(
hypershift_cluster.name,
expected_hypershift_node_pool_delete_payload,
"new-workers",
)


Expand All @@ -1069,6 +1058,7 @@ def non_default_hypershift_worker_machine_pool() -> dict:
"id": "new-workers",
"instance_type": "m5.xlarge",
"replicas": 3,
"subnet": "subnet-3",
}


Expand All @@ -1087,16 +1077,19 @@ def existing_multiple_hypershift_node_pools_with_defaults() -> list[dict]:
"id": "workers",
"aws_node_pool": {"instance_type": "m5.xlarge"},
"replicas": 3,
"subnet": "subnet-1"
},
{
"id": "workers-1",
"aws_node_pool": {"instance_type": "m5.xlarge"},
"replicas": 3,
"subnet": "subnet-2"
},
{
"id": "new-workers",
"aws_node_pool": {"instance_type": "m5.xlarge"},
"replicas": 3,
"subnet": "subnet-3"
},
]

Expand All @@ -1121,6 +1114,7 @@ def test_update_app_interface_with_subnet(
mocker: MockerFixture,
hypershift_cluster: ClusterV1,
) -> None:
hypershift_cluster.machine_pools[0].subnet = None
setup_mocks(
mocker,
clusters=[hypershift_cluster],
Expand Down
3 changes: 1 addition & 2 deletions reconcile/utils/ocm/ocm.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def get_node_pools(self, cluster):

return get_node_pools(self._ocm_client, cluster_id)

def delete_node_pool(self, cluster, spec):
def delete_node_pool(self, cluster, node_pool_id):
"""Deletes an existing Node Pool
:param cluster: cluster name
Expand All @@ -585,7 +585,6 @@ def delete_node_pool(self, cluster, spec):
:type spec: dictionary
"""
cluster_id = self.cluster_ids[cluster]
node_pool_id = spec["id"]
api = f"{CS_API_BASE}/v1/clusters/{cluster_id}/node_pools/" + f"{node_pool_id}"
self._delete(api)

Expand Down

0 comments on commit f5e21ce

Please sign in to comment.