-
Notifications
You must be signed in to change notification settings - Fork 48
Support YARN endpoints protected by Kerberos/SPNEGO #16
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b1ff2c5
Enable building universal distribution
lresende 418ba77
Update git configuration files
lresende c04e2fc
Support YARN endpoints protected by Kerberos/SPNEGO
lresende 8ef5cae
Integration tests run against provided YARN ENDPOINT
lresende a21f612
Bump version in preparation for 0.3.0 release
lresende File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Set the default behavior to have all files normalized to Unix-style | ||
| # line endings upon check-in. | ||
| * text=auto | ||
| # Declare files that will always have CRLF line endings on checkout. | ||
| *.bat text eol=crlf | ||
| # Denote all files that are truly binary and should not be modified. | ||
| *.dll binary | ||
| *.exp binary | ||
| *.lib binary | ||
| *.pdb binary | ||
| *.exe binary | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # -*- coding: utf-8 -*- | ||
| try: | ||
| from unittest2 import TestCase | ||
| except ImportError: | ||
| from unittest import TestCase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| import os | ||
|
|
||
| from pprint import pprint | ||
| from unittest import TestCase | ||
| from yarn_api_client.resource_manager import ResourceManager | ||
|
|
||
| try: | ||
| from urlparse import urlparse | ||
| except ImportError: | ||
| from urllib.parse import urlparse | ||
|
|
||
|
|
||
| class ResourceManagerTestCase(TestCase): | ||
| """ | ||
| Integration test that, given a provided YARN ENDPOINT, | ||
| execute some real scenario test against that server. | ||
|
|
||
| Note that, if no YARN ENDPOINT is provided, the tests | ||
| are ignored. | ||
| """ | ||
| @classmethod | ||
| def setUpClass(self): | ||
| self.configured = False | ||
| if os.getenv('YARN_ENDPOINT'): | ||
| yarn_endpoint = os.getenv('YARN_ENDPOINT') | ||
| yarn_endpoint_uri = urlparse(yarn_endpoint) | ||
|
|
||
| if yarn_endpoint_uri.hostname and yarn_endpoint_uri.port: | ||
| self.configured = True | ||
| self.resourceManager = ResourceManager(yarn_endpoint_uri.hostname, yarn_endpoint_uri.port) | ||
|
|
||
| def test_cluster_information(self): | ||
| if self.configured: | ||
| info = self.resourceManager.cluster_information() | ||
| pprint(info.data) | ||
| self.assertEqual(info.data['clusterInfo']['state'], 'STARTED') | ||
|
|
||
| def test_cluster_metrics(self): | ||
| if self.configured: | ||
| metrics = self.resourceManager.cluster_metrics() | ||
| pprint(metrics.data) | ||
| self.assertGreater(metrics.data['clusterMetrics']['activeNodes'], 0) | ||
| self.assertIsNotNone(metrics.data['clusterMetrics']['totalNodes']) | ||
|
|
||
| def test_cluster_scheduler(self): | ||
| if self.configured: | ||
| scheduler = self.resourceManager.cluster_scheduler() | ||
| pprint(scheduler.data) | ||
| self.assertIsNotNone(scheduler.data['scheduler']['schedulerInfo']) | ||
|
|
||
| def test_cluster_applications(self): | ||
| if self.configured: | ||
| apps = self.resourceManager.cluster_applications() | ||
| pprint(apps.data) | ||
| self.assertIsNotNone(apps.data['apps']) | ||
|
|
||
| def test_cluster_application_state(self): | ||
| if self.configured: | ||
| apps = self.resourceManager.cluster_applications() | ||
| appid = apps.data['apps']['app'][0]['id'] | ||
| print(appid) | ||
| response = self.resourceManager.cluster_application_state(appid) | ||
| pprint(response.data) | ||
| pprint(response.data['state']) | ||
| self.assertIsNotNone(apps.data['apps']) | ||
|
|
||
| def test_cluster_application_statistics(self): | ||
| if self.configured: | ||
| appstats = self.resourceManager.cluster_application_statistics() | ||
| pprint(appstats.data) | ||
| self.assertIsNotNone(appstats.data['appStatInfo']) | ||
|
|
||
| def test_cluster_nodes(self): | ||
| if self.configured: | ||
| nodes = self.resourceManager.cluster_nodes() | ||
| pprint(nodes.data) | ||
| self.assertIsNotNone(nodes.data['nodes']) | ||
|
|
||
| running_nodes = self.resourceManager.cluster_nodes(state='RUNNING', healthy='true') | ||
| pprint(running_nodes.data) | ||
| self.assertIsNotNone(nodes.data['nodes']) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [bdist_wheel] | ||
| universal=1 | ||
|
|
||
| [metadata] | ||
| description-file=README.rst | ||
| license_file = LICENSE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,56 +4,66 @@ | |
| except ImportError: | ||
| from http.client import OK | ||
|
|
||
| from mock import patch | ||
| from tests import TestCase | ||
| import json | ||
| import requests | ||
| import requests_mock | ||
|
|
||
| from tests import TestCase | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wish I would use pytest for testing |
||
| from yarn_api_client import base | ||
| from yarn_api_client.errors import APIError, ConfigurationError | ||
|
|
||
|
|
||
| class BaseYarnAPITestCase(TestCase): | ||
| def test_request(self): | ||
| client = self.get_client() | ||
| with patch('yarn_api_client.base.HTTPConnection') as http_conn_mock: | ||
| with patch('yarn_api_client.base.json'): | ||
| http_conn_mock().getresponse().status = OK | ||
| @staticmethod | ||
| def success_response(): | ||
| return { | ||
| 'status':'success' | ||
| } | ||
|
|
||
| client.request('/ololo', foo='bar') | ||
| def test_valid_request(self): | ||
| with requests_mock.mock() as requests_get_mock: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps, use requests_mock as a decorator? |
||
| requests_get_mock.get('/ololo', text=json.dumps(BaseYarnAPITestCase.success_response())) | ||
|
|
||
| http_conn_mock().request.assert_called_with('GET', '/ololo?foo=bar') | ||
| client = self.get_client() | ||
| response = client.request('/ololo', foo='bar') | ||
|
|
||
| http_conn_mock.reset_mock() | ||
| client.request('/ololo') | ||
| assert requests_get_mock.called | ||
| self.assertIn(response.data['status'], 'success') | ||
|
|
||
|
|
||
| def test_valid_request_with_parameters(self): | ||
| with requests_mock.mock() as requests_get_mock: | ||
| requests_get_mock.get('/ololo?foo=bar', text=json.dumps(BaseYarnAPITestCase.success_response())) | ||
|
|
||
| http_conn_mock() | ||
| client = self.get_client() | ||
| response = client.request('/ololo', foo='bar') | ||
|
|
||
| http_conn_mock().request.assert_called_with('GET', '/ololo') | ||
| assert requests_get_mock.called | ||
| self.assertIn(response.data['status'], 'success') | ||
|
|
||
| def test_bad_request(self): | ||
| client = self.get_client() | ||
| with patch('yarn_api_client.base.HTTPConnection') as http_conn_mock: | ||
| http_conn_mock().getresponse().status = 404 | ||
| with requests_mock.mock() as requests_get_mock: | ||
| requests_get_mock.get('/ololo', status_code=404) | ||
|
|
||
| client = self.get_client() | ||
| with self.assertRaises(APIError): | ||
| client.request('/ololo') | ||
|
|
||
| def test_http_configuration(self): | ||
| client = self.get_client() | ||
| client.address = None | ||
| client.port = 80 | ||
|
|
||
| with self.assertRaises(ConfigurationError): | ||
| conn = client.http_conn | ||
| def test_http_configuration(self): | ||
| with requests_mock.mock() as requests_get_mock: | ||
| requests_get_mock.get('/ololo', text=json.dumps(BaseYarnAPITestCase.success_response())) | ||
|
|
||
| client.address = 'localhost' | ||
| client.port = None | ||
| client = self.get_client() | ||
| client.address = None | ||
| client.port = 80 | ||
|
|
||
| with self.assertRaises(ConfigurationError): | ||
| conn = client.http_conn | ||
| with self.assertRaises(ConfigurationError): | ||
| client.request('/ololo') | ||
|
|
||
| def get_client(self): | ||
| client = base.BaseYarnAPI() | ||
| client.address = 'example.com' | ||
| client.port = 80 | ||
| client.timeout = 0 | ||
| client.kerberos_enabled = False | ||
| return client | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,11 @@ | ||
| [tox] | ||
| envlist = py26,py27,py34,py35 | ||
| envlist = py27,py35,py36 | ||
|
|
||
| [testenv] | ||
| deps = | ||
| coverage | ||
| mock | ||
| coverage | ||
| mock | ||
| requests | ||
| requests-kerberos | ||
| requests_mock | ||
| commands = coverage run --source=yarn_api_client setup.py test | ||
|
|
||
| [testenv:py26] | ||
| deps = | ||
| argparse | ||
| coverage | ||
| mock | ||
| unittest2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is it possible to make integration tests as a part of CI process?
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.
The integration tests require a running yarn, we could probably add docker, etc... let me create an issue to address that in the near future.