Commit 4ed72fcc authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

wip: TestSlapgridUsageReport tests are passing

parent 21fdbbc4
...@@ -478,6 +478,12 @@ class ComputerForTest(object): ...@@ -478,6 +478,12 @@ class ComputerForTest(object):
"portal_type": "Software Instance", "portal_type": "Software Instance",
"success": "Done" "success": "Done"
}, indent=2) }, indent=2)
if "requested_instance_list" in content:
return json.dumps({
"reference": requested_instance.name,
"portal_type": "Software Instance",
"success": "Done"
}, indent=2)
else: else:
return json.dumps({ return json.dumps({
"status": "404", "status": "404",
...@@ -2024,6 +2030,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase): ...@@ -2024,6 +2030,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
computer.sequence = [] computer.sequence = []
instance.requested_state = 'destroyed' instance.requested_state = 'destroyed'
self.grid.computer_partition_list = None
self.assertEqual(self.grid.agregateAndSendUsage(), slapgrid.SLAPGRID_SUCCESS) self.assertEqual(self.grid.agregateAndSendUsage(), slapgrid.SLAPGRID_SUCCESS)
# Assert partition directory is empty # Assert partition directory is empty
self.assertInstanceDirectoryListEqual(['0']) self.assertInstanceDirectoryListEqual(['0'])
...@@ -2068,26 +2075,24 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase): ...@@ -2068,26 +2075,24 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
# Then run usage report and see if it is still working # Then run usage report and see if it is still working
computer.sequence = [] computer.sequence = []
self.grid.computer_partition_list = None
self.assertEqual(self.grid.agregateAndSendUsage(), slapgrid.SLAPGRID_SUCCESS) self.assertEqual(self.grid.agregateAndSendUsage(), slapgrid.SLAPGRID_SUCCESS)
# registerComputerPartition will create one more file:
from slapos.slap.slap import COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
request_list_file = COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME % instance.name
self.assertInstanceDirectoryListEqual(['0']) self.assertInstanceDirectoryListEqual(['0'])
six.assertCountEqual(self, os.listdir(instance.partition_path), six.assertCountEqual(self, os.listdir(instance.partition_path),
['.slapgrid', '.0_wrapper.log', 'buildout.cfg', ['.slapgrid', '.0_wrapper.log', 'buildout.cfg',
'etc', 'software_release', 'worked', 'etc', 'software_release', 'worked',
'.slapos-retention-lock-delay', request_list_file]) '.slapos-retention-lock-delay'])
wrapper_log = os.path.join(instance.partition_path, '.0_wrapper.log') wrapper_log = os.path.join(instance.partition_path, '.0_wrapper.log')
self.assertLogContent(wrapper_log, 'Working') self.assertLogContent(wrapper_log, 'Working')
self.assertInstanceDirectoryListEqual(['0']) self.assertInstanceDirectoryListEqual(['0'])
six.assertCountEqual(self, os.listdir(instance.partition_path), six.assertCountEqual(self, os.listdir(instance.partition_path),
['.slapgrid', '.0_wrapper.log', 'buildout.cfg', ['.slapgrid', '.0_wrapper.log', 'buildout.cfg',
'etc', 'software_release', 'worked', 'etc', 'software_release', 'worked',
'.slapos-retention-lock-delay', request_list_file]) '.slapos-retention-lock-delay'])
wrapper_log = os.path.join(instance.partition_path, '.0_wrapper.log') wrapper_log = os.path.join(instance.partition_path, '.0_wrapper.log')
self.assertLogContent(wrapper_log, 'Working') self.assertLogContent(wrapper_log, 'Working')
self.assertEqual(computer.sequence, self.assertEqual(computer.sequence,
['/api/allDocs']) ['/api/allDocs/'])
self.assertEqual('started', instance.state) self.assertEqual('started', instance.state)
def test_slapgrid_instance_ignore_free_instance(self): def test_slapgrid_instance_ignore_free_instance(self):
...@@ -2107,7 +2112,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase): ...@@ -2107,7 +2112,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self.assertInstanceDirectoryListEqual(['0']) self.assertInstanceDirectoryListEqual(['0'])
six.assertCountEqual(self, os.listdir(instance.partition_path), []) six.assertCountEqual(self, os.listdir(instance.partition_path), [])
six.assertCountEqual(self, os.listdir(self.software_root), [instance.software.software_hash]) six.assertCountEqual(self, os.listdir(self.software_root), [instance.software.software_hash])
self.assertEqual(computer.sequence, ['/getFullComputerInformation']) self.assertEqual(computer.sequence, ['/api/allDocs/'])
def test_slapgrid_report_ignore_free_instance(self): def test_slapgrid_report_ignore_free_instance(self):
""" """
...@@ -2126,7 +2131,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase): ...@@ -2126,7 +2131,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self.assertInstanceDirectoryListEqual(['0']) self.assertInstanceDirectoryListEqual(['0'])
six.assertCountEqual(self, os.listdir(instance.partition_path), []) six.assertCountEqual(self, os.listdir(instance.partition_path), [])
six.assertCountEqual(self, os.listdir(self.software_root), [instance.software.software_hash]) six.assertCountEqual(self, os.listdir(self.software_root), [instance.software.software_hash])
self.assertEqual(computer.sequence, ['/getFullComputerInformation']) self.assertEqual(computer.sequence, ['/api/allDocs/'])
class TestSlapgridSoftwareReleaseSlapTool(SlapToolMasterMixin, unittest.TestCase): class TestSlapgridSoftwareReleaseSlapTool(SlapToolMasterMixin, unittest.TestCase):
......
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