Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make inter-server-sync to export/import dates in UTC (bsc#1221505) #9681

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/spacewalk/common/suseLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def channelForProduct(product, parent_id=None, org_id=None, user_id=None):
c.name,
c.summary,
c.description,
to_char(c.last_modified, 'YYYYMMDDHH24MISS') last_modified,
TO_CHAR(c.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified,
-- If user_id is null, then the channel is subscribable
rhn_channel.loose_user_role_check(c.id, :user_id, 'subscribe') subscribable
FROM rhnChannel c
Expand Down
1 change: 1 addition & 0 deletions python/spacewalk/satellite_tools/diskImportLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def get_backend(self):
return self.__backend

Backend.__backend = SQLBackend()
Backend.__backend.setSessionTimeZoneToUTC()
return Backend.__backend


Expand Down
34 changes: 17 additions & 17 deletions python/spacewalk/satellite_tools/disk_dumper/dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def get_channels_statement(self):
"""
select c.id channel_id, c.label,
ct.label as checksum_type,
TO_CHAR(c.last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(c.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnChannel c left outer join rhnChecksumType ct on c.checksum_type_id = ct.id,
rhnChannelFamilyMembers cfm,
(%s
Expand All @@ -140,7 +140,7 @@ def get_packages_statement(self):
# pylint: disable-next=consider-using-f-string
"""
select p.id package_id,
TO_CHAR(p.last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(p.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnChannelPackage cp, rhnPackage p,
rhnChannelFamilyMembers cfm,
(%s
Expand All @@ -159,7 +159,7 @@ def get_source_packages_statement(self):
# pylint: disable-next=consider-using-f-string
"""
select ps.id package_id,
TO_CHAR(ps.last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(ps.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnChannelPackage cp, rhnPackage p, rhnPackageSource ps,
rhnChannelFamilyMembers cfm,
(%s
Expand All @@ -181,7 +181,7 @@ def get_errata_statement(self):
# pylint: disable-next=consider-using-f-string
"""
select e.id errata_id,
TO_CHAR(e.last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(e.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnChannelErrata ce, rhnErrata e,
rhnChannelFamilyMembers cfm,
(%s
Expand Down Expand Up @@ -402,7 +402,7 @@ def dump_channel_packages_short(
_query_get_channel_packages = rhnSQL.Statement(
"""
select cp.package_id,
TO_CHAR(p.last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(p.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnChannelPackage cp,
rhnPackage p
where cp.channel_id = :channel_id
Expand Down Expand Up @@ -613,7 +613,7 @@ def _validate_channels(self, channel_labels=None):
_query_validate_kickstarts = rhnSQL.Statement(
"""
select kt.label kickstart_label,
TO_CHAR(kt.modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(kt.modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnKickstartableTree kt
where kt.channel_id = :channel_id
and kt.org_id is null
Expand Down Expand Up @@ -900,7 +900,7 @@ class ChannelsDumper(exportLib.ChannelsDumper):
c.label, ca.label channel_arch, c.basedir, c.name,
c.summary, c.description, c.gpg_key_url, c.update_tag,
c.installer_updates, ct.label checksum_type,
TO_CHAR(c.last_modified, 'YYYYMMDDHH24MISS') last_modified,
TO_CHAR(c.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified,
pc.label parent_channel, c.channel_access
from rhnChannel c left outer join rhnChannel pc on c.parent_channel = pc.id
left outer join rhnChecksumType ct on c.checksum_type_id = ct.id, rhnChannelArch ca
Expand Down Expand Up @@ -953,7 +953,7 @@ class ChannelsDumperEx(CachedDumper, exportLib.ChannelsDumper):
"""
select c.id, c.label, ca.label channel_arch, c.basedir, c.name,
c.summary, c.description, c.gpg_key_url, c.installer_updates, c.update_tag, c.org_id,
TO_CHAR(c.last_modified, 'YYYYMMDDHH24MISS') last_modified,
TO_CHAR(c.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified,
c.channel_product_id,
pc.label parent_channel,
cp.product channel_product,
Expand Down Expand Up @@ -992,7 +992,7 @@ class ShortPackagesDumper(CachedDumper, exportLib.ShortPackagesDumper):
c.checksum_type,
c.checksum,
p.package_size,
TO_CHAR(p.last_modified, 'YYYYMMDDHH24MISS') as last_modified
TO_CHAR(p.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') as last_modified
from rhnPackage p, rhnPackageName pn, rhnPackageEVR pe,
rhnPackageArch pa, rhnChecksumView c
where p.id = :package_id
Expand Down Expand Up @@ -1027,7 +1027,7 @@ class PackagesDumper(CachedDumper, exportLib.PackagesDumper):
p.payload_size,
p.installed_size,
p.build_host,
TO_CHAR(p.build_time, 'YYYYMMDDHH24MISS') as build_time,
TO_CHAR(p.build_time at time zone 'UTC', 'YYYYMMDDHH24MISS') as build_time,
sr.name as source_rpm,
c.checksum_type,
c.checksum,
Expand All @@ -1039,7 +1039,7 @@ class PackagesDumper(CachedDumper, exportLib.PackagesDumper):
p.header_end,
p.copyright,
p.cookie,
TO_CHAR(p.last_modified, 'YYYYMMDDHH24MISS') as last_modified
TO_CHAR(p.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') as last_modified
from rhnPackage p, rhnPackageName pn, rhnPackageEVR pe,
rhnPackageArch pa, rhnPackageGroup pg, rhnSourceRPM sr,
rhnChecksumView c
Expand Down Expand Up @@ -1068,15 +1068,15 @@ class SourcePackagesDumper(CachedDumper, exportLib.SourcePackagesDumper):
ps.rpm_version,
ps.payload_size,
ps.build_host,
TO_CHAR(ps.build_time, 'YYYYMMDDHH24MISS') build_time,
TO_CHAR(ps.build_time at time zone 'UTC', 'YYYYMMDDHH24MISS') build_time,
sig.checksum sigchecksum,
sig.checksum_type sigchecksum_type,
ps.vendor,
ps.cookie,
ps.package_size,
c.checksum_type,
c.checksum,
TO_CHAR(ps.last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(ps.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnPackageSource ps, rhnPackageGroup pg, rhnSourceRPM sr,
rhnChecksumView c, rhnChecksumView sig
where ps.id = :package_id
Expand Down Expand Up @@ -1108,9 +1108,9 @@ class ErrataDumper(exportLib.ErrataDumper):
e.synopsis,
e.topic,
e.solution,
TO_CHAR(e.issue_date, 'YYYYMMDDHH24MISS') issue_date,
TO_CHAR(e.update_date, 'YYYYMMDDHH24MISS') update_date,
TO_CHAR(e.last_modified, 'YYYYMMDDHH24MISS') last_modified,
TO_CHAR(e.issue_date at time zone 'UTC', 'YYYYMMDDHH24MISS') issue_date,
TO_CHAR(e.update_date at time zone 'UTC', 'YYYYMMDDHH24MISS') update_date,
TO_CHAR(e.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified,
e.refers_to,
e.notes,
e.errata_from,
Expand Down Expand Up @@ -1139,7 +1139,7 @@ class KickstartableTreesDumper(CachedDumper, exportLib.KickstartableTreesDumper)
ktt.label "kstree-type-label",
kit.name "install-type-name",
kit.label "install-type-label",
TO_CHAR(kt.last_modified, 'YYYYMMDDHH24MISS') "last-modified"
TO_CHAR(kt.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') "last-modified"
from rhnKickstartableTree kt,
rhnKSTreeType ktt,
rhnKSInstallType kit,
Expand Down
12 changes: 6 additions & 6 deletions python/spacewalk/satellite_tools/disk_dumper/iss.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def __init__(
try:
query = """
select ch.id channel_id, label,
TO_CHAR(last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnChannel ch
where ch.label = :label
"""
Expand Down Expand Up @@ -481,7 +481,7 @@ def __init__(
if self.whole_errata and self.start_date:
query = """
select rp.id package_id,
TO_CHAR(rp.last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(rp.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnChannelPackage rcp, rhnPackage rp
left join rhnErrataPackage rep on rp.id = rep.package_id
left join rhnErrata re on rep.errata_id = re.id
Expand All @@ -491,7 +491,7 @@ def __init__(
else:
query = """
select rp.id package_id,
TO_CHAR(rp.last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(rp.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnPackage rp, rhnChannelPackage rcp
where rcp.channel_id = :channel_id
and rcp.package_id = rp.id
Expand Down Expand Up @@ -677,7 +677,7 @@ def __init__(
try:
query = """
select kt.id kstree_id, kt.label kickstart_label,
TO_CHAR(kt.last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(kt.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnKickstartableTree kt
where kt.channel_id = :channel_id
"""
Expand Down Expand Up @@ -724,10 +724,10 @@ def __init__(
select rktf.relative_filename "relative-path",
c.checksum_type "checksum-type", c.checksum,
rktf.file_size "file-size",
TO_CHAR(rktf.last_modified, 'YYYYMMDDHH24MISS') "last-modified",
TO_CHAR(rktf.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') "last-modified",
rkt.base_path "base-path",
rkt.label "label",
TO_CHAR(rkt.modified, 'YYYYMMDDHH24MISS') "modified"
TO_CHAR(rkt.modified at time zone 'UTC', 'YYYYMMDDHH24MISS') "modified"
from rhnKSTreeFile rktf, rhnKickstartableTree rkt,
rhnChecksumView c
where rktf.kstree_id = :kstree_id
Expand Down
16 changes: 8 additions & 8 deletions python/spacewalk/satellite_tools/exporter/exportLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def _get_ids(self, query_with_limit, query_with_rhnlimit, query_no_limits):
_query_get_source_package_ids = rhnSQL.Statement(
"""
select distinct ps.id, sr.name source_rpm,
TO_CHAR(ps.last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(ps.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnChannelPackage cp, rhnPackage p, rhnPackageSource ps,
rhnSourceRPM sr
where cp.channel_id = :channel_id
Expand All @@ -576,7 +576,7 @@ def _get_cursor_source_packages(self):
_query__get_errata_ids = rhnSQL.Statement(
"""
select ce.errata_id as id, e.advisory_name,
TO_CHAR(e.last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(e.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnChannelErrata ce, rhnErrata e
where ce.channel_id = :channel_id
and ce.errata_id = e.id
Expand Down Expand Up @@ -680,7 +680,7 @@ def _get_channel_product_details(self):

_query_channel_comps_last_modified = rhnSQL.Statement(
"""
select to_char(last_modified, 'YYYYMMDDHH24MISS') as comps_last_modified
select TO_CHAR(last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') as comps_last_modified
from rhnChannelComps
where channel_id = :channel_id
and comps_type_id = 1
Expand All @@ -696,7 +696,7 @@ def _channel_comps_last_modified(self):

_query_channel_modules_last_modified = rhnSQL.Statement(
"""
select to_char(last_modified, 'YYYYMMDDHH24MISS') as modules_last_modified
select TO_CHAR(last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') as modules_last_modified
from rhnChannelComps
where channel_id = :channel_id
and comps_type_id = 2
Expand Down Expand Up @@ -1300,7 +1300,7 @@ def set_iterator(self):
"""
select
name, text,
TO_CHAR(time, 'YYYYMMDDHH24MISS') as time
TO_CHAR(time at time zone 'UTC', 'YYYYMMDDHH24MISS') as time
from rhnPackageChangeLog
where package_id = :package_id
"""
Expand Down Expand Up @@ -1384,7 +1384,7 @@ def set_iterator(self):
select
pc.name, pf.device, pf.inode, pf.file_mode, pf.username,
pf.groupname, pf.rdev, pf.file_size,
TO_CHAR(mtime, 'YYYYMMDDHH24MISS') mtime,
TO_CHAR(mtime at time zone 'UTC', 'YYYYMMDDHH24MISS') mtime,
c.checksum_type as "checksum-type",
c.checksum, pf.linkto, pf.flags, pf.verifyflags, pf.lang
from rhnPackageFile pf
Expand Down Expand Up @@ -2200,7 +2200,7 @@ def set_iterator(self):
c.checksum_type,
c.checksum,
file_size,
TO_CHAR(last_modified, 'YYYYMMDDHH24MISS') "last-modified"
TO_CHAR(last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') "last-modified"
from rhnKSTreeFile, rhnChecksumView c
where kstree_id = :kstree_id
and checksum_id = c.id
Expand All @@ -2224,7 +2224,7 @@ class KickstartableTreesDumper(BaseSubelementDumper, BaseQueryDumper):
ktt.label "kstree-type-label",
kit.name "install-type-name",
kit.label "install-type-label",
TO_CHAR(kt.last_modified, 'YYYYMMDDHH24MISS') "last-modified"
TO_CHAR(kt.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') "last-modified"
from rhnKickstartableTree kt,
rhnKSTreeType ktt,
rhnKSInstallType kit,
Expand Down
16 changes: 12 additions & 4 deletions python/spacewalk/satellite_tools/satsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# __lang. imports__
# pylint: disable=E0012, C0413
import datetime
import time
import os
import sys
import stat
Expand Down Expand Up @@ -1122,7 +1123,6 @@ def processShortPackages(self):
if package_ids:
lm = self._channel_collection.get_channel_timestamp(channel_label)
channel_last_modified = int(rhnLib.timestamp(lm))

stream_loader.set_args(channel_label, channel_last_modified)
stream_loader.process(package_ids)

Expand All @@ -1132,7 +1132,7 @@ def processShortPackages(self):

_query_compare_packages = """
select p.id, c.checksum_type, c.checksum, p.path, p.package_size,
TO_CHAR(p.last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(p.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnPackage p, rhnChecksumView c
where p.name_id = lookup_package_name(:name)
and p.evr_id = lookup_evr(:epoch, :version, :release, :package_type)
Expand Down Expand Up @@ -1307,6 +1307,7 @@ def _process_package(
db_checksum = row["checksum"]
db_package_size = row["package_size"]
db_path = row["path"]
log(3, "PKG Metadata values: {}, {}, {}, {}".format(checksum_type, checksum, package_size, l_timestamp))

if not (
l_timestamp <= db_timestamp
Expand All @@ -1315,6 +1316,8 @@ def _process_package(
):
# package doesn't match
channel_package = package_id
log(3, "Package id {} has different checksum {} vs. {}, package size {} vs. {} or timestamp {} > {}".format(
channel_package, checksum, db_checksum, package_size, db_package_size, l_timestamp, db_timestamp))

if check_rpms:
if db_path:
Expand All @@ -1326,15 +1329,20 @@ def _process_package(
# file doesn't match
fs_package = package_id
channel_package = package_id
log(3, "Package id {} - {} verify failed: {}".format(package_id, db_path, errcode))
path = db_path
else:
# upload package and reimport metadata
channel_package = package_id
fs_package = package_id
log(3, "Package id {} path not found in db".format(package_id))
else:
log(3, "Package id {} found in DB, but missing checksum_type {}".format(package_id, checksum_type))
else:
# package is missing from the DB
channel_package = package_id
fs_package = package_id
log(3, "Package id {} not found in db".format(package_id))

if channel_package:
m_channel_packages.append(channel_package)
Expand Down Expand Up @@ -1500,7 +1508,7 @@ def _compute_not_cached_source_packages(self):

_query_compare_source_packages = """
select ps.id, c.checksum_type, c.checksum, ps.path, ps.package_size,
TO_CHAR(ps.last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(ps.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnPackageSource ps, rhnChecksumView c
where ps.source_rpm_id = lookup_source_name(:package_id)
and (ps.org_id = :org_id or
Expand Down Expand Up @@ -1790,7 +1798,7 @@ def _compute_not_cached_errata(self):
_query_get_db_errata = rhnSQL.Statement(
"""
select e.id, e.advisory_name,
TO_CHAR(e.last_modified, 'YYYYMMDDHH24MISS') last_modified
TO_CHAR(e.last_modified at time zone 'UTC', 'YYYYMMDDHH24MISS') last_modified
from rhnChannelErrata ce, rhnErrata e, rhnChannel c
where c.label = :channel
and ce.channel_id = c.id
Expand Down
4 changes: 2 additions & 2 deletions python/spacewalk/satellite_tools/xmlSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -1423,8 +1423,8 @@ def _normalizeDateType(value):
except ValueError:
# string
return value
# Timestamp
return backendLib.localtime(value)
# Timestamp in UTC
return backendLib.gmtime(value)


#
Expand Down
8 changes: 8 additions & 0 deletions python/spacewalk/server/importlib/backendOracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,10 @@ def setSessionTimeZoneToLocalTimeZone(self):
)
sth.execute()

def setSessionTimeZoneToUTC(self):
sth = self.dbmodule.prepare("alter session set time_zone = 'UTC'")
sth.execute()

def init(self):
"""
Override parent to do explicit setting of the date format. (Oracle
Expand All @@ -768,6 +772,10 @@ def setSessionTimeZoneToLocalTimeZone(self):
)
sth.execute()

def setSessionTimeZoneToUTC(self):
sth = self.dbmodule.prepare("set session time zone 'UTC'")
sth.execute()

def init(self):
"""
Avoid the Oracle specific stuff here in parent method.
Expand Down
Loading
Loading