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