Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #563 from gamechanger/js-fix-stale-env-issue
Browse files Browse the repository at this point in the history
always get new environment per client request
  • Loading branch information
jsingle committed Sep 2, 2015
2 parents 786ea69 + 9adb82f commit ba8a657
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 32 deletions.
25 changes: 9 additions & 16 deletions dusty/systems/docker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,16 @@ def get_dusty_images():
def get_dusty_container_name(service_name):
return 'dusty_{}_1'.format(service_name)

def _get_set_envs():
env = {}
for key in ('DOCKER_HOST', 'DOCKER_CERT_PATH', 'DOCKER_TLS_VERIFY'):
if key in os.environ:
env[key] = os.environ[key]
return env

@memoized
def get_docker_env():
env = _get_set_envs()
if len(env.keys()) < 3:
output = check_output_demoted(['docker-machine', 'env', constants.VM_MACHINE_NAME], redirect_stderr=True)
for line in output.splitlines():
if not line.strip().startswith('export'):
continue
k, v = line.strip().split()[1].split('=')
v = v.replace('"', '')
env[k] = v
env = {}
output = check_output_demoted(['docker-machine', 'env', constants.VM_MACHINE_NAME], redirect_stderr=True)
for line in output.splitlines():
if not line.strip().startswith('export'):
continue
k, v = line.strip().split()[1].split('=')
v = v.replace('"', '')
env[k] = v
return env

@memoized
Expand Down
19 changes: 3 additions & 16 deletions tests/unit/systems/docker/init_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,12 @@ def test_get_docker_env_1(self, fake_check_output, fake_config_value):
result = get_docker_env()
self.assertItemsEqual(result, expected)

@patch('dusty.subprocess.get_config_value')
@patch('dusty.systems.docker.check_output_demoted')
@patch.dict('dusty.systems.docker.os.environ', {'DOCKER_TLS_VERIFY': '1',
'DOCKER_HOST': 'tcp://192.168.59.103:2376',
'DOCKER_CERT_PATH': '/Users/root/.docker/machine/machines/dusty/cert.pem'})
def test_get_docker_env_2(self, fake_check_output, fake_config_value):
fake_config_value.return_value = 'root'
fake_check_output.return_value = """Variables are already set"""
expected = {'DOCKER_TLS_VERIFY': '1',
'DOCKER_HOST': 'tcp://192.168.59.103:2376',
'DOCKER_CERT_PATH': '/Users/root/.docker/machine/machines/dusty/cert.pem'}
result = get_docker_env()
self.assertItemsEqual(result, expected)

@patch('dusty.subprocess.get_config_value')
@patch('dusty.systems.docker.check_output_demoted')
@patch('dusty.systems.docker.os.environ', {'DOCKER_TLS_VERIFY': '2',
'DOCKER_HOST': 'tcp://192.168.59.103:2375'})
def test_get_docker_env_3(self, fake_check_output, fake_config_value):
'DOCKER_HOST': 'tcp://192.168.59.103:2375',
'DOCKER_CERT_PATH': 'baaaaaad'})
def test_get_docker_env_2(self, fake_check_output, fake_config_value):
fake_config_value.return_value = 'root'
fake_check_output.return_value = """ export DOCKER_TLS_VERIFY=1
export DOCKER_HOST=tcp://192.168.59.103:2376
Expand Down

0 comments on commit ba8a657

Please sign in to comment.