From 10e5640f8dcd8c1e44744fe252aa74074c7d92f8 Mon Sep 17 00:00:00 2001 From: John Fulton Date: Tue, 6 Apr 2021 21:01:02 +0000 Subject: [PATCH] Use ceph_mon_network to find Ceph monitor IPs for export When 'openstack overcloud export ceph' is run, do not assume the storage_ip will be set. Instead, find the ceph_mon_network name in the service_net_map, e.g. 'storage' or 'ctlplane', and then use that network name to get the IP from the inventory. Closes-Bug: #1922788 Change-Id: I962bed846b2cae7206c76f883f9294d366031245 (cherry picked from commit 1e690136913062dc0b14b328a295f34fb1c02bd1) (cherry picked from commit 1683e1bff97bf0d0db6221fc6d56ed8069f1e5d7) (cherry picked from commit 226a9078711a89a90b0c270c51bf911a8d16c421) --- tripleoclient/export.py | 19 +++++++++++++++++-- tripleoclient/tests/test_export.py | 25 ++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/tripleoclient/export.py b/tripleoclient/export.py index 059541609..0543580d0 100644 --- a/tripleoclient/export.py +++ b/tripleoclient/export.py @@ -142,7 +142,22 @@ def export_stack(heat, stack, should_filter=False, return data -def export_storage_ips(stack, config_download_dir=constants.DEFAULT_WORK_DIR): +def export_ceph_net_key(stack, config_download_dir=constants.DEFAULT_WORK_DIR): + file = os.path.join(config_download_dir, stack, "global_vars.yaml") + with open(file, 'r') as ff: + try: + global_data = yaml.safe_load(ff) + except Exception as e: + LOG.error( + _('Could not read file %s') % file) + LOG.error(e) + return str(global_data['service_net_map']['ceph_mon_network']) + '_ip' + + +def export_storage_ips(stack, config_download_dir=constants.DEFAULT_WORK_DIR, + ceph_net_key=''): + if len(ceph_net_key) == 0: + ceph_net_key = export_ceph_net_key(stack, config_download_dir) inventory_file = "ceph-ansible/inventory.yml" file = os.path.join(config_download_dir, stack, inventory_file) with open(file, 'r') as ff: @@ -155,7 +170,7 @@ def export_storage_ips(stack, config_download_dir=constants.DEFAULT_WORK_DIR): mon_ips = [] for mon_role in inventory_data['mons']['children'].keys(): for hostname in inventory_data[mon_role]['hosts']: - ip = inventory_data[mon_role]['hosts'][hostname]['storage_ip'] + ip = inventory_data[mon_role]['hosts'][hostname][ceph_net_key] mon_ips.append(ip) return mon_ips diff --git a/tripleoclient/tests/test_export.py b/tripleoclient/tests/test_export.py index d1bb6901e..ac1006111 100644 --- a/tripleoclient/tests/test_export.py +++ b/tripleoclient/tests/test_export.py @@ -46,7 +46,10 @@ class TestExport(TestCase): 'DistributedComputeHCI': { 'hosts': { 'dcn0-distributedcomputehci-0': { - 'storage_ip': '192.168.24.42' + 'foo_ip': '192.168.24.42' + }, + 'dcn0-distributedcomputehci-1': { + 'foo_ip': '192.168.8.8' } } }, @@ -58,6 +61,13 @@ class TestExport(TestCase): } self.mock_open_ceph_inv = mock.mock_open(read_data=str(ceph_inv)) + ceph_global = { + 'service_net_map': { + 'ceph_mon_network': 'storage' + } + } + self.mock_open_ceph_global = mock.mock_open(read_data=str(ceph_global)) + ceph_all = { 'cluster': 'dcn0', 'fsid': 'a5a22d37-e01f-4fa0-a440-c72585c7487f', @@ -171,11 +181,20 @@ class TestExport(TestCase): self.assertEqual(mock_passwords['passwords'], data) + def test_export_ceph_net_key(self): + with mock.patch('six.moves.builtins.open', self.mock_open_ceph_global): + mon_key = export.export_ceph_net_key('dcn0', + config_download_dir='/foo') + self.assertEqual(mon_key, 'storage_ip') + self.mock_open_ceph_global.assert_called_once_with( + '/foo/dcn0/global_vars.yaml', 'r') + def test_export_storage_ips(self): with mock.patch('six.moves.builtins.open', self.mock_open_ceph_inv): storage_ips = export.export_storage_ips('dcn0', - config_download_dir='/foo') - self.assertEqual(storage_ips, ['192.168.24.42']) + config_download_dir='/foo', + ceph_net_key='foo_ip') + self.assertEqual(storage_ips, ['192.168.24.42', '192.168.8.8']) self.mock_open_ceph_inv.assert_called_once_with( '/foo/dcn0/ceph-ansible/inventory.yml', 'r')