-
Notifications
You must be signed in to change notification settings - Fork 71
Infer datacenter from existing nodes when adding without explicit datacenter #704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: fruch <[email protected]>
Previously, __update_topology_files() was only called when data_center was explicitly provided. This caused issues when adding nodes without specifying data_center, as the cassandra-rackdc.properties file would not be created with default values (dc1, RAC1). The fix moves __update_topology_files() outside the data_center check, ensuring topology files are always updated. The method itself handles None values by using defaults. Fixes issue: "Can't add new node to the cluster if I don't specify data-center explicitly." Co-authored-by: fruch <[email protected]>
ccmlib/cluster.py
Outdated
| if data_center is not None: | ||
| self.debug(f"{node.name}: data_center={node.data_center} rack={node.rack} snitch={self.snitch}") | ||
| self.__update_topology_files() | ||
| self.__update_topology_files() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a good fix, I would expect caching the data center selected on node 1, and passing it along when creating node2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the implementation to infer datacenter from existing nodes rather than always calling __update_topology_files(). When adding a node without specifying datacenter, it now inherits from the first existing node. See commit c5a86b9.
Instead of always defaulting to dc1, the add() method now looks at existing nodes and infers the datacenter from them when not explicitly specified. This ensures that new nodes added to a cluster inherit the datacenter of existing nodes, which is more intuitive behavior. - If datacenter is not specified and there are existing nodes with a datacenter, use theirs - Also infer rack from existing nodes if not specified - Updated tests to verify the new inference behavior Addresses review feedback from @fruch Co-authored-by: fruch <[email protected]>
| from ccmlib.node import Node | ||
|
|
||
|
|
||
| class TestAddNodeWithoutDatacenter: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot please switch to pytest style, using function and fixtures to minimize the code duplication between tests
also on a seperate commit add this comment (about using pytest style) to the instructions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch from class-based tests to function-based tests using pytest fixtures to minimize code duplication and follow pytest best practices: - Use @pytest.fixture for setup (temp_dir, mock_cluster, mock_node) - Convert class methods to standalone test functions - Remove manual try/finally cleanup in favor of fixture teardown - Create factory fixture (mock_node) for creating multiple mock nodes This makes tests more readable and maintainable while keeping the same test coverage and assertions. Co-authored-by: fruch <[email protected]>
This reverts commit 8e79170.
Switch from class-based tests to function-based tests using pytest fixtures to minimize code duplication and follow pytest best practices: - Use @pytest.fixture for setup (temp_dir, mock_cluster, mock_node) - Convert class methods to standalone test functions - Remove manual try/finally cleanup in favor of fixture teardown - Create factory fixture (mock_node) for creating multiple mock nodes This makes tests more readable and maintainable while keeping the same test coverage and assertions.
Document best practices for writing tests in scylla-ccm: - Use function-based tests with pytest fixtures - Create reusable fixtures to minimize code duplication - Use @pytest.fixture decorator for setup/teardown - Prefer fixtures over manual try/finally blocks This provides guidance for contributors to write tests that follow the project's conventions and pytest best practices.
Summary
Fixed the issue by making the
add()method infer datacenter from existing nodes when not explicitly specified. Refactored tests to use pytest best practices with fixtures instead of class-based tests. Added pytest style guidelines to copilot instructions in separate commits as requested.Commit Structure
Changes
Tests now follow pytest best practices with function-based tests and reusable fixtures.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.