SRU ADT regression: Remove the no-longer-needed state-file backup functionality as currently there's basically low risk that we'd crash mid-state-save. Add a test for this.

master
Łukasz 'sil2100' Zemczak 5 years ago
parent c8492d4cc7
commit 49e3d7e51c

@ -35,11 +35,6 @@ class SRUADTRegressionPolicy(BasePolicy, Rest):
with open(self.state_filename, encoding='utf-8') as data:
self.state = json.load(data)
self.log('Loaded state file %s' % self.state_filename)
tmp = self.state_filename + '.new'
if os.path.exists(tmp):
with open(tmp, encoding='utf-8') as data:
self.state.update(json.load(data))
self.restore_state()
# Remove any old entries from the statefile
self.cleanup_state()
@ -134,19 +129,9 @@ class SRUADTRegressionPolicy(BasePolicy, Rest):
if series not in self.state[distro]:
self.state[distro][series] = {}
self.state[distro][series][source] = version
tmp = self.state_filename + '.new'
with open(tmp, 'w', encoding='utf-8') as data:
with open(self.state_filename, 'w', encoding='utf-8') as data:
json.dump(self.state, data)
def restore_state(self):
try:
os.rename(self.state_filename + '.new', self.state_filename)
# If we haven't written any state, don't clobber the old one
except FileNotFoundError:
pass
self.log('Wrote SRU ADT regression state to %s' % self.state_filename)
def cleanup_state(self):
'''Remove all no-longer-valid package entries from the statefile'''
for distro_name in self.state:

@ -189,6 +189,13 @@ class T(unittest.TestCase):
}
self.assertDictEqual(pol.state, expected_state)
log.assert_called_with('Sending ADT regression message to LP: #2 regarding testpackage/55.0 in zazzy')
# But also test if the state has been correctly recorded to the
# state file
state_path = os.path.join(
options.unstable, 'sru_regress_inform_state')
with open(state_path) as f:
saved_state = json.load(f)
self.assertDictEqual(saved_state, expected_state)
@patch('smtplib.SMTP')
@patch('britney2.policies.sruadtregression.SRUADTRegressionPolicy.bugs_from_changes', return_value={1, 2})

Loading…
Cancel
Save