backend/satellite_tools/sync_handlers.py | 2 +
backend/server/importlib/backend.py | 33 ++++++++++++++++++++++++++++++
backend/server/importlib/channelImport.py | 9 ++++++--
backend/server/importlib/orgImport.py | 33 +++++++++++++++++-------------
backend/spacewalk-backend.spec | 5 +++-
rel-eng/packages/spacewalk-backend | 2 -
6 files changed, 66 insertions(+), 18 deletions(-)
New commits:
commit 749defd841d2cf9f9731ea5b3376872e6df410c0
Author: Stephen Herr <sherr(a)redhat.com>
Date: Thu Jun 27 15:19:30 2013 -0400
Automatic commit of package [spacewalk-backend] release [1.10.52-1].
diff --git a/backend/spacewalk-backend.spec b/backend/spacewalk-backend.spec
index 5132abe..d1218b5 100644
--- a/backend/spacewalk-backend.spec
+++ b/backend/spacewalk-backend.spec
@@ -12,7 +12,7 @@ Name: spacewalk-backend
Summary: Common programs needed to be installed on the Spacewalk servers/proxies
Group: Applications/Internet
License: GPLv2
-Version: 1.10.51
+Version: 1.10.52
Release: 1%{?dist}
URL:
https://fedorahosted.org/spacewalk
Source0:
https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
@@ -639,6 +639,9 @@ rm -f %{rhnconf}/rhnSecret.py*
# $Id$
%changelog
+* Thu Jun 27 2013 Stephen Herr <sherr(a)redhat.com> 1.10.52-1
+- 977878 - trust syncing should remove trusts that no longer exist
+
* Tue Jun 25 2013 Stephen Herr <sherr(a)redhat.com> 1.10.51-1
- 977878 - fixing checkstyle errors
diff --git a/rel-eng/packages/spacewalk-backend b/rel-eng/packages/spacewalk-backend
index c17f862..10e625c 100644
--- a/rel-eng/packages/spacewalk-backend
+++ b/rel-eng/packages/spacewalk-backend
@@ -1 +1 @@
-1.10.51-1 backend/
+1.10.52-1 backend/
commit b8290655ca8d89093555012728cd6f46211d3281
Author: Stephen Herr <sherr(a)redhat.com>
Date: Thu Jun 27 15:18:43 2013 -0400
977878 - trust syncing should remove trusts that no longer exist
diff --git a/backend/satellite_tools/sync_handlers.py
b/backend/satellite_tools/sync_handlers.py
index 974ffc9..66e7370 100644
--- a/backend/satellite_tools/sync_handlers.py
+++ b/backend/satellite_tools/sync_handlers.py
@@ -223,6 +223,8 @@ def import_channels(channels, orgid=None, master=None):
c_obj['org_id'] = org_map[c_obj['org_id']]
else:
c_obj['org_id'] = orgid
+ if c_obj.has_key('trust_list'):
+ del(c_obj['trust_list'])
for family in c_obj['families']:
family['label'] = 'private-channel-family-' + \
str(c_obj['org_id'])
diff --git a/backend/server/importlib/backend.py b/backend/server/importlib/backend.py
index fc73cde..5491517 100644
--- a/backend/server/importlib/backend.py
+++ b/backend/server/importlib/backend.py
@@ -360,6 +360,17 @@ class Backend:
ret[row['org_id']].append(row['org_trust_id'])
return ret
+ def clearOrgTrusts(self, org_id):
+ # Delete all trusts involving this org; trusts are always
+ # bi-directional
+ sql = """
+ delete from rhnTrustedOrgs
+ where org_id = :org_id
+ or org_trust_id = :org_id
+ """
+ h = self.dbmodule.prepare(sql)
+ h.execute(org_id=org_id)
+
def createOrgTrusts(self, trusts):
# Create org trusts
insert = [[],[]]
@@ -926,6 +937,28 @@ class Backend:
self.__processObjectCollection(channels, 'rhnChannel', childTables,
'channel_id', uploadForce=4, ignoreUploaded=1, forceVerify=1)
+ def orgTrustExists(self, org_id, trust_id):
+ sql = """
+ select *
+ from rhnTrustedOrgs
+ where org_id = :org_id
+ and org_trust_id = :trust_id
+ """
+ h = self.dbmodule.prepare(sql)
+ h.execute(org_id=org_id, trust_id=trust_id)
+ row = h.fetchone_dict()
+ if row:
+ return True
+ return False
+
+ def clearChannelTrusts(self, label):
+ sql = """
+ delete from rhnChannelTrust where channel_id =
+ (select id from rhnChannel where label = :label)
+ """
+ h = self.dbmodule.prepare(sql)
+ h.execute(label=label)
+
def processChannelTrusts(self, channel_trusts):
# Create channel trusts
insert = [[],[]]
diff --git a/backend/server/importlib/channelImport.py
b/backend/server/importlib/channelImport.py
index cd2fccc..cd95b57 100644
--- a/backend/server/importlib/channelImport.py
+++ b/backend/server/importlib/channelImport.py
@@ -135,9 +135,14 @@ class ChannelImport(Import):
continue
if (channel.has_key('trust_list')
and channel['trust_list']):
+ self.backend.clearChannelTrusts(channel['label'])
for trust in channel['trust_list']:
- channel_trusts.append({'channel-label':
channel['label'],
- 'org-id': trust['org_trust_id']})
+ if (channel.has_key('org_id') and channel['org_id']
+ and self.backend.orgTrustExists(
+ channel['org_id'], trust['org_trust_id'])):
+ channel_trusts.append(
+ {'channel-label': channel['label'],
+ 'org-id': trust['org_trust_id']})
parent = channel['parent_channel']
if not parent:
nullParentBatch.append(channel)
diff --git a/backend/server/importlib/orgImport.py
b/backend/server/importlib/orgImport.py
index da0b807..b612da6 100644
--- a/backend/server/importlib/orgImport.py
+++ b/backend/server/importlib/orgImport.py
@@ -18,9 +18,15 @@
from importLib import Import
-# Here is how this is supposed to work:
-# 1) Satellite sync creates a bunch of
importLib.Org objects.
-# All ids are master ids.
+# Thanks for this class goes to Alex Martelli:
+#
http://stackoverflow.com/questions/1151658/python-hashable-dicts
+class hashabledict(dict):
+ def __key(self):
+ return tuple((k,self[k]) for k in sorted(self))
+ def __hash__(self):
+ return hash(self.__key())
+ def __eq__(self, other):
+ return self.__key() == other.__key()
class OrgImport(Import):
def __init__(self, batch, backend, master_label, create_orgs=False):
@@ -83,26 +89,25 @@ class OrgImport(Import):
# Iff we have a master org mapped to local org, create org
# trust records
- existing_trusts = self.backend.lookupOrgTrusts()
- trusts_to_create = []
# we need to uniquify in case user has mapped multiple orgs
# together
- hashes = set([])
+ trusts_to_create = set([])
for org in self.batch:
for trust in org['org_trust_ids']:
if (org['id'] in self.mi_to_li.keys()
and trust['org_id'] in self.mi_to_li.keys()):
my_org_id = self.mi_to_li[org['id']]
+ self.backend.clearOrgTrusts(my_org_id)
my_trust_id = self.mi_to_li[trust['org_id']]
- _hash = (str(self.mi_to_li[org['id']]) +
- str(self.mi_to_li[trust['org_id']]))
- if (_hash not in hashes
- and not (my_org_id in existing_trusts.keys()
- and my_trust_id in existing_trusts[my_org_id])):
- trusts_to_create.append({
+ trusts_to_create.add(hashabledict({
'org_id': my_org_id,
- 'trust': my_trust_id})
- hashes.add(_hash)
+ 'trust': my_trust_id}))
+ # org trusts are always bi-directional
+ # (even if we are not syncing the other org)
+ trusts_to_create.add(hashabledict({
+ 'org_id': my_trust_id,
+ 'trust': my_org_id}))
+
if len(trusts_to_create) > 0:
self.backend.createOrgTrusts(trusts_to_create)
except: