Skip to content

Commit f1d2ec3

Browse files
authored
Merge pull request #690 from globocom/fix-stage3-wrong-host
Fix stage 3 host migrate from new infra
2 parents 4a088d1 + 06f5996 commit f1d2ec3

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

dbaas/drivers/replication_topologies/redis.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,8 @@ def get_database_migrate_steps_stage_3(self):
708708
'workflow.steps.util.infra.DisableSourceInstances',
709709
'workflow.steps.util.database.StopSourceDatabaseMigrate',
710710
'workflow.steps.util.volume_provider.DestroyOldEnvironment',
711+
)}, {
712+
'Cleaning up 2': (
711713
'workflow.steps.util.host_provider.DestroyVirtualMachineMigrate',
712714
'workflow.steps.util.host_provider.DestroyIPMigrate',
713715
'workflow.steps.util.host_provider.DestroyServiceAccountMigrate',

dbaas/maintenance/tasks_database_migrate.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@ def build_hosts_migrate(hosts_zones, database_migrate):
3636
return instances
3737

3838

39-
def rebuild_hosts_migrate(current_db_migrate, previous_db_migrate):
39+
def rebuild_hosts_migrate(current_db_migrate,
40+
previous_db_migrate, validate_hosts=False):
4041
instances = []
4142
previous_hosts_migrate = previous_db_migrate.hosts.all()
43+
4244
for previous_host_migrate in previous_hosts_migrate:
45+
if (validate_hosts and
46+
previous_host_migrate.host.first_instance_dns !=
47+
previous_host_migrate.host.address):
48+
continue
4349
host = previous_host_migrate.host
4450
zone = previous_host_migrate.zone
4551
snapshot = previous_host_migrate.snapshot
@@ -143,7 +149,8 @@ def database_environment_migrate(
143149
if not can_migrate(database, task, migration_stage, False):
144150
return
145151
database_migrate = rebuild_database_migrate(task, step_manager)
146-
instances = rebuild_hosts_migrate(database_migrate, step_manager)
152+
instances = rebuild_hosts_migrate(database_migrate, step_manager,
153+
infra.in_last_migration_stage)
147154
else:
148155
infra.migration_stage += 1
149156
if not can_migrate(database, task, infra.migration_stage, False):
@@ -161,7 +168,8 @@ def database_environment_migrate(
161168
database=database,
162169
status=DatabaseMigrate.SUCCESS
163170
).last()
164-
instances = rebuild_hosts_migrate(database_migrate, last_db_migrate)
171+
instances = rebuild_hosts_migrate(database_migrate, last_db_migrate,
172+
infra.in_last_migration_stage)
165173
instances = sorted(instances, key=lambda k: k.id)
166174
steps = get_migrate_steps(database, infra.migration_stage)
167175
if not can_migrate_check_steps(
@@ -176,14 +184,11 @@ def database_environment_migrate(
176184
if result:
177185
database = database_migrate.database
178186
infra = database.infra
179-
is_ha = infra.plan.is_ha
180187
migration_stage = infra.migration_stage
181-
if ((is_ha and migration_stage == infra.STAGE_3) or
182-
(not is_ha and migration_stage == infra.STAGE_2)):
183-
188+
if infra.in_last_migration_stage:
184189
database.environment = database_migrate.environment
185190
database.save()
186-
191+
187192
infra.environment = database_migrate.environment
188193
infra.plan = infra.plan.get_equivalent_plan_for_env(
189194
database_migrate.environment

dbaas/physical/models.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,14 @@ def migration_in_progress(self):
10661066
def total_stages_migration(self):
10671067
return 3 if self.plan.is_ha else 2
10681068

1069+
@property
1070+
def in_last_migration_stage(self):
1071+
if not self.migration_in_progress:
1072+
return False
1073+
1074+
return (self.plan.is_ha and self.migration_stage == self.STAGE_3) or\
1075+
(not self.plan.is_ha and self.migration_stage == self.STAGE_2)
1076+
10691077
@classmethod
10701078
def get_unique_databaseinfra_name(cls, base_name):
10711079
"""
@@ -1336,6 +1344,13 @@ def non_database_instance(self):
13361344

13371345
return None
13381346

1347+
@property
1348+
def first_instance_dns(self):
1349+
for instance in self.instances.all():
1350+
return instance.dns
1351+
1352+
return None
1353+
13391354
@property
13401355
def is_database(self):
13411356
return self.database_instance() is not None

0 commit comments

Comments
 (0)