Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for cleanse #5499

Merged
merged 14 commits into from
Sep 25, 2017
Merged

Add tests for cleanse #5499

merged 14 commits into from
Sep 25, 2017

Conversation

pwalczysko
Copy link
Member

@pwalczysko pwalczysko commented Sep 8, 2017

What this PR does

Adds tests for bin/omero admin cleanse command on CLI.
Atm,4 tests are added, "admin-only" when the executor of the command is not an admin, and a successful execution of the command for root with expected ending of the output checked.
Also, a more detailed test of functionality (checking that a file and directory were really removed, and Restricted Admin test as well were added.
See https://trello.com/c/3gBK3okF/752-integration-test-for-bin-omero-admin-cleanse
and https://trello.com/c/vsLBC6Aq/35-define-additional-markers-for-local-tests

As discussed, we can attempt to merge this PR, so putting for review for tomorrow.

@joshmoore @mtbc @sbesson
Ready for review

@mtbc
Copy link
Member

mtbc commented Sep 8, 2017

One idea:

  1. import an image
  2. change the name property of one of its files to nonsense
  3. run cleanse
  4. make sure that file disappeared from the filesystem.

Note that even a simple fake image has two files: the .fake and the import log. Could test each.

self.args += [data_dir]
self.cli.invoke(self.args, strict=True)
out, err = capsys.readouterr()
output_string = "Removing empty directories from...\n " + data_dir + "ManagedRepository\n"
Copy link
Member

Choose a reason for hiding this comment

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

See what the actual cleanse method does with client.getManagedRepository(description=True)

@jburel
Copy link
Member

jburel commented Sep 8, 2017

flake8 issues

./components/tools/OmeroPy/test/integration/clitest/test_cleanse.py:40:80: E501 line too long (83 > 79 characters)
./components/tools/OmeroPy/test/integration/clitest/test_cleanse.py:47:1: E302 expected 2 blank lines, found 1
./components/tools/OmeroPy/test/integration/clitest/test_cleanse.py:56:80: E501 line too long (83 > 79 characters)
./components/tools/OmeroPy/test/integration/clitest/test_cleanse.py:60:80: E501 line too long (98 > 79 characters)

@jburel jburel added the develop label Sep 8, 2017
@mtbc
Copy link
Member

mtbc commented Sep 14, 2017

Following on from conversation, some useful tips may include,

  • LightAdminPrivilegesTest.testDeleteManagedRepoPrivilegeDeletionViaRepo imports a fake file with an odd name then,
    • uses that name to find the file
    • uses that file to find the fileset.

However,

  • In Python tests I think image = self.import_fake_file() will import a fake image and give you the image ID (at the least) so you can find the fileset more easily.

  • You do have IQuery, IUpdate handy, e.g.,

query_service = client.sf.getQueryService()
update_service = client.sf.getUpdateService()
  • fs.py has useful code that you could borrow, including methods like,
    • logfile: given a fileset, returns the logfile
    • ls: given a fileset, lists its files (would be your fake).

@pwalczysko
Copy link
Member Author

pwalczysko commented Sep 14, 2017

@mtbc : I am afraid that the test as suggested by you in #5499 (comment) is not passing. If the cleanse would really remove the file from the ManagedRepository, then this line 4d69e5d#diff-1d5c6c10d23d75593370d2d5806c17bcR112 would be failing. But it passes. Verified also manually - simply re-run the cleanse after the test finished, whilst checking that the name in the OrigiinalFile table is still showing "nonsensical" and then looking for the file on the filesystem -> the file is still there.

@mtbc
Copy link
Member

mtbc commented Sep 15, 2017

My apologies, I am probably wrong about what "cleanse" actually does, I am usually not very sure; @joshmoore may wish to weigh in. Too many of my attempts to help you with Python tests are but guesswork.

@pwalczysko
Copy link
Member Author

And the test passed on CI as well, indicating that the cleanse is not doing what we think it is doing https://ci.openmicroscopy.org/view/Failing/job/OMERO-DEV-merge-integration-python/lastCompletedBuild/testReport/OmeroPy.test.integration.clitest.test_cleanse/TestCleanseRoot/
(if @mtbc 's assumption #5499 (comment) was right, the test would have to fail, see #5499 (comment))

@pwalczysko
Copy link
Member Author

@mtbc : no need to apologize, this is the part of the testing (getting the feature described correctly) :)

@pwalczysko
Copy link
Member Author

Manual testing:
Run in sql:

DELETE FROM filesetentry WHERE id = 892;
DELETE FROM originalfile WHERE id = 1736;

the filesetentry and the corresponding originalfile deleted from the DB successfully.
Check that the corresponding ...fake file still exists on the disk in ManagedRepo.

bin/omero admin cleanse /Users/pwalczysko/var/develop
...
After this first run of the cleanse, only the file inside the directory was removed.
After repeated run of the cleanse, nothing happened (the now empty directory was not removed).
After the third run of the cleanse, the empty directory was removed.

@pwalczysko
Copy link
Member Author

@mtbc @joshmoore : this is what I intended to do here on the cleanse test according to the brief. Are more tests desirable ?

@joshmoore
Copy link
Member

As mentioned in chat, happy for this to go in as is or see the addition of light admin tests before merging.

@jburel
Copy link
Member

jburel commented Sep 19, 2017

@pwalczysko do you think you will be able to add the test for lightadmin tomorrow?

@pwalczysko
Copy link
Member Author

...you will be able to add the test for lightadmin tomorrow?

Should be doable, did some prep yesterday evening.

@pwalczysko
Copy link
Member Author

@jburel @joshmoore : test for Restricted Admins added

@pwalczysko
Copy link
Member Author

Ready for review.

@pwalczysko pwalczysko changed the title Add 2 basic tests for cleanse (admin only and admin pass with output) Add tests for cleanse Sep 20, 2017
Copy link
Member

@joshmoore joshmoore left a comment

Choose a reason for hiding this comment

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

Few minor comments added. Happy for any/all to be addressed later.

As an aside, I did spend some time trying to figure out why this is the current behavior, but I haven't yet gotten to the bottom of it. That being said, happy to have a passing test to describe what needs figuring out.

# default value None makes the new user to Full Admin
# For Restricted Admin with no privileges, set the value to []
# Can be overriden by test instances
DEFAULT_PRIVILEGES = None
Copy link
Member

Choose a reason for hiding this comment

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

This is a very well-done test feature. Thank you!

Copy link
Member

Choose a reason for hiding this comment

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

One point though: it is better to use () (which is immutable) rather than [] so that subclasses cannot modify the value and cause confusion.

Copy link
Member

Choose a reason for hiding this comment

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

You can blame me for that one, I know little more Python than @pwalczysko. 😃

Copy link
Member Author

Choose a reason for hiding this comment

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

@joshmoore : Not sure I understand now, in your second comment here you suggested to use round brackets instead of square brackets. Which I implemented. Your commit now seem to revert on this chenge ? Or is there some granularity (doc vs non-doc) which I am missing ?

Copy link
Member

Choose a reason for hiding this comment

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

Apologies, I was trying to correct another line while preparing for a call and inadvertently changed this one. Give me just a bit to try to correct my mistake.

Copy link
Member

Choose a reason for hiding this comment

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

Force pushed the correction. Please let me know what you think.

assert err.endswith("SecurityViolation: Admins only!\n")


class TestCleanseRoot(RootCLITest):
Copy link
Member

Choose a reason for hiding this comment

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

For comparison, this might could/should be TestCleanFullAdmin and use DEFAULT_PRIVILEGES = None

self.args += ["admin", "cleanse"]
self.group_ctx = {'omero.group': str(self.group.id.val)}
config_service = self.root.sf.getConfigService()
self.mrepo_dir = config_service.getConfigValue("omero.managed.dir")
Copy link
Member

Choose a reason for hiding this comment

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

A next step here (5.4.1+) should be to check if the test is running locally to this directory and xfail or skip_if. This could be done in a base class and made available to all tests: self.is_local_to_server()

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Added this point to https://trello.com/c/3gBK3okF/51-integration-test-for-bin-omero-admin-cleanse (last unchecked point on the checklist)

@pwalczysko
Copy link
Member Author

This should address the comments of @joshmoore except #5499 (comment) which was carded #5499 (comment).

Ready for re-review.

@@ -538,7 +538,7 @@ def new_user(cls, group=None, perms=None,
:system: If user is to be a system group member
:privileges: If system group member is to have privileges
privileges=None gives all privileges (full admin)
privileges=[] gives no privileges
privileges=() gives no privileges
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that is how it should be, consistent. I forgot about this one, thank you @joshmoore

@joshmoore
Copy link
Member

👍 Happy to follow-up the local issues. Many thanks, @pwalczysko

@joshmoore joshmoore merged commit b189e70 into ome:develop Sep 25, 2017
@pwalczysko pwalczysko deleted the cleanse-test branch September 25, 2017 15:01
@sbesson sbesson added this to the 5.4.0 milestone Oct 6, 2017
@sbesson
Copy link
Member

sbesson commented Oct 9, 2017

I missed the details of this test PR and especially the testlib improvements 9f79786 allowing some granularity on the user created at the class setup.

Seconding #5499 (comment) and following a discussion @pwalczysko last week, an immediate implication is that we might be able to simplify the current complexity of the CLI test classes hierarchy as follows:

  • tests should only use CLITest which specializes omero.testlib.ITest for CLI based tests
  • classes performing CLI tests on root or light-admins should override DEFAULT_SYSTEM to True as done in this PR
  • AbstractCLITtest and RootCLITest classes should be deprecated in favor of the former

@sbesson sbesson mentioned this pull request Oct 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants