def test_wait(self, ostd): """ Check that wait returns successfully """ ostd.return_value = (0, "safe to destroy") with patch.object(osd.OSDWeight, "__init__", lambda self, _id: None): osdw = osd.OSDWeight(0) osdw.osd_id = 0 osdw.settings = {'timeout': 1, 'delay': 1} ret = osdw.wait() assert ret == 'osd.0 is safe to destroy'
def test_restore_no_files(self, ur, uw): """ Restore does nothing if files are absent """ with patch.object(osd.OSDWeight, "__init__", lambda self, _id: None): osdw = osd.OSDWeight(0) osdw.osd_id = 0 osdw.settings = {'filename': '/weight', 'rfilename': '/reweight'} osdw.restore() assert uw.call_count == 0 assert ur.call_count == 0
def test_wait_loops(self, ostd, od, sleep): """ Check that wait does loop """ od = {} ostd.return_value = (-16, "Ceph is busy") with patch.object(osd.OSDWeight, "__init__", lambda self, _id: None): osdw = osd.OSDWeight(0) osdw.osd_id = 0 osdw.settings = {'timeout': 2, 'delay': 1, 'osd_id': 0} ret = osdw.wait() assert ostd.call_count == 2
def test_wait_timeout(self, ostd, od, sleep): """ Check that wait can timeout """ od = {} ostd.return_value = (-16, "Ceph is busy") with patch.object(osd.OSDWeight, "__init__", lambda self, _id: None): osdw = osd.OSDWeight(0) osdw.osd_id = 0 osdw.settings = {'timeout': 1, 'delay': 1, 'osd_id': 0} ret = osdw.wait() assert 'Timeout expired' in ret
def test_save_defaults(self, osd_df): """ No files created with default values """ osd_df.return_value = {'crush_weight': 0, 'reweight': 1.0} with patch.object(osd.OSDWeight, "__init__", lambda self, _id: None): osdw = osd.OSDWeight(0) osdw.osd_id = 0 osdw.settings = {'filename': '/weight', 'rfilename': '/reweight'} osdw.save() assert f_os.path.exists('/weight') == False assert f_os.path.exists('/reweight') == False
def test_update_reweight(self): """ Check that the reweight command is built correctly """ osd.__salt__ = {} osd.__salt__['helper.run'] = mock.Mock() with patch.object(osd.OSDWeight, "__init__", lambda self, _id: None): osdw = osd.OSDWeight(0) osdw.osd_id = 0 osdw.settings = { 'keyring': 'admin.keyring', 'client': 'client.admin' } osdw.update_reweight('1.1') cmd = "ceph --keyring=admin.keyring --name=client.admin osd reweight osd.0 1.1" osd.__salt__['helper.run'].assert_called_with(cmd)
def test_restore(self, ur, uw): """ Restore calls routines with custom values """ with open("/weight", 'w') as weight: weight.write("0.9") with open("/reweight", 'w') as reweight: reweight.write("1.1") with patch.object(osd.OSDWeight, "__init__", lambda self, _id: None): osdw = osd.OSDWeight(0) osdw.osd_id = 0 osdw.settings = {'filename': '/weight', 'rfilename': '/reweight'} osdw.restore() uw.assert_called_with('0.9') ur.assert_called_with('1.1') fs.RemoveFile('/weight') fs.RemoveFile('/reweight')
def test_save_custom_values(self, osd_df): """ Files created with custom values """ osd_df.return_value = {'crush_weight': 0.9, 'reweight': 1.1} with patch.object(osd.OSDWeight, "__init__", lambda self, _id: None): osdw = osd.OSDWeight(0) osdw.osd_id = 0 osdw.settings = {'filename': '/weight', 'rfilename': '/reweight'} osdw.save() assert f_os.path.exists('/weight') assert f_os.path.exists('/reweight') with open("/weight") as weight: contents = weight.read().rstrip('\n') assert contents == "0.9" with open("/reweight") as reweight: contents = reweight.read().rstrip('\n') assert contents == "1.1" fs.RemoveFile('/weight') fs.RemoveFile('/reweight')