Skip to content

Add package and repository#43

Open
colin-msphere wants to merge 24 commits into
masterfrom
add-repository
Open

Add package and repository#43
colin-msphere wants to merge 24 commits into
masterfrom
add-repository

Conversation

@colin-msphere

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

Comment thread dcos_test_utils/package.py Outdated
}
if version is not None:
params['packageVersion'] = version
if options and type(options) == dict:

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.

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

Comment thread dcos_test_utils/package.py Outdated
'uri': uri,
'name': name,
}
if index is not None and type(index) == int:

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.

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

Comment thread dcos_test_utils/package.py Outdated
if app_id:
params['appId'] = app_id
return self._make_request('install', params,
{'response_version': '2', })

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.

extra ,?

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Rebased.

@falseperfection falseperfection left a comment

Copy link
Copy Markdown

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.

Comment thread integration_test.py
assert found
pack_api.uninstall('hello-world', app_id=installed_id)

pack_api.describe('jenkins')

Copy link
Copy Markdown

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
Copy Markdown
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.

Comment thread tests/helpers.py
@@ -0,0 +1,69 @@
from requests import HTTPError

Copy link
Copy Markdown

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

Comment thread dcos_test_utils/package.py Outdated
:return: JSON response
:rtype: dict
"""
params = {}

Copy link
Copy Markdown

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.

@colin-msphere colin-msphere Apr 4, 2018

Copy link
Copy Markdown
Contributor Author

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.

Comment thread integration_test.py
assert len(listings) > 0
old_name, old_uri = listings[0]['name'], listings[0]['uri']

repo.delete(old_name)

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
Contributor Author

dcos-launch issue, but the tests passed.

@margaret

margaret commented Apr 13, 2018

Copy link
Copy Markdown
Contributor

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.

@mellenburg mellenburg left a comment

Copy link
Copy Markdown

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

return self._post('/list', {})


class Repository(Cosmos):

Copy link
Copy Markdown

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 👍

Comment thread tests/test_package.py Outdated
monkeypatch.setattr(requests, 'Session',
lambda *args, **kwargs: mock_session)

yield mock_session

Copy link
Copy Markdown

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
Copy Markdown

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