Commit e3b07565 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_erp5: Test timestamp with start/stop use cases

parent b9929aeb
......@@ -147,16 +147,16 @@ class TestSlapOSAllocationScenario(TestSlapOSAllocationScenarioMixin):
parameter_dict = software_instance._asParameterDict()
timestamp = parameter_dict['timestamp']
self.assertTrue(int(timestamp) > before_timestamp,
self.assertTrue(timestamp > before_timestamp,
"timestamp: %s < begin:%s" % (timestamp, before_timestamp))
# At first we expect that partition is modified later them
# bang_timestamp
partition = software_instance.getAggregateValue()
partition_timestamp = str(int(float(partition.getModificationDate()) * 1e6))
partition_timestamp = int(float(partition.getModificationDate()) * 1e6)
self.assertEqual(timestamp, partition_timestamp)
instance_timestamp = str(int(software_instance.getBangTimestamp()))
instance_timestamp = int(software_instance.getBangTimestamp())
self.assertTrue(partition_timestamp > instance_timestamp,
"partition: %s < instance:%s" % (partition_timestamp, instance_timestamp))
......@@ -165,14 +165,14 @@ class TestSlapOSAllocationScenario(TestSlapOSAllocationScenarioMixin):
parameter_dict = software_instance._asParameterDict()
timestamp_after_bang = parameter_dict['timestamp']
self.assertTrue(int(timestamp_after_bang) > int(timestamp),
self.assertTrue(timestamp_after_bang > timestamp,
"after_bang: %s < before_bang:%s" % (timestamp_after_bang, timestamp))
self.assertEqual(partition_timestamp,
str(int(float(partition.getModificationDate()) * 1e6)))
int(float(partition.getModificationDate()) * 1e6))
instance_timestamp = str(int(software_instance.getBangTimestamp()))
self.assertTrue(int(partition_timestamp) < int(instance_timestamp),
instance_timestamp = int(software_instance.getBangTimestamp())
self.assertTrue(partition_timestamp < instance_timestamp,
"partition: %s > instance:%s" % (partition_timestamp, instance_timestamp))
self.assertEqual(timestamp_after_bang, instance_timestamp)
......@@ -184,10 +184,10 @@ class TestSlapOSAllocationScenario(TestSlapOSAllocationScenarioMixin):
timestamp = parameter_dict['timestamp']
self.assertNotEqual(timestamp,
str(int(software_instance.getBangTimestamp())))
int(software_instance.getBangTimestamp()))
self.assertEqual(str(int(float(partition.getModificationDate()) * 1e6)), timestamp)
self.assertTrue(int(timestamp_after_bang) < int(timestamp),
self.assertEqual(int(float(partition.getModificationDate()) * 1e6), timestamp)
self.assertTrue(timestamp_after_bang < timestamp,
"after_bang: %s > after_edit:%s" % (timestamp_after_bang, timestamp))
computer_information_dict = compute_node._getCacheComputeNodeInformation(None)
......@@ -246,7 +246,7 @@ class TestSlapOSAllocationScenario(TestSlapOSAllocationScenarioMixin):
if d['partition_id'] == partition_reference][0]
timestamp = partition_parameter_dict['_parameter_dict']['timestamp']
self.assertTrue(int(timestamp) > before_timestamp,
self.assertTrue(timestamp > before_timestamp,
"timestamp: %s < begin:%s" % (timestamp, before_timestamp))
self.login(owner_person.getUserId())
......@@ -282,11 +282,11 @@ class TestSlapOSAllocationScenario(TestSlapOSAllocationScenarioMixin):
if d['partition_id'] == partition_reference][0]
timestamp = partition_parameter_dict['_parameter_dict']['timestamp']
self.assertTrue(int(timestamp) > int(before_allocation_timestamp),
"timestamp: %s < begin:%s" % (timestamp, before_allocation_timestamp))
self.assertTrue(timestamp > before_allocation_timestamp,
"timestamp: %s < before_allocation_timestamp:%s" % (timestamp, before_allocation_timestamp))
self.assertTrue(int(timestamp) > int(before_allocation_instance_timestamp),
"timestamp: %s < begin:%s" % (timestamp, before_allocation_instance_timestamp))
self.assertTrue(timestamp > before_allocation_instance_timestamp,
"timestamp: %s < before_instance_allocation:%s" % (timestamp, before_allocation_instance_timestamp))
slave_instance = self.portal.portal_catalog.getResultValue(
portal_type='Slave Instance', title=slave_instance_title)
......@@ -294,17 +294,214 @@ class TestSlapOSAllocationScenario(TestSlapOSAllocationScenarioMixin):
# The slave instance was bang so that's why timestamp was updated,
# this ensure response to server is updated.
self.assertEqual(timestamp,
str(int(slave_instance.getBangTimestamp())))
int(slave_instance.getBangTimestamp()))
parameter_slave_list = partition_parameter_dict['_parameter_dict']['slave_instance_list']
self.assertEqual(len(parameter_slave_list), 1)
self.assertEqual(parameter_slave_list[0]['timestamp'], timestamp)
self.login(owner_person.getUserId())
self.checkSlaveInstanceUnallocation(owner_person.getUserId(),
self.checkSlaveInstanceUnallocation(
owner_person.getUserId(),
owner_person.getReference(), slave_instance_title,
slave_server_software, slave_instance_type, compute_node,
project.getReference())
self.tic()
computer_information_dict = compute_node._getCacheComputeNodeInformation(None)
# Ensure compute node gets the proper timestamp
partition_parameter_dict = [d
for d in computer_information_dict['_computer_partition_list']
if d['partition_id'] == partition_reference][0]
parameter_slave_list = partition_parameter_dict['_parameter_dict']['slave_instance_list']
self.assertEqual(len(parameter_slave_list), 0)
timestamp_before_unallocation = timestamp
timestamp = partition_parameter_dict['_parameter_dict']['timestamp']
self.assertNotEqual(timestamp_before_unallocation, timestamp)
self.assertTrue(timestamp > timestamp_before_unallocation,
"timestamp: %s < before_unallocation:%s" % (timestamp, timestamp_before_unallocation))
self.removeSoftwareReleaseFromComputer(owner_person,
compute_node, software_release)
self.checkERP5StateBeforeExit()
def test_stopped_slave_instance_allocation_scenario(self):
project, owner_person = self.bootstrapVirtualMasterTestWithProject()
self.logout()
# and install some software on them
software_release = self.generateNewSoftwareReleaseUrl()
software_type = 'public type'
compute_node = self.createComputeNodeForOwner(
computer_owner=owner_person,
project=project,
software_release=software_release,
software_type=software_type)
before_timestamp = int(float(DateTime()) * 1e6)
instance_title = 'Public title %s' % self.generateNewId()
self.checkInstanceAllocation(owner_person.getUserId(),
owner_person.getReference(), instance_title,
software_release, software_type,
compute_node, project.getReference())
self.login(owner_person.getUserId())
# let's find instances of user and check connection strings
partition_reference = [q.getSuccessorValue().getAggregateReference() for q in
self._getCurrentInstanceTreeList()
if q.getTitle() == instance_title][0]
computer_information_dict = compute_node._getCacheComputeNodeInformation(None)
# Ensure compute node gets the proper timestamp
partition_parameter_dict = [d
for d in computer_information_dict['_computer_partition_list']
if d['partition_id'] == partition_reference][0]
timestamp = partition_parameter_dict['_parameter_dict']['timestamp']
self.assertTrue(timestamp > before_timestamp,
"timestamp: %s < begin:%s" % (timestamp, before_timestamp))
self.login(owner_person.getUserId())
instance_node_title = 'Shared Instance for %s' % owner_person.getReference()
# 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=instance_title)
before_allocation_instance_timestamp = software_instance.getBangTimestamp()
instance_node = self.addInstanceNode(instance_node_title, software_instance)
slave_server_software = self.generateNewSoftwareReleaseUrl()
slave_instance_type = 'slave type'
software_product, slave_software_release, software_type = self.addSoftwareProduct(
'share product', project, slave_server_software, slave_instance_type
)
self.addAllocationSupply("for instance node", instance_node,
software_product, slave_software_release, software_type)
slave_instance_title = 'Slave title %s' % self.generateNewId()
self.checkSlaveInstanceAllocation(owner_person.getUserId(),
owner_person.getReference(), slave_instance_title,
slave_server_software, slave_instance_type,
compute_node, project.getReference())
self.login(owner_person.getUserId())
before_allocation_timestamp = timestamp
computer_information_dict = compute_node._getCacheComputeNodeInformation(None)
# Ensure compute node gets the proper timestamp
partition_parameter_dict = [d
for d in computer_information_dict['_computer_partition_list']
if d['partition_id'] == partition_reference][0]
timestamp = partition_parameter_dict['_parameter_dict']['timestamp']
self.assertTrue(timestamp > before_allocation_timestamp,
"timestamp: %s < before_allocation_timestamp:%s" % (timestamp, before_allocation_timestamp))
self.assertTrue(timestamp > before_allocation_instance_timestamp,
"timestamp: %s < before_instance_allocation:%s" % (timestamp, before_allocation_instance_timestamp))
slave_instance = self.portal.portal_catalog.getResultValue(
portal_type='Slave Instance', title=slave_instance_title)
# The slave instance was bang so that's why timestamp was updated,
# this ensure response to server is updated.
self.assertEqual(timestamp,
int(slave_instance.getBangTimestamp()))
parameter_slave_list = partition_parameter_dict['_parameter_dict']['slave_instance_list']
self.assertEqual(len(parameter_slave_list), 1)
self.assertEqual(parameter_slave_list[0]['timestamp'], timestamp)
self.login(owner_person.getUserId())
self.personRequestInstance(
software_release=slave_server_software,
software_type=slave_instance_type,
partition_reference=slave_instance_title,
shared_xml='<marshal><bool>1</bool></marshal>',
state='<marshal><string>stopped</string></marshal>',
project_reference=project.getReference()
)
self.simulateSlapgridCP(compute_node)
self.tic()
self.assertEqual(slave_instance.getSlapState(), 'stop_requested')
before_stop_timestamp = timestamp
computer_information_dict = compute_node._getCacheComputeNodeInformation(None)
# Ensure compute node gets the proper timestamp
partition_parameter_dict = [d
for d in computer_information_dict['_computer_partition_list']
if d['partition_id'] == partition_reference][0]
timestamp = partition_parameter_dict['_parameter_dict']['timestamp']
self.assertTrue(timestamp > before_stop_timestamp,
"timestamp: %s < before_stop_timestamp:%s" % (timestamp, before_stop_timestamp))
self.assertEqual(timestamp,
int(software_instance.getBangTimestamp()))
# no entry expected
parameter_slave_list = partition_parameter_dict['_parameter_dict']['slave_instance_list']
self.assertEqual(len(parameter_slave_list), 0)
# Start again and re-check if the timestamp was updated
self.login(owner_person.getUserId())
self.personRequestInstance(
software_release=slave_server_software,
software_type=slave_instance_type,
partition_reference=slave_instance_title,
shared_xml='<marshal><bool>1</bool></marshal>',
state='<marshal><string>started</string></marshal>',
project_reference=project.getReference()
)
self.simulateSlapgridCP(compute_node)
self.tic()
before_start_timestamp = timestamp
computer_information_dict = compute_node._getCacheComputeNodeInformation(None)
# Ensure compute node gets the proper timestamp
partition_parameter_dict = [d
for d in computer_information_dict['_computer_partition_list']
if d['partition_id'] == partition_reference][0]
timestamp = partition_parameter_dict['_parameter_dict']['timestamp']
self.assertTrue(timestamp > before_start_timestamp,
"timestamp: %s < before_start_timestamp:%s" % (timestamp, before_start_timestamp))
# The slave instance was bang so that's why timestamp was updated,
# this ensure response to server is updated.
self.assertEqual(timestamp,
int(slave_instance.getBangTimestamp()))
parameter_slave_list = partition_parameter_dict['_parameter_dict']['slave_instance_list']
self.assertEqual(len(parameter_slave_list), 1)
self.assertEqual(parameter_slave_list[0]['timestamp'], timestamp)
self.login(owner_person.getUserId())
self.checkSlaveInstanceUnallocation(
owner_person.getUserId(),
owner_person.getReference(), slave_instance_title,
slave_server_software, slave_instance_type, compute_node,
project.getReference())
self.tic()
computer_information_dict = compute_node._getCacheComputeNodeInformation(None)
# Ensure compute node gets the proper timestamp
partition_parameter_dict = [d
for d in computer_information_dict['_computer_partition_list']
if d['partition_id'] == partition_reference][0]
parameter_slave_list = partition_parameter_dict['_parameter_dict']['slave_instance_list']
self.assertEqual(len(parameter_slave_list), 0)
timestamp_before_unallocation = timestamp
timestamp = partition_parameter_dict['_parameter_dict']['timestamp']
self.assertNotEqual(timestamp_before_unallocation, timestamp)
self.assertTrue(timestamp > timestamp_before_unallocation,
"timestamp: %s < before_unallocation:%s" % (timestamp, timestamp_before_unallocation))
self.removeSoftwareReleaseFromComputer(owner_person,
compute_node, software_release)
......
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