PR#3819: track update time in host table

Merges #3819
https://pagure.io/koji/pull-request/3819

Fixes: #3789
https://pagure.io/koji/issue/3789
This commit is contained in:
Tomas Kopecek 2023-05-17 10:58:12 +02:00
commit 576e5d6f3b
10 changed files with 83 additions and 41 deletions

View file

@ -34,6 +34,7 @@ class TestHostinfo(utils.CliTestCase):
'comment': 'test-comment',
'description': 'test-description'}
self.last_update = 1615875554.862938
self.last_update_str = '2021-03-16 06:19:14.862938-00:00'
self.list_channels = [{'id': 1, 'name': 'default'}, {'id': 2, 'name': 'createrepo'}]
self.error_format = """Usage: %s hostinfo [options] <hostname> [<hostname> ...]
(Specify the --help global option for a list of other help options)
@ -142,6 +143,7 @@ None
@mock.patch('sys.stdout', new_callable=StringIO)
def test_hostinfo_valid_param_error(self, stdout):
'''Test the fallback code for getting timestamps from old hubs'''
expected = """Name: kojibuilder
ID: 1
Arches: x86_64
@ -157,7 +159,8 @@ Active Buildroots:
None
"""
self.session.getHost.return_value = self.hostinfo
self.session.getLastHostUpdate.side_effect = [koji.ParameterError, self.last_update]
# simulate an older hub that doesn't support the ts option for getLastHostUpdate
self.session.getLastHostUpdate.side_effect = [koji.ParameterError, self.last_update_str]
self.session.listChannels.return_value = self.list_channels
rv = anon_handle_hostinfo(self.options, self.session, [self.hostinfo['name']])
self.assertEqual(rv, None)

View file

@ -179,10 +179,12 @@ kojibuilder N Y 0.0/2.0 x86_64 Tue, 16 Mar 2021 06:19:14 UTC
@mock.patch('sys.stdout', new_callable=StringIO)
def test_list_hosts_param_error_get_last_host_update(self, stdout):
host_update = 1615875554.862938
# host_update = 1615875554.862938
host_update = '2021-03-16 06:19:14.862938-00:00'
expected = "kojibuilder N Y 0.0/2.0 x86_64 " \
"Tue, 16 Mar 2021 06:19:14 UTC \n"
# simulate an older hub that doesn't support the ts option for getLastHostUpdate
self.session.getLastHostUpdate.side_effect = [koji.ParameterError, host_update]
self.session.multiCall.return_value = [[host_update]]
self.session.listHosts.return_value = self.list_hosts

View file

@ -33,12 +33,13 @@ class TestSetHostEnabled(unittest.TestCase):
self.assertEqual(len(self.queries), 1)
query = self.queries[0]
columns = ['host.id', 'host.user_id', 'host.name', 'host.ready',
columns = ['host.id', 'host.user_id', 'host.name',
"date_part('epoch', host.update_time)", 'host.ready',
'host.task_load', 'host_config.arches',
'host_config.capacity', 'host_config.description',
'host_config.comment', 'host_config.enabled']
joins = ['host ON host.id = host_config.host_id']
aliases = ['id', 'user_id', 'name', 'ready', 'task_load',
aliases = ['id', 'user_id', 'name', 'update_ts', 'ready', 'task_load',
'arches', 'capacity', 'description', 'comment', 'enabled']
clauses = ['(host_config.active = TRUE)', '(host.name = %(host_name)s)']
values = {'host_name': 'hostname'}
@ -54,12 +55,13 @@ class TestSetHostEnabled(unittest.TestCase):
self.assertEqual(len(self.queries), 1)
query = self.queries[0]
columns = ['host.id', 'host.user_id', 'host.name', 'host.ready',
columns = ['host.id', 'host.user_id', 'host.name',
"date_part('epoch', host.update_time)", 'host.ready',
'host.task_load', 'host_config.arches',
'host_config.capacity', 'host_config.description',
'host_config.comment', 'host_config.enabled']
joins = ['host ON host.id = host_config.host_id']
aliases = ['id', 'user_id', 'name', 'ready', 'task_load',
aliases = ['id', 'user_id', 'name', 'update_ts', 'ready', 'task_load',
'arches', 'capacity', 'description', 'comment', 'enabled']
clauses = ['(host_config.create_event <= 345 AND ( host_config.revoke_event IS NULL '
'OR 345 < host_config.revoke_event ))',

View file

@ -28,7 +28,7 @@ class TestGetLastHostUpdate(DBQueryTestCase):
self.assertEqual(query.joins, ['host ON sessions.user_id = host.user_id'])
self.assertEqual(query.clauses, ['host.id = %(hostID)i'])
self.assertEqual(query.values, {'hostID': 1})
self.assertEqual(query.columns, ['update_time'])
self.assertEqual(query.columns, ['sessions.update_time'])
def test_valid_datetime(self):
if sys.version_info[1] <= 6:

View file

@ -45,7 +45,7 @@ class TestGetReadyHosts(unittest.TestCase):
'host_config ON host.id = host_config.host_id'])
self.assertEqual(query.clauses, ['active IS TRUE', 'enabled IS TRUE', 'expired IS FALSE',
'master IS NULL', 'ready IS TRUE',
"update_time > NOW() - '5 minutes'::interval"])
"sessions.update_time > NOW() - '5 minutes'::interval"])
self.assertEqual(query.values, {})
self.assertEqual(query.columns, ['arches', 'capacity', 'host.id', 'name', 'task_load'])