-
Notifications
You must be signed in to change notification settings - Fork 95
Script to update from release 0.11 or earlier #951
Conversation
""" | ||
|
||
tmp_tenant_name = "__tmp_name_upgrade_0_11" | ||
sql_query = sql_query_template.format(old_uuid, STATIC_UUID, tmp_tenant_name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we make sure those DB update is in a DB transaction? I think we should try/catch DB errors here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SQLite3.py automatically wraps any modifying call in a transaction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those modifying call can throw exception, we should catch and print the exception I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is it different from printing exception and exiting , which is the current behavior in case there is an exception ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we handle the possible exception by running this "cursor.executescript(sql_query)"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't. My point is that if it happens, python will print the traceback and exit, which is what we want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, got it.
|
||
# STEP : convert dir names to new UUID if needed. | ||
print("Starting conversion of _DEFAULT tenant directory names. old_uid is {0}".format(old_uuid)) | ||
stores = vmdk_utils.get_datastores() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You stopped the service earlier. So, stores is always going to be None right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we do not ask anything from the service since we directly import and use proper modules.
print(" Skipping {0} - not found".format(old_dir)) | ||
continue | ||
if os.path.isdir(new_dir): | ||
print(" Skipping {0} - {1} already exists".format(old_dir, new_dir)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continue missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, good catch !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Updates ESX with vSphere Docker Volume Service 0.11 (and earlier) | ||
# to 0.11.1 and further | ||
# | ||
# This code expects to be places in /usr/lib/vmware/vmdkops/bin/ to pick up correct modules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we check pwd
in the begining?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can, but I think I just need to drop the comment since the file is now in the bin in the proper place . I'll drop the comment
|
||
if stop_service: | ||
print("Stopping vmdk-opsd service") | ||
os.system("/etc/init.d/vmdk-opsd stop") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it a good idea to stop service first before initiating backup process?
# note that: | ||
# {0} is old_uuid (default tenant uuid pre-upgrade) | ||
# {1} is new_uuid (default tenant uuid post-upgrade) | ||
# {2} is tmp name - we need it to comply with DB constrants |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: constrants => constraints ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
sys.exit(ERROR) | ||
|
||
print("Found default tenant: {0} {1} {2} {3}".format(tenant_id, | ||
tenant_name, tenant_desr, tenant_def_db)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can you please rename "tenant_def_db" to "tenant_def_ds" for better reading?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cursor.execute("SELECT * from tenants") | ||
for r in cursor.fetchone(): | ||
print(r) | ||
print("Done") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious to know here: don't we need to close()
the db connection after finishing migration?
if os.path.isdir(new_dir): | ||
print(" Skipping {0} - {1} already exists".format(old_dir, new_dir)) | ||
print(" Renaming {0} to {1}".format(old_dir, new_dir)) | ||
os.rename(old_dir, new_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while executing this upgrade script on multi-esx testbed, line#131 is failing while invoking on second ESX host.
[root@sc-rdops-vm17-dhcp-15-100:~] python /usr/lib/vmware/vmdkops/bin/script.py
Found default tenant: 5be05130-5e18-490b-ba99-42f4b798153d _DEFAULT This is a default tenant on 100
Backing up Config DB to '/etc/vmware/vmdkops/auth-db.bck'
Stopping vmdk-opsd service
Stopping vmdkops-opsd with PID=1240898
vmdkops-opsd is not running
Starting conversion of _DEFAULT tenant directory names. old_uid is 5be05130-5e18-490b-ba99-42f4b798153d
Working on Datastore 'sharedVmfs-0'
Info: /vmfs/volumes/sharedVmfs-0/dockvols/11111111-1111-1111-1111-111111111111 /vmfs/volumes/sharedVmfs-0/dockvols/5be05130-5e18-490b-ba99-42f4b798153d /vmfs/volumes/sharedVmfs-0/dockvols/_DEFAULT
Skipping /vmfs/volumes/sharedVmfs-0/dockvols/5be05130-5e18-490b-ba99-42f4b798153d - /vmfs/volumes/sharedVmfs-0/dockvols/11111111-1111-1111-1111-111111111111 already exists
Renaming /vmfs/volumes/sharedVmfs-0/dockvols/5be05130-5e18-490b-ba99-42f4b798153d to /vmfs/volumes/sharedVmfs-0/dockvols/11111111-1111-1111-1111-111111111111
Traceback (most recent call last):
File "/usr/lib/vmware/vmdkops/bin/script.py", line 187, in <module>
main()
File "/usr/lib/vmware/vmdkops/bin/script.py", line 129, in main
os.rename(old_dir, new_dir)
OSError: [Errno 39] Directory not empty: '/vmfs/volumes/sharedVmfs-0/dockvols/5be05130-5e18-490b-ba99-42f4b798153d' -> '/vmfs/volumes/sharedVmfs-0/dockvols/11111111-1111-1111-1111-111111111111' ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while referring @pdhamdhere's previous comment, I've added missing continue
as shown below to get the script working.
With the following code block I got the script working but it tends to data loss i.e. volumes created on shared datastore from docker_host resided on the second ESX (shared vmfs & vsan) are no longer accessible/visible (not sure I have misunderstood the previous comment) .. please have a look at following code block.
IMO, we definitely need to add continue
but before releasing the control need to copy existing vmdk data to 111-111...111
folder i.e. _DEFAULT tenant folder.
if not os.path.isdir(old_dir):
print(" Skipping {0} - not found".format(old_dir))
continue
if os.path.isdir(new_dir):
print(" Skipping {0} - {1} already exists".format(old_dir, new_dir))
continue <==== this is modified part as per Prashant's previous comment.
print(" Renaming {0} to {1}".format(old_dir, new_dir))
b416028
to
fc1b12b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@shuklanirdesh82 double checked on dual esx/multiple DS data stores and it worked as expected. Merging. |
…andom UUID). This script massages DB and moves VMDK to comply with 0.11.1 and later (1) checks that the DB needs upgrade (2) renames default tenant folder and flips the _DEFAULT symlink (or moves files if needed) (3) patches DB to use static uuid for default tenant, and patched DB version
fc1b12b
to
344c5a7
Compare
Script to update from release 0.11 or earlier (i.e. from the version with Default tenant picking random UUID.). See #942 and #193 for more details.
This script massages DB and moves VMDK to comply with 0.11.1 and later
Steps:
(1) checks that the DB needs upgrade
(2) renames default tenant folder and flips the _DEFAULT symlink
(3) patches DB to use static uuid for default tenant, and patched DB version
Testing: Manual
docker volume create
fails with/usr/lib/vmware/vmdkops/bin/vmdkops_post_update.11.1.py
docker run
and `docker volume ls.Script output
//CC @pdhamdhere @shuklanirdesh82 @lipingxue