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 package and repository #43

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open

Add package and repository #43

wants to merge 24 commits into from

Conversation

colin-msphere
Copy link
Contributor

Add a package property to DCOS API Session. This returns a new Package object that maps directly to the "/package" context.

A repository property is available on Package that maps to "/package/repository" and provides methods to interact with the repository context.

@colin-msphere
Copy link
Contributor Author

This is missing unit tests, which I will add soon.

}
if version is not None:
params['packageVersion'] = version
if options and type(options) == dict:
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to raise a TypeError on these instead of silently skipping the param if it's not the expected type?

'uri': uri,
'name': name,
}
if index is not None and type(index) == int:
Copy link
Contributor

Choose a reason for hiding this comment

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

Raise a TypeError if it's not an int instead?

if app_id:
params['appId'] = app_id
return self._make_request('install', params,
{'response_version': '2', })
Copy link
Contributor

Choose a reason for hiding this comment

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

extra ,?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trailing comma is valid, although I am not using it well. I will remove it 👍

@colin-msphere
Copy link
Contributor Author

Rebased.

Copy link

@falseperfection falseperfection left a comment

Choose a reason for hiding this comment

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

So repetitive! Looks good. I had two questions but nothing big.

assert found
pack_api.uninstall('hello-world', app_id=installed_id)

pack_api.describe('jenkins')

Choose a reason for hiding this comment

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

Is there no assert because these methods raise exceptions on failure? Looking through the implementation above it wasn't 100% obvious that _make_request couldn't just return empty when you expected output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These methods will raise an HTTPError when a response is not "OK"-like. Because this is talking to an actual cosmos instance, I did not want to assert on content, as that may change or the server under test may have a custom universe installed (package repo).

A lack of raise is a decent check to ensure the request is valid.

@@ -0,0 +1,69 @@
from requests import HTTPError

Choose a reason for hiding this comment

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

+1 abstracting these utilities out

:return: JSON response
:rtype: dict
"""
params = {}

Choose a reason for hiding this comment

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

Is a param required? Or can someone do r.delete() with no params? If required, I'd raise an exception if neither is set like you do above with the int type check.

Copy link
Contributor Author

@colin-msphere colin-msphere Apr 4, 2018

Choose a reason for hiding this comment

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

Not sure - thanks for the question. I need to run some tests.

assert len(listings) > 0
old_name, old_uri = listings[0]['name'], listings[0]['uri']

repo.delete(old_name)

Choose a reason for hiding this comment

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

Verify the delete? Is this a possibility:

  • repo.delete(old_name) does nothing because of some error
  • repo.add(old_name, old_uri, 0) adds the repo a second time (or it silently skips, IDK the behavior)
  • assert says everything went fine because old_name is still there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add this.

@colin-msphere
Copy link
Contributor Author

dcos-launch issue, but the tests passed.

@margaret
Copy link
Contributor

margaret commented Apr 13, 2018

Errors in the latest run of integration tests (on dcos-launch wait) are https://jira.mesosphere.com/browse/QUALITY-2025 which also appeared in #44 which only slowed down a retrying rate, so I think it's a previously introduced bug.

Copy link

@mellenburg mellenburg left a comment

Choose a reason for hiding this comment

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

Great use of python and beautiful docs+testing.

Only change I would make is ensure that debug data is actually dumped in the unit tests

@@ -93,3 +93,222 @@ def list_packages(self):
"""
self._update_headers('list')
return self._post('/list', {})


class Repository(Cosmos):

Choose a reason for hiding this comment

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

You've went and gone full-python now 👍

monkeypatch.setattr(requests, 'Session',
lambda *args, **kwargs: mock_session)

yield mock_session

Choose a reason for hiding this comment

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

This should probably be wrapped in a try: finally block so that we always get the debug cache after an exception is raised

mellenburg
mellenburg previously approved these changes Apr 16, 2018
@mellenburg
Copy link

Errors are related to cluster cleanup which is done by dcos-launch, which is outside of this repo

Add a `package` property to DCOS API Session. This returns
a new `Package` object that maps directly to the "/package"
context.

A `repository` property is available on Package that maps to
"/package/repository" and provides methods to interact with the
repository context.
Repository was using the wrong "post" method.

Integration test for repository was using copy/pasted code that
called a nonexistant method on `marathon`.
Move mocks to a helpers file so that both Jobs
and Repository tests can use them.
Add more unit tests to verify URL and params.

All package requests go through a single method instead of
repeating the same code again and again.

The default versions for endpoints is now 'v1' instead of
'v2'. The `install` path sets it to 'v2'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants