Commit e88d2877 authored by Romain Courteaud's avatar Romain Courteaud

slapos_erp5: use Allocation Supply to check where to allocate

Ensure Slave Instance can be instanciated on other software release instance (thanks to Instance Node)
parent da8d85b7
...@@ -40,6 +40,86 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin): ...@@ -40,6 +40,86 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
project.validate() project.validate()
return project return project
def addSoftwareProduct(self, title, project, public_server_software,
public_instance_type):
software_product = self.portal.software_product_module.newContent(
portal_type="Software Product",
title=title,
follow_up_value=project,
quantity_unit='time/month',
)
software_product.newContent(
portal_type="Software Product Release Variation",
title="my old release",
url_string=public_server_software + '-1'
)
release_variation = software_product.newContent(
portal_type="Software Product Release Variation",
title="my current release",
url_string=public_server_software
)
software_product.newContent(
portal_type="Software Product Release Variation",
title="my futur release",
url_string=public_server_software + '+1'
)
software_product.newContent(
portal_type="Software Product Type Variation",
title=public_instance_type + '-1'
)
type_variation = software_product.newContent(
portal_type="Software Product Type Variation",
title=public_instance_type
)
software_product.newContent(
portal_type="Software Product Type Variation",
title=public_instance_type + '+1'
)
software_product.validate()
return software_product, release_variation, type_variation
def addAllocationSupply(self, title, node, software_product,
software_release, software_type):
allocation_supply = self.portal.allocation_supply_module.newContent(
portal_type="Allocation Supply",
title=title,
aggregate_value=node,
destination_project_value=node.getFollowUpValue(),
)
resource_vcl = [
'software_release/%s' % software_release.getRelativeUrl(),
'software_type/%s' % software_type.getRelativeUrl()
]
resource_vcl.sort()
allocation_supply_line = allocation_supply.newContent(
portal_type="Allocation Supply Line",
resource_value=software_product,
)
allocation_supply_line.edit(
p_variation_base_category_list=allocation_supply_line.getVariationRangeBaseCategoryList()
)
base_id = 'path'
allocation_supply_line.setCellRange(
base_id=base_id,
*allocation_supply_line.SupplyLine_asCellRange(base_id=base_id)
)
#cell_key = list(allocation_supply_line.getCellKeyList(base_id=base_id))[0]
cell_key = resource_vcl
allocation_supply_line.log(resource_vcl, cell_key)
allocation_supply_cell = allocation_supply_line.newCell(
base_id=base_id,
portal_type='Allocation Supply Cell',
*cell_key
)
allocation_supply_cell.edit(
mapped_value_property_list=['allocable'],
allocable=True,
predicate_category_list=cell_key,
variation_category_list=cell_key
)
allocation_supply.validate()
return allocation_supply
def stepcheckERP5Consistency(self): def stepcheckERP5Consistency(self):
not_consistent_document = self.portal.portal_catalog.getResultValue( not_consistent_document = self.portal.portal_catalog.getResultValue(
consistency_error=1, consistency_error=1,
...@@ -92,11 +172,20 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin): ...@@ -92,11 +172,20 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
# and install some software on them # and install some software on them
public_server_software = self.generateNewSoftwareReleaseUrl() public_server_software = self.generateNewSoftwareReleaseUrl()
public_instance_type = 'public type'
self.supplySoftware(public_server, public_server_software) self.supplySoftware(public_server, public_server_software)
# format the compute_nodes # format the compute_nodes
self.formatComputeNode(public_server) self.formatComputeNode(public_server)
software_product, release_variation, type_variation = self.addSoftwareProduct(
"instance product", project, public_server_software, public_instance_type
)
self.addAllocationSupply("for compute node", public_server, software_product,
release_variation, type_variation)
# join as the another visitor and request software instance on public # join as the another visitor and request software instance on public
# compute_node # compute_node
self.logout() self.logout()
...@@ -109,7 +198,6 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin): ...@@ -109,7 +198,6 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
reference=public_reference).getParentValue() reference=public_reference).getParentValue()
public_instance_title = 'Public title %s' % self.generateNewId() public_instance_title = 'Public title %s' % self.generateNewId()
public_instance_type = 'public type'
self.checkInstanceAllocation(public_person.getUserId(), self.checkInstanceAllocation(public_person.getUserId(),
public_reference, public_instance_title, public_reference, public_instance_title,
public_server_software, public_instance_type, public_server_software, public_instance_type,
...@@ -149,8 +237,10 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin): ...@@ -149,8 +237,10 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
# 3 (can reduce to 2) assignment, 1 instance tree, 1 compute node, 1 software installation # 3 (can reduce to 2) assignment, 1 instance tree, 1 compute node, 1 software installation
# 1 software instance # 1 software instance
# 2 credential request # 2 credential request
# 3 allocation supply, line, cell
# 1 software product
related_object_list = project.Base_getRelatedObjectList(**{'category.category_strict_membership': 1}) related_object_list = project.Base_getRelatedObjectList(**{'category.category_strict_membership': 1})
assert len(related_object_list) == 9, [x.getRelativeUrl() for x in related_object_list] assert len(related_object_list) == 13, [x.getRelativeUrl() for x in related_object_list]
self.stepcheckERP5Consistency() self.stepcheckERP5Consistency()
...@@ -211,40 +301,9 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin): ...@@ -211,40 +301,9 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
sale_trade_condition.validate() sale_trade_condition.validate()
software_product = self.portal.software_product_module.newContent( software_product, release_variation, type_variation = self.addSoftwareProduct(
portal_type="Software Product", "instance product", project, public_server_software, public_instance_type
title="foo software product",
follow_up_value=project,
quantity_unit='time/month',
)
software_product.newContent(
portal_type="Software Product Release Variation",
title="my old release",
url_string=public_server_software + '-1'
)
release_variation = software_product.newContent(
portal_type="Software Product Release Variation",
title="my current release",
url_string=public_server_software
)
software_product.newContent(
portal_type="Software Product Release Variation",
title="my futur release",
url_string=public_server_software + '+1'
)
software_product.newContent(
portal_type="Software Product Type Variation",
title=public_instance_type + '-1'
) )
type_variation = software_product.newContent(
portal_type="Software Product Type Variation",
title=public_instance_type
)
software_product.newContent(
portal_type="Software Product Type Variation",
title=public_instance_type + '+1'
)
software_product.validate()
sale_supply = self.portal.sale_supply_module.newContent( sale_supply = self.portal.sale_supply_module.newContent(
portal_type="Sale Supply", portal_type="Sale Supply",
...@@ -287,6 +346,9 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin): ...@@ -287,6 +346,9 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
self.assertNotEqual(None, public_server) self.assertNotEqual(None, public_server)
self.setServerOpenPublic(public_server) self.setServerOpenPublic(public_server)
self.addAllocationSupply("for compute node", public_server, software_product,
release_variation, type_variation)
# and install some software on them # and install some software on them
self.supplySoftware(public_server, public_server_software) self.supplySoftware(public_server, public_server_software)
...@@ -388,9 +450,10 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin): ...@@ -388,9 +450,10 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
# 1 sale trace condition # 1 sale trace condition
# 1 supply, 1 supply line # 1 supply, 1 supply line
# 1 open order line / 1 cell # 1 open order line / 1 cell
# 3 allocation supply / line / cell
related_object_list = project.Base_getRelatedObjectList(**{'category.category_strict_membership': 1}) related_object_list = project.Base_getRelatedObjectList(**{'category.category_strict_membership': 1})
assert len(related_object_list) == 26, [x.getRelativeUrl() for x in related_object_list] assert len(related_object_list) == 29, [x.getRelativeUrl() for x in related_object_list]
self.stepcheckERP5Consistency() self.stepcheckERP5Consistency()
...@@ -399,6 +462,17 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin): ...@@ -399,6 +462,17 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
assert last_message is None, last_message assert last_message is None, last_message
def addInstanceNode(self, title, software_instance):
instance_node = self.portal.compute_node_module.newContent(
portal_type='Instance Node',
title=title,
specialise_value=software_instance,
follow_up_value=software_instance.getFollowUpValue()
)
instance_node.validate()
return instance_node
def test_virtual_master_slave_without_accounting_scenario(self): def test_virtual_master_slave_without_accounting_scenario(self):
# create a default project # create a default project
project = self.addProject() project = self.addProject()
...@@ -445,6 +519,15 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin): ...@@ -445,6 +519,15 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
public_server_software = self.generateNewSoftwareReleaseUrl() public_server_software = self.generateNewSoftwareReleaseUrl()
self.supplySoftware(public_server, public_server_software) self.supplySoftware(public_server, public_server_software)
#software_product, release_variation, type_variation = self.addSoftwareProduct(
public_instance_type = 'public type'
software_product, software_release, software_type = self.addSoftwareProduct(
"instance product", project, public_server_software, public_instance_type
)
self.addAllocationSupply("for compute node", public_server, software_product,
software_release, software_type)
# format the compute_nodes # format the compute_nodes
self.formatComputeNode(public_server) self.formatComputeNode(public_server)
...@@ -460,16 +543,32 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin): ...@@ -460,16 +543,32 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
reference=public_reference).getParentValue() reference=public_reference).getParentValue()
public_instance_title = 'Public title %s' % self.generateNewId() public_instance_title = 'Public title %s' % self.generateNewId()
public_instance_type = 'public type'
self.checkInstanceAllocation(public_person.getUserId(), self.checkInstanceAllocation(public_person.getUserId(),
public_reference, public_instance_title, public_reference, public_instance_title,
public_server_software, public_instance_type, public_server_software, public_instance_type,
public_server, project.getReference()) public_server, project.getReference())
public_instance_title = 'Slave title %s' % self.generateNewId() # hooray, now it is time to create compute_nodes
self.login(owner_person.getUserId())
instance_node_title = 'Shared Instance for %s' % owner_reference
# Convert the Software Instance into an Instance Node
# to explicitely mark it as accepting Slave Instance
software_instance = self.portal.portal_catalog.getResultValue(
portal_type='Software Instance', title=public_instance_title)
instance_node = self.addInstanceNode(instance_node_title, software_instance)
slave_server_software = self.generateNewSoftwareReleaseUrl()
slave_instance_type = 'slave type'
software_product, software_release, software_type = self.addSoftwareProduct(
'share product', project, slave_server_software, slave_instance_type
)
self.addAllocationSupply("for instance node", instance_node, software_product,
software_release, software_type)
slave_instance_title = 'Slave title %s' % self.generateNewId()
self.checkSlaveInstanceAllocation(public_person.getUserId(), self.checkSlaveInstanceAllocation(public_person.getUserId(),
public_reference, public_instance_title, public_reference, slave_instance_title,
public_server_software, public_instance_type, slave_server_software, slave_instance_type,
public_server, project.getReference()) public_server, project.getReference())
self.login() self.login()
...@@ -479,8 +578,8 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin): ...@@ -479,8 +578,8 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
# and the instances # and the instances
self.checkSlaveInstanceUnallocation(public_person.getUserId(), self.checkSlaveInstanceUnallocation(public_person.getUserId(),
public_reference, public_instance_title, public_reference, slave_instance_title,
public_server_software, public_instance_type, public_server, slave_server_software, slave_instance_type, public_server,
project.getReference()) project.getReference())
# and uninstall some software on them # and uninstall some software on them
...@@ -506,8 +605,11 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin): ...@@ -506,8 +605,11 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
# 3 (can reduce to 2) assignment, 2 instance tree, 1 compute node, 1 software installation # 3 (can reduce to 2) assignment, 2 instance tree, 1 compute node, 1 software installation
# 2 software instance # 2 software instance
# 2 credential request # 2 credential request
# 2 software product
# 6 allocation supply/line/cell
# 1 instance node
related_object_list = project.Base_getRelatedObjectList(**{'category.category_strict_membership': 1}) related_object_list = project.Base_getRelatedObjectList(**{'category.category_strict_membership': 1})
assert len(related_object_list) == 11, [x.getRelativeUrl() for x in related_object_list] assert len(related_object_list) == 20, [x.getRelativeUrl() for x in related_object_list]
self.stepcheckERP5Consistency() self.stepcheckERP5Consistency()
......
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