Commit 421c8876 authored by Marco Mariani's avatar Marco Mariani

'slapos node instance' reports unknown partitions

parent f469ae7d
...@@ -228,6 +228,13 @@ def create_slapgrid_object(options, logger): ...@@ -228,6 +228,13 @@ def create_slapgrid_object(options, logger):
computer_partition_filter_list=op.get('only-cp', op.get('only_cp'))) computer_partition_filter_list=op.get('only-cp', op.get('only_cp')))
def check_required_only_partitions(existing, required):
missing = set(required) - set(existing)
if missing:
plural = ['s', ''][len(missing)==1]
raise ValueError('Unknown partition%s: %s' % (plural, ', '.join(sorted(missing))))
class Slapgrid(object): class Slapgrid(object):
""" Main class for SlapGrid. Fetches and processes informations from master """ Main class for SlapGrid. Fetches and processes informations from master
server and pushes usage information to master server. server and pushes usage information to master server.
...@@ -737,6 +744,9 @@ class Slapgrid(object): ...@@ -737,6 +744,9 @@ class Slapgrid(object):
# Boolean to know if every promises correctly passed # Boolean to know if every promises correctly passed
clean_run_promise = True clean_run_promise = True
check_required_only_partitions([cp.getId() for cp in self.getComputerPartitionList()],
self.computer_partition_filter_list)
# Filter all dummy / empty partitions # Filter all dummy / empty partitions
computer_partition_list = self.FilterComputerPartitionList( computer_partition_list = self.FilterComputerPartitionList(
self.getComputerPartitionList()) self.getComputerPartitionList())
......
...@@ -153,6 +153,29 @@ class BasicMixin: ...@@ -153,6 +153,29 @@ class BasicMixin:
shutil.rmtree(self._tempdir, True) shutil.rmtree(self._tempdir, True)
class TestRequiredOnlyPartitions(unittest2.TestCase):
def test_no_errors(self):
required = ['one', 'three']
existing = ['one', 'two', 'three']
slapgrid.check_required_only_partitions(existing, required)
def test_one_missing(self):
required = ['foobar', 'two', 'one']
existing = ['one', 'two', 'three']
self.assertRaisesRegexp(ValueError,
'Unknown partition: foobar',
slapgrid.check_required_only_partitions,
existing, required)
def test_several_missing(self):
required = ['foobar', 'barbaz']
existing = ['one', 'two', 'three']
self.assertRaisesRegexp(ValueError,
'Unknown partitions: barbaz, foobar',
slapgrid.check_required_only_partitions,
existing, required)
class TestBasicSlapgridCP(BasicMixin, unittest2.TestCase): class TestBasicSlapgridCP(BasicMixin, unittest2.TestCase):
def test_no_software_root(self): def test_no_software_root(self):
self.assertRaises(OSError, self.grid.processComputerPartitionList) self.assertRaises(OSError, self.grid.processComputerPartitionList)
......
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