Read about our upcoming Code of Conduct on this issue

Commit 23a57aa7 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Heptapod: invalidate instance cache according to type and URL

With the new testing of production servers, the fixed user
names can differ from an instance (e.g. local, for tests development)
to another (actual production), leading to errors.

Invalidating based on URL only would not be enough for people that
actually work on the production mode – by testing it on a local
instance (typically provided by the HDK).

There already was a invalidation system for the token itself (test
and recreate if it does not work), but not for the mere existence
of an user in the registry.

branch : stable
parent c7516a71cef9
......@@ -74,6 +74,17 @@ class Heptapod:
default_group = None
"""Group instance where to create projects in by default."""
instance_type = 'development'
"""The type of instance, meaning how these tests operate on it.
It is of course completely possible to treat a development instance
as if it were for production: that's what happens when developping the
production server tests, of course.
Treating a production instance as a development one is also technically
possible (strongly discouraged of course).
def __init__(self, url, ssh_user, ssh_port,
......@@ -216,6 +227,12 @@ class Heptapod:
def load_instance_cache(self):
path = self.instance_cache_file()
def invalidate_retry():
logger.warning("Removing cache file %r and starting afresh.", path)
return self.load_instance_cache()
with open(path) as cachef:
cached = json.load(cachef)
......@@ -225,13 +242,32 @@ class Heptapod:
"Heptapod instance info will be retrieved "
"or initialized", path)
instance_type = cached.get('instance_type')
if instance_type != self.instance_type:
# None means before the introduction of this invalidation
# in case anyone wonders (not worth a specific message)
"Cache file %r is for another instance type (%r) ",
path, instance_type)
return invalidate_retry()
url = cached.get('url')
# for now all development instances have the same two
# fixed test users (root and test_basic). There is already
# a token invalidation logic.
if instance_type == 'production' and url != self.url:
# None means before the introduction of this invalidation
# in case anyone wonders (not worth a specific message)
"Cache file %r is for another instance (%r) ",
path, url)
return invalidate_retry()
for name, info in cached['users'].items():
if 'id' not in info:
logger.warning("Cache file %r is from an earlier version "
"of heptapod-tests. "
"Removing to start afresh.", path)
return self.load_instance_cache()
"of heptapod-tests. ", path)
return invalidate_retry()
self.users[name] = User(heptapod=self,
......@@ -241,7 +277,9 @@ class Heptapod:
users = { dict(token=user.token,
for user in self.users.values()}
with open(self.instance_cache_file(), 'w') as cachef:
json.dump(dict(users=users), cachef)
users=users), cachef)
def prepare(self, root_password):
"""Make all preparations for the Heptapod instance to be testable.
......@@ -491,6 +529,8 @@ class ProductionHeptapod(Heptapod):
and personal namespaces of a couple of users.
instance_type = 'production'
def __init__(self, group_owner_credentials, default_group_id,
super(ProductionHeptapod, self).__init__(**kw)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment