Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Print tenant name in logs instead of tenant ID #1387

Merged
merged 1 commit into from
Jun 14, 2017

Conversation

shivanshu21
Copy link
Contributor

Description

Changed approach after discussion with Mark. Closing previous pull request.
This fixes #955

If the request comes with a tenant_name already, I return a path with symlink name instead of tenant UUID. The OS will handle resolving symlinks.

Testing done:

Manual tests:

  1. Create VMDK
  2. Remove VMDK

Ran multiple runs of CI automation.
After multiple ESX server operations, logs do not show tenant UUID in vmdk_path anymore.
Here is a CI test I scheduled on build server: https://ci.vmware.run/vmware/docker-volume-vsphere/458

Log Excerpts

06/09/17 20:57:14 5055174 [photon-VM0.2-sharedVmfs-0._DEFAULT.option_volume_3132227180552437724] [INFO ] *** createVMDK: /vmfs/volumes/sharedVmfs-0/dockvols/_DEFAULT/option_volume_3132227180552437724.vmdk opts = {'fstype': 'ext4', 'size': '10gb'} vm_name=photon-VM0.2 tenant_uuid=11111111-1111-1111-1111-111111111111 datastore_url=/vmfs/volumes/591cfe9a-12f9884b-340d-020037ced216

06/09/17 20:57:27 5055174 [photon-VM0.2-sharedVmfs-0._DEFAULT.option_volume_8185258463521160967] [INFO ] *** removeVMDK: /vmfs/volumes/sharedVmfs-0/dockvols/_DEFAULT/option_volume_8185258463521160967.vmdk

06/09/17 20:57:18 5055174 [photon-VM0.2-sharedVmfs-0._DEFAULT.option_volume_182702735967048418] [INFO ] *** attachVMDK: /vmfs/volumes/sharedVmfs-0/dockvols/_DEFAULT/option_volume_182702735967048418.vmdk to photon-VM0.2 VM uuid = 564d5cac-bc2b-bfde-45ca-14f6f8437476

@vmwclabot
Copy link

@shivanshu21, VMware has rejected your signed contributor license agreement. The merge can not proceed until the agreement has been resigned. Click here to resign the agreement.

Copy link
Contributor

@msterin msterin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looking good. A few comments inside - please take a look


path = dock_vol_path = os.path.join("/vmfs/volumes", datastore, DOCK_VOLS_DIR)
rpath = path = dock_vol_path = os.path.join("/vmfs/volumes", datastore, DOCK_VOLS_DIR)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does "r" stands for in "rpath" ? It would be better to use full names, whatever it is .... - easier to read

@@ -696,20 +696,24 @@ def get_vol_path(datastore, tenant_name=None):
# is created on <datastore>/DOCK_VOLS_DIR/tenant_uuid
# a symlink <datastore>/DOCK_VOLS_DIR/tenant_name will be created to point to
# path <datastore>/DOCK_VOLS_DIR/tenant_uuid
# If the command is under a tenant then the path returned contains tenant
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what "command is under a tenant" mean. Can you elaborate ?

Copy link
Contributor Author

@shivanshu21 shivanshu21 Jun 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just an extension of the already present comment at the start of this function mentioned below:

"If the command is NOT running under a tenant, the folder for Docker volumes is created on /DOCK_VOLS_DIR"

By this the original commenter means that tenant_name is not none in the args.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then let's change the comment (including the original one) so it is clear


if tenant_name:
error_info, tenant = auth_api.get_tenant_from_db(tenant_name)
if error_info:
logging.error("get_vol_path: failed to find tenant info for tenant %s", tenant_name)
path = dock_vol_path
path = os.path.join(dock_vol_path, tenant.id)
rpath = os.path.join(dock_vol_path, tenant_name)

if os.path.isdir(path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not it be if os.path.ispath(rpath) ?


if os.path.isdir(path):
# If the path exists then return it as is.
logging.debug("Found %s, returning", path)
return path, None
logging.debug("Found %s, returning", rpath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also should check (out of healty paranoia) if os.path.exists(os.path.realpath(rpath)) and thow or print a warning if it does not


if tenant_name:
error_info, tenant = auth_api.get_tenant_from_db(tenant_name)
if error_info:
logging.error("get_vol_path: failed to find tenant info for tenant %s", tenant_name)
path = dock_vol_path
path = os.path.join(dock_vol_path, tenant.id)
rpath = os.path.join(dock_vol_path, tenant_name)
Copy link
Contributor

@luomiao luomiao Jun 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why rpath? (in the sense, what's "r" stands for?)
update: oops just saw this one is duplicated with Mark's review above :)

And it looks like rpath is in fact the same thing as the symlink_path on Line 739. Can you just use symlink_path here?

# If the path exists then return it as is.
logging.debug("Found %s, returning", path)
return path, None
if os.path.isdir(readable_path) or os.path.isdir(path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just feel the new logic here is different from old ones...
Before this fix, if path is not a dir, it will go ahead to the following steps to create it or run necessary things.
But the new logic is, as long as the readable_path is there (even path is not a dir), it will never go to the rest of the code.
Is it possible that, the original path is getting deleted but the symlink path is still existing. Then the original path will never be created again?
I am not sure if this is a possible situation. Just raise the concern.
So I think it's better to keep this check as it was "if os.path.isdir(path):", but add your following checks.

@luomiao
Copy link
Contributor

luomiao commented Jun 12, 2017

And sorry I just noticed here: line 751
I guess you may want to add the return of readable_path here too (with the checks).

And btw for line 734, it looks like the second half "not os.path.isdir(path)" check is not necessary.

@shivanshu21
Copy link
Contributor Author

@luomiao We can leave line 734 for abundance of caution. The original writer might have put it for some corner case. Fixed line 751.

@luomiao
Copy link
Contributor

luomiao commented Jun 12, 2017

LGTM but need Mark's final call :)

Copy link
Contributor

@msterin msterin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small request (change logging.debug to logging,warning) and it's ready to merge when CI passes.
Thanks for taking care of this !

logging.debug("Found %s, returning", readable_path)
return readable_path, None
else:
logging.debug("Tenant name symlink not found for path %s", readable_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be logging.warning("internal: Tenant name symlink not found for path %s. Using UUID path instead") - it is not a normal situation

Addressing Marks and Miaos comments

Fixing comment

Addressing Miaos comments

Changing no symlink case to warning
@pshahzeb
Copy link
Contributor

Merging this. Comments have been addressed by @shivanshu21 .

@pshahzeb pshahzeb merged commit 0c6cda5 into vmware-archive:master Jun 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use the tenant name in the logs instead of tenant IDs
5 participants