Commit 0e7288a0 authored by Łukasz Nowak's avatar Łukasz Nowak

Checkpoint: public computer's instance worked.

The user which request instance on public computer was able to read its
connection parameters and they were correctly set during simulateSlapgridCP run.
parent a502aec6
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
from testSlapOSSecurityGroup import TestSlapOSSecurityMixin from testSlapOSSecurityGroup import TestSlapOSSecurityMixin
import re import re
from xml_marshaller import xml_marshaller import xml_marshaller
from AccessControl.SecurityManagement import getSecurityManager, \
setSecurityManager
def changeSkin(skin_name): def changeSkin(skin_name):
def decorator(func): def decorator(func):
...@@ -70,7 +73,7 @@ class TestSlapOSDefaultScenario(TestSlapOSSecurityMixin): ...@@ -70,7 +73,7 @@ class TestSlapOSDefaultScenario(TestSlapOSSecurityMixin):
requestXml = self.portal.portal_slap.requestComputer(title) requestXml = self.portal.portal_slap.requestComputer(title)
self.tic() self.tic()
self.assertTrue('marshal' in requestXml) self.assertTrue('marshal' in requestXml)
computer = xml_marshaller.loads(requestXml) computer = xml_marshaller.xml_marshaller.loads(requestXml)
computer_id = getattr(computer, '_computer_id', None) computer_id = getattr(computer, '_computer_id', None)
self.assertNotEqual(None, computer_id) self.assertNotEqual(None, computer_id)
return computer_id return computer_id
...@@ -97,6 +100,8 @@ class TestSlapOSDefaultScenario(TestSlapOSSecurityMixin): ...@@ -97,6 +100,8 @@ class TestSlapOSDefaultScenario(TestSlapOSSecurityMixin):
allocation_scope='open/public', subject_list=[]) allocation_scope='open/public', subject_list=[])
self.assertEqual('open/public', server.getAllocationScope()) self.assertEqual('open/public', server.getAllocationScope())
self.assertEqual('close', server.getCapacityScope()) self.assertEqual('close', server.getCapacityScope())
server.edit(capacity_scope='open')
self.tic()
@changeSkin('Hosting') @changeSkin('Hosting')
def setServerOpenPersonal(self, server): def setServerOpenPersonal(self, server):
...@@ -104,6 +109,7 @@ class TestSlapOSDefaultScenario(TestSlapOSSecurityMixin): ...@@ -104,6 +109,7 @@ class TestSlapOSDefaultScenario(TestSlapOSSecurityMixin):
allocation_scope='open/personal', subject_list=[]) allocation_scope='open/personal', subject_list=[])
self.assertEqual('open/personal', server.getAllocationScope()) self.assertEqual('open/personal', server.getAllocationScope())
self.assertEqual('open', server.getCapacityScope()) self.assertEqual('open', server.getCapacityScope())
self.tic()
@changeSkin('Hosting') @changeSkin('Hosting')
def setServerOpenFriend(self, server, friend_list=None): def setServerOpenFriend(self, server, friend_list=None):
...@@ -114,6 +120,85 @@ class TestSlapOSDefaultScenario(TestSlapOSSecurityMixin): ...@@ -114,6 +120,85 @@ class TestSlapOSDefaultScenario(TestSlapOSSecurityMixin):
self.assertEqual('open/friend', server.getAllocationScope()) self.assertEqual('open/friend', server.getAllocationScope())
self.assertEqual('open', server.getCapacityScope()) self.assertEqual('open', server.getCapacityScope())
self.assertSameSet(friend_list, server.getSubjectList()) self.assertSameSet(friend_list, server.getSubjectList())
self.tic()
@changeSkin('Hosting')
def WebSection_getCurrentHostingSubscriptionList(self):
return self.web_site.hosting.myspace.my_services\
.WebSection_getCurrentHostingSubscriptionList()
def formatComputer(self, computer, partition_count=10):
computer_dict = dict(
software_root='/opt',
reference=computer.getReference(),
netmask='255.255.255.0',
address='128.0.0.1',
instance_root='/srv'
)
computer_dict['partition_list'] = []
a = computer_dict['partition_list'].append
for i in range(1, partition_count+1):
a(dict(
reference='part%s' % i,
tap=dict(name='tap%s' % i),
address_list=[
dict(addr='p%sa1' % i, netmask='p%sn1' % i),
dict(addr='p%sa2' % i, netmask='p%sn2' % i)
]
))
sm = getSecurityManager()
try:
self.login(computer.getReference())
self.portal.portal_slap.loadComputerConfigurationFromXML(
xml_marshaller.xml_marshaller.dumps(computer_dict))
self.tic()
self.assertEqual(partition_count,
len(computer.contentValues(portal_type='Computer Partition')))
finally:
setSecurityManager(sm)
def simulateSlapgridCP(self, computer):
sm = getSecurityManager()
computer_reference = computer.getReference()
try:
self.login(computer_reference)
computer_xml = self.portal.portal_slap.getFullComputerInformation(
computer_id=computer.getReference())
slap_computer = xml_marshaller.xml_marshaller.loads(computer_xml)
self.assertEqual('Computer', slap_computer.__class__.__name__)
for partition in slap_computer._computer_partition_list:
if partition._requested_state in ('started', 'stopped'):
instance_reference = partition._instance_guid
ip_list = partition._parameter_dict['ip_list']
connection_xml = xml_marshaller.xml_marshaller.dumps(dict(
url_1 = 'http://%s/' % ip_list[0][1],
url_2 = 'http://%s/' % ip_list[1][1],
))
oldsm = getSecurityManager()
try:
self.login(instance_reference)
self.portal.portal_slap.setComputerPartitionConnectionXml(
computer_id=computer_reference,
computer_partition_id=partition._partition_id,
connection_xml=connection_xml
)
finally:
setSecurityManager(oldsm)
finally:
setSecurityManager(sm)
self.tic()
def personRequestInstanceNotReady(self, **kw):
response = self.portal.portal_slap.requestComputerPartition(**kw)
status = getattr(response, 'status', None)
self.assertEqual(408, status)
self.tic()
def personRequestInstance(self, **kw):
response = self.portal.portal_slap.requestComputerPartition(**kw)
self.assertTrue(isinstance(response, str))
software_instance = xml_marshaller.xml_marshaller.loads(response)
self.assertEqual('SoftwareInstance', software_instance.__class__.__name__)
return software_instance
def test(self): def test(self):
# some preparation # some preparation
...@@ -149,7 +234,6 @@ class TestSlapOSDefaultScenario(TestSlapOSSecurityMixin): ...@@ -149,7 +234,6 @@ class TestSlapOSDefaultScenario(TestSlapOSSecurityMixin):
self.setServerOpenFriend(friend_server) self.setServerOpenFriend(friend_server)
# and install some software on them # and install some software on them
public_server_software = self.generateNewSoftwareReleaseUrl() public_server_software = self.generateNewSoftwareReleaseUrl()
self.supplySoftware(public_server, public_server_software) self.supplySoftware(public_server, public_server_software)
...@@ -158,5 +242,55 @@ class TestSlapOSDefaultScenario(TestSlapOSSecurityMixin): ...@@ -158,5 +242,55 @@ class TestSlapOSDefaultScenario(TestSlapOSSecurityMixin):
friend_server_software = self.generateNewSoftwareReleaseUrl() friend_server_software = self.generateNewSoftwareReleaseUrl()
self.supplySoftware(friend_server, friend_server_software) self.supplySoftware(friend_server, friend_server_software)
# format the computers
self.formatComputer(public_server)
self.formatComputer(personal_server)
self.formatComputer(friend_server)
# now join as the another visitor and request software instance
# on public computer
self.logout()
public_reference = 'public-%s' % self.generateNewId()
self.joinSlapOS(self.web_site, public_reference)
self.login(public_reference)
public_instance_title = 'Public title %s' % self.generateNewId()
self.personRequestInstanceNotReady(
software_release=public_server_software,
software_type='public type',
partition_reference=public_instance_title,
)
self.stepCallSlaposAllocateInstanceAlarm()
self.tic()
self.personRequestInstance(
software_release=public_server_software,
software_type='public type',
partition_reference=public_instance_title,
)
# now instantiate it on computer and set some nice connection dict
self.simulateSlapgridCP(public_server)
# let's find instances of user and check connection strings
hosting_subscription_list = self.\
WebSection_getCurrentHostingSubscriptionList()
self.assertEqual(1, len(hosting_subscription_list))
hosting_subscription = hosting_subscription_list[0].getObject()
software_instance = hosting_subscription.getPredecessorValue()
self.assertEqual(software_instance.getTitle(),
hosting_subscription.getTitle())
connection_dict = software_instance.getConnectionXmlAsDict()
self.assertSameSet(('url_1', 'url_2'), connection_dict.keys())
self.login()
partition = software_instance.getAggregateValue()
self.assertSameSet(
['http://%s/' % q.getIpAddress() for q in
partition.contentValues(portal_type='Internet Protocol Address')],
connection_dict.values())
# remove the assertion after test is finished # remove the assertion after test is finished
self.assertTrue(False, 'Test not finished') self.assertTrue(False, 'Test not finished')
69 70
\ No newline at end of file \ No newline at end of file
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