-
Notifications
You must be signed in to change notification settings - Fork 7
LIU-458: Upgrade test_docker.py images to 22.04 #318
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
base: master
Are you sure you want to change the base?
Conversation
- Doing this alone causes errors because nc is not available on base ubuntu:22.04 images. - Need to install netstat (nc) onto image - Easiest way to do this is using a dockerfile with the docker-py API.
Reviewer's Guide by SourceryThis PR upgrades the base image for DockerApp tests from Ubuntu 14.04 to Ubuntu 22.04. It introduces a Sequence diagram for DockerApp IP replacementsequenceDiagram
participant DockerApp
participant ContainerIpWaiter
DockerApp->>ContainerIpWaiter: Add ContainerIpWaiter
activate ContainerIpWaiter
ContainerIpWaiter->>DockerApp: waitForIp()
activate DockerApp
DockerApp-->>ContainerIpWaiter: uid, ip
deactivate DockerApp
ContainerIpWaiter-->>DockerApp: uid, ip
deactivate ContainerIpWaiter
DockerApp->>DockerApp: Replace %containerIp[{uid}]% with ip
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @myxie - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding a method to
CustomContainer
to check if an image exists before creating it. - Consider adding a teardown method to
DockerTests
to remove the custom container after the tests are complete.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
if isinstance(drop, DockerApp): | ||
if "%containerIp[{0}]%".format(drop.uid) in self._command: | ||
if f"%containerIp[{{{drop.uid}}}]%" in self._command: | ||
self._waiters.append(ContainerIpWaiter(drop)) | ||
logger.debug("%r: Added ContainerIpWaiter for %r", self, drop) |
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.
suggestion (code-quality): Merge nested if conditions (merge-nested-ifs
)
if isinstance(drop, DockerApp): | |
if "%containerIp[{0}]%".format(drop.uid) in self._command: | |
if f"%containerIp[{{{drop.uid}}}]%" in self._command: | |
self._waiters.append(ContainerIpWaiter(drop)) | |
logger.debug("%r: Added ContainerIpWaiter for %r", self, drop) | |
if isinstance(drop, DockerApp) and f"%containerIp[{{{drop.uid}}}]%" in self._command: | |
self._waiters.append(ContainerIpWaiter(drop)) | |
logger.debug("%r: Added ContainerIpWaiter for %r", self, drop) | |
Explanation
Too much nesting can make code difficult to understand, and this is especiallytrue in Python, where there are no brackets to help out with the delineation of
different nesting levels.
Reading deeply nested code is confusing, since you have to keep track of which
conditions relate to which levels. We therefore strive to reduce nesting where
possible, and the situation where two if
conditions can be combined using
and
is an easy win.
command="cp /opt/file %s" % (tempDir,), | ||
additionalBindings=[tempDir, "%s:/opt/file" % (tempFile,)], |
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.
suggestion (code-quality): Replace interpolated string formatting with f-string [×2] (replace-interpolation-with-fstring
)
command="cp /opt/file %s" % (tempDir,), | |
additionalBindings=[tempDir, "%s:/opt/file" % (tempFile,)], | |
command=f"cp /opt/file {tempDir}", | |
additionalBindings=[tempDir, f"{tempFile}:/opt/file"], |
JIRA Ticket
LIU-458
Type
Problem/Issue
Our test_docker instances are using Ubuntu:14.04 containers, which is incredibly old. We should support tests using newer versions of ubuntu.
Solution
I have updated to 22.04 containers. This was almost as simple as bumping the numbers, but our
test_clientServer
test case uses thenc
(netstat) command. This is not installed available by default on Ubuntu 22.04 (presumably because they are slimmer images).I have added a
CustomContainer
class intest_docker.py
that builds a Dockerfile from an input string and then builds the image, using the docker-py library we already use. The image is not cleaned up so it takes much less time to run the test after the first time the image is built (I have added code to do so if needed).Checklist
Summary by Sourcery
Upgrade test Docker images from Ubuntu 14.04 to Ubuntu 22.04 and add support for installing netcat in test containers
New Features:
Bug Fixes:
Enhancements: