mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
Return stub records in testing.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
# Copyright (c) 2014 Ansible, Inc.
|
# Copyright (c) 2014 Ansible, Inc.
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
@@ -14,16 +16,34 @@ class InstanceManager(models.Manager):
|
|||||||
"""
|
"""
|
||||||
def me(self):
|
def me(self):
|
||||||
"""Return the currently active instance."""
|
"""Return the currently active instance."""
|
||||||
|
# If we are running unit tests, return a stub record.
|
||||||
|
if len(sys.argv) >= 2 and sys.argv[1] == 'test':
|
||||||
|
return self.model(id=1, primary=True,
|
||||||
|
uuid='00000000-0000-0000-0000-000000000000')
|
||||||
|
|
||||||
|
# Return the appropriate record from the database.
|
||||||
return self.get(uuid=settings.SYSTEM_UUID)
|
return self.get(uuid=settings.SYSTEM_UUID)
|
||||||
|
|
||||||
def my_role(self):
|
def my_role(self):
|
||||||
"""Return the role of the currently active instance, as a string
|
"""Return the role of the currently active instance, as a string
|
||||||
('primary' or 'secondary').
|
('primary' or 'secondary').
|
||||||
"""
|
"""
|
||||||
|
# If we are running unit tests, we are primary, because reasons.
|
||||||
|
if len(sys.argv) >= 2 and sys.argv[1] == 'test':
|
||||||
|
return 'primary'
|
||||||
|
|
||||||
|
# Check if this instance is primary; if so, return "primary", otherwise
|
||||||
|
# "secondary".
|
||||||
if self.me().primary:
|
if self.me().primary:
|
||||||
return 'primary'
|
return 'primary'
|
||||||
return 'secondary'
|
return 'secondary'
|
||||||
|
|
||||||
def primary(self):
|
def primary(self):
|
||||||
"""Return the primary instance."""
|
"""Return the primary instance."""
|
||||||
|
# If we are running unit tests, return a stub record.
|
||||||
|
if len(sys.argv) >= 2 and sys.argv[1] == 'test':
|
||||||
|
return self.model(id=1, primary=True,
|
||||||
|
uuid='00000000-0000-0000-0000-000000000000')
|
||||||
|
|
||||||
|
# Return the appropriate record from the database.
|
||||||
return self.get(primary=True)
|
return self.get(primary=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user