Merge pull request #1082 from dod-ccpo/env-provisioning-tweaks

Tweaks to environment provisioning jobs
This commit is contained in:
richard-dds 2019-09-19 15:29:25 -04:00 committed by GitHub
commit 4ba3e6cd97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 6 deletions

View File

@ -104,6 +104,7 @@ class Environments(object):
.join(CLIN) .join(CLIN)
.filter(CLIN.start_date <= now) .filter(CLIN.start_date <= now)
.filter(CLIN.end_date > now) .filter(CLIN.end_date > now)
.filter(Environment.deleted == False)
.filter( .filter(
or_( or_(
Environment.claimed_until == None, Environment.claimed_until == None,

View File

@ -108,19 +108,19 @@ def do_work(fn, task, csp, **kwargs):
raise task.retry(exc=e) raise task.retry(exc=e)
@celery.task(bind=True) @celery.task(bind=True, base=RecordEnvironmentFailure)
def create_environment(self, environment_id=None): def create_environment(self, environment_id=None):
do_work(do_create_environment, self, app.csp.cloud, environment_id=environment_id) do_work(do_create_environment, self, app.csp.cloud, environment_id=environment_id)
@celery.task(bind=True) @celery.task(bind=True, base=RecordEnvironmentFailure)
def create_atat_admin_user(self, environment_id=None): def create_atat_admin_user(self, environment_id=None):
do_work( do_work(
do_create_atat_admin_user, self, app.csp.cloud, environment_id=environment_id do_create_atat_admin_user, self, app.csp.cloud, environment_id=environment_id
) )
@celery.task(bind=True) @celery.task(bind=True, base=RecordEnvironmentFailure)
def create_environment_baseline(self, environment_id=None): def create_environment_baseline(self, environment_id=None):
do_work( do_work(
do_create_environment_baseline, do_create_environment_baseline,

View File

@ -102,8 +102,10 @@ def test_create_environment_baseline(csp, session):
def test_dispatch_create_environment(session, monkeypatch): def test_dispatch_create_environment(session, monkeypatch):
# Given that I have a portfolio with an active CLIN and two environments,
# one of which is deleted
portfolio = PortfolioFactory.create( portfolio = PortfolioFactory.create(
applications=[{"environments": [{}]}], applications=[{"environments": [{}, {}]}],
task_orders=[ task_orders=[
{ {
"create_clins": [ "create_clins": [
@ -115,13 +117,20 @@ def test_dispatch_create_environment(session, monkeypatch):
} }
], ],
) )
[e1, e2] = portfolio.applications[0].environments
e2.deleted = True
session.add(e2)
session.commit()
mock = Mock() mock = Mock()
monkeypatch.setattr("atst.jobs.create_environment", mock) monkeypatch.setattr("atst.jobs.create_environment", mock)
environment = portfolio.applications[0].environments[0]
# When dispatch_create_environment is called
dispatch_create_environment.run() dispatch_create_environment.run()
mock.delay.assert_called_once_with(environment_id=environment.id) # It should cause the create_environment task to be called once with the
# non-deleted environment
mock.delay.assert_called_once_with(environment_id=e1.id)
def test_dispatch_create_atat_admin_user(session, monkeypatch): def test_dispatch_create_atat_admin_user(session, monkeypatch):