mirror of
https://github.com/ansible/awx.git
synced 2026-03-13 15:09:32 -02:30
drop mongo database when complete
This commit is contained in:
@@ -1,10 +1,23 @@
|
|||||||
|
|
||||||
from awx.fact.models import FactVersion
|
from awx.fact.models import FactVersion
|
||||||
|
from mongoengine.connection import ConnectionError
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
def drop_system_tracking_db():
|
||||||
|
try:
|
||||||
|
db = FactVersion._get_db()
|
||||||
|
db.connection.drop_database(settings.MONGO_DB)
|
||||||
|
except ConnectionError:
|
||||||
|
# TODO: Log this. Not a deal-breaker. Just let the user know they
|
||||||
|
# may need to manually drop/delete the database.
|
||||||
|
pass
|
||||||
|
|
||||||
def migrate_facts(apps, schema_editor):
|
def migrate_facts(apps, schema_editor):
|
||||||
Fact = apps.get_model('main', "Fact")
|
Fact = apps.get_model('main', "Fact")
|
||||||
Host = apps.get_model('main', "Host")
|
Host = apps.get_model('main', "Host")
|
||||||
|
|
||||||
|
# TODO: Check to see if mongo connection works and mongo is on.
|
||||||
|
|
||||||
migrated_count = 0
|
migrated_count = 0
|
||||||
not_migrated_count = 0
|
not_migrated_count = 0
|
||||||
for factver in FactVersion.objects.all():
|
for factver in FactVersion.objects.all():
|
||||||
@@ -18,4 +31,5 @@ def migrate_facts(apps, schema_editor):
|
|||||||
# This isn't a hard error. Just something the user would want to know.
|
# This isn't a hard error. Just something the user would want to know.
|
||||||
not_migrated_count += 1
|
not_migrated_count += 1
|
||||||
|
|
||||||
|
drop_system_tracking_db()
|
||||||
return (migrated_count, not_migrated_count)
|
return (migrated_count, not_migrated_count)
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ from awx.main.models.fact import Fact
|
|||||||
|
|
||||||
from awx.main.migrations import _system_tracking as system_tracking
|
from awx.main.migrations import _system_tracking as system_tracking
|
||||||
|
|
||||||
|
from awx.fact.models.fact import Fact as FactMongo
|
||||||
|
from awx.fact.models.fact import FactVersion, FactHost
|
||||||
|
|
||||||
def micro_to_milli(micro):
|
def micro_to_milli(micro):
|
||||||
return micro - (((int)(micro / 1000)) * 1000)
|
return micro - (((int)(micro / 1000)) * 1000)
|
||||||
|
|
||||||
@@ -58,3 +61,19 @@ def test_migrate_facts_hostname_does_not_exist(inventories, hosts, hosts_mongo,
|
|||||||
assert len(fact) == 1
|
assert len(fact) == 1
|
||||||
assert fact[0] is not None
|
assert fact[0] is not None
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
@pytest.mark.mongo_db
|
||||||
|
def test_drop_system_tracking_db(inventories, hosts, hosts_mongo, fact_scans):
|
||||||
|
inventory_objs = inventories(1)
|
||||||
|
hosts_mongo(1, inventory_objs)
|
||||||
|
facts_known = fact_scans(1, inventory_objs)
|
||||||
|
|
||||||
|
assert FactMongo.objects.all().count() > 0
|
||||||
|
assert FactVersion.objects.all().count() > 0
|
||||||
|
assert FactHost.objects.all().count() > 0
|
||||||
|
|
||||||
|
system_tracking.drop_system_tracking_db()
|
||||||
|
|
||||||
|
assert FactMongo.objects.all().count() == 0
|
||||||
|
assert FactVersion.objects.all().count() == 0
|
||||||
|
assert FactHost.objects.all().count() == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user