Update after ops_sunbeam configure_charm changes

* Use a wrapper around the create cell command to
  make it a noop. Otherwise if the cell already
  exists the create cell command throws an
  exception.
* Stop using deprecated use_juju_for_storage=True

Depends-On: I6b46bae1dc700f5e8b597374c660c0af9c069172
Change-Id: I771bb62520e392222e50e80361594f2a58b7f898
This commit is contained in:
Liam Young 2023-02-27 07:33:31 +00:00
parent 2478785684
commit 885ba87f37
3 changed files with 28 additions and 25 deletions
charms/nova-k8s

@ -276,17 +276,7 @@ class NovaOperatorCharm(sunbeam_charm.OSBaseOperatorAPICharm):
cell_database,
],
["sudo", "-u", "nova", "nova-manage", "db", "sync"],
[
"sudo",
"-u",
"nova",
"nova-manage",
"cell_v2",
"create_cell",
"--name",
"cell1",
"--verbose",
],
["/root/cell_create_wrapper.sh", "cell1"],
]
@property
@ -392,6 +382,19 @@ class NovaOperatorCharm(sunbeam_charm.OSBaseOperatorAPICharm):
)
return _cadapters
@property
def container_configs(self) -> List[sunbeam_core.ContainerConfigFile]:
"""Container configuration files for the service."""
_cconfigs = super().container_configs
_cconfigs.extend(
[
sunbeam_core.ContainerConfigFile(
"/root/cell_create_wrapper.sh", "root", "root", 0o755
)
]
)
return _cconfigs
def get_shared_metadatasecret(self):
"""Return the shared metadata secret."""
return self.leader_get(self.shared_metadata_secret_key)
@ -529,6 +532,4 @@ class NovaOperatorCharm(sunbeam_charm.OSBaseOperatorAPICharm):
if __name__ == "__main__":
# Note: use_juju_for_storage=True required per
# https://github.com/canonical/operator/issues/506
main(NovaOperatorCharm, use_juju_for_storage=True)
main(NovaOperatorCharm)

@ -0,0 +1,12 @@
#!/bin/bash
cell_name=$1
sudo -u nova nova-manage cell_v2 list_cells | \
awk '{FS="|"} /cell/ {print "!" $2 "!"}' | \
grep -E "${cell_name}\s" &> /dev/null
if [[ $? -eq 0 ]]; then
echo "${cell_name} already exists"
else
sudo -u nova nova-manage cell_v2 create_cell --name $cell_name --verbose
fi

@ -118,17 +118,7 @@ class TestNovaOperatorCharm(test_utils.CharmTestCase):
"mysql+pymysql://foo:hardpassword@10.0.0.10/nova_cell0",
],
["sudo", "-u", "nova", "nova-manage", "db", "sync"],
[
"sudo",
"-u",
"nova",
"nova-manage",
"cell_v2",
"create_cell",
"--name",
"cell1",
"--verbose",
],
["/root/cell_create_wrapper.sh", "cell1"],
]
for cmd in setup_cmds:
self.assertIn(cmd, self.container_calls.execute["nova-api"])