-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement bootstrap raft action (#359)
Co-authored-by: Ghislain Bourgeois <[email protected]>
- Loading branch information
1 parent
be4c676
commit 4ac790b
Showing
4 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2025 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
|
||
import ops.testing as testing | ||
import pytest | ||
from charms.vault_k8s.v0.vault_managers import ManagerError | ||
from ops.testing import ActionFailed | ||
|
||
from tests.unit.fixtures import VaultCharmFixtures | ||
|
||
|
||
class TestCharmBootstrapRaftAction(VaultCharmFixtures): | ||
def test_given_no_network_when_bootstrap_raft_action_then_fails(self): | ||
state_in = testing.State( | ||
leader=True, | ||
) | ||
|
||
with pytest.raises(ActionFailed) as e: | ||
self.ctx.run(self.ctx.on.action("bootstrap-raft"), state_in) | ||
assert e.value.message == "Network bind address is not available" | ||
|
||
def test_when_bootstrap_raft_raises_manager_error_then_action_fails_with_error_message(self): | ||
self.mock_raft_manager.bootstrap.side_effect = ManagerError("some error message") | ||
peer_relation = testing.PeerRelation( | ||
endpoint="vault-peers", | ||
) | ||
state_in = testing.State( | ||
leader=False, | ||
relations=[peer_relation], | ||
networks={ | ||
testing.Network( | ||
"vault-peers", | ||
bind_addresses=[testing.BindAddress([testing.Address("1.2.1.2")])], | ||
) | ||
}, | ||
) | ||
|
||
with pytest.raises(ActionFailed) as e: | ||
self.ctx.run(self.ctx.on.action("bootstrap-raft"), state_in) | ||
assert e.value.message == "Failed to bootstrap raft: some error message" |