Esempio n. 1
0
 def test_resolve_property5(self):
     '''Test resolution with a property containing special characters'''
     service = BaseEntity('test_service')
     service.add_var('NODES', HOSTNAME)
     service.target = '%NODES'
     self.assertEqual(service.resolve_property('target'),
         NodeSet(HOSTNAME))
Esempio n. 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')
Esempio n. 3
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')
Esempio n. 4
0
 def test_lookup_variables3(self):
     '''Test variables resolution with an undefined var'''
     service = BaseEntity('test_service')
     service.add_var('VAR', 'test')
     group = BaseEntity('group_service')
     group.add_var('GVAR', 'group')
     service.parent = group
     self.assertRaises(UndefinedVariableError,
                       service._lookup_variable, 'BAD_VAR')
Esempio n. 5
0
 def test_lookup_variables2(self):
     '''Test variables resolution through multiple entities'''
     service = BaseEntity('test_service')
     service.add_var('VAR', 'test')
     group = BaseEntity('group_service')
     group.add_var('GVAR', 'group')
     service.parent = group
     self.assertEqual(service._lookup_variable('VAR'), 'test')
     self.assertEqual(service._lookup_variable('GVAR'), 'group')
Esempio n. 6
0
 def test_lookup_variables3(self):
     '''Test variables resolution with an undefined var'''
     service = BaseEntity('test_service')
     service.add_var('VAR', 'test')
     group = BaseEntity('group_service')
     group.add_var('GVAR', 'group')
     service.parent = group
     self.assertRaises(UndefinedVariableError, service._lookup_variable,
                       'BAD_VAR')
Esempio n. 7
0
 def test_lookup_variables2(self):
     '''Test variables resolution through multiple entities'''
     service = BaseEntity('test_service')
     service.add_var('VAR', 'test')
     group = BaseEntity('group_service')
     group.add_var('GVAR', 'group')
     service.parent = group
     self.assertEqual(service._lookup_variable('VAR'), 'test')
     self.assertEqual(service._lookup_variable('GVAR'), 'group')
Esempio n. 8
0
 def test_lookup_variables4(self):
     '''Test variables resolution with a var referencing a property'''
     service = BaseEntity('test_service')
     service.add_var('VAR', 'test')
     group = BaseEntity('group_service')
     group.add_var('GVAR', 'group')
     service.parent = group
     self.assertEqual(service._lookup_variable('GVAR'), 'group')
     self.assertEqual(service._lookup_variable('TARGET'), None)
     self.assertEqual(service._lookup_variable('NAME'), 'test_service')
Esempio n. 9
0
 def test_lookup_variables4(self):
     '''Test variables resolution with a var referencing a property'''
     service = BaseEntity('test_service')
     service.add_var('VAR', 'test')
     group = BaseEntity('group_service')
     group.add_var('GVAR', 'group')
     service.parent = group
     self.assertEqual(service._lookup_variable('GVAR'), 'group')
     self.assertEqual(service._lookup_variable('TARGET'), None)
     self.assertEqual(service._lookup_variable('NAME'), 'test_service')
Esempio n. 10
0
 def test_resolve_property1(self):
     '''Test replacement of symbols within a property'''
     service = BaseEntity('test_service')
     service.add_var('NODES', 'localhost,127.0.0.1')
     service.desc = 'start %NAME on %TARGET'
     service.target = '%NODES'
     self.assertEqual(service.resolve_property('target'),
                      NodeSet('localhost,127.0.0.1'))
     self.assertEqual(service.resolve_property('name'), 'test_service')
     self.assertEqual(service.resolve_property('desc'),
                      'start test_service on 127.0.0.1,localhost')
Esempio n. 11
0
 def test_resolve_all_variables(self):
     """resolve_all() resolves variables only once"""
     entity = BaseEntity('entity')
     entity.add_var('foo', 'cool')
     entity.add_var('bar', '%foo')
     entity.add_var('baz', '%foo')
     entity.fromdict({'desc': 'New %bar'})
     entity.resolve_all()
     self.assertEqual(entity.variables['foo'], entity.variables['bar'])
     self.assertEqual(entity.variables['foo'], entity.variables['baz'])
     self.assertEqual(entity.desc, 'New cool')
Esempio n. 12
0
 def test_resolve_all_variables(self):
     """resolve_all() resolves variables only once"""
     entity = BaseEntity('entity')
     entity.add_var('foo', 'cool')
     entity.add_var('bar', '%foo')
     entity.add_var('baz', '%foo')
     entity.fromdict({'desc': 'New %bar'})
     entity.resolve_all()
     self.assertEqual(entity.variables['foo'], entity.variables['bar'])
     self.assertEqual(entity.variables['foo'], entity.variables['baz'])
     self.assertEqual(entity.desc, 'New cool')
Esempio n. 13
0
 def test_resolve_property1(self):
     '''Test replacement of symbols within a property'''
     service = BaseEntity('test_service')
     service.add_var('NODES', 'localhost,127.0.0.1')
     service.desc = 'start %NAME on %TARGET'
     service.target = '%NODES'
     self.assertEqual(service.resolve_property('target'),
         NodeSet('localhost,127.0.0.1'))
     self.assertEqual(service.resolve_property('name'),
         'test_service')
     self.assertEqual(service.resolve_property('desc'),
         'start test_service on 127.0.0.1,localhost')
Esempio n. 14
0
    def test_remove_variable(self):
        '''Remove a variable, defined or not, is fine.'''
        svc = BaseEntity('test_var')
        svc.add_var('var', 'foo')
        self.assertEqual(svc._lookup_variable('var'), 'foo')

        # Remove it
        svc.remove_var('var')
        self.assertRaises(UndefinedVariableError, svc._lookup_variable, 'var')

        # Remove it again does not raise an exception.
        svc.remove_var('var')
        self.assertRaises(UndefinedVariableError, svc._lookup_variable, 'var')
Esempio n. 15
0
    def test_remove_variable(self):
        '''Remove a variable, defined or not, is fine.'''
        svc = BaseEntity('test_var')
        svc.add_var('var', 'foo')
        self.assertEqual(svc._lookup_variable('var'), 'foo')

        # Remove it
        svc.remove_var('var')
        self.assertRaises(UndefinedVariableError, svc._lookup_variable, 'var')

        # Remove it again does not raise an exception.
        svc.remove_var('var')
        self.assertRaises(UndefinedVariableError, svc._lookup_variable, 'var')
Esempio n. 16
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')
Esempio n. 17
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')
Esempio n. 18
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')
Esempio n. 19
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')
Esempio n. 20
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')
Esempio n. 21
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')
Esempio n. 22
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!')
Esempio n. 23
0
 def test_lookup_variables1(self):
     '''Test variables resolution through a single entity'''
     service = BaseEntity('test_service')
     service.add_var('VAR', 'test')
     self.assertEqual(service._lookup_variable('VAR'), 'test')
Esempio n. 24
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')
Esempio n. 25
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')
Esempio n. 26
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'), '')
Esempio n. 27
0
 def test_resolve_property5(self):
     '''Test resolution with a property containing special characters'''
     service = BaseEntity('test_service')
     service.add_var('NODES', HOSTNAME)
     service.target = '%NODES'
     self.assertEqual(service.resolve_property('target'), NodeSet(HOSTNAME))
Esempio n. 28
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'), '')
Esempio n. 29
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')
Esempio n. 30
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')
Esempio n. 31
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')
Esempio n. 32
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')
Esempio n. 33
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')
Esempio n. 34
0
 def test_lookup_variables1(self):
     '''Test variables resolution through a single entity'''
     service = BaseEntity('test_service')
     service.add_var('VAR', 'test')
     self.assertEqual(service._lookup_variable('VAR'), 'test')
Esempio n. 35
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!')
Esempio n. 36
0
 def test_resolve_all(self):
     """resolve_all() resolves all BaseEntity properties"""
     entity = BaseEntity('entity')
     entity.add_var('TGT', 'localhost')
     entity.add_var('NBR1', 1)
     entity.add_var('NBR2', 2)
     entity.add_var('NBR3', 3)
     entity.add_var('NBR4', 4)
     entity.add_var('NBR5', 5)
     entity.add_var('NBR6', 6)
     entity.add_var('KEYWORD', 'delegate')
     entity.add_var('TXT', 'I am the entity')
     entity.fromdict({
         'target': "%TGT",
         'timeout': "%NBR1",
         'retry': "%NBR2",
         'fanout': "%NBR3",
         'delay': "%NBR4",
         'warnings': "%NBR5",
         'errors': "%NBR6",
         'desc': "%TXT",
         'mode': "%KEYWORD"
     })
     entity.resolve_all()
     self.assertEqual(entity.desc, "I am the entity")
     self.assertEqual(entity.target, NodeSet('localhost'))
     self.assertEqual(entity.timeout, 1)
     self.assertEqual(entity.maxretry, 2)
     self.assertEqual(entity.fanout, 3)
     self.assertEqual(entity.delay, 4)
     self.assertEqual(entity.errors, 6)
     self.assertEqual(entity.warnings, 5)
     self.assertEqual(entity.mode, 'delegate')
Esempio n. 37
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')
Esempio n. 38
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'])
Esempio n. 39
0
 def test_resolve_all(self):
     """resolve_all() resolves all BaseEntity properties"""
     entity = BaseEntity('entity')
     entity.add_var('TGT', 'localhost')
     entity.add_var('NBR1', 1)
     entity.add_var('NBR2', 2)
     entity.add_var('NBR3', 3)
     entity.add_var('NBR4', 4)
     entity.add_var('NBR5', 5)
     entity.add_var('NBR6', 6)
     entity.add_var('KEYWORD', 'delegate')
     entity.add_var('TXT', 'I am the entity')
     entity.fromdict({
                      'target': "%TGT",
                      'timeout': "%NBR1",
                      'retry': "%NBR2",
                      'fanout': "%NBR3",
                      'delay': "%NBR4",
                      'warnings': "%NBR5",
                      'errors': "%NBR6",
                      'desc': "%TXT",
                      'mode': "%KEYWORD"
                     })
     entity.resolve_all()
     self.assertEqual(entity.desc, "I am the entity")
     self.assertEqual(entity.target, NodeSet('localhost'))
     self.assertEqual(entity.timeout, 1)
     self.assertEqual(entity.maxretry, 2)
     self.assertEqual(entity.fanout, 3)
     self.assertEqual(entity.delay, 4)
     self.assertEqual(entity.errors, 6)
     self.assertEqual(entity.warnings, 5)
     self.assertEqual(entity.mode, 'delegate')
Esempio n. 40
0
 def test_add_variable_twice(self):
     '''Add a variable twice raises VariableAlreadyExistError'''
     svc = BaseEntity('test_var')
     svc.add_var('var', 'foo')
     self.assertRaises(VariableAlreadyExistError, svc.add_var, 'var', 'foo')
Esempio n. 41
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'])
Esempio n. 42
0
 def test_add_variable_twice(self):
     '''Add a variable twice raises VariableAlreadyExistError'''
     svc = BaseEntity('test_var')
     svc.add_var('var', 'foo')
     self.assertRaises(VariableAlreadyExistError, svc.add_var, 'var', 'foo')