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

Fixing list_volumes_and_policies() to correctly list volumes #953

Merged
merged 4 commits into from Feb 24, 2017

Conversation

pshahzeb
Copy link
Contributor

@pshahzeb pshahzeb commented Feb 23, 2017

  1. Using get_volumes() in list_volumes_and_policies() instead of
    list_vmdks() to properly walk in dockvols directory which contain
    tenant-uuid based subdirectories
    This fixes output by admin policy ls command
  2. Fixing update_vsan_objects_with_policy to make proper use
    of list_volumes_and_policies()

Testing:
Porting the update_vsan_policy test to tenant based Vmdk ops test suite

Manual testing of admin policy ls command done

[root@sc-rdops-vm07-dhcp-208-78:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py policy create --name poltest --content '(("proportionalCapacity" i0)("hostFailuresToTolerate" i0))'
Successfully created policy: poltest
[root@sc-rdops-vm07-dhcp-208-78:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py policy ls
Policy Name  Policy Content                                              Active
-----------  ----------------------------------------------------------  ------
poltest      (("proportionalCapacity" i0)("hostFailuresToTolerate" i0))  Unused

Creating two volumes using the above policy

root@photon-HqYoHLUks [ ~ ]# docker volume create --driver=vmdk --name=vol_poltest -o vsan-policy-name=poltest
vol_poltest
root@photon-HqYoHLUks [ ~ ]# docker volume create --driver=vmdk --name=vol_poltest_2 -o vsan-policy-name=poltest
vol_poltest_2
[root@sc-rdops-vm07-dhcp-208-78:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py policy ls
Policy Name  Policy Content                                              Active
-----------  ----------------------------------------------------------  -------------------
poltest      (("proportionalCapacity" i0)("hostFailuresToTolerate" i0))  In use by 2 volumes

Resolves: #853 #948

1. Using get_volumes() in list_volumes_and_policies() instead of
   list_vmdks() to properly walk in dockvols directory which contain
   tenant-uuid based subdirectories
   This fixes output by admin policy ls command
2. Fixing update_vsan_objects_with_policy to make proper use
   of list_volumes_and_policies()

Testing:
Porting the update_vsan_policy test to tenant based Vmdk ops test suite
Manual testing of admin policy ls command done

Resolves: #853
Copy link
Contributor

@pdhamdhere pdhamdhere left a comment

Choose a reason for hiding this comment

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

LGTM contingent to CI pass.

Can you also confirm in-use policy name can't be deleted?

@@ -204,33 +204,6 @@ def testAttachAsOpts(self):

@unittest.skipIf(not vsan_info.get_vsan_datastore(),
"VSAN is not found - skipping vsan_info tests")
def testPolicyUpdate(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason for removing this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test creates a vmdk inside dockvols folder, assign a good policy to it and then update the policy with bad content. In this case, it tries to list the vmdks associated with the good policy and set the updated policy to it. The test expects the update to fail because of the bad content. In this process, when the vsan_policy update api is invoked, no vmdks are listed because the vmdks are created inside tenant uuid named sub directories as per multi tenancy design. As no vmdk that would be affected are returned, this test case wasn't throwing an error.
I haven't removed it, but moved it to the test suite where tenant based vmdks are created.
Hence it properly lists the vmdk files, tries to update it and fails appropriately because of the bad content of policy

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay great!! Makes sense!

@@ -1039,6 +1012,55 @@ def test_vmdkops_on_tenant_vm(self):
error_info = vmdk_ops.executeRequest(vm1_uuid, self.vm1_name, self.vm1_config_path, auth.CMD_REMOVE, self.tenant1_vol1_name, opts)
self.assertEqual(None, error_info)

@unittest.skipIf(not vsan_info.get_vsan_datastore(),
"VSAN is not found - skipping vsan_info tests")
def testPolicyUpdateBackup(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

can you confirm whether the test is added to cover proposed code in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The proposed code in this PR hits in two ways. One through vsan update policy flow, for which following the test case is added. Second is the policy ls admin command which I have described in manual testing in description. Will add a unit test for this as well.

@pshahzeb
Copy link
Contributor Author

@pdhamdhere
Even after this fix, it is possible to delete the policy which is in use by any volume.
Looking into this through #948

1. Minor change to use list_volumes_and_policies()
   instead of list_vmdks() to find vmdks using a policy
Testing:
1. Manual testing done
2. Adding test cases to cover policy ls and policy rm
   functionality in vmdk_ops_test

Resolves: #948
@pshahzeb
Copy link
Contributor Author

This also fixes #948

Copy link
Contributor

@pdhamdhere pdhamdhere left a comment

Choose a reason for hiding this comment

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

LGTM.

@shuklanirdesh82 Are you okay with Shahzeb's explanation?

@@ -204,33 +204,6 @@ def testAttachAsOpts(self):

@unittest.skipIf(not vsan_info.get_vsan_datastore(),
"VSAN is not found - skipping vsan_info tests")
def testPolicyUpdate(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay great!! Makes sense!

@shuklanirdesh82
Copy link
Contributor

Are you okay with Shahzeb's explanation?
@pdhamdhere Yeah!

@pshahzeb, couple of things to take care

  1. Need to repush your changes to validate CI run.. it seems your PR was the victim of starvation today and did not get executed
  2. Need to update summary of the PR to reflect changes for Prohibit policy delete from admin cli if it is in use by any volume #948 for future reference (stopping policy deletion if attached to any volume)

Copy link
Contributor

@shuklanirdesh82 shuklanirdesh82 left a comment

Choose a reason for hiding this comment

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

few comments for the added testcase.

if len(datastores) > 1:
datastore1 = datastores[1]
self.datastore1_name = datastore1[0]
self.datastoer1_path = datastore[2]
Copy link
Contributor

Choose a reason for hiding this comment

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

do you mean datastore1[2]?

self.datastore1_name = datastore1[0]
self.datastoer1_path = datastore[2]
logging.debug("Found second datastore: datastore_name=%s datastore_path=%s",
self.datastore1_name, self.datastore1_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

are we really using self.datastore1_name?

self.vm1_config_path = vmdk_utils.get_vm_config_path(self.vm1_name)
logging.info("VmdkTenantPolicyUsageTestCase: create vm1 name=%s Done", self.vm1_name)

error, self.vm2 = create_vm(si=si,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for creating second vm? it seems your test is not consuming second vm unless I have mistaken. Please clarify here.

error_info = vmdk_ops.executeRequest(vm1_uuid, self.vm1_name, self.vm1_config_path,
auth.CMD_REMOVE, self.default_tenant_vol4_name, opts)
self.assertEqual(None, error_info)

Copy link
Contributor

Choose a reason for hiding this comment

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

can you add similar check after removing volumes .. usage count should drop to 0 or vmdkops_admin.py policy ls?

Copy link
Contributor

@shuklanirdesh82 shuklanirdesh82 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for addressing comments quickly!

You may want to squash the commit into one.

@shuklanirdesh82 shuklanirdesh82 merged commit 2ff4deb into master Feb 24, 2017
@shuklanirdesh82 shuklanirdesh82 deleted the issue_853.pshahzeb branch February 24, 2017 22:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'policy ls' command does not show the name of the volume using that policy
4 participants