Skip to content

Commit

Permalink
fix config-option name in charm_state.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cbartz committed Jul 3, 2024
1 parent 38ee335 commit bd5a470
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src-docs/charm_state.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ State of the Charm.
- **OPENSTACK_IMAGE_BUILD_UNIT_CONFIG_NAME**
- **PATH_CONFIG_NAME**
- **RECONCILE_INTERVAL_CONFIG_NAME**
- **REACTIVE_MQ_URI_CONFIG_NAME**
- **REACTIVE_MQ_DB_NAME_CONFIG_NAME**
- **REPO_POLICY_COMPLIANCE_TOKEN_CONFIG_NAME**
- **REPO_POLICY_COMPLIANCE_URL_CONFIG_NAME**
- **RUNNER_STORAGE_CONFIG_NAME**
Expand Down
6 changes: 3 additions & 3 deletions src/charm_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
OPENSTACK_IMAGE_BUILD_UNIT_CONFIG_NAME = "experimental-openstack-image-build-unit"
PATH_CONFIG_NAME = "path"
RECONCILE_INTERVAL_CONFIG_NAME = "reconcile-interval"
REACTIVE_MQ_URI_CONFIG_NAME = "experimental-reactive-mq-uri"
REACTIVE_MQ_DB_NAME_CONFIG_NAME = "experimental-reactive-mq-database-name"
# bandit thinks this is a hardcoded password
REPO_POLICY_COMPLIANCE_TOKEN_CONFIG_NAME = "repo-policy-compliance-token" # nosec
REPO_POLICY_COMPLIANCE_URL_CONFIG_NAME = "repo-policy-compliance-url"
Expand Down Expand Up @@ -974,7 +974,7 @@ def from_charm(cls, charm: CharmBase) -> "ReactiveConfig | None":
MissingIntegrationError: If the reactive MQ integration is missing.
MissingIntegrationDataError: If the respective reactive MQ integration data is missing.
"""
db_name = cast(str, charm.config.get(REACTIVE_MQ_URI_CONFIG_NAME, ""))
db_name = cast(str, charm.config.get(REACTIVE_MQ_DB_NAME_CONFIG_NAME, ""))
integration_existing = bool(charm.model.relations.get(MONGO_DB_INTEGRATION_NAME))

if not (db_name or integration_existing):
Expand All @@ -984,7 +984,7 @@ def from_charm(cls, charm: CharmBase) -> "ReactiveConfig | None":
raise MissingIntegrationError(f"Missing {MONGO_DB_INTEGRATION_NAME} integration")

if not db_name:
raise CharmConfigInvalidError(f"Missing {REACTIVE_MQ_URI_CONFIG_NAME} configuration")
raise CharmConfigInvalidError(f"Missing {REACTIVE_MQ_DB_NAME_CONFIG_NAME} configuration")

database_requires = DatabaseRequires(
charm, relation_name=MONGO_DB_INTEGRATION_NAME, database_name=db_name
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
OPENSTACK_IMAGE_BUILD_UNIT_CONFIG_NAME,
OPENSTACK_NETWORK_CONFIG_NAME,
PATH_CONFIG_NAME,
REACTIVE_MQ_URI_CONFIG_NAME,
REACTIVE_MQ_DB_NAME_CONFIG_NAME,
RECONCILE_INTERVAL_CONFIG_NAME,
RUNNER_STORAGE_CONFIG_NAME,
TEST_MODE_CONFIG_NAME,
Expand Down Expand Up @@ -139,7 +139,7 @@ class Meta:
OPENSTACK_IMAGE_BUILD_UNIT_CONFIG_NAME: -1,
PATH_CONFIG_NAME: factory.Sequence(lambda n: f"mock_path_{n}"),
RECONCILE_INTERVAL_CONFIG_NAME: 10,
REACTIVE_MQ_URI_CONFIG_NAME: "",
REACTIVE_MQ_DB_NAME_CONFIG_NAME: "",
RUNNER_STORAGE_CONFIG_NAME: "juju-storage",
TEST_MODE_CONFIG_NAME: "",
TOKEN_CONFIG_NAME: factory.Sequence(lambda n: f"mock_token_{n}"),
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_charm_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ def test_reactive_config_from_charm():
}
mock_charm.model.relations[charm_state.MONGO_DB_INTEGRATION_NAME] = [relation_mock]
db_name = secrets.token_hex(8)
mock_charm.config[charm_state.REACTIVE_MQ_URI_CONFIG_NAME] = db_name
mock_charm.config[charm_state.REACTIVE_MQ_DB_NAME_CONFIG_NAME] = db_name

connection_info = charm_state.ReactiveConfig.from_charm(mock_charm)

Expand Down Expand Up @@ -957,7 +957,7 @@ def test_reactive_config_from_charm_integration_missing():
"""
mock_charm = MockGithubRunnerCharmFactory()
db_name = secrets.token_hex(8)
mock_charm.config[charm_state.REACTIVE_MQ_URI_CONFIG_NAME] = db_name
mock_charm.config[charm_state.REACTIVE_MQ_DB_NAME_CONFIG_NAME] = db_name

del mock_charm.model.relations[charm_state.MONGO_DB_INTEGRATION_NAME]

Expand All @@ -983,7 +983,7 @@ def test_reactive_config_from_charm_reactive_config_missing():
with pytest.raises(CharmConfigInvalidError) as exc:
charm_state.ReactiveConfig.from_charm(mock_charm)

assert f"Missing {charm_state.REACTIVE_MQ_URI_CONFIG_NAME} configuration" in str(exc.value)
assert f"Missing {charm_state.REACTIVE_MQ_DB_NAME_CONFIG_NAME} configuration" in str(exc.value)


def test_reactive_config_from_charm_integration_data_missing():
Expand All @@ -1000,7 +1000,7 @@ def test_reactive_config_from_charm_integration_data_missing():
mock_charm.model.relations[charm_state.MONGO_DB_INTEGRATION_NAME] = [relation_mock]

db_name = secrets.token_hex(8)
mock_charm.config[charm_state.REACTIVE_MQ_URI_CONFIG_NAME] = db_name
mock_charm.config[charm_state.REACTIVE_MQ_DB_NAME_CONFIG_NAME] = db_name

with pytest.raises(MissingIntegrationDataError) as exc:
charm_state.ReactiveConfig.from_charm(mock_charm)
Expand Down

0 comments on commit bd5a470

Please sign in to comment.