Commit c47d0343 authored by Łukasz Nowak's avatar Łukasz Nowak

Implement asynchronous request call.

OpenOrder.request and ComputerPartition.request are not raising
ResourceNotReady anymore.

Instead if there is need to access value which needs server connection and
ComputerPartition class detects that request have to be done, it is begin
invoked, which *can* result with late ResourceNotReady.

Some tests were moved from ERP5 Vifib test suite to slapos.core package, to do
checks on library level, instead of client level.

ERP5 Vifib test suite was updated in order to follow non raising Request. Also
simplification was done, as there is no need to repeat logic of library testing.

Squashed commit of the following:

commit 4abc0e3d6bc22955ef062c9066ec2139fa74ff1b
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Tue Sep 27 11:14:01 2011 +0200

    Rename in order to follow reality.

    This steps are checking for HTTP responses directly, and not library exception.

commit 9222aab2fe026ff7e5ae63d0a0ce7c0a95e72b43
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Tue Sep 27 11:13:04 2011 +0200

    Remove not used garbage.

commit 9b035f2b497c5d33a01e8bde9e23154ec9fa844c
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Tue Sep 27 11:11:31 2011 +0200

    Move specialised steps to proper module.

commit 70ceace0ca08c55803d9c5f6db40f11a07bcb5cf
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Tue Sep 27 11:05:31 2011 +0200

    Drop person based request with NotReadyResponse.

commit 1464473c3ef99e89513df40b69b8ae096d183dac
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Tue Sep 27 10:53:07 2011 +0200

    Drop not ready, tic in normal request (slave scenario).

commit 9bf8944c168ef1d4394a6133aeb1ef09218dc3d1
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Tue Sep 27 10:52:49 2011 +0200

    NotReady is not raised anymore by library.

commit d85d73a3ddb386c048dc3cff688abb5a9fb8bcfa
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Tue Sep 27 10:49:46 2011 +0200

    Logic of slave request is the same.

    slap library itself implements such tests, and change was applied: no
    NotReadyResponse is raised.

commit 444b8d3f5b853e3a3120e36c7fc3451565ea0219
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Tue Sep 27 10:40:59 2011 +0200

    No need to request twice.

    Library is sending request, which is being fulfilled after first call, as tic
    happens immediately on server side.

commit 95232273592a79f91050c903469990c0c6243c85
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Tue Sep 27 10:35:17 2011 +0200

    Covered in dc4cb3dcda23418e57c8faabdd7520850830aa5e

commit dc4cb3dcda23418e57c8faabdd7520850830aa5e
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Tue Sep 27 10:34:04 2011 +0200

    Cover more logic.

    Check that request is really send (with rest of tests replaces
    test_ComputerPartition_request_firstNotReady)

commit f27992b951dff29072ba9c34fe29b8e32beac7bb
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Tue Sep 27 10:22:01 2011 +0200

    Follow new BT5 addition.

commit 3165c700faac2d32a9332438a94dfaab60bfdd88
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Tue Sep 27 10:19:46 2011 +0200

    Follow egg restructuring.

commit 1eddc381ff7bf055e29061804b1f44f920eab07d
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 18:13:58 2011 +0200

    Tic in order to have all...

    ...but this test fails in Vifib.

    It shall be reimplemented on slap library level.

commit 98ce5cc53fb5604bdff3c81262a5fcb60a0d30bc
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 18:07:24 2011 +0200

    Typo.

commit ac8cc9acfe6a05c71f06884ea01b36653feb8db8
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 17:55:54 2011 +0200

    Request in simple manner.

commit 9aa538e5f1e432f9db3c6d1890e9f430addba5eb
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 18:03:34 2011 +0200

    Support requestComputerPartition.

commit 5a3376d62567a405da91d6a05ddf0828a45788d6
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 18:02:05 2011 +0200

    Really request during request.

    Just in case of ResourceNotReady request later.

commit 085ae669f2763f02a955f2450ae1cec95e3c17f8
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 17:49:39 2011 +0200

    Forgotten tic after another request.

commit aef8445dfdefa09a806a6b94c64af7af61ce4fb6
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 17:46:49 2011 +0200

    Typo.

commit 1ac2cde4df2ef53a14418170a1c9fb1e81003160
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 17:41:54 2011 +0200

    Drop ResourceNotReady exception.

    stepRequestComputerPartitionNotReadyResponse is removed, as request became
    asynchronous and stepRequestComputerPartition does all what is needed to have
    correctly requested partition.

commit 9a7cf1c65cd8b17a08dee687e3a1657b048fab62
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 17:39:05 2011 +0200

    Do not except ResourceNotReady while requesting.

commit c8845909d24777e74d68cad292c341569a0cfb17
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 17:36:41 2011 +0200

    Do not access async parameter.

    getId would raise ResourceNotReady.

commit ebb3380d9ac0357a76393024eb19388360bc57c0
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 17:35:25 2011 +0200

    Follow asynchronous request functionality.

    It raises ResourceNotReady in case of accessing first remote based parameter.

commit 6650b58fec82242f4eb00f445155247849a6572d
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 17:16:12 2011 +0200

    Follow ComputerPartition.request coverage.

commit 5064bb93bf085d82e618bad6b0cf365f9c10b330
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 17:13:11 2011 +0200

    Rename method name.

commit b502321daff6562f81194357726da389bbbde846
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 17:00:29 2011 +0200

    Cover more cases.

    Check that requesting raises correctly in case if not fulfilled.
    Check that data are fetched in async way in case of request.

commit 3c2ed706f1c158ef0f25ca384b68331e743233b9
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 16:38:18 2011 +0200

    Return passed status.

commit 4c01e36979a0c023b69bfcffdd586e79dc87781e
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 16:33:00 2011 +0200

    Mock current method.

commit 4364b1de3c01f745a6b8de6893e9d6e1c692f92f
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 16:32:34 2011 +0200

    Return always proper method call.

commit 9366301aa8dddf91d77f515f78da0037179056d2
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 15:57:10 2011 +0200

    Prove that request method is async and do not raise.

commit 145a58332539ce2445b909da11c35072e864af39
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 15:50:56 2011 +0200

    Use mocked server.

commit 34068539f865b4e79f798e06790f14ec4c2d38b2
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 15:24:24 2011 +0200

    Check parameters on runtime.

commit 2269d2283b11bee74345e13482d8e7a3aa0aaea7
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 14:15:55 2011 +0200

    Make request asynchronous.

    Do communication when data of computer partition are being accessed, thanks
    to this request method returns "lazy" CP object, and does not do any
    communication itself.

commit 8bd6d7587821def17617c455be9729c71e8fd5df
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 15:42:20 2011 +0200

    User not password are not used in slap.

    Authentication is done by SSL keys.

commit 89fd61f45f60d9999dd281152e34bec24a50bb47
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Sep 26 15:41:42 2011 +0200

    Move and make test running (!=passing)
parent 4734ebf9
......@@ -30,7 +30,7 @@
import unittest
from VifibMixin import testVifibMixin
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from slapos.slap.tests import testinterface
from slapos.tests import interface
# from slapos.slap.tests import testslap
"""Test to check slap in ERP5 test runner
......@@ -46,7 +46,7 @@ class VifibServerMixin(testVifibMixin):
testVifibMixin.afterSetUp(self)
self.server_url = self.portal.portal_slap.absolute_url()
class TestSlapInterface(ERP5TypeTestCase, testinterface.TestInterface):
class TestSlapInterface(ERP5TypeTestCase, interface.TestInterface):
"""Wrapper class for TestInterface
Note: This is here because there is no test runner for eggs."""
......
......@@ -165,13 +165,16 @@ class OpenOrder(SlapDocument):
}
if software_type is not None:
request_dict['software_type'] = software_type
self._connection_helper.POST('/requestComputerPartition', request_dict)
xml = self._connection_helper.response.read()
software_instance = xml_marshaller.loads(xml)
computer_partition = ComputerPartition(
software_instance.slap_computer_id.encode('UTF-8'),
software_instance.slap_computer_partition_id.encode('UTF-8'))
return computer_partition
try:
self._connection_helper.POST('/requestComputerPartition', request_dict)
except ResourceNotReady:
return ComputerPartition(request_dict=request_dict)
else:
xml = self._connection_helper.response.read()
software_instance = xml_marshaller.loads(xml)
return ComputerPartition(
software_instance.slap_computer_id.encode('UTF-8'),
software_instance.slap_computer_partition_id.encode('UTF-8'))
def _syncComputerInformation(func):
"""
......@@ -267,14 +270,41 @@ def _syncComputerPartitionInformation(func):
return func(self, *args, **kw)
return decorated
def _requestIfNeeded(func):
"""Request computer partition if required"""
def decorated(self, *args, **kw):
request_dict = getattr(self, '_request_dict', None)
if request_dict is None:
# no need to request self
return func(self, *args, **kw)
self._connection_helper.POST('/requestComputerPartition', request_dict)
xml = self._connection_helper.response.read()
software_instance = xml_marshaller.loads(xml)
self._computer_id = software_instance.slap_computer_id.encode('UTF-8')
self._partition_id = software_instance.slap_computer_partition_id.encode('UTF-8')
self._request_dict = None
return func(self, *args, **kw)
return decorated
class ComputerPartition(SlapDocument):
zope.interface.implements(interface.IComputerPartition)
def __init__(self, computer_id, partition_id):
def __init__(self, computer_id=None, partition_id=None, request_dict=None):
if request_dict is not None and (computer_id is not None or
partition_id is not None):
raise TypeError('request_dict conflicts with computer_id and '
'partition_id')
if request_dict is None and (computer_id is None or partition_id is None):
raise TypeError('computer_id and partition_id or request_dict are '
'required')
self._computer_id = computer_id
self._partition_id = partition_id
self._request_dict = request_dict
@_requestIfNeeded
def __getinitargs__(self):
return (self._computer_id, self._partition_id, )
......@@ -283,6 +313,7 @@ class ComputerPartition(SlapDocument):
# and not when try to access to real partition is required.
# To have later raising (like in case of calling methods), the way how
# Computer Partition data are fetch from server shall be delayed
@_requestIfNeeded
@_syncComputerPartitionInformation
def request(self, software_release, software_type, partition_reference,
shared=False, partition_parameter_kw=None, filter_kw=None,
......@@ -310,59 +341,72 @@ class ComputerPartition(SlapDocument):
'filter_xml': xml_marshaller.dumps(filter_kw),
'state': xml_marshaller.dumps(state),
}
self._connection_helper.POST('/requestComputerPartition', request_dict)
xml = self._connection_helper.response.read()
software_instance = xml_marshaller.loads(xml)
computer_partition = ComputerPartition(
software_instance.slap_computer_id.encode('UTF-8'),
software_instance.slap_computer_partition_id.encode('UTF-8'))
return computer_partition
try:
self._connection_helper.POST('/requestComputerPartition', request_dict)
except ResourceNotReady:
return ComputerPartition(request_dict=request_dict)
else:
xml = self._connection_helper.response.read()
software_instance = xml_marshaller.loads(xml)
return ComputerPartition(
software_instance.slap_computer_id.encode('UTF-8'),
software_instance.slap_computer_partition_id.encode('UTF-8'))
@_requestIfNeeded
def building(self):
self._connection_helper.POST('/buildingComputerPartition', {
'computer_id': self._computer_id,
'computer_partition_id': self._partition_id})
@_requestIfNeeded
def available(self):
self._connection_helper.POST('/availableComputerPartition', {
'computer_id': self._computer_id,
'computer_partition_id': self._partition_id})
@_requestIfNeeded
def destroyed(self):
self._connection_helper.POST('/destroyedComputerPartition', {
'computer_id': self._computer_id,
'computer_partition_id': self._partition_id,
})
@_requestIfNeeded
def started(self):
self._connection_helper.POST('/startedComputerPartition', {
'computer_id': self._computer_id,
'computer_partition_id': self._partition_id,
})
@_requestIfNeeded
def stopped(self):
self._connection_helper.POST('/stoppedComputerPartition', {
'computer_id': self._computer_id,
'computer_partition_id': self._partition_id,
})
@_requestIfNeeded
def error(self, error_log):
self._connection_helper.POST('/softwareInstanceError', {
'computer_id': self._computer_id,
'computer_partition_id': self._partition_id,
'error_log': error_log})
@_requestIfNeeded
def getId(self):
return self._partition_id
@_requestIfNeeded
@_syncComputerPartitionInformation
def getState(self):
return self._requested_state
@_requestIfNeeded
@_syncComputerPartitionInformation
def getInstanceParameterDict(self):
return getattr(self, '_parameter_dict', None) or {}
@_requestIfNeeded
@_syncComputerPartitionInformation
def getSoftwareRelease(self):
"""
......@@ -374,6 +418,7 @@ class ComputerPartition(SlapDocument):
else:
return self._software_release_document
@_requestIfNeeded
def setConnectionDict(self, connection_dict, slave_reference=None):
self._connection_helper.POST('/setComputerPartitionConnectionXml', {
'computer_id': self._computer_id,
......@@ -381,6 +426,7 @@ class ComputerPartition(SlapDocument):
'connection_xml': xml_marshaller.dumps(connection_dict),
'slave_reference': slave_reference})
@_requestIfNeeded
@_syncComputerPartitionInformation
def getConnectionParameter(self, key):
connection_dict = getattr(self, '_connection_dict', None) or {}
......@@ -393,6 +439,7 @@ class ComputerPartition(SlapDocument):
# XXX: this implementation has not been reviewed
self.usage = usage_log
@_requestIfNeeded
def getCertificate(self):
self._connection_helper.GET(
'/getComputerPartitionCertificate?computer_id=%s&'
......
......@@ -41,7 +41,7 @@ class HTTPConnection(object):
def request(self, method, url, body=None, headers=None):
status, headers, body = self._callback(url, method, body, headers)
self.__response = HTTPResponse('HTTP/1.1', 200, 'OK', body, headers)
self.__response = HTTPResponse('HTTP/1.1', status, 'OK', body, headers)
def getresponse(self):
......
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