Skip to content

Commit

Permalink
Merge branch 'fix/zone_migration_and_switch_master' into 'master'
Browse files Browse the repository at this point in the history
Fix/zone migration and switch master

See merge request dbdev/dbaas!5
  • Loading branch information
iago.henrique committed Jun 6, 2023
2 parents 168b062 + b6a88a0 commit f99b2e7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
4 changes: 2 additions & 2 deletions dbaas/drivers/redis.py
Expand Up @@ -528,7 +528,7 @@ def switch_master(self, instance=None, preferred_slave_instance=None):
fi
}"""

if self.engine.major_version == 6:
if self.databaseinfra.engine.major_version == 6:
script += """
/usr/bin/redis-cli -h {} -p {} <<EOF_DBAAS
SENTINEL failover {}
Expand Down Expand Up @@ -747,7 +747,7 @@ def switch_master(self, instance=None, preferred_slave_instance=None):
fi
}"""

if self.engine.major_version == 6:
if self.databaseinfra.engine.major_version == 6:
script += """
/usr/bin/redis-cli -h {} -p {} -a {} -c<<EOF_DBAAS
CLUSTER FAILOVER
Expand Down
Expand Up @@ -124,7 +124,9 @@ <h3>Regions</h3>
{% endfor %}
{% endif %}
</select>
<button data-toggle="modal" id="migrate_region_btn" class="resize_button btn host-zone-btn" data-region-name="{{reg.region}}" data-region-id="{{reg.env}}" data-target="#migrate_region_modal" disabled>Migrate Region to GCP</button>
{% if is_dba %}
<button data-toggle="modal" id="migrate_region_btn" class="resize_button btn host-zone-btn" data-region-name="{{reg.region}}" data-region-id="{{reg.env}}" data-target="#migrate_region_modal">Migrate Region to GCP</button>
{% endif %}
</p>
</td>
</div>
Expand Down Expand Up @@ -270,9 +272,11 @@ <h3>Regions</h3>
$("#migrate_region").change(function() {
if ((is_in_waiting) || ($(this).val() === "---------")){
status_migrate("migrate_region_btn", "DISABLE", "DISABLE");
status_migrate("migrate_host_btn_" + hostId, "DISABLE", "DISABLE");
}
else {
status_migrate("migrate_region_btn", "DISABLE", "DISABLE");
status_migrate("migrate_region_btn", "DISABLE", "False");
status_migrate("migrate_host_btn_" + hostId, "DISABLE", "DISABLE");
}
});

Expand Down
1 change: 1 addition & 0 deletions dbaas/logical/views.py
Expand Up @@ -2372,6 +2372,7 @@ def database_migrate(request, context, database):
context["environments"] = set()
context['zones'] = sorted(zones)
context['hosts'] = sorted(hosts, key=lambda host: host.hostname)
context['is_dba'] = request.user.team_set.filter(role__name="role_dba")

environment_groups = environment.groups.all()
if not environment_groups:
Expand Down
49 changes: 34 additions & 15 deletions dbaas/workflow/steps/redis/upgrade/sentinel.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from time import sleep
from workflow.steps.util.base import BaseInstanceStep
from workflow.steps.redis.util import reset_sentinel
from workflow.steps.redis.util import reset_sentinel, reset_sentinel_redis_6


class Reset(BaseInstanceStep):
Expand All @@ -15,13 +15,22 @@ def sentinel_instance(self):

def do(self):
sleep(10)
if self.sentinel_instance:
reset_sentinel(
self.host,
self.sentinel_instance.address,
self.sentinel_instance.port,
self.sentinel_instance.databaseinfra.name
)
if self.infra.engine.major_version == 6:
if self.sentinel_instance:
reset_sentinel_redis_6(
self.host,
self.sentinel_instance.address,
self.sentinel_instance.port,
self.sentinel_instance.databaseinfra.name
)
else:
if self.sentinel_instance:
reset_sentinel(
self.host,
self.sentinel_instance.address,
self.sentinel_instance.port,
self.sentinel_instance.databaseinfra.name
)

def undo(self):
pass
Expand All @@ -34,13 +43,23 @@ def __unicode__(self):

def reset_sentinels(self):
driver = self.infra.get_driver()
for sentinel_instance in driver.get_non_database_instances():
reset_sentinel(
sentinel_instance.hostname,
sentinel_instance.address,
sentinel_instance.port,
self.infra.name
)
if self.infra.engine.major_version == 6:
for sentinel_instance in driver.get_non_database_instances():
reset_sentinel_redis_6(
sentinel_instance.hostname,
sentinel_instance.address,
sentinel_instance.port,
self.infra.name
)
else:
for sentinel_instance in driver.get_non_database_instances():
reset_sentinel(
self.host,
self.sentinel_instance.address,
self.sentinel_instance.port,
self.sentinel_instance.databaseinfra.name
)


def do(self):
self.reset_sentinels()
Expand Down

0 comments on commit f99b2e7

Please sign in to comment.