Use get_availability_zone() on cloud-compute relation

Commit 9f4369d9 added a feature to set the availability zone of
the nova-compute unit on the cloud-compute relation. This uses the
value of the JUJU_AVAILABILITY_ZONE environment variable, which is
not consistent with how the nova-compute service sets its availability
zone.

Use the nova_compute_utils.get_availability_zone() method instead.

Closes-Bug #1925412

Change-Id: Ie68ecd808a60baf0d5bfe526f4355ce3c7ae5c77
This commit is contained in:
Billy Olsen 2021-04-21 20:48:46 -07:00
parent fc835f8c54
commit bfc3436a32
2 changed files with 9 additions and 11 deletions

View File

@ -345,9 +345,9 @@ def compute_joined(rid=None):
'migration', cidr_network=config('libvirt-migration-network')), 'migration', cidr_network=config('libvirt-migration-network')),
} }
juju_az = os.environ.get('JUJU_AVAILABILITY_ZONE') az = get_availability_zone()
if juju_az: if az:
relation_set(relation_id=rid, availability_zone=juju_az) relation_set(relation_id=rid, availability_zone=az)
if migration_enabled(): if migration_enabled():
auth_type = config('migration-auth-type') auth_type = config('migration-auth-type')

View File

@ -378,19 +378,17 @@ class NovaComputeRelationsTests(CharmTestCase):
hooks.image_service_changed() hooks.image_service_changed()
configs.write.assert_called_with('/etc/nova/nova.conf') configs.write.assert_called_with('/etc/nova/nova.conf')
def test_compute_joined_no_migration_no_resize(self): @patch.object(hooks, 'get_availability_zone')
def test_compute_joined_no_migration_no_resize(self, mock_az):
mock_az.return_value = ''
self.migration_enabled.return_value = False self.migration_enabled.return_value = False
hooks.compute_joined() hooks.compute_joined()
self.assertFalse(self.relation_set.called) self.assertFalse(self.relation_set.called)
@patch('os.environ.get') @patch.object(hooks, 'get_availability_zone')
def test_compute_joined_with_juju_az(self, mock_env_get): def test_compute_joined_with_juju_az(self, mock_az):
def environ_get_side_effect(key):
return {
'JUJU_AVAILABILITY_ZONE': 'az1',
}[key]
mock_env_get.side_effect = environ_get_side_effect
self.migration_enabled.return_value = False self.migration_enabled.return_value = False
mock_az.return_value = 'az1'
hooks.compute_joined('cloud-compute:2') hooks.compute_joined('cloud-compute:2')
self.relation_set.assert_called_with(**{ self.relation_set.assert_called_with(**{
'relation_id': 'cloud-compute:2', 'relation_id': 'cloud-compute:2',