def test_unmanaged_managed_transition(self): """ That when a pesky user doesn't initially install salt on OSD servers but later adds it, we correctly transition from paying attention to the CRUSH config to paying attention to the salt data, and fill in the correct FQDNs. """ sm = ServerMonitor(Mock(), Mock(), Mock()) sm.on_server_heartbeat(MON_FQDN, MON_CEPH_SERVICES) sm.on_osd_map(OSD_MAP) self.assertListEqual(sm.servers.keys(), [MON_FQDN, OSD_HOSTNAME]) self.assertListEqual(sm.servers[MON_FQDN].services.keys(), [ ServiceId(FSID, 'mon', MON_HOSTNAME) ]) self.assertListEqual(sm.servers[OSD_HOSTNAME].services.keys(), [ ServiceId(FSID, 'osd', '1'), ServiceId(FSID, 'osd', '0') ]) sm.on_server_heartbeat(OSD_FQDN, OSD_CEPH_SERVICES) self.assertListEqual(sm.servers.keys(), [MON_FQDN, OSD_FQDN]) self.assertEqual(sm.servers[OSD_FQDN].fqdn, OSD_FQDN) self.assertListEqual(sm.servers[MON_FQDN].services.keys(), [ ServiceId(FSID, 'mon', MON_HOSTNAME) ]) self.assertListEqual(sm.servers[OSD_FQDN].services.keys(), [ ServiceId(FSID, 'osd', '1'), ServiceId(FSID, 'osd', '0') ])
def test_unmanaged_service_relocate(self): """ That when an OSD disappears from one server's salt.services output and reappears on another server, this is reflected in the state. """ sm = ServerMonitor(Mock(), Mock(), Mock()) sm.on_server_heartbeat(MON_FQDN, MON_CEPH_SERVICES) sm.on_osd_map(OSD_MAP) # osd.1 initially on unmanaged server OSD self.assertEqual(sm.services[ServiceId(FSID, 'osd', "1")].server_state.fqdn, OSD_HOSTNAME) sm.on_server_heartbeat(MON_FQDN, MON_CEPH_SERVICES_MIGRATED) sm.on_osd_map(OSD_MAP_MIGRATED) # osd.1 now on managed server MON self.assertEqual(sm.services[ServiceId(FSID, 'osd', "1")].server_state.fqdn, MON_FQDN) # Check the servers' lists of services are up to date too self.assertListEqual(sm.servers[MON_FQDN].services.keys(), [ ServiceId(FSID, 'osd', '1'), ServiceId(FSID, 'mon', MON_HOSTNAME) ]) self.assertListEqual(sm.servers[OSD_HOSTNAME].services.keys(), [ ServiceId(FSID, 'osd', '0') ])
def test_on_osd_map(self, mocket): def get_name_info(addr, _): if addr == ":/0": return [''] else: return [OSD_HOSTNAME] def get_fqdn(thing): if thing == [""]: return '' else: return OSD_FQDN mocket.getnameinfo = get_name_info mocket.getfqdn = get_fqdn sm = ServerMonitor(Mock(), Mock(), Mock()) sm.on_osd_map(BAD_MAP) sm.on_osd_map(BAD_MAP2) sm.on_osd_map(BAD_MAP3)
def test_unmanaged_servers(self): """ That when only the mons are sending salt messages, we generate a correct view of service locations including OSDs. """ sm = ServerMonitor(Mock(), Mock(), Mock()) sm.on_server_heartbeat(MON_FQDN, MON_CEPH_SERVICES) sm.on_osd_map(OSD_MAP) self.assertEqual(len(sm.servers), 2) self.assertEqual(len(sm.services), 3) self.assertEqual(len(sm.fsid_services), 1) self.assertEqual(len(sm.hostname_to_server), 2) self.assertListEqual(sm.servers[MON_FQDN].services.keys(), [ServiceId(FSID, 'mon', MON_HOSTNAME)]) self.assertListEqual( sm.servers[OSD_HOSTNAME].services.keys(), [ServiceId(FSID, 'osd', '1'), ServiceId(FSID, 'osd', '0')])
def test_unmanaged_servers(self): """ That when only the mons are sending salt messages, we generate a correct view of service locations including OSDs. """ sm = ServerMonitor(Mock(), Mock(), Mock()) sm.on_server_heartbeat(MON_FQDN, MON_CEPH_SERVICES) sm.on_osd_map(OSD_MAP) self.assertEqual(len(sm.servers), 2) self.assertEqual(len(sm.services), 3) self.assertEqual(len(sm.fsid_services), 1) self.assertEqual(len(sm.hostname_to_server), 2) self.assertListEqual(sm.servers[MON_FQDN].services.keys(), [ ServiceId(FSID, 'mon', MON_HOSTNAME) ]) self.assertListEqual(sm.servers[OSD_HOSTNAME].services.keys(), [ ServiceId(FSID, 'osd', '1'), ServiceId(FSID, 'osd', '0') ])
def test_remove_osd(self): """ That when an OSD is disappears from the OSD map, it is also removed from ServerMonitor's worldview """ sm = ServerMonitor(Mock(), Mock(), Mock()) sm.on_server_heartbeat(MON_FQDN, MON_CEPH_SERVICES) sm.on_server_heartbeat(OSD_FQDN, OSD_CEPH_SERVICES) self.assertListEqual(sm.services.keys(), [ ServiceId(FSID, 'osd', '0'), ServiceId(FSID, 'osd', '1'), ServiceId(FSID, 'mon', MON_HOSTNAME) ]) sm.on_osd_map(OSD_MAP_1_REMOVED) self.assertListEqual(sm.services.keys(), [ ServiceId(FSID, 'osd', '0'), ServiceId(FSID, 'mon', MON_HOSTNAME) ])