Fail reconcile if no region found
This commit is contained in:
parent
73571f2e2d
commit
a2b6ced6bc
@ -120,6 +120,10 @@ class Reconciler(object):
|
||||
reconciled = False
|
||||
launch = models.InstanceUsage.objects.get(id=launched_id)
|
||||
region = self._region_for_usage(launch)
|
||||
|
||||
if not region:
|
||||
return False
|
||||
|
||||
try:
|
||||
instance = self.client.get_instance(region, launch.instance)
|
||||
if instance['deleted'] and instance['deleted_at'] is not None:
|
||||
@ -140,6 +144,10 @@ class Reconciler(object):
|
||||
def failed_validation(self, exists):
|
||||
reconciled = False
|
||||
region = self._region_for_usage(exists)
|
||||
|
||||
if not region:
|
||||
return False
|
||||
|
||||
try:
|
||||
instance = self.client.get_instance(region, exists.instance,
|
||||
get_metadata=True)
|
||||
|
@ -229,6 +229,21 @@ class ReconcilerTestCase(unittest.TestCase):
|
||||
self.assertFalse(result)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_missing_exists_for_instance_region_not_found(self):
|
||||
launch_id = 1
|
||||
beginning_d = utils.decimal_utc()
|
||||
launch = self.mox.CreateMockAnything()
|
||||
launch.instance = INSTANCE_ID_1
|
||||
launch.launched_at = beginning_d - (60*60)
|
||||
launch.instance_type_id = 1
|
||||
models.InstanceUsage.objects.get(id=launch_id).AndReturn(launch)
|
||||
launch.deployment().AndReturn(None)
|
||||
self.mox.ReplayAll()
|
||||
result = self.reconciler.missing_exists_for_instance(launch_id,
|
||||
beginning_d)
|
||||
self.assertFalse(result)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_failed_validation(self):
|
||||
exists = self._fake_usage(is_exists=True, mock_deployment=True)
|
||||
launched_at = exists.launched_at
|
||||
@ -344,6 +359,21 @@ class ReconcilerTestCase(unittest.TestCase):
|
||||
self.assertFalse(result)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_failed_validation_region_not_found(self):
|
||||
beginning_d = utils.decimal_utc()
|
||||
exists = self.mox.CreateMockAnything()
|
||||
exists.instance = INSTANCE_ID_1
|
||||
launched_at = beginning_d - (60*60)
|
||||
exists.launched_at = launched_at
|
||||
exists.instance_type_id = 1
|
||||
exists.deleted_at = None
|
||||
exists.deployment().AndReturn(None)
|
||||
ex = exceptions.NotFound()
|
||||
self.mox.ReplayAll()
|
||||
result = self.reconciler.failed_validation(exists)
|
||||
self.assertFalse(result)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_fields_match(self):
|
||||
exists = self._fake_usage(is_exists=True)
|
||||
kwargs = {'launched_at': exists.launched_at}
|
||||
|
Loading…
x
Reference in New Issue
Block a user