Commit e2c03518 authored by Jérome Perrin's avatar Jérome Perrin

wip initializeConnection raise connection error

parent 8f5ddd97
......@@ -32,6 +32,7 @@ import pkg_resources
import re
import subprocess
import sys
import time
from slapos.cli.command import must_be_root
from slapos.format import FormatConfig
......@@ -245,10 +246,8 @@ def do_configure(args, fetch_config_func, logger):
configp = fetch_config_func(args)
conf = FormatConfig(logger=logger)
conf.mergeConfig(args, configp)
slapgrid = create_slapgrid_object(conf.__dict__, logger)
createPrivateDirectory(os.path.join(conf.slapos_buildout_directory, 'log'))
_runFormat(conf.slapos_buildout_directory)
slapgrid.checkEnvironmentAndCreateStructure()
proxy_configuration_file = _generateSlaposProxyConfigurationFile(conf)
conf.proxy_configuration_file = proxy_configuration_file
_addProxyToSupervisor(conf)
......@@ -258,5 +257,20 @@ def do_configure(args, fetch_config_func, logger):
if not os.path.exists(slapos_client_cfg_path):
os.symlink(slapos_node_config_path, slapos_client_cfg_path)
launchSupervisord(instance_root=conf.instance_root, logger=logger)
# wait for slapproxy
retries = 0
while True:
time.sleep(.5)
try:
slapgrid = create_slapgrid_object(conf.__dict__, logger)
except Exception, e:
retries += 1
if retries > 20:
raise
else:
break
slapgrid.checkEnvironmentAndCreateStructure()
_runFormat(conf.slapos_buildout_directory)
return 0
......@@ -845,12 +845,15 @@ class slap:
slapgrid_rest_uri = getHateoasUrl_cache[getHateoasUrl_cache_key]
except KeyError:
pass
if not slapgrid_rest_uri:
if not slapgrid_rest_uri and slapgrid_uri != 'null':
try:
slapgrid_rest_uri = getHateoasUrl_cache[getHateoasUrl_cache_key] = self._connection_helper.GET('getHateoasUrl')
except NotFoundError, e:
# master does not implement HATEOAS
pass
except Exception, e:
raise Exception("Exception raised ... %r / locals: %r" % (e, locals()))
raise
if slapgrid_rest_uri:
self._hateoas_navigator = SlapHateoasNavigator(
slapgrid_rest_uri,
......
......@@ -222,7 +222,6 @@ class TestSlap(SlapMixin):
computer raises NotFoundError exception
"""
computer_guid = self._getTestComputerId()
self.slap.initializeConnection(self.server_url)
partition_id = 'PARTITION_01'
def handler(url, req):
......@@ -237,6 +236,7 @@ class TestSlap(SlapMixin):
return {'status_code': 0}
with httmock.HTTMock(handler):
self.slap.initializeConnection(self.server_url)
self.assertRaises(slapos.slap.NotFoundError,
self.slap.registerComputerPartition,
computer_guid, partition_id)
......@@ -247,7 +247,7 @@ class TestSlap(SlapMixin):
Asserts that calling getFullComputerInformation with empty computer_id
raises early, before calling master.
"""
self.slap.initializeConnection(self.server_url)
self.slap.initializeConnection(self.server_url, hateoas_url=self.server_url)
def handler(url, req):
# Shouldn't even be called
......@@ -263,7 +263,7 @@ class TestSlap(SlapMixin):
Asserts that calling registerComputerPartition with empty computer_id
raises early, before calling master.
"""
self.slap.initializeConnection(self.server_url)
self.slap.initializeConnection(self.server_url, hateoas_url=self.server_url)
def handler(url, req):
# Shouldn't even be called
......@@ -279,7 +279,7 @@ class TestSlap(SlapMixin):
Asserts that calling registerComputerPartition with empty
computer_partition_id raises early, before calling master.
"""
self.slap.initializeConnection(self.server_url)
self.slap.initializeConnection(self.server_url, hateoas_url=self.server_url)
def handler(url, req):
# Shouldn't even be called
......@@ -295,7 +295,7 @@ class TestSlap(SlapMixin):
Asserts that calling registerComputerPartition with empty
computer_partition_id raises early, before calling master.
"""
self.slap.initializeConnection(self.server_url)
self.slap.initializeConnection(self.server_url, hateoas_url=self.server_url)
def handler(url, req):
# Shouldn't even be called
......@@ -313,7 +313,6 @@ class TestSlap(SlapMixin):
"/getSoftwareReleaseListFromSoftwareProduct" URL with correct parameters,
with software_product_reference parameter being specified.
"""
self.slap.initializeConnection(self.server_url)
software_product_reference = 'random_reference'
software_release_url_list = ['1', '2']
......@@ -327,6 +326,7 @@ class TestSlap(SlapMixin):
}
with httmock.HTTMock(handler):
self.slap.initializeConnection(self.server_url)
self.assertEqual(
self.slap.getSoftwareReleaseListFromSoftwareProduct(
software_product_reference=software_product_reference),
......@@ -339,7 +339,6 @@ class TestSlap(SlapMixin):
"/getSoftwareReleaseListFromSoftwareProduct" URL with correct parameters,
with software_release_url parameter being specified.
"""
self.slap.initializeConnection(self.server_url)
software_release_url = 'random_url'
software_release_url_list = ['1', '2']
......@@ -353,6 +352,7 @@ class TestSlap(SlapMixin):
}
with httmock.HTTMock(handler):
self.slap.initializeConnection(self.server_url)
self.assertEqual(
self.slap.getSoftwareReleaseListFromSoftwareProduct(
software_release_url=software_release_url),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment