Skip to content

Commit

Permalink
Remove deprecated fixtures
Browse files Browse the repository at this point in the history
Signed-off-by: Webster Mudge <[email protected]>
  • Loading branch information
wmudge committed Dec 16, 2024
1 parent 5dcb396 commit 9e4fa4f
Showing 1 changed file with 0 additions and 95 deletions.
95 changes: 0 additions & 95 deletions tests/unit/plugins/modules/service_config/test_service_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,101 +86,6 @@ def zk_service_config(cm_api_client, zk_service, request):
)


@pytest.fixture(scope="module")
def target_service(cm_api_client, base_cluster, request):
api = ServicesResourceApi(cm_api_client)

if os.getenv("CM_SERVICE_NAME", None):
yield api.read_service(
cluster_name=base_cluster.name, service_name=os.getenv("CM_SERVICE_NAME")
)
else:
cluster_api = ClustersResourceApi(cm_api_client)
name = Path(request.node.name).stem + "_zookeeper"

service = ApiService(
name=name,
type="ZOOKEEPER",
)

api.create_services(
cluster_name=base_cluster.name, body=ApiServiceList(items=[service])
)
cluster_api.auto_assign_roles(cluster_name=base_cluster.name)

# configure = cluster_api.auto_configure(cluster_name=target_cluster.name)
wait_for_command(
cm_api_client,
api.first_run(cluster_name=base_cluster.name, service_name=name),
)

yield api.read_service(cluster_name=base_cluster.name, service_name=name)

api.delete_service(cluster_name=base_cluster.name, service_name=name)


@pytest.fixture
def target_service_config(cm_api_client, target_service, request):
marker = request.node.get_closest_marker("prepare")

if marker is None:
raise Exception("No prepare marker found.")
elif "service_config" not in marker.kwargs:
raise Exception("No 'service_config' parameter found.")

service_api = ServicesResourceApi(cm_api_client)

# Retrieve all of the pre-setup configurations
pre = service_api.read_service_config(
cluster_name=target_service.cluster_ref.cluster_name,
service_name=target_service.name,
)

# Set the test configurations
# Do so serially, since a failed update due to defaults (see ApiException) will cause remaining
# configuration entries to not run. Long-term solution is to check-and-set, which is
# what the Ansible modules do...
for k, v in marker.kwargs["service_config"].items():
try:
service_api.update_service_config(
cluster_name=target_service.cluster_ref.cluster_name,
service_name=target_service.name,
message=f"test_service_config::{request.node.name}:set",
body=ApiServiceConfig(items=[ApiConfig(name=k, value=v)]),
)
except ApiException as ae:
if ae.status != 400 or "delete with template" not in str(ae.body):
raise Exception(str(ae))

# Return the targeted service and go run the test
yield target_service

# Retrieve all of the post-setup configurations
post = service_api.read_service_config(
cluster_name=target_service.cluster_ref.cluster_name,
service_name=target_service.name,
)

# Reconcile the configurations
pre_set = set([c.name for c in pre.items])

reconciled = pre.items.copy()
reconciled.extend(
[
ApiConfig(name=k.name, value=None)
for k in post.items
if k.name not in pre_set
]
)

service_api.update_service_config(
cluster_name=target_service.cluster_ref.cluster_name,
service_name=target_service.name,
message=f"test_service_config::{request.node.name}::reset",
body=ApiServiceConfig(items=reconciled),
)


def test_missing_required(conn, module_args):
module_args(conn)

Expand Down

0 comments on commit 9e4fa4f

Please sign in to comment.