Allow to load only some resources

- adding option to load only resources which starts with a given string.

It will allow to load in examples already created node resources.

Change-Id: Iaae9ba4e837d588ee6b806ed035e0ac763a9f1fc
Related-bug: #1537176
Related-bug: #1533609
This commit is contained in:
Łukasz Oleś 2016-02-01 11:10:06 +01:00
parent 2164e76012
commit 33d2bc3b9c
2 changed files with 27 additions and 2 deletions

View File

@ -348,8 +348,13 @@ def load_updated(since=None, with_childs=True):
# TODO
def load_all():
candids = DBResource.updated.filter(StrInt.p_min(), StrInt.p_max())
def load_all(startswith=None):
if startswith:
start = startswith
end = startswith + '~'
candids = DBResource.bucket.get_index("$key", start, end).results
else:
candids = DBResource.updated.filter(StrInt.p_min(), StrInt.p_max())
return [Resource(r) for r in DBResource.multi_get(candids)]

View File

@ -166,3 +166,23 @@ input:
with self.assertRaises(Exception): # NOQA
sample1.input_computable_change('value', '{{value}}')
return sample1
def test_load_all(self):
sample_meta_dir = self.make_resource_meta("""
id: sample
handler: ansible
version: 1.0.0
input:
value:
schema: int
value: 0
""")
self.create_resource('sample1', sample_meta_dir, {'value': 1})
self.create_resource('sample2', sample_meta_dir, {'value': 1})
self.create_resource('x_sample1', sample_meta_dir, {'value': 1})
assert len(resource.load_all()) == 3
assert len(resource.load_all(startswith='sample')) == 2
assert len(resource.load_all(startswith='x_sample')) == 1
assert len(resource.load_all(startswith='nothing')) == 0