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."""
......
......@@ -26,7 +26,7 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
def test_ComputerPartition_request_noFreePartition(self):
"""
Check that first call to request raises NotReady response
Check that first call to request raises NotFound response
"""
sequence_list = SequenceList()
sequence_string = self.prepare_install_requested_computer_partition_sequence_string + '\
......@@ -37,20 +37,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def test_ComputerPartition_request_firstNotReady(self):
"""
Check that first call to request raises NotReady response
"""
self.computer_partition_amount = 2
sequence_list = SequenceList()
sequence_string = self.prepare_install_requested_computer_partition_sequence_string + '\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartitionNotReadyResponse \
SlapLogout \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
# XXX: This test fails because test_vifib_customer security is cached
# and this user is not in SOFTINST-x group. We do not want to clear
# cache in tests.
......@@ -64,11 +50,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
self.computer_partition_amount = 2
sequence_list = SequenceList()
sequence_string = self.prepare_install_requested_computer_partition_sequence_string + '\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartitionNotReadyResponse \
Tic \
SlapLogout \
\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartition \
Tic \
......@@ -103,11 +84,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
self.computer_partition_amount = 2
sequence_list = SequenceList()
sequence_string = self.prepare_install_requested_computer_partition_sequence_string + '\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartitionNotReadyResponse \
Tic \
SlapLogout \
\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartition \
Tic \
......@@ -172,11 +148,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
sequence_string = self.prepare_install_requested_computer_partition_sequence_string + '\
SetInstanceStateStopped \
SlapLoginCurrentSoftwareInstance \
RequestComputerPartitionNotReadyResponse \
Tic \
SlapLogout \
\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartition \
Tic \
SlapLogout \
......@@ -235,11 +206,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
self.computer_partition_amount = 2
sequence_list = SequenceList()
sequence_string = self.prepare_install_requested_computer_partition_sequence_string + '\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartitionNotReadyResponse \
Tic \
SlapLogout \
\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartition \
Tic \
......@@ -321,6 +287,26 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def stepDirectRequestComputerPartitionHttpRequestTimeoutResponseWithoutState(self,
sequence, **kw):
request_dict = { 'computer_id': sequence['computer_reference'] ,
'computer_partition_id': sequence['computer_partition_reference'],
'software_release': sequence['software_release_uri'],
'software_type': sequence.get('requested_reference', 'requested_reference'),
'partition_reference': sequence.get('requested_reference', 'requested_reference'),
'shared_xml': xml_marshaller.dumps(kw.get("shared", False)),
'partition_parameter_xml': xml_marshaller.dumps({}),
'filter_xml': xml_marshaller.dumps({}),
#'state': Note: State is omitted
}
scheme, netloc, path, query, fragment = urlparse.urlsplit(self.server_url)
connection = httplib.HTTPConnection(host=netloc)
connection.request("POST", path + '/requestComputerPartition',
urllib.urlencode(request_dict),
{'Content-type': "application/x-www-form-urlencoded"})
response = connection.getresponse()
self.assertEqual(httplib.REQUEST_TIMEOUT, response.status)
def test_ComputerPartition_request_state_is_optional(self):
"""Checks that state is optional parameter on Slap Tool
......@@ -330,7 +316,7 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
sequence_string = \
self.prepare_install_requested_computer_partition_sequence_string + '\
SlapLoginCurrentSoftwareInstance \
DirectRequestComputerPartitionNotReadyResponseWithoutState \
DirectRequestComputerPartitionHttpRequestTimeoutResponseWithoutState \
Tic \
SlapLogout \
\
......@@ -350,11 +336,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
self.computer_partition_amount = 2
sequence_list = SequenceList()
sequence_string = self.prepare_install_requested_computer_partition_sequence_string + '\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartitionNotReadyResponse \
Tic \
SlapLogout \
\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartition \
Tic \
......@@ -438,8 +419,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
SelectRequestedParameterDictRequestedParameter \
\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartitionNotReadyResponse \
Tic \
RequestComputerPartition \
Tic \
SlapLogout \
......@@ -467,8 +446,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
SelectEmptyRequestedParameterDict \
\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartitionNotReadyResponse \
Tic \
RequestComputerPartition \
Tic \
SlapLogout \
......@@ -537,8 +514,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
Logout
SlapLoginCurrentSoftwareInstance
RequestComputerPartitionNotReadyResponse
Tic
RequestComputerPartition
Tic
SlapLogout
......@@ -565,8 +540,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
Logout
SlapLoginCurrentSoftwareInstance
RequestComputerPartitionNotReadyResponse
Tic
RequestComputerPartition
Tic
SlapLogout
......@@ -611,14 +584,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
SelectRequestedReference
SelectEmptyRequestedParameterDict
SetSoftwareInstanceChildrenA
RequestComputerPartitionNotReadyResponse
SetSoftwareInstanceChildrenB
RequestComputerPartitionNotReadyResponse
Tic
SetSoftwareInstanceChildrenA
RequestComputerPartition
Tic
......@@ -658,8 +623,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
Logout
SlapLoginCurrentSoftwareInstance
RequestComputerPartitionNotReadyResponse
Tic
RequestComputerPartition
Tic
SlapLogout
......@@ -674,8 +637,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
Logout
SlapLoginCurrentSoftwareInstance
RequestComputerPartitionNotReadyResponse
Tic
RequestComputerPartition
Tic
SlapLogout
......@@ -720,7 +681,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
Logout
SlapLoginCurrentSoftwareInstance
RequestComputerPartitionNotReadyResponse
RequestComputerPartition
Tic
SlapLogout
......@@ -734,7 +694,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
Logout
SlapLoginCurrentSoftwareInstance
RequestComputerPartitionNotReadyResponse
RequestComputerPartition
Tic
SlapLogout
......@@ -787,20 +746,11 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
self.prepare_install_requested_computer_partition_sequence_string + \
self.prepare_another_computer_sequence_string + '\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartitionNotReadyResponse \
Tic \
SlapLogout \
\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartition \
Tic \
SlapLogout \
\
SelectAnotherRequestedReference \
SlapLoginCurrentSoftwareInstance \
RequestComputerPartitionNotReadyResponse \
Tic \
SlapLogout \
\
SlapLoginCurrentSoftwareInstance \
RequestComputerPartition \
......@@ -820,22 +770,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
########################################
# ComputerPartition.request - slave
########################################
def test_ComputerPartition_request_slave_firstNotReady(self):
"""
Check that first call to request raises NotReadyResponse
"""
self.computer_partition_amount = 2
sequence_list = SequenceList()
sequence_string = self.prepare_install_requested_computer_partition_sequence_string + '\
SlapLoginCurrentSoftwareInstance \
SelectEmptyRequestedParameterDict \
SetRandomRequestedReference \
RequestSlaveInstanceFromComputerPartitionNotReadyResponse \
SlapLogout \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def test_ComputerPartition_request_slave_simpleCase(self):
"""
Check the most simple case of request. The behaviour should
......@@ -849,11 +783,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
SlapLoginCurrentSoftwareInstance
SelectEmptyRequestedParameterDict \
SetRandomRequestedReference \
RequestSlaveInstanceFromComputerPartitionNotReadyResponse \
Tic \
SlapLogout \
\
SlapLoginCurrentSoftwareInstance \
RequestSlaveInstanceFromComputerPartition \
Tic \
SlapLogout
......@@ -880,11 +809,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
SlapLoginCurrentSoftwareInstance
SelectEmptyRequestedParameterDict
SetRandomRequestedReference
RequestSlaveInstanceFromComputerPartitionNotReadyResponse
Tic
SlapLogout
SlapLoginCurrentSoftwareInstance
RequestSlaveInstanceFromComputerPartition
Tic
SlapLogout
......@@ -936,11 +860,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
SlapLoginCurrentSoftwareInstance
SelectEmptyRequestedParameterDict
SelectRequestedReference
RequestSlaveInstanceFromComputerPartitionNotReadyResponse
Tic
SlapLogout
SlapLoginCurrentSoftwareInstance \
RequestSlaveInstanceFromComputerPartition \
Tic
SlapLogout
......@@ -999,11 +918,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
SlapLoginCurrentSoftwareInstance
SelectEmptyRequestedParameterDict \
SetRandomRequestedReference \
RequestSlaveInstanceFromComputerPartitionNotReadyResponse \
Tic \
SlapLogout \
\
SlapLoginCurrentSoftwareInstance \
RequestSlaveInstanceFromComputerPartition \
Tic \
SlapLogout
......@@ -1049,6 +963,12 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def stepDirectRequestComputerPartitionHttpRequestTimeoutResponseWithoutStateAndSharedTrue(
self, sequence, **kw):
kw["shared"] = True
self.stepDirectRequestComputerPartitionHttpRequestTimeoutResponseWithoutState(
sequence, **kw)
def test_ComputerPartition_request_slave_state_is_optional(self):
"""Checks that state is optional parameter on Slap Tool This ensures
backward compatibility with old libraries."""
......@@ -1057,7 +977,7 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
sequence_string = \
self.prepare_install_requested_computer_partition_sequence_string + '\
SlapLoginCurrentSoftwareInstance \
DirectRequestComputerPartitionNotReadyResponseWithoutStateAndSharedTrue \
DirectRequestComputerPartitionHttpRequestTimeoutResponseWithoutStateAndSharedTrue \
Tic \
SlapLogout \
'
......@@ -1089,11 +1009,6 @@ class TestVifibSlapComputerPartitionRequest(TestVifibSlapWebServiceMixin):
\
SlapLoginCurrentSoftwareInstance \
SetRequestedFilterParameterDict \
RequestSlaveInstanceFromComputerPartitionNotReadyResponse \
Tic \
SlapLogout \
\
SlapLoginCurrentSoftwareInstance \
RequestSlaveInstanceFromComputerPartition \
Tic \
SlapLogout \
......
......@@ -919,8 +919,6 @@ class TestVifibSlapWebServiceMixin(testVifibMixin):
Logout
SlapLoginCurrentSoftwareInstance
RequestComputerPartitionNotReadyResponse
Tic
RequestComputerPartition
Tic
SlapLogout
......@@ -932,8 +930,6 @@ class TestVifibSlapWebServiceMixin(testVifibMixin):
Logout
SlapLoginCurrentSoftwareInstance
RequestComputerPartitionNotReadyResponse
Tic
RequestComputerPartition
Tic
SlapLogout
......@@ -999,14 +995,6 @@ class TestVifibSlapWebServiceMixin(testVifibMixin):
SelectCurrentComputerPartitionAsSlaveOwner
"""
check_positive_request_shared = """
RequestSharedComputerPartitionNotReadyResponse
Tic
RequestSharedComputerPartition
CheckSoftwareInstanceAndRelatedSlavePartition
CheckRequestedSoftwareInstanceAndRelatedSlavePartition
"""
prepare_two_purchase_packing_list = \
prepare_software_release_purchase_packing_list + '\
LoginDefaultUser \
......@@ -1503,33 +1491,14 @@ class TestVifibSlapWebServiceMixin(testVifibMixin):
filter_kw=sequence.get('requested_filter_dict', {}),
state=sequence.get('instance_state'))
# tic as request is done on slap level library
self.stepTic()
sequence.edit(
requested_slap_computer_partition=requested_slap_computer_partition,
requested_computer_partition_reference=\
requested_slap_computer_partition.getId())
def stepRequestSlaveInstanceFromComputerPartitionNotReadyResponse(self, sequence, **kw):
software_release_uri = sequence['software_release_uri']
requested_reference = sequence['requested_reference']
requested_parameter_dict = sequence['requested_parameter_dict']
self.slap = slap.slap()
self.slap.initializeConnection(self.server_url)
slap_computer_partition = self.slap.registerComputerPartition(
sequence['computer_reference'],
sequence['computer_partition_reference'])
# first try will raise slap.ResourceNotReady
self.assertRaises(slap.ResourceNotReady,
slap_computer_partition.request,
software_release=software_release_uri,
software_type="SlaveInstance",
partition_reference=requested_reference,
partition_parameter_kw=requested_parameter_dict,
shared=True,
filter_kw=sequence.get('requested_filter_dict', {}),
state=sequence.get('instance_state'))
def stepRequestSlaveInstanceFromComputerPartitionNotFoundError(self, sequence, **kw):
software_release_uri = sequence['software_release_uri']
requested_reference = sequence['requested_reference']
......@@ -1559,16 +1528,12 @@ class TestVifibSlapWebServiceMixin(testVifibMixin):
sequence['computer_partition_reference'])
software_release = sequence['software_release_uri']
software_type = sequence.get('requested_reference', 'requested_reference')
self.assertRaises(slap.ResourceNotReady, slap_computer_partition.request,
software_release, software_type, software_type + str(1))
self.assertRaises(slap.ResourceNotReady, slap_computer_partition.request,
software_release, software_type, software_type + str(2))
transaction.commit()
self.tic()
first = slap_computer_partition.request(software_release,
software_type, software_type + str(1))
second = slap_computer_partition.request(software_release,
software_type, software_type + str(2))
transaction.commit()
self.tic()
self.assertNotEqual(first.getId(), second.getId())
def stepRequestComputerPartition(self, sequence, **kw):
......@@ -1577,8 +1542,7 @@ class TestVifibSlapWebServiceMixin(testVifibMixin):
slap_computer_partition = self.slap.registerComputerPartition(
sequence['computer_reference'],
sequence['computer_partition_reference'])
requested_slap_computer_partition = slap_computer_partition.request(
software_release=sequence['software_release_uri'],
kw = dict(software_release=sequence['software_release_uri'],
software_type=sequence.get('requested_reference', 'requested_reference'),
partition_reference=sequence.get('requested_reference',
'requested_reference'),
......@@ -1586,52 +1550,14 @@ class TestVifibSlapWebServiceMixin(testVifibMixin):
filter_kw=sequence.get('requested_filter_dict', {}),
state=sequence.get('instance_state'))
requested_slap_computer_partition = slap_computer_partition.request(**kw)
self.stepTic()
sequence.edit(
requested_slap_computer_partition=requested_slap_computer_partition,
requested_computer_partition_reference=\
requested_slap_computer_partition.getId())
def stepDirectRequestComputerPartitionNotReadyResponseWithoutStateAndSharedTrue(
self, sequence, **kw):
kw["shared"] = True
self.stepDirectRequestComputerPartitionNotReadyResponseWithoutState(
sequence, **kw)
def stepDirectRequestComputerPartitionNotReadyResponseWithoutState(self,
sequence, **kw):
request_dict = { 'computer_id': sequence['computer_reference'] ,
'computer_partition_id': sequence['computer_partition_reference'],
'software_release': sequence['software_release_uri'],
'software_type': sequence.get('requested_reference', 'requested_reference'),
'partition_reference': sequence.get('requested_reference', 'requested_reference'),
'shared_xml': xml_marshaller.dumps(kw.get("shared", False)),
'partition_parameter_xml': xml_marshaller.dumps({}),
'filter_xml': xml_marshaller.dumps({}),
#'state': Note: State is omitted
}
scheme, netloc, path, query, fragment = urlparse.urlsplit(self.server_url)
connection = httplib.HTTPConnection(host=netloc)
connection.request("POST", path + '/requestComputerPartition',
urllib.urlencode(request_dict),
{'Content-type': "application/x-www-form-urlencoded"})
response = connection.getresponse()
self.assertEqual(httplib.REQUEST_TIMEOUT, response.status)
def stepRequestComputerPartitionNotReadyResponse(self, sequence, **kw):
self.slap = slap.slap()
self.slap.initializeConnection(self.server_url)
slap_computer_partition = self.slap.registerComputerPartition(
sequence['computer_reference'],
sequence['computer_partition_reference'])
self.assertRaises(slap.ResourceNotReady, slap_computer_partition.request,
software_release=sequence['software_release_uri'],
software_type=sequence.get('requested_reference', 'requested_reference'),
partition_reference=sequence.get('requested_reference',
'requested_reference'),
partition_parameter_kw=sequence.get('requested_parameter_dict', {}),
filter_kw=sequence.get('requested_filter_dict', {}),
state=sequence.get('instance_state'))
def stepRequestComputerPartitionNotFoundResponse(self, sequence, **kw):
self.slap = slap.slap()
self.slap.initializeConnection(self.server_url)
......@@ -1744,7 +1670,7 @@ class TestVifibSlapWebServiceMixin(testVifibMixin):
slap_computer_partition = self.slap.registerComputerPartition(
computer_guid,
children_partition.getReference())
self.assertRaises(slap.ResourceNotReady, slap_computer_partition.request,
slap_computer_partition.request(
software_release=software_release_uri, software_type=requested_reference,
partition_reference=requested_reference,
partition_parameter_kw=requested_parameter_dict)
......@@ -1760,7 +1686,7 @@ class TestVifibSlapWebServiceMixin(testVifibMixin):
slap_computer_partition = self.slap.registerComputerPartition(
computer_guid,
children_partition.getReference())
self.assertRaises(slap.ResourceNotReady, slap_computer_partition.request,
slap_computer_partition.request(
software_release=software_release_uri,
software_type=requested_reference,
partition_reference=requested_reference,
......@@ -4610,13 +4536,13 @@ class TestVifibSlapWebService(TestVifibSlapWebServiceMixin):
filter_kw=sequence.get('requested_filter_dict', {})
)
def stepPersonRequestSlapSoftwareInstanceNotReadyResponse(self, sequence,
def stepPersonRequestSlapSoftwareInstancePrepare(self, sequence,
**kw):
software_release = sequence['software_release_uri']
self.slap = slap.slap()
self.slap.initializeConnection(self.server_url)
open_order = self.slap.registerOpenOrder()
self.assertRaises(slap.ResourceNotReady, open_order.request,
open_order.request(
software_release=software_release,
software_type=sequence.get('software_type', 'software_type'),
partition_reference=sequence.get('requested_reference',
......@@ -4674,7 +4600,7 @@ class TestVifibSlapWebService(TestVifibSlapWebServiceMixin):
SetRandomRequestedReference
SlapLoginTestVifibCustomer
PersonRequestSlapSoftwareInstanceNotReadyResponse
PersonRequestSlapSoftwareInstancePrepare
Tic
SlapLogout
......@@ -4755,7 +4681,7 @@ class TestVifibSlapWebService(TestVifibSlapWebServiceMixin):
SetRandomRequestedReference
SlapLoginTestVifibCustomer
PersonRequestSlapSoftwareInstanceNotReadyResponse
PersonRequestSlapSoftwareInstancePrepare
Tic
SlapLogout
......@@ -4776,7 +4702,7 @@ class TestVifibSlapWebService(TestVifibSlapWebServiceMixin):
SelectYetAnotherRequestedReference
SlapLoginTestVifibCustomer
PersonRequestSlapSoftwareInstanceNotReadyResponse
PersonRequestSlapSoftwareInstancePrepare
Tic
SlapLogout
......@@ -5127,11 +5053,6 @@ class TestVifibSlapWebService(TestVifibSlapWebServiceMixin):
RestoreComputerReferenceFromBufferA
RestoreComputerUidFromBufferA
RestoreSoftwareInstanceUidFromBufferA
SlapLoginCurrentSoftwareInstance
RequestComputerPartitionNotReadyResponse
Tic
SlapLogout
SlapLoginCurrentSoftwareInstance
RequestComputerPartition
Tic
......@@ -5510,10 +5431,6 @@ class TestVifibSlapWebService(TestVifibSlapWebServiceMixin):
# From root request B
SelectRequestedReferenceB
SlapLoginCurrentSoftwareInstance
RequestComputerPartitionNotReadyResponse
Tic
SlapLogout
SlapLoginCurrentSoftwareInstance
RequestComputerPartition
......@@ -5537,11 +5454,6 @@ class TestVifibSlapWebService(TestVifibSlapWebServiceMixin):
# From B request C
SelectRequestedReferenceC
SlapLoginCurrentSoftwareInstance
RequestComputerPartitionNotReadyResponse
Tic
SlapLogout
SlapLoginCurrentSoftwareInstance
RequestComputerPartition
Tic
......@@ -5659,11 +5571,6 @@ class TestVifibSlapWebService(TestVifibSlapWebServiceMixin):
# From root request B
SelectRequestedReferenceB
SlapLoginCurrentSoftwareInstance
RequestComputerPartitionNotReadyResponse
Tic
SlapLogout
SlapLoginCurrentSoftwareInstance
RequestComputerPartition
Tic
......@@ -5686,11 +5593,6 @@ class TestVifibSlapWebService(TestVifibSlapWebServiceMixin):
# From B request C
SelectRequestedReferenceC
SlapLoginCurrentSoftwareInstance
RequestComputerPartitionNotReadyResponse
Tic
SlapLogout
SlapLoginCurrentSoftwareInstance
RequestComputerPartition
Tic
......@@ -5818,11 +5720,6 @@ class TestVifibSlapWebService(TestVifibSlapWebServiceMixin):
# From root request B
SelectRequestedReferenceB
SlapLoginCurrentSoftwareInstance
RequestComputerPartitionNotReadyResponse
Tic
SlapLogout
SlapLoginCurrentSoftwareInstance
RequestComputerPartition
Tic
......
......@@ -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):
......
......@@ -24,13 +24,12 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import xml_marshaller
import unittest
import slap
import urlparse
import httplib
import slapos.slap
import os
from slap.slap import SlapDocument
SERVER_URL = os.environ.get('TEST_SLAP_SERVER_URL',
'https://user:pass@server/path/path')
class UndefinedYetException(Exception):
"""To catch exceptions which are not yet defined"""
......@@ -39,7 +38,34 @@ class SlapMixin(unittest.TestCase):
"""
Usefull methods for slap tests
"""
server_url = SERVER_URL
def setUp(self):
self._server_url = os.environ.get('TEST_SLAP_SERVER_URL', None)
if self._server_url is None:
self._patchHttplib()
self.server_url = 'http://localhost/'
else:
self.server_url = self._server_url
def tearDown(self):
if self._server_url is None:
self._unpatchHttplib()
def _patchHttplib(self):
"""Overrides httplib"""
import mock.httplib
self.saved_httplib = dict()
for fake in vars(mock.httplib):
self.saved_httplib[fake] = getattr(httplib, fake, None)
setattr(httplib, fake, getattr(mock.httplib, fake))
def _unpatchHttplib(self):
"""Restores httplib overriding"""
import httplib
for name, original_value in self.saved_httplib.items():
setattr(httplib, name, original_value)
del self.saved_httplib
def _getTestComputerId(self):
"""
......@@ -58,10 +84,10 @@ class TestSlap(SlapMixin):
Asserts that slap initialisation works properly in case of
passing correct url
"""
slap_instance = slap.slap()
slap_instance = slapos.slap.slap()
slap_instance.initializeConnection(self.server_url)
self.assertTrue(SlapDocument._connection_helper.host in self.server_url)
self.assertTrue(SlapDocument._connection_helper.path in self.server_url)
self.assertTrue(slapos.slap.SlapDocument._connection_helper.host in self.server_url)
self.assertTrue(slapos.slap.SlapDocument._connection_helper.path in self.server_url)
def test_slap_initialisation_wrong_url(self):
"""
......@@ -69,7 +95,7 @@ class TestSlap(SlapMixin):
is not correct
"""
server_url = 'https://user:pass@server/path/path?parameter=notAcceptable'
slap_instance = slap.slap()
slap_instance = slapos.slap.slap()
self.assertRaises(AttributeError,
slap_instance.initializeConnection, server_url)
......@@ -79,10 +105,10 @@ class TestSlap(SlapMixin):
Computer object
"""
computer_guid = self._getTestComputerId()
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
computer = self.slap.registerComputer(computer_guid)
self.assertTrue(isinstance(computer, slap.Computer))
self.assertTrue(isinstance(computer, slapos.slap.Computer))
def test_registerComputer_with_existing_guid(self):
"""
......@@ -90,13 +116,13 @@ class TestSlap(SlapMixin):
returns Computer object
"""
computer_guid = self._getTestComputerId()
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
computer = self.slap.registerComputer(computer_guid)
self.assertTrue(isinstance(computer, slap.Computer))
self.assertTrue(isinstance(computer, slapos.slap.Computer))
computer2 = self.slap.registerComputer(computer_guid)
self.assertTrue(isinstance(computer2, slap.Computer))
self.assertTrue(isinstance(computer2, slapos.slap.Computer))
# XXX: There is naming conflict in slap library.
# SoftwareRelease is currently used as suboject of Slap transmission object
......@@ -106,10 +132,11 @@ class TestSlap(SlapMixin):
returns SoftwareRelease object
"""
software_release_uri = 'http://server/' + self._getTestComputerId()
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
software_release = self.slap.registerSoftwareRelease(software_release_uri)
self.assertTrue(isinstance(software_release, slap.SoftwareRelease))
self.assertTrue(isinstance(software_release,
slapos.slap.SoftwareRelease))
def test_registerSoftwareRelease_with_existing_uri(self):
"""
......@@ -117,13 +144,15 @@ class TestSlap(SlapMixin):
used guid returns SoftwareRelease object
"""
software_release_uri = 'http://server/' + self._getTestComputerId()
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
software_release = self.slap.registerSoftwareRelease(software_release_uri)
self.assertTrue(isinstance(software_release, slap.SoftwareRelease))
self.assertTrue(isinstance(software_release,
slapos.slap.SoftwareRelease))
software_release2 = self.slap.registerSoftwareRelease(software_release_uri)
self.assertTrue(isinstance(software_release2, slap.SoftwareRelease))
self.assertTrue(isinstance(software_release2,
slapos.slap.SoftwareRelease))
def test_registerComputerPartition_new_partition_id_known_computer_guid(self):
"""
......@@ -131,14 +160,14 @@ class TestSlap(SlapMixin):
returns ComputerPartition object
"""
self.computer_guid = self._getTestComputerId()
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
self.partition_id = 'PARTITION_01'
self.slap.registerComputer(self.computer_guid)
partition = self.slap.registerComputerPartition(self.computer_guid,
self.partition_id)
self.assertTrue(isinstance(partition, slap.ComputerPartition))
self.assertTrue(isinstance(partition, slapos.slap.ComputerPartition))
def test_registerComputerPartition_existing_partition_id_known_computer_guid(self):
"""
......@@ -148,7 +177,7 @@ class TestSlap(SlapMixin):
self.test_registerComputerPartition_new_partition_id_known_computer_guid()
partition = self.slap.registerComputerPartition(self.computer_guid,
self.partition_id)
self.assertTrue(isinstance(partition, slap.ComputerPartition))
self.assertTrue(isinstance(partition, slapos.slap.ComputerPartition))
def test_registerComputerPartition_unknown_computer_guid(self):
"""
......@@ -156,7 +185,7 @@ class TestSlap(SlapMixin):
computer raises (not defined yet) exception
"""
computer_guid = self._getTestComputerId()
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
partition_id = 'PARTITION_01'
......@@ -166,7 +195,7 @@ class TestSlap(SlapMixin):
class TestComputer(SlapMixin):
"""
Tests slap.Computer class functionality
Tests slapos.slap.slap.Computer class functionality
"""
def test_computer_getComputerPartitionList_no_partition(self):
......@@ -175,7 +204,7 @@ class TestComputer(SlapMixin):
Partitions returns empty list
"""
self.computer_guid = self._getTestComputerId()
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
self.computer = self.slap.registerComputer(self.computer_guid)
self.assertEqual(self.computer.getComputerPartitionList(), [])
......@@ -187,7 +216,7 @@ class TestComputer(SlapMixin):
"""
self.computer_guid = self._getTestComputerId()
partition_id = 'PARTITION_01'
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
self.computer = self.slap.registerComputer(self.computer_guid)
self.partition = self.slap.registerComputerPartition(self.computer_guid,
......@@ -200,7 +229,7 @@ class TestComputer(SlapMixin):
(not defined yet) XML raises (not defined yet) exception
"""
self.computer_guid = self._getTestComputerId()
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
self.computer = self.slap.registerComputer(self.computer_guid)
non_dtd_xml = """<xml>
......@@ -217,7 +246,7 @@ class TestComputer(SlapMixin):
"""
self.computer_guid = self._getTestComputerId()
partition_id = 'PARTITION_01'
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
self.computer = self.slap.registerComputer(self.computer_guid)
self.partition = self.slap.registerComputerPartition(self.computer_guid,
......@@ -229,11 +258,175 @@ class TestComputer(SlapMixin):
self.assertRaises(UndefinedYetException, self.computer.reportUsage,
bad_partition_dtd_xml)
class RequestWasCalled(Exception):
pass
class TestComputerPartition(SlapMixin):
"""
Tests slap.ComputerPartition class functionality
Tests slapos.slap.slap.ComputerPartition class functionality
"""
def test_request_sends_request(self):
partition_id = 'PARTITION_01'
request_called_amount = 0
def server_response(self, path, method, body, header):
parsed_url = urlparse.urlparse(path.lstrip('/'))
parsed_qs = urlparse.parse_qs(parsed_url.query)
if parsed_url.path == 'registerComputerPartition' and \
'computer_reference' in parsed_qs and \
'computer_partition_reference' in parsed_qs:
slap_partition = slapos.slap.ComputerPartition(
parsed_qs['computer_reference'][0],
parsed_qs['computer_partition_reference'][0])
return (200, {}, xml_marshaller.xml_marshaller.dumps(slap_partition))
elif parsed_url.path == 'getComputerInformation' and \
'computer_id' in parsed_qs:
slap_computer = slapos.slap.Computer(parsed_qs['computer_id'][0])
slap_computer._software_release_list = []
slap_partition = slapos.slap.ComputerPartition(
parsed_qs['computer_id'][0],
partition_id)
slap_computer._computer_partition_list = [slap_partition]
return (200, {}, xml_marshaller.xml_marshaller.dumps(slap_computer))
elif parsed_url.path == 'requestComputerPartition':
raise RequestWasCalled
else:
return (404, {}, '')
httplib.HTTPConnection._callback = server_response
self.computer_guid = self._getTestComputerId()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
computer_partition = self.slap.registerComputerPartition(
self.computer_guid, partition_id)
self.assertRaises(RequestWasCalled, computer_partition.request,
'http://server/new/' + self._getTestComputerId(),
'software_type',
'myref')
def test_request_not_raises(self):
partition_id = 'PARTITION_01'
def server_response(self, path, method, body, header):
parsed_url = urlparse.urlparse(path.lstrip('/'))
parsed_qs = urlparse.parse_qs(parsed_url.query)
if parsed_url.path == 'registerComputerPartition' and \
'computer_reference' in parsed_qs and \
'computer_partition_reference' in parsed_qs:
slap_partition = slapos.slap.ComputerPartition(
parsed_qs['computer_reference'][0],
parsed_qs['computer_partition_reference'][0])
return (200, {}, xml_marshaller.xml_marshaller.dumps(slap_partition))
elif parsed_url.path == 'getComputerInformation' and \
'computer_id' in parsed_qs:
slap_computer = slapos.slap.Computer(parsed_qs['computer_id'][0])
slap_computer._software_release_list = []
slap_partition = slapos.slap.ComputerPartition(
parsed_qs['computer_id'][0],
partition_id)
slap_computer._computer_partition_list = [slap_partition]
return (200, {}, xml_marshaller.xml_marshaller.dumps(slap_computer))
elif parsed_url.path == 'requestComputerPartition':
return (408, {}, '')
else:
return (404, {}, '')
httplib.HTTPConnection._callback = server_response
self.computer_guid = self._getTestComputerId()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
computer_partition = self.slap.registerComputerPartition(
self.computer_guid, partition_id)
requested_partition = computer_partition.request(
'http://server/new/' + self._getTestComputerId(),
'software_type',
'myref')
self.assertTrue(isinstance(requested_partition,
slapos.slap.ComputerPartition))
def test_request_raises_later(self):
partition_id = 'PARTITION_01'
def server_response(self, path, method, body, header):
parsed_url = urlparse.urlparse(path.lstrip('/'))
parsed_qs = urlparse.parse_qs(parsed_url.query)
if parsed_url.path == 'registerComputerPartition' and \
'computer_reference' in parsed_qs and \
'computer_partition_reference' in parsed_qs:
slap_partition = slapos.slap.ComputerPartition(
parsed_qs['computer_reference'][0],
parsed_qs['computer_partition_reference'][0])
return (200, {}, xml_marshaller.xml_marshaller.dumps(slap_partition))
elif parsed_url.path == 'getComputerInformation' and \
'computer_id' in parsed_qs:
slap_computer = slapos.slap.Computer(parsed_qs['computer_id'][0])
slap_computer._software_release_list = []
slap_partition = slapos.slap.ComputerPartition(
parsed_qs['computer_id'][0],
partition_id)
slap_computer._computer_partition_list = [slap_partition]
return (200, {}, xml_marshaller.xml_marshaller.dumps(slap_computer))
elif parsed_url.path == 'requestComputerPartition':
return (408, {}, '')
else:
return (404, {}, '')
httplib.HTTPConnection._callback = server_response
self.computer_guid = self._getTestComputerId()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
computer_partition = self.slap.registerComputerPartition(
self.computer_guid, partition_id)
requested_partition = computer_partition.request(
'http://server/new/' + self._getTestComputerId(),
'software_type',
'myref')
self.assertTrue(isinstance(requested_partition,
slapos.slap.ComputerPartition))
# as request method does not raise, accessing data raises
self.assertRaises(slapos.slap.ResourceNotReady, requested_partition.getId)
def test_request_fullfilled_work(self):
partition_id = 'PARTITION_01'
requested_partition_id = 'PARTITION_02'
computer_guid = self._getTestComputerId()
def server_response(self, path, method, body, header):
parsed_url = urlparse.urlparse(path.lstrip('/'))
parsed_qs = urlparse.parse_qs(parsed_url.query)
if parsed_url.path == 'registerComputerPartition' and \
'computer_reference' in parsed_qs and \
'computer_partition_reference' in parsed_qs:
slap_partition = slapos.slap.ComputerPartition(
parsed_qs['computer_reference'][0],
parsed_qs['computer_partition_reference'][0])
return (200, {}, xml_marshaller.xml_marshaller.dumps(slap_partition))
elif parsed_url.path == 'getComputerInformation' and \
'computer_id' in parsed_qs:
slap_computer = slapos.slap.Computer(parsed_qs['computer_id'][0])
slap_computer._software_release_list = []
slap_partition = slapos.slap.ComputerPartition(
parsed_qs['computer_id'][0],
partition_id)
slap_computer._computer_partition_list = [slap_partition]
return (200, {}, xml_marshaller.xml_marshaller.dumps(slap_computer))
elif parsed_url.path == 'requestComputerPartition':
from slapos.slap.slap import SoftwareInstance
slap_partition = SoftwareInstance(
slap_computer_id=computer_guid,
slap_computer_partition_id=requested_partition_id)
return (200, {}, xml_marshaller.xml_marshaller.dumps(slap_partition))
else:
return (404, {}, '')
httplib.HTTPConnection._callback = server_response
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
computer_partition = self.slap.registerComputerPartition(
computer_guid, partition_id)
requested_partition = computer_partition.request(
'http://server/new/' + self._getTestComputerId(),
'software_type',
'myref')
self.assertTrue(isinstance(requested_partition,
slapos.slap.ComputerPartition))
# as request method does not raise, accessing data in case when
# request was done works correctly
self.assertEqual(requested_partition_id, requested_partition.getId())
def _test_new_computer_partition_state(self, state):
"""
Helper method to automate assertions of failing states on new Computer
......@@ -241,7 +434,7 @@ class TestComputerPartition(SlapMixin):
"""
self.computer_guid = self._getTestComputerId()
partition_id = 'PARTITION_01'
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
computer_partition = self.slap.registerComputerPartition(
self.computer_guid, partition_id)
......@@ -282,7 +475,7 @@ class TestComputerPartition(SlapMixin):
"""
self.computer_guid = self._getTestComputerId()
partition_id = 'PARTITION_01'
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
computer_partition = self.slap.registerComputerPartition(
self.computer_guid, partition_id)
......@@ -300,7 +493,7 @@ class TestSoftwareRelease(SlapMixin):
Release
"""
self.software_release_uri = 'http://server/' + self._getTestComputerId()
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
software_release = self.slap.registerSoftwareRelease(
self.software_release_uri)
......@@ -326,7 +519,7 @@ class TestSoftwareRelease(SlapMixin):
Asserts that calling SoftwareRelease.error on new software release works
"""
self.software_release_uri = 'http://server/' + self._getTestComputerId()
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
software_release = self.slap.registerSoftwareRelease(
self.software_release_uri)
......@@ -334,18 +527,66 @@ class TestSoftwareRelease(SlapMixin):
software_release.error('some error')
class TestOpenOrder(SlapMixin):
def test_OpenOrder_request_raises(self):
"""
Asserts that calling OpenOrder.request with new URI raises
(not defined yet) exception
"""
def test_request_sends_request(self):
software_release_uri = 'http://server/new/' + self._getTestComputerId()
self.slap = slap.slap()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
# XXX: Interface lack registerOpenOrder method declaration
open_order = self.slap.registerOpenOrder()
self.assertRaises(UndefinedYetException, open_order.request,
software_release_uri)
def server_response(self, path, method, body, header):
parsed_url = urlparse.urlparse(path.lstrip('/'))
if parsed_url.path == 'requestComputerPartition':
raise RequestWasCalled
httplib.HTTPConnection._callback = server_response
self.assertRaises(RequestWasCalled, open_order.request, software_release_uri, 'myrefe')
def test_request_not_raises(self):
software_release_uri = 'http://server/new/' + self._getTestComputerId()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
# XXX: Interface lack registerOpenOrder method declaration
open_order = self.slap.registerOpenOrder()
computer_partition = open_order.request(software_release_uri, 'myrefe')
self.assertTrue(isinstance(computer_partition,
slapos.slap.ComputerPartition))
def test_request_raises_later(self):
software_release_uri = 'http://server/new/' + self._getTestComputerId()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
# XXX: Interface lack registerOpenOrder method declaration
open_order = self.slap.registerOpenOrder()
def server_response(self, path, method, body, header):
return (408, {}, '')
httplib.HTTPConnection._callback = server_response
computer_partition = open_order.request(software_release_uri, 'myrefe')
self.assertTrue(isinstance(computer_partition,
slapos.slap.ComputerPartition))
self.assertRaises(slapos.slap.ResourceNotReady, computer_partition.getId)
def test_request_fullfilled_work(self):
software_release_uri = 'http://server/new/' + self._getTestComputerId()
self.slap = slapos.slap.slap()
self.slap.initializeConnection(self.server_url)
# XXX: Interface lack registerOpenOrder method declaration
open_order = self.slap.registerOpenOrder()
computer_guid = self._getTestComputerId()
requested_partition_id = 'PARTITION_01'
def server_response(self, path, method, body, header):
parsed_url = urlparse.urlparse(path.lstrip('/'))
parsed_qs = urlparse.parse_qs(parsed_url.query)
from slapos.slap.slap import SoftwareInstance
slap_partition = SoftwareInstance(
slap_computer_id=computer_guid,
slap_computer_partition_id=requested_partition_id)
return (200, {}, xml_marshaller.xml_marshaller.dumps(slap_partition))
httplib.HTTPConnection._callback = server_response
computer_partition = open_order.request(software_release_uri, 'myrefe')
self.assertTrue(isinstance(computer_partition,
slapos.slap.ComputerPartition))
self.assertTrue(requested_partition_id, computer_partition.getId())
if __name__ == '__main__':
print 'Testing against SLAP server %r' % SERVER_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