Skip to content

integration_tests: introduce skipping of tests by OS#702

Merged
OddBloke merged 5 commits into
canonical:masterfrom
OddBloke:test_images
Dec 3, 2020
Merged

integration_tests: introduce skipping of tests by OS#702
OddBloke merged 5 commits into
canonical:masterfrom
OddBloke:test_images

Conversation

@OddBloke
Copy link
Copy Markdown
Collaborator

@OddBloke OddBloke commented Dec 1, 2020

Proposed Commit Message

integration_tests: introduce skipping of tests by OS

This introduces an optional, more complex OS_IMAGE format (`<image
id>::<os>::<release>`) which allows the specification of the OS/OS
release which the given image ID corresponds to.  This information is
used to skip tests which do not apply to the image.
 
This commit is comprised of the following discrete changes:
* introduce the IntegrationImage class, to handle parsing and storing
   the new OS_IMAGE format
* support inferring the OS and OS release of Ubuntu series, so that we
  can continue to set OS_IMAGE to just a series name and have test
  skipping work
* add documentation on Image Selection to integration_tests.rst
* introduce the actual skipping behaviour based on OS marks
* apply the `ubuntu` mark to all tests that should be skipped on
  non-Ubuntu operating systems

Additional Context

See the added "Image Selection" doc section for an overview.

Test Steps

Travis should continue to pass, and it should be observed that tests are skipped on non-Ubuntu releases. This can be seen by using an Ubuntu image but lying about its origin with a full OS_IMAGE specification:

$ CLOUD_INIT_OS_IMAGE="ubuntu:focal::notubuntu::noreally" pytest --log-cli-level=INFO tests/integration_tests/ -rsXx
...
INFO     integration_testing:clouds.py:74 Detected image: image_id=ubuntu:focal os=notubuntu release=noreally
...
=== short test summary info ===
SKIPPED [12] tests/integration_tests/conftest.py:69: Cannot run on OS notubuntu

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

Copy link
Copy Markdown
Contributor

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

Overall the idea makes sense and seems like a good way forward.

Comment thread tests/integration_tests/clouds.py Outdated
Comment thread tests/integration_tests/clouds.py Outdated
Comment thread tests/integration_tests/clouds.py Outdated
return []


class IntegrationImage:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you foresee this class growing or taking on more functionality? If not, I don't think it needs to be a class. The constructor isn't directly invoked, so that leaves us with the classmethod constructor and a helper for building. Would it make more sense as a function returning a namedtuple?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think we'll be able to write the mark matching logic more succinctly if this class implements a matches(os, release) (or something broadly along those lines). Roughly:

--- a/tests/integration_tests/clouds.py
+++ b/tests/integration_tests/clouds.py
@@ -75,6 +75,11 @@ class ImageSpecification:
             "Image tuple: (%s, %s, %s)", self.image_id, self.os, self.release
         )
 
+    def matches(self, os, release):
+        matches_os = self.os is None or self.os == os
+        matches_release = self.release is None or self.release == release
+        return matches_os and matches_release
+
     @classmethod
     def from_os_image(cls):
         parts = integration_settings.OS_IMAGE.split("::", 2)
diff --git a/tests/integration_tests/conftest.py b/tests/integration_tests/conftest.py
index fc52a8de..b482cfa2 100644
--- a/tests/integration_tests/conftest.py
+++ b/tests/integration_tests/conftest.py
@@ -64,14 +64,7 @@ def pytest_runtest_setup(item):
     image = ImageSpecification.from_os_image()
     if "only_bionic" in test_marks:
         # TODO: implement generic matching logic
-
-        # Run Ubuntu tests if we either know this image is Ubuntu, or don't
-        # know what it is at all
-        run_ubuntu_tests = image.os is None or image.os == "ubuntu"
-        # Run bionic tests if we either know this image is bionic, or don't
-        # know what it is at all
-        run_bionic_tests = image.release is None or image.release == "bionic"
-        if not (run_ubuntu_tests and run_bionic_tests):
+        if not image.matches("ubuntu", "bionic"):
             pytest.skip("Only runs on Ubuntu bionic")

(And even if I didn't think the above: arguably a namedtuple with a function that constructs it is just a class without a namespace to put __init__ in. 😉)

Comment thread tests/integration_tests/clouds.py Outdated
Comment thread tests/integration_tests/clouds.py Outdated
Comment thread tests/integration_tests/conftest.py Outdated
Comment thread tests/integration_tests/clouds.py Outdated
except (ValueError, IndexError):
pass
return _released_image_id
return image.image_spec
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this supposed to be image_id? I don't see where image_spec comes from.

@OddBloke
Copy link
Copy Markdown
Collaborator Author

OddBloke commented Dec 2, 2020 via email

@OddBloke OddBloke force-pushed the test_images branch 3 times, most recently from a8de3ff to 3ef0819 Compare December 2, 2020 15:47
In order to skip tests based on OS or OS release, we need a way of
gathering and storing that information.  `IntegrationImage` is a class
to contain that information and is now used to deconstruct the more
complex OS_IMAGE values we now support.
@OddBloke OddBloke changed the title WIP: Skip tests based on OS or OS release version integration_tests: introduce skipping of tests by OS Dec 2, 2020
Comment thread tests/integration_tests/clouds.py Outdated
Comment thread tests/integration_tests/clouds.py Outdated
Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

LGTM!

@OddBloke OddBloke merged commit 6c4e87b into canonical:master Dec 3, 2020
@OddBloke OddBloke deleted the test_images branch December 3, 2020 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants