Fix the bug: upgrade failed in VIC if replication policies exist
This commit is contained in:
Wenkai Yin 2018-05-03 00:37:35 +08:00 committed by Yan
parent 30152b19c1
commit 5f58c01e4a
2 changed files with 43 additions and 11 deletions

View File

@ -27,6 +27,7 @@ depends_on = None
from alembic import op
from db_meta import *
import os
from sqlalchemy.dialects import mysql
@ -53,6 +54,15 @@ def upgrade():
unenabled_policies = session.query(ReplicationPolicy).filter(ReplicationPolicy.enabled == 0)
enabled_policies = session.query(ReplicationPolicy).filter(ReplicationPolicy.enabled == 1)
# As projects aren't stored in database of Harbor, migrate all replication
# policies with manual trigger
if os.getenv('WITH_ADMIRAL', '') == 'true':
print ("deployed with admiral, migrating all replication policies with manual trigger")
enabled_policies.update({
ReplicationPolicy.enabled: 1,
ReplicationPolicy.cron_str: '{"kind":"Manual"}'
})
else:
# migrate enabeld policies
enabled_policies.update({
ReplicationPolicy.cron_str: '{"kind":"Immediate"}'

View File

@ -6,6 +6,14 @@ import os
import sys
import argparse
if sys.version_info[:3][0] == 2:
import ConfigParser as ConfigParser
import StringIO as StringIO
if sys.version_info[:3][0] == 3:
import configparser as ConfigParser
import io as StringIO
RC_VALIDATE = 101
RC_UP = 102
RC_DOWN = 103
@ -17,8 +25,22 @@ RC_GEN = 110
class DBMigrator():
def __init__(self, target):
path = "/harbor-migration/harbor-cfg/harbor.cfg"
env = ""
if os.path.exists(path):
temp_section = "configuration"
conf = StringIO.StringIO()
conf.write("[%s]\n" % temp_section)
conf.write(open(path).read())
conf.seek(0, os.SEEK_SET)
rcp = ConfigParser.RawConfigParser()
rcp.readfp(conf)
if rcp.get(temp_section, "admiral_url") != "NA":
env = "WITH_ADMIRAL=true"
else:
print("harbor.cfg not found, WITH_ADMIRAL will not be set to true")
self.target = target
self.script = "./db/run.sh"
self.script = env + " ./db/run.sh"
def backup(self):
return run_cmd(self.script + " backup") == 0