Beispiel #1
0
 def test_resolve_2_command_substitutions(self):
     '''Test 2 command substitutions'''
     service = BaseEntity('test_service')
     service.add_var('EXCLUDED_NODES', 'foo')
     service.add_var('SELECTED_NODES', 'bar')
     expr = '%([ -n "%SELECTED_NODES" ] && echo "-n %SELECTED_NODES")' + \
           ' %([ -n "%EXCLUDED_NODES" ] && echo "-x %EXCLUDED_NODES")'
     self.assertEqual(service._resolve(expr), '-n bar -x foo')
Beispiel #2
0
 def test_resolve_2_command_substitutions(self):
     '''Test 2 command substitutions'''
     service = BaseEntity('test_service')
     service.add_var('EXCLUDED_NODES', 'foo')
     service.add_var('SELECTED_NODES', 'bar')
     expr = '%([ -n "%SELECTED_NODES" ] && echo "-n %SELECTED_NODES")' + \
           ' %([ -n "%EXCLUDED_NODES" ] && echo "-x %EXCLUDED_NODES")'
     self.assertEqual(service._resolve(expr), '-n bar -x foo')
Beispiel #3
0
 def test_resolve_value2(self):
     '''Test replacement of variable referenced in the entity'''
     service = BaseEntity('test_service')
     service.add_var('NODES', 'localhost,127.0.0.1')
     self.assertEqual(service._resolve('%NODES'), 'localhost,127.0.0.1')
Beispiel #4
0
 def test_resolve_recurse(self):
     '''Test recursive variable resolution'''
     service = BaseEntity('test_service')
     service.add_var('foo', 'key')
     service.add_var('bar', 'Keep my %foo')
     self.assertEqual(service._resolve('%bar'), 'Keep my key')
Beispiel #5
0
 def test_resolve_2_variables(self):
     '''Test resolution with two adjacent variables'''
     service = BaseEntity('test_service')
     service.add_var('FOO', 'foo')
     service.add_var('BAR', 'bar')
     self.assertEqual(service._resolve('%FOO%BAR'), 'foobar')
Beispiel #6
0
 def test_resolve_double_exec(self):
     """Test resolution of 2 successive expressions."""
     service = BaseEntity('base')
     self.assertEqual(service._resolve('%(echo foo) %(echo bar)'), 'foo bar')
Beispiel #7
0
 def test_resolve_value6(self):
     '''Test resolution of variable inside an expression'''
     service = BaseEntity('test_service')
     self.assertEqual(service._resolve('%(echo %NAME)'),
                      'test_service')
Beispiel #8
0
 def test_resolve_value4(self):
     '''Test resolution of an expression'''
     service = BaseEntity('test_service')
     self.assertEqual(service._resolve('%(echo hello world)'),
                      'hello world')
Beispiel #9
0
 def test_resolve_property4(self):
     '''Command substitution with a non-zero exit code should be ok'''
     service = BaseEntity('test_service')
     service.add_var('NODES', '%(/bin/false)')
     self.assertEqual(service._resolve('%NODES'), '')
Beispiel #10
0
 def test_resolve_double_exec(self):
     """Test resolution of 2 successive expressions."""
     service = BaseEntity('base')
     self.assertEqual(service._resolve('%(echo foo) %(echo bar)'),
                      'foo bar')
Beispiel #11
0
 def test_resolve_value7(self):
     '''Test resolution of variable inside an expression (2)'''
     service = BaseEntity('test_service')
     service.add_var('CMD', 'echo')
     self.assertEqual(service._resolve('%(%CMD foo)'), 'foo')
Beispiel #12
0
 def test_resolve_value6(self):
     '''Test resolution of variable inside an expression'''
     service = BaseEntity('test_service')
     self.assertEqual(service._resolve('%(echo %NAME)'), 'test_service')
Beispiel #13
0
 def test_resolve_value5(self):
     '''Test combining resolution of variables and expressions'''
     service = BaseEntity('test_service')
     service.add_var('NODES', 'localhost,127.0.0.1')
     self.assertEqual(service._resolve('%NODES %(echo hello world) %NAME'),
                      'localhost,127.0.0.1 hello world test_service')
Beispiel #14
0
 def test_resolve_value4(self):
     '''Test resolution of an expression'''
     service = BaseEntity('test_service')
     self.assertEqual(service._resolve('%(echo hello world)'),
                      'hello world')
Beispiel #15
0
 def test_resolve_value3(self):
     '''Test multiple variable replacements'''
     service = BaseEntity('test_service')
     service.add_var('NODES', 'localhost,127.0.0.1')
     self.assertEqual(service._resolve('%NODES %NAME'),
                      'localhost,127.0.0.1 test_service')
Beispiel #16
0
 def test_resolve_value2(self):
     '''Test replacement of variable referenced in the entity'''
     service = BaseEntity('test_service')
     service.add_var('NODES', 'localhost,127.0.0.1')
     self.assertEqual(service._resolve('%NODES'), 'localhost,127.0.0.1')
Beispiel #17
0
 def test_resolve_value3(self):
     '''Test multiple variable replacements'''
     service = BaseEntity('test_service')
     service.add_var('NODES', 'localhost,127.0.0.1')
     self.assertEqual(service._resolve('%NODES %NAME'),
                      'localhost,127.0.0.1 test_service')
Beispiel #18
0
 def test_resolve_2_variables(self):
     '''Test resolution with two adjacent variables'''
     service = BaseEntity('test_service')
     service.add_var('FOO', 'foo')
     service.add_var('BAR', 'bar')
     self.assertEqual(service._resolve('%FOO%BAR'), 'foobar')
Beispiel #19
0
 def test_resolve_value5(self):
     '''Test combining resolution of variables and expressions'''
     service = BaseEntity('test_service')
     service.add_var('NODES', 'localhost,127.0.0.1')
     self.assertEqual(service._resolve('%NODES %(echo hello world) %NAME'),
                      'localhost,127.0.0.1 hello world test_service')
Beispiel #20
0
 def test_resolve_escape_char(self):
     '''Test resolution with a variable escaping %'''
     service = BaseEntity('test_service')
     service.add_var('FOO', 'Keep my %%noeval!')
     self.assertEqual(service._resolve('%FOO'), 'Keep my %noeval!')
Beispiel #21
0
 def test_resolve_value7(self):
     '''Test resolution of variable inside an expression (2)'''
     service = BaseEntity('test_service')
     service.add_var('CMD', 'echo')
     self.assertEqual(service._resolve('%(%CMD foo)'), 'foo')
Beispiel #22
0
 def test_resolve_recurse(self):
     '''Test recursive variable resolution'''
     service = BaseEntity('test_service')
     service.add_var('foo', 'key')
     service.add_var('bar', 'Keep my %foo')
     self.assertEqual(service._resolve('%bar'), 'Keep my key')
Beispiel #23
0
 def test_resolve_property4(self):
     '''Command substitution with a non-zero exit code should be ok'''
     service = BaseEntity('test_service')
     service.add_var('NODES', '%(/bin/false)')
     self.assertEqual(service._resolve('%NODES'), '')
Beispiel #24
0
 def test_resolve_command_substitution(self):
     '''Test command substitution'''
     service = BaseEntity('test_service')
     service.add_var('EXCLUDED_NODES', 'foo')
     expr = '%([ -n "%EXCLUDED_NODES" ] && echo "-n %EXCLUDED_NODES")'
     self.assertEqual(service._resolve(expr), '-n foo')
Beispiel #25
0
 def test_resolve_escape_char(self):
     '''Test resolution with a variable escaping %'''
     service = BaseEntity('test_service')
     service.add_var('FOO', 'Keep my %%noeval!')
     self.assertEqual(service._resolve('%FOO'), 'Keep my %noeval!')
Beispiel #26
0
 def test_resolve_list_value(self):
     """resolve a variable with a non-string value (list)"""
     service = BaseEntity('test_service')
     service.add_var('list', ['a', 'b'])
     self.assertEqual(service._resolve("%list"), ['a', 'b'])
Beispiel #27
0
 def test_resolve_command_substitution(self):
     '''Test command substitution'''
     service = BaseEntity('test_service')
     service.add_var('EXCLUDED_NODES', 'foo')
     expr = '%([ -n "%EXCLUDED_NODES" ] && echo "-n %EXCLUDED_NODES")'
     self.assertEqual(service._resolve(expr), '-n foo')
Beispiel #28
0
 def test_resolve_value1(self):
     '''Test no replacement to do so just return the initial value'''
     service = BaseEntity('test_service')
     self.assertEqual(service._resolve('hello world'), 'hello world')
Beispiel #29
0
 def test_resolve_list_value(self):
     """resolve a variable with a non-string value (list)"""
     service = BaseEntity('test_service')
     service.add_var('list', ['a', 'b'])
     self.assertEqual(service._resolve("%list"), ['a', 'b'])
Beispiel #30
0
 def test_resolve_value1(self):
     '''Test no replacement to do so just return the initial value'''
     service = BaseEntity('test_service')
     self.assertEqual(service._resolve('hello world'), 'hello world')