Skip to content

Commit

Permalink
Scheduler now also garbage-collects VMs from weave-net-tests.
Browse files Browse the repository at this point in the history
This is required so that VMs started by build-tools/provisioning against the weave-net-tests project in GCP are garbage collected, should an issue arise and therefore, should the VMs be kept up and running for no good reason.
  • Loading branch information
marccarre committed Jan 11, 2017
1 parent 4b7d5c6 commit 4085df9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions scheduler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,19 @@ def avg(test):
schedule = Schedule.get_or_insert(schedule_id, shards=shards)
return flask.json.jsonify(tests=schedule.shards[str(shard)])

NAME_RE = re.compile(r'^host(?P<index>\d+)-(?P<build>\d+)-(?P<shard>\d+)$')
NAME_REGEXES = [
re.compile(r'^host(?P<index>\d+)-(?P<build>\d+)-(?P<shard>\d+)$'),
re.compile(r'^test-(?P<build>\d+)-(?P<shard>\d+)-(?P<index>\d+)$'),
]

def _matches_any_regex(name):
for regex in NAME_REGEXES:
matches = regex.match(name)
if matches:
return matches

PROJECTS = [
('weaveworks/weave', 'weave-net-tests', 'us-central1-a'),
('weaveworks/weave', 'positive-cocoa-90213', 'us-central1-a'),
('weaveworks/scope', 'scope-integration-tests', 'us-central1-a'),
]
Expand All @@ -111,8 +121,8 @@ def gc_project(compute, repo, project, zone):

host_by_build = collections.defaultdict(list)
for instance in instances['items']:
matches = NAME_RE.match(instance['name'])
if matches is None:
matches = _matches_any_regex(instance['name'])
if not matches:
continue
host_by_build[int(matches.group('build'))].append(instance['name'])
logging.info("Running VMs by build: %r", host_by_build)
Expand Down

0 comments on commit 4085df9

Please sign in to comment.