Browse Source

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 1e69013691)
(cherry picked from commit 1683e1bff9)
changes/27/786227/1
John Fulton 1 month ago
parent
commit
226a907871
2 changed files with 39 additions and 5 deletions
  1. +17
    -2
      tripleoclient/export.py
  2. +22
    -3
      tripleoclient/tests/test_export.py

+ 17
- 2
tripleoclient/export.py View File

@ -143,7 +143,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:
@ -156,7 +171,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


+ 22
- 3
tripleoclient/tests/test_export.py View File

@ -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',
@ -177,11 +187,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')


Loading…
Cancel
Save