Skip to content

Commit

Permalink
Add globbing. More refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-a-abramov committed Apr 10, 2019
1 parent 35d7430 commit 2b8da76
Show file tree
Hide file tree
Showing 19 changed files with 411 additions and 143 deletions.
382 changes: 244 additions & 138 deletions salt/utils/saltclass.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
classes:
- L0.D.Y.B
- L0.D.Y.A.*
- L0.D.Y.C.C
- L0.D.Y.D.D1

pillars:
X: X

states:
- X

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pillars:
X-init: X-init

states:
- X-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pillars:
A1: A1

states:
- A11
- A12
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pillars:
A2: A2

states:
- A2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pillars:
A3: A3

states:
- A31
- A32
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pillars:
absent: absent

states:
- absent
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
classes:
- .

pillars:
B1: B1

states:
- B1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pillars:
B2: B2

states:
- B2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pillars:
B3: B3

states:
- B3
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
classes:
- .*

pillars:
B-init: B-init

states:
- B-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
classes:
- .C1

pillars:
C: C

states:
- C
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
classes:
- .C2

pillars:
C1: C1

states:
- C1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pillars:
C2: C2

states:
- C2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pillars:
C3: absent

states:
- absent
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
classes:
- .

pillars:
D1: D1

states:
- D1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
classes:
- .

pillars:
D-init: D-init

states:
- D-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
classes:
- L0.D.X.*

environment: base
61 changes: 56 additions & 5 deletions tests/unit/pillar/test_saltclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
fake_minion_id3 = 'fake_id3'
fake_minion_id4 = 'fake_id4'
fake_minion_id5 = 'fake_id5'

fake_minion_id6 = 'fake_id6'

fake_pillar = {}
fake_args = ({'path': os.path.abspath(
os.path.join(base_path, '..', '..', 'integration',
'files', 'saltclass', 'examples-new'))})
os.path.join(base_path, '..', '..', 'integration',
'files', 'saltclass', 'examples-new'))})
fake_opts = {}
fake_salt = {}
fake_grains = {}
Expand All @@ -33,7 +33,8 @@
@skipIf(NO_MOCK, NO_MOCK_REASON)
class SaltclassTestCase(TestCase, LoaderModuleMockMixin):
'''
New tests for salt.pillar.saltclass
Tests for salt.pillar.saltclass
TODO: change node and class names in mocks to make them more readable - all these A, B, C, X, L0 are unreadable
'''

def setup_loader_modules(self):
Expand Down Expand Up @@ -156,9 +157,59 @@ def test_nonsaltclass_pillars(self):
}
result = saltclass.ext_pillar(fake_minion_id4, nonsaltclass_pillars, fake_args)
filtered_result = {}
for key in expected_result.keys():
for key in expected_result:
filtered_result[key] = result.get(key)
self.assertDictEqual(filtered_result, expected_result)

def test_fail(self):
self.assertRaises(SaltException, saltclass.ext_pillar, fake_minion_id5, {}, fake_args)

def test_globbing(self):
result = saltclass.ext_pillar(fake_minion_id6, {}, fake_args)
expected_result = {'A1': 'A1',
'A2': 'A2',
'A3': 'A3',
'B-init': 'B-init',
'B1': 'B1',
'B2': 'B2',
'B3': 'B3',
'C': 'C',
'C1': 'C1',
'C2': 'C2',
'D-init': 'D-init',
'D1': 'D1',
'X': 'X',
'X-init': 'X-init',
'__saltclass__': {'classes': ['L0.D.X',
'L0.D.X.X',
'L0.D.Y.B',
'L0.D.Y.B.B1',
'L0.D.Y.B.B2',
'L0.D.Y.B.B3',
'L0.D.Y.A.A1',
'L0.D.Y.A.A2',
'L0.D.Y.A.A3',
'L0.D.Y.C.C',
'L0.D.Y.C.C1',
'L0.D.Y.C.C2',
'L0.D.Y.D.D1',
'L0.D.Y.D'],
'environment': 'base',
'nodename': 'fake_id6',
'states': ['X-init',
'X',
'B-init',
'B1',
'B2',
'B3',
'A11',
'A12',
'A2',
'A31',
'A32',
'C',
'C1',
'C2',
'D1',
'D-init']}}
self.assertDictEqual(result, expected_result)

0 comments on commit 2b8da76

Please sign in to comment.