Commit 7a164026 authored by Romain Courteaud's avatar Romain Courteaud

slapos_erp5: test remote slave allocation

parent 80957db3
...@@ -102,11 +102,13 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin): ...@@ -102,11 +102,13 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
def addAllocationSupply(self, title, node, software_product, def addAllocationSupply(self, title, node, software_product,
software_release, software_type, software_release, software_type,
destination_value=None,
is_slave_on_same_instance_tree_allocable=False): is_slave_on_same_instance_tree_allocable=False):
allocation_supply = self.portal.allocation_supply_module.newContent( allocation_supply = self.portal.allocation_supply_module.newContent(
portal_type="Allocation Supply", portal_type="Allocation Supply",
title=title, title=title,
aggregate_value=node, aggregate_value=node,
destination_value=destination_value,
destination_project_value=software_product.getFollowUpValue(), destination_project_value=software_product.getFollowUpValue(),
slave_on_same_instance_tree_allocable=is_slave_on_same_instance_tree_allocable slave_on_same_instance_tree_allocable=is_slave_on_same_instance_tree_allocable
) )
...@@ -954,6 +956,233 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin): ...@@ -954,6 +956,233 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
assert last_message is None, last_message assert last_message is None, last_message
def test_virtual_master_slave_instance_on_remote_tree_without_accounting_scenario(self):
self.web_site = self.portal.web_site_module.slapos_master_panel
preference = self.portal.portal_preferences.slapos_default_system_preference
####################################
# Create a remote project
####################################
remote_project = self.addProject()
preference.edit(
preferred_subscription_assignment_category_list=[
'function/customer',
'role/client',
'destination_project/%s' % remote_project.getRelativeUrl()
]
)
# some preparation
self.logout()
# lets join as slapos administrator, which will own few compute_nodes
remote_owner_reference = 'remote-owner-%s' % self.generateNewId()
self.joinSlapOS(self.web_site, remote_owner_reference)
self.login()
remote_owner_person = self.portal.portal_catalog.getResultValue(
portal_type="ERP5 Login",
reference=remote_owner_reference).getParentValue()
# first slapos administrator assignment can only be created by
# the erp5 manager
self.addProjectProductionManagerAssignment(remote_owner_person, remote_project)
self.tic()
# hooray, now it is time to create compute_nodes
self.login(remote_owner_person.getUserId())
remote_server_title = 'Remote Server for %s' % remote_owner_person
remote_server_id = self.requestComputeNode(remote_server_title, remote_project.getReference())
remote_server = self.portal.portal_catalog.getResultValue(
portal_type='Compute Node', reference=remote_server_id)
self.setAccessToMemcached(remote_server)
self.assertNotEqual(None, remote_server)
self.setServerOpenPublic(remote_server)
# and install some software on them
remote_server_software = self.generateNewSoftwareReleaseUrl()
remote_instance_type = 'public type'
self.supplySoftware(remote_server, remote_server_software)
# format the compute_nodes
self.formatComputeNode(remote_server)
remote_software_product, remote_release_variation, remote_type_variation = self.addSoftwareProduct(
"remote product", remote_project, remote_server_software, remote_instance_type
)
self.addAllocationSupply("for compute node", remote_server, remote_software_product,
remote_release_variation, remote_type_variation,
destination_value=remote_owner_person)
private_instance_title = 'Private title %s' % self.generateNewId()
self.checkInstanceAllocation(remote_owner_person.getUserId(),
remote_owner_reference, private_instance_title,
remote_server_software, remote_instance_type,
remote_server, remote_project.getReference())
# Convert the Software Instance into an Instance Node
# to explicitely mark it as accepting Slave Instance
private_software_instance = self.portal.portal_catalog.getResultValue(
portal_type='Software Instance', title=private_instance_title)
instance_node_title = 'Shared Instance for %s' % remote_owner_reference
instance_node = self.addInstanceNode(instance_node_title, private_software_instance)
self.addAllocationSupply(
"for instance node", instance_node, remote_software_product,
remote_release_variation, remote_type_variation)
# join as the another visitor and request software instance on public
# compute_node
self.logout()
remote_public_reference = 'remote-public-%s' % self.generateNewId()
self.joinSlapOS(self.web_site, remote_public_reference)
self.login()
remote_public_person = self.portal.portal_catalog.getResultValue(
portal_type="ERP5 Login",
reference=remote_public_reference).getParentValue()
####################################
# Create a local project
####################################
project = self.addProject()
preference.edit(
preferred_subscription_assignment_category_list=[
'function/customer',
'role/client',
'destination_project/%s' % project.getRelativeUrl()
]
)
owner_person = remote_public_person
# first slapos administrator assignment can only be created by
# the erp5 manager
self.addProjectProductionManagerAssignment(owner_person, project)
self.tic()
# hooray, now it is time to create compute_nodes
self.login(owner_person.getUserId())
remote_compute_node = self.requestRemoteNode(project, remote_project,
remote_public_person)
# and install some software on them
public_server_software = remote_server_software
remote_compute_node.requestSoftwareRelease(software_release_url=public_server_software,
state='available')
#software_product, release_variation, type_variation = self.addSoftwareProduct(
public_instance_type = remote_instance_type
software_product, software_release, software_type = self.addSoftwareProduct(
"instance product", project, public_server_software, public_instance_type
)
self.addAllocationSupply("for remote node", remote_compute_node, software_product,
software_release, software_type)
self.tic()
# join as the another visitor and request software instance on public
# compute_node
self.logout()
public_reference = 'public-%s' % self.generateNewId()
self.joinSlapOS(self.web_site, public_reference)
self.login()
public_person = self.portal.portal_catalog.getResultValue(
portal_type="ERP5 Login",
reference=public_reference).getParentValue()
public_instance_title = 'Public title %s' % self.generateNewId()
self.checkRemoteInstanceAllocation(public_person.getUserId(),
public_reference, public_instance_title,
public_server_software, public_instance_type,
remote_compute_node, project.getReference(),
slave=True)
# XXX Do this for every scenario tests
self.logout()
for _ in range(3):
self.stepCallAlarmList()
self.tic()
# now instantiate it on compute_node and set some nice connection dict
self.simulateSlapgridCP(remote_server)
self.tic()
self.login()
# owner_person should have one Instance Tree created by alarm
owner_instance_tree_list = self.portal.portal_catalog(
portal_type='Instance Tree',
destination_section__uid=owner_person.getUid()
)
self.assertEqual(1, len(owner_instance_tree_list))
owner_software_instance = owner_instance_tree_list[0].getSuccessorValue()
self.assertEqual('Slave Instance', owner_software_instance.getPortalType())
self.assertEqual(
remote_server.getRelativeUrl(),
owner_software_instance.getAggregateValue().getParentValue().getRelativeUrl()
)
# public_person should have one Instance Tree
public_instance_tree_list = self.portal.portal_catalog(
portal_type='Instance Tree',
destination_section__uid=public_person.getUid()
)
self.assertEqual(1, len(public_instance_tree_list))
self.assertEqual(
'_remote_%s_%s' % (project.getReference(),
public_instance_tree_list[0].getSuccessorReference()),
owner_software_instance.getTitle()
)
connection_dict = owner_software_instance.getConnectionXmlAsDict()
self.assertSameSet(('url_1', 'url_2'), connection_dict.keys())
self.assertSameSet(
['http://%s/%s' % (q.getIpAddress(), owner_software_instance.getReference()) for q in
owner_software_instance.getAggregateValue().contentValues(portal_type='Internet Protocol Address')],
connection_dict.values())
self.checkRemoteInstanceAllocation(public_person.getUserId(),
public_reference, public_instance_title,
public_server_software, public_instance_type,
remote_compute_node, project.getReference(),
connection_dict_to_check=owner_software_instance.getConnectionXmlAsDict(),
slave=True)
self.login()
# Ensure no unexpected object has been created
# 3 (can reduce to 2) assignment, 1 remote node, 1 software installation
# 1 compute node
# 1 instance node
# 2 instance tree, 1 software instance, 1 slave instance
# 2 credential request
# 1 software product
# 6 allocation supply/line/cell
related_object_list = remote_project.Base_getRelatedObjectList(**{'category.category_strict_membership': 1})
assert len(related_object_list) == 20, [x.getRelativeUrl() for x in related_object_list]
# Ensure no unexpected object has been created
# 2 (can reduce to 2) assignment, 1 remote node, 1 software installation
# 1 instance tree, 1 slave instance
# 1 credential request
# 1 software product
# 3 allocation supply/line/cell
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]
self.stepcheckERP5Consistency()
# after accept, an email is send containing the reset link
last_message = self.portal.MailHost._last_message
assert last_message is None, last_message
def test_open_order_with_service_scenario(self): def test_open_order_with_service_scenario(self):
# create a default project # create a default project
......
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