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

Move logic out of storage.py #23

Merged
merged 19 commits into from
Jun 8, 2018
Merged

Conversation

rgayon
Copy link
Collaborator

@rgayon rgayon commented Jun 7, 2018

Couple things happening here

  • Get rid of useless unicode stuff
  • Move methods that search for containers out of the Storage object and back to the DockerExplorer (GetContainer, GetAllContainers, etc) because this is independent of the storage Driver.
  • Have most methods use Container object as argument (instead of container ID string)
  • Factor some common code in tests.py, and reflect previous changes

@rgayon rgayon requested a review from tomchop June 7, 2018 11:25
Copy link
Collaborator

@tomchop tomchop left a comment

Choose a reason for hiding this comment

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

PTAL at the docstring comments in tests

"""Returns a Container object given a container_id.

Args:
container_id (str): the ID of the container.
Returns:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a newline between Args and Returns

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Returns:
Namespace: the populated namespace.
Container: the container's info.
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is returned is a container.Container object right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

return [self.GetContainer(cid) for cid in container_ids_list]

def GetContainersList(self, only_running=False):
"""Returns a list of container ids which were running, sorted by start date.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't this return Container objects rather than container ids?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed


Args:
only_running (bool): Whether we display only running Containers.
Returns:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a newline (starting to wonder if that's in fact what the style guide specifies)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

docker_version (int): (Optional) the version of the Docker storage module.

Raises:
errors.BadContainerException: if there was an error with parsing
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/with parsing/when parsing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

tests.py Outdated
self.assertEqual(expected_docker_root, options.docker_directory)

def testDetectStorageFail(self):
"""Tests that the DockerExplorer.DetectStorage function fails."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

As a general rule I try to make dosctrings in tests more specific. Here I would specify under which conditions the functinon should fail: Tests that DockerExplorer.DetectStrorage fails when a nonexistent directory is specified

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


@classmethod
def setUpClass(cls):
cls._setup('aufs', aufs.AufsStorage)

def testGetAllContainers(self):
"""Tests the GetAllContainers function on a AuFS storage."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not super familiar with testing but it seems this test case bundles a bunch of different tests: testing name, timestamp, image name, and length of the returned items

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes.
I "test" one function per test here. Probably not the best.
filed #24 to deal with this later

'sha256:{0:s}'.format(self.image_id))
layer_info = self.de_object.storage_object.GetLayerInfo(
'sha256:'
'7968321274dc6b6171697c33df7815310468e694ac5be0ec03ff053bb135e768')
self.assertEqual('2017-01-13T22:13:54.401355854Z', layer_info['created'])
self.assertEqual(['/bin/sh', '-c', '#(nop) ', 'CMD ["sh"]'],
layer_info['container_config']['Cmd'])

def testShowRepositories(self):
"""Tests the Storage.ShowRepositories function on a AUFS storage."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Test that ShowRepositories returns a correctly formatted info string"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See #24
I'll make test docstrings more explicit at the same time I split unit tests.

tests.py Outdated
@@ -75,7 +75,8 @@ def testParseArguments(self):
self.assertEqual(expected_docker_root, options.docker_directory)

def testDetectStorageFail(self):
"""Tests that the DockerExplorer.DetectStorage function fails."""
"""Tests that the DockerExplorer.DetectStorage function fails on
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a word missing ? ("nonexistent")

@rgayon rgayon merged commit 2b2f32c into google:master Jun 8, 2018
@rgayon rgayon deleted the rework-storage-7-tosplit branch June 12, 2018 12:20
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.

2 participants