diff --git a/hooks/ceph_hooks.py b/hooks/ceph_hooks.py index 928a49fb..22925d10 100755 --- a/hooks/ceph_hooks.py +++ b/hooks/ceph_hooks.py @@ -195,8 +195,16 @@ def az_info(): config_az = config("availability_zone") juju_az_info = os.environ.get('JUJU_AVAILABILITY_ZONE') if juju_az_info: + # NOTE(jamespage): avoid conflicting key with root + # of crush hierarchy + if juju_az_info == 'default': + juju_az_info = 'default-rack' az_info = "{} rack={}".format(az_info, juju_az_info) if config_az: + # NOTE(jamespage): avoid conflicting key with root + # of crush hierarchy + if config_az == 'default': + config_az = 'default-row' az_info = "{} row={}".format(az_info, config_az) if az_info != "": log("AZ Info: " + az_info) diff --git a/unit_tests/test_ceph_hooks.py b/unit_tests/test_ceph_hooks.py index f40d07fe..6be78cc1 100644 --- a/unit_tests/test_ceph_hooks.py +++ b/unit_tests/test_ceph_hooks.py @@ -388,3 +388,54 @@ class CephHooksTestCase(unittest.TestCase): mock_os_path_exists.assert_called() mock_get_blacklist.assert_called() self.assertEqual(devices, set(['/dev/vdb'])) + + @patch.object(ceph_hooks, 'log') + @patch.object(ceph_hooks, 'config') + @patch('os.environ') + def test_az_info_unset(self, environ, config, log): + config.return_value = None + environ.get.return_value = None + + self.assertEqual(ceph_hooks.az_info(), None) + + config.assert_called_with('availability_zone') + environ.get.assert_called_with('JUJU_AVAILABILITY_ZONE') + + @patch.object(ceph_hooks, 'log') + @patch.object(ceph_hooks, 'config') + @patch('os.environ') + def test_az_info_config(self, environ, config, log): + config.return_value = 'dc-01' + environ.get.return_value = None + + self.assertEqual(ceph_hooks.az_info(), + ' row=dc-01') + + config.assert_called_with('availability_zone') + environ.get.assert_called_with('JUJU_AVAILABILITY_ZONE') + + @patch.object(ceph_hooks, 'log') + @patch.object(ceph_hooks, 'config') + @patch('os.environ') + def test_az_info_juju_az(self, environ, config, log): + config.return_value = 'dc-01' + environ.get.return_value = 'zone1' + + self.assertEqual(ceph_hooks.az_info(), + ' rack=zone1 row=dc-01') + + config.assert_called_with('availability_zone') + environ.get.assert_called_with('JUJU_AVAILABILITY_ZONE') + + @patch.object(ceph_hooks, 'log') + @patch.object(ceph_hooks, 'config') + @patch('os.environ') + def test_az_info_default_remap(self, environ, config, log): + config.return_value = 'default' + environ.get.return_value = 'default' + + self.assertEqual(ceph_hooks.az_info(), + ' rack=default-rack row=default-row') + + config.assert_called_with('availability_zone') + environ.get.assert_called_with('JUJU_AVAILABILITY_ZONE')