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

Scottx611x/read input from url #20

Merged
merged 29 commits into from
Apr 17, 2018
Merged

Conversation

scottx611x
Copy link
Member

No description provided.

# Returns a url that will resolve to the SimpleHTTPServer we spin up below
# so that the Docker container can make requests to files existing
# under the cwd i.e. `./test-data/input.json`
get_python_server_url() {
Copy link
Member Author

Choose a reason for hiding this comment

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

@mccalluc I feel bad about using this again, but it works...

Copy link
Member

Choose a reason for hiding this comment

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

We can't do this. it might be catching edge cases we're unaware of, but if it did break, we're not in a place to understand it's behavior. There's a grep example earlier in that thread, or I could find perl readable here:

ifconfig | perl -ne 'print $2 if /inet (addr:)?(\d+\.\d+\.\d+\.\d+)/ and $2 ne "127.0.0.1"'

Copy link
Member

Choose a reason for hiding this comment

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

Or move this whole script into python?


# Spin up a server so that the container can GET input data from the `test-data` dir
python -m SimpleHTTPServer $PYTHON_SERVER_PORT &
PYTHON_SERVER_PID=$!

for FIXTURE in `ls input_fixtures`; do
Copy link
Member

Choose a reason for hiding this comment

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

just glob instead of subprocess?:

 for FIXTURE in input_fixtures/*; do

python test.py

kill $PYTHON_SERVER_PID
Copy link
Member

Choose a reason for hiding this comment

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

Unless you nohup, shouldn't the child exit with the parent?

from cgi import escape


def get_refinery_input():
""" Make a GET request to acquire the input data for the container"""
return requests.get(os.environ["INPUT_JSON_URL"]).json()
Copy link
Member

Choose a reason for hiding this comment

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

But isn't refinery using using json in INPUT_JSON? I could be confused.

Copy link
Member Author

Choose a reason for hiding this comment

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

INPUT_JSON_URL is what refinery is passing along to containers after: refinery-platform/refinery-platform#2677

status = requests.get(
url, headers={
'Range': 'bytes=0-0'}).status_code
except requests.exceptions.RequestException as e:
Copy link
Member

Choose a reason for hiding this comment

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

weird line breaks...

}

# Spin up a server so that the container can GET input data from the `test-data` dir
python -m SimpleHTTPServer $PYTHON_SERVER_PORT &
Copy link
Member

Choose a reason for hiding this comment

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

http.server for python3?

test.py Outdated


class ContainerTest(unittest.TestCase):

def get_url(self, name):
command = "docker port {} | perl -pne 's/.*://'".format(name)
port = subprocess.check_output(command, shell=True).strip().decode('utf-8')
port = subprocess.check_output(
command, shell=True).strip().decode('utf-8')
Copy link
Member

Choose a reason for hiding this comment

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

I would put another linebreak after True to respect structure.

test.py Outdated
self.assertIn(expected, response.text)
# TODO: Not ideal for error pages
self.assertEqual(200, response.status_code)
if expected is not None:
Copy link
Member

Choose a reason for hiding this comment

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

why do we need this? Stricter tests are usually better.

test.py Outdated
def test_data_directory(self):
self.assert_expected_response('good', '{', '/data/input.json')
def test_input_data_url(self):
self.assert_expected_response('good', path='/options.json')
Copy link
Member

Choose a reason for hiding this comment

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

why no expected?

test.py Outdated
print '{} -> {}'.format(name, url)
return url
print('Still waiting for server...')
time.sleep(1)
self.fail('Server never came up: ' + name)

def assert_expected_response(self, name, expected, path='/'):
def assert_expected_response(self, name, expected=None, path='/'):
Copy link
Member

Choose a reason for hiding this comment

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

You can still using positional params when a default is given...

Copy link
Member

@mccalluc mccalluc left a comment

Choose a reason for hiding this comment

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

Lots of little things...

@@ -61,7 +71,7 @@ def validate_urls(urls):
if status != 206 # If byte-ranges are handled, should be 206, not 200.
]
if messages:
raise StandardError('\n'.join(messages))
raise Exception('\n'.join(messages))
Copy link
Member Author

Choose a reason for hiding this comment

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

back to StandardError? Or move to Python3

@@ -72,9 +82,10 @@ def start_server():
if __name__ == '__main__':
try:
write_igv_configuration()
except StandardError, e:
except Exception as e:
Copy link
Member Author

Choose a reason for hiding this comment

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

back to StandardError? Or move to Python3

define_repo.sh Outdated
@@ -2,4 +2,5 @@

OWNER=gehlenborglab
NAME=docker_igv_js
export NAME=$NAME
Copy link
Member Author

Choose a reason for hiding this comment

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

export NAME=docker_igv_js

test.py Outdated
url = 'http://localhost:{}'.format(port)
for i in xrange(5):
if 0 == subprocess.call('curl --fail --silent ' + url + ' > /dev/null', shell=True):
Copy link
Member Author

Choose a reason for hiding this comment

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

This was updated to requests somewhee, use that code

test.py Outdated
import requests
import unittest

from test_utils import TestContainerRunner


class ContainerTest(unittest.TestCase):

def get_url(self, name):
command = "docker port {} | perl -pne 's/.*://'".format(name)
Copy link
Member Author

Choose a reason for hiding this comment

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

double check docker-py functionality for getting port

test.py Outdated
test_container_runner.cleanup_containers()
Copy link
Member Author

Choose a reason for hiding this comment

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

maybe look into bumping this out

test.py Outdated
@@ -55,10 +67,14 @@ def test_no_parameters(self):


if __name__ == '__main__':
test_container_runner = TestContainerRunner()
Copy link
Member Author

Choose a reason for hiding this comment

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

as a context manager?

test_utils.py Outdated
self.containers.append(container)

def cleanup_containers(self):
map(
Copy link
Member Author

Choose a reason for hiding this comment

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

for container in containers:
container remove

Copy link
Member Author

@scottx611x scottx611x left a comment

Choose a reason for hiding this comment

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

Fix these, please

@scottx611x scottx611x merged commit bbc33bf into master Apr 17, 2018
@scottx611x scottx611x deleted the scottx611x/read_input_from_url branch April 17, 2018 15:09
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.

None yet

2 participants