Example #1
0
 def test_create_service_imbrications(self):
     '''Test create service with mutliple level of subservices'''
     sergrp = ServiceGroup('groupinit')
     sergrp.fromdict(
         {'services':
             {'svcA':
                 {'require': ['subgroup'],
                 'actions':
                     {'start': {'cmd': '/bin/True'},
                     'stop': {'cmd': '/bin/False'}},
                     'desc': 'I am the subservice $NAME'},
             'subgroup':
                 {'services':
                     {'svcB':
                         {'require_weak':['svcC'],
                         'actions':
                             {'start': {'cmd': '/bin/True'},
                         '   stop': {'cmd': '/bin/False'}},
                         'desc': 'I am the subservice $NAME'},
                     'svcC':
                         {'actions':
                             {'start': {'cmd': '/bin/True'},
                             'stop': {'cmd': '/bin/False'}},
                             'desc': 'I am the subservice $NAME'}},
                     'target': '127.0.0.1',
                     'desc': "I'm the service $NAME"}},
         'desc': 'I am a group',
         'target': 'localhost',
     })
     for subservice in ('svcA', 'subgroup'):
         if isinstance(sergrp._subservices[subservice], ServiceGroup):
             for subsubser in ('svcB', 'svcC'):
                 self.assertTrue(
                 sergrp._subservices[subservice].has_subservice(subsubser))
         self.assertTrue(sergrp.has_subservice(subservice))
Example #2
0
 def test_inheritance(self):
     '''Test properties inherited from ServiceGroup to Service and Action'''
     sergrp = ServiceGroup('groupinit')
     sergrp.fromdict({
         'services': {
             'svcA': {
                 'require': ['subgroup'],
                 'actions': {
                     'start': {
                         'cmd': '/bin/True'
                     },
                     'stop': {
                         'cmd': '/bin/False'
                     }
                 },
                 'desc': 'I am the subservice $NAME'
             },
             'subgroup': {
                 'services': {
                     'svcB': {
                         'require_weak': ['svcC'],
                         'actions': {
                             'start': {
                                 'cmd': '/bin/True'
                             },
                             '   stop': {
                                 'cmd': '/bin/False'
                             }
                         },
                         'desc': 'I am the subservice $NAME'
                     },
                     'svcC': {
                         'actions': {
                             'start': {
                                 'cmd': '/bin/True'
                             },
                             'stop': {
                                 'cmd': '/bin/False'
                             }
                         },
                         'desc': 'I am the subservice $NAME'
                     }
                 },
                 'target': '127.0.0.1',
                 'desc': "I'm the service $NAME"
             }
         },
         'desc': 'I am a group',
         'target': 'localhost',
     })
     self.assertEqual(sergrp._subservices['svcA'].target,
                      NodeSet('localhost'))
     self.assertEqual(sergrp._subservices['subgroup'].target,
                      NodeSet('127.0.0.1'))
     subgroup = sergrp._subservices['subgroup']
     self.assertEqual(subgroup._subservices['svcB'].target,
                      NodeSet('127.0.0.1'))
     self.assertEqual(subgroup._subservices['svcC'].target,
                      NodeSet('127.0.0.1'))
Example #3
0
 def test_create_service_imbrications(self):
     '''Test create service with mutliple level of subservices'''
     sergrp = ServiceGroup('groupinit')
     sergrp.fromdict({
         'services': {
             'svcA': {
                 'require': ['subgroup'],
                 'actions': {
                     'start': {
                         'cmd': '/bin/True'
                     },
                     'stop': {
                         'cmd': '/bin/False'
                     }
                 },
                 'desc': 'I am the subservice $NAME'
             },
             'subgroup': {
                 'services': {
                     'svcB': {
                         'require_weak': ['svcC'],
                         'actions': {
                             'start': {
                                 'cmd': '/bin/True'
                             },
                             '   stop': {
                                 'cmd': '/bin/False'
                             }
                         },
                         'desc': 'I am the subservice $NAME'
                     },
                     'svcC': {
                         'actions': {
                             'start': {
                                 'cmd': '/bin/True'
                             },
                             'stop': {
                                 'cmd': '/bin/False'
                             }
                         },
                         'desc': 'I am the subservice $NAME'
                     }
                 },
                 'target': '127.0.0.1',
                 'desc': "I'm the service $NAME"
             }
         },
         'desc': 'I am a group',
         'target': 'localhost',
     })
     for subservice in ('svcA', 'subgroup'):
         if isinstance(sergrp._subservices[subservice], ServiceGroup):
             for subsubser in ('svcB', 'svcC'):
                 self.assertTrue(
                     sergrp._subservices[subservice].has_subservice(
                         subsubser))
         self.assertTrue(sergrp.has_subservice(subservice))
Example #4
0
    def test_subservices_with_different_actions(self):
        '''Test a service group with subservices with different actions'''
        sergrp = ServiceGroup('group1')
        sergrp.fromdict({
            'services': {
                'svc1': {
                    'actions': {
                        'start': {
                            'cmd': '/bin/True'
                        },
                        'status': {
                            'cmd': '/bin/True'
                        },
                        'stop': {
                            'cmd': '/bin/True'
                        },
                    }
                },
                'svc2': {
                    'require': ['svc1'],
                    'actions': {
                        'start': {
                            'cmd': '/bin/True'
                        },
                        'stop': {
                            'cmd': '/bin/True'
                        },
                        'status': {
                            'cmd': '/bin/True'
                        },
                    }
                },
                'svc3': {
                    'require': ['svc1'],
                    'actions': {
                        'start': {
                            'cmd': '/bin/True'
                        },
                        'stop': {
                            'cmd': '/bin/True'
                        },
                        'status': {
                            'cmd': '/bin/True'
                        },
                    }
                },
            }
        })

        self.assertEqual(len(sergrp._subservices), 3)
        self.assertTrue(sergrp.has_subservice('svc1'))
        self.assertTrue(sergrp.has_subservice('svc2'))
        self.assertTrue(sergrp.has_subservice('svc3'))
        self.assertEqual(len(sergrp._subservices['svc1']._actions), 3)
        self.assertEqual(len(sergrp._subservices['svc2']._actions), 3)
        self.assertEqual(len(sergrp._subservices['svc3']._actions), 3)
Example #5
0
 def test_non_existing_target(self):
     '''Test expected behaviour on an non-existing target'''
     sergrp = ServiceGroup('group1')
     sergrp.fromdict(
             { 'services':
             { 'svc1': {
                 'actions': {
                     'start': {'cmd': '/bin/True'},
                 },
               'target': '@none',
             }}})
     self.assertEqual(sergrp._subservices['svc1'].target, NodeSet())
Example #6
0
    def test_resolve_all_with_full_config(self):
        """Test instantiation of a service group with variables subservices."""
        sergrp = ServiceGroup('S1')
        sergrp.add_var('TOUT', 1)
        sergrp.add_var('RET', 2)
        sergrp.add_var('FAN', 3)
        sergrp.add_var('DLY', 4)
        sergrp.add_var('ERRS', 0)
        sergrp.add_var('WARN', 5)
        sergrp.add_var('DSC', 'I am the service')
        sergrp.add_var('MD', 'delegate')
        sergrp.add_var('REQUIRES', ["dep1", "dep2"])

        sergrp.fromdict({
                    'desc':   "Check variables",
                    'target': "localhost",
                    'services': {
                        'dep1':
                            {'actions': {'start': {'cmd': '/bin/True'}} },
                        'dep2':
                            {'actions': {'start': {'cmd': '/bin/True'}} },
                        'fullvars': {
                                     'target': 'localhost',
                                     'require': "%REQUIRES",
                                     'timeout': "%TOUT",
                                     'retry': "%RET",
                                     'fanout': "%FAN",
                                     'delay': "%DLY",
                                     'errors': "%ERRS",
                                     'warnings': "%WARN",
                                     'mode': "%MD",
                                     'actions': {
                                                 'start': {'cmd': '/bin/True'},
                                                 'stop':  {'cmd': '/bin/False'}
                                                },
                                     'desc': "%DSC"
                                    }
                         },
                    })
        sergrp.resolve_all()
        service = sergrp._subservices['fullvars']
        self.assertEqual(service.target, NodeSet('localhost'))
        self.assertEqual(service.timeout, 1)
        self.assertEqual(service.maxretry, 2)
        self.assertEqual(service.fanout, 3)
        self.assertEqual(service.delay, 4)
        self.assertEqual(service.errors, 0)
        self.assertEqual(service.warnings, 5)
        self.assertEqual(service.mode, 'delegate')
        self.assertEqual(service.desc, "I am the service")
        self.assertTrue('dep1' in service.deps())
        self.assertTrue('dep2' in service.deps())
Example #7
0
    def test_graph(self):
        '''Test DOT graph output'''
        manager = service_manager_self()
        sergrp = ServiceGroup('S1')
        sergrp.fromdict(
           {'services':
                {'srv1':
                     {'target': 'localhost',
                      'actions':
                        {'start': {'cmd':'/bin/True'},
                         'stop': {'cmd': '/bin/False'}},
                      'desc': "I'm the service srv1"
                    },
                'subgroup':
                    {'services':
                        {'svcB':
                            {'require_weak':['svcC'],
                            'actions':
                                {'start': {'cmd': '/bin/True'},
                            '   stop': {'cmd': '/bin/False'}},
                            'desc': 'I am the subservice $NAME'},
                        'svcC':
                            {'actions':
                                {'start': {'cmd': '/bin/True'},
                                'stop': {'cmd': '/bin/False'}},
                                'desc': 'I am the subservice $NAME'}},
                        'target': '127.0.0.1',
                        'desc': "I'm the service $NAME"}},
                })
        manager.register_services(sergrp)
        self.assertEqual(manager.output_graph(), 
"""digraph dependency {
compound=true;
node [style=filled];
subgraph "cluster_S1" {
label="S1";
style=rounded;
node [style=filled];
"S1.__hook" [style=invis];
"S1.srv1";
subgraph "cluster_S1.subgroup" {
label="S1.subgroup";
style=rounded;
node [style=filled];
"S1.subgroup.__hook" [style=invis];
"S1.subgroup.svcB" -> "S1.subgroup.svcC" [style=dashed];
"S1.subgroup.svcC";
}
}
}
""")
Example #8
0
    def test_graph(self):
        '''Test DOT graph output'''
        manager = ServiceManager()
        sergrp = ServiceGroup('S1')
        sergrp.fromdict(
           {'services':
                {'srv1':
                     {'target': 'localhost',
                      'actions':
                        {'start': {'cmd':'/bin/True'},
                         'stop': {'cmd': '/bin/False'}},
                      'desc': "I'm the service srv1"
                    },
                'subgroup':
                    {'services':
                        {'svcB':
                            {'require_weak':['svcC'],
                            'actions':
                                {'start': {'cmd': '/bin/True'},
                            '   stop': {'cmd': '/bin/False'}},
                            'desc': 'I am the subservice $NAME'},
                        'svcC':
                            {'actions':
                                {'start': {'cmd': '/bin/True'},
                                'stop': {'cmd': '/bin/False'}},
                                'desc': 'I am the subservice $NAME'}},
                        'target': '127.0.0.1',
                        'desc': "I'm the service $NAME"}},
                })
        manager.add_service(sergrp)
        self.assertEqual(manager.output_graph(), 
"""digraph dependency {
compound=true;
node [style=filled];
subgraph "cluster_S1" {
label="S1";
style=rounded;
node [style=filled];
"S1.__hook" [style=invis];
"S1.srv1";
subgraph "cluster_S1.subgroup" {
label="S1.subgroup";
style=rounded;
node [style=filled];
"S1.subgroup.__hook" [style=invis];
"S1.subgroup.svcB" -> "S1.subgroup.svcC" [style=dashed];
"S1.subgroup.svcC";
}
}
}
""")
Example #9
0
 def test_require_no_list(self):
     """Test parsing require with a simple singleton (no list)"""
     grp = ServiceGroup('grp')
     grp.fromdict({'services': {
                       'svc1': {
                           'actions': {'start': {'cmd': '/bin/true'}}
                       },
                       'svc2': {
                           'require': 'svc1',
                           'actions': {'start': {'cmd': '/bin/true'}}
                       }
                   }})
     svc1 = grp._subservices['svc2'].parents['svc1']
     self.assertEqual(svc1.dep_type, REQUIRE)
Example #10
0
    def test_fromdict1(self):
        '''Test instanciation of a service group from a dictionnary'''
        sergrp = ServiceGroup('S1')
        sergrp.fromdict({
            'services': {
                'hpss_nfs': {
                    'target': 'localhost',
                    'actions': {
                        'start': {
                            'cmd': '/bin/True'
                        },
                        'stop': {
                            'cmd': '/bin/False'
                        }
                    },
                    'desc': "I'm the service hpss_nfs"
                },
                'lustre': {
                    'target': 'localhost',
                    'actions': {
                        'start': {
                            'cmd': '/bin/True'
                        },
                        'stop': {
                            'cmd': '/bin/False'
                        }
                    },
                    'desc': "I'm the service lustre"
                }
            },
            'desc': "I'm the service S1",
            'target': 'localhost',
            'variables': {
                'var1': 'toto',
                'var2': 'titi'
            },
        })

        self.assertEqual(len(sergrp.variables), 2)
        self.assertTrue('var1' in sergrp.variables)
        self.assertTrue('var2' in sergrp.variables)
        self.assertTrue(sergrp.has_subservice('hpss_nfs'))
        self.assertTrue(sergrp.has_subservice('lustre'))
        self.assertTrue(sergrp._subservices['hpss_nfs'].has_parent_dep('sink'))
        self.assertTrue(
            sergrp._subservices['hpss_nfs'].has_child_dep('source'))
        self.assertTrue(sergrp._subservices['lustre'].has_parent_dep('sink'))
        self.assertTrue(sergrp._subservices['lustre'].has_child_dep('source'))
Example #11
0
 def test_fromdict_after(self):
     """Test 'after' as an alias of 'require_weak'"""
     grp = ServiceGroup('grp')
     grp.fromdict({
         'services': {
             'svc1': {
                 'actions': { 'start': { 'cmd': '/bin/true' } }
             },
             'svc2': {
                 'after': [ 'svc1' ],
                 'actions': { 'start': { 'cmd': '/bin/true' } }
             }
         }
     })
     svc1 = grp._subservices['svc2'].parents['svc1']
     self.assertEqual(svc1.dep_type, REQUIRE_WEAK)
Example #12
0
 def test_before(self):
     """Test 'before' as an alias of 'after' (only for v1.0 compat)"""
     grp = ServiceGroup('grp')
     grp.fromdict({
         'services': {
             'svc1': {
                 'actions': {'start': {'cmd': '/bin/true'}}
             },
             'svc2': {
                 'before': ['svc1'],
                 'actions': {'start': {'cmd': '/bin/true'}}
             }
         }
     })
     svc1 = grp._subservices['svc2'].parents['svc1']
     self.assertEqual(svc1.dep_type, REQUIRE_WEAK)
Example #13
0
 def test_filter(self):
     """Test parsing 'filter' dependency type"""
     grp = ServiceGroup('grp')
     grp.fromdict({
         'services': {
             'svc1': {
                 'actions': {'start': {'cmd': '/bin/true'}}
             },
             'svc2': {
                 'filter': ['svc1'],
                 'actions': {'start': {'cmd': '/bin/true'}}
             }
         }
     })
     svc1 = grp._subservices['svc2'].parents['svc1']
     self.assertEqual(svc1.dep_type, FILTER)
Example #14
0
 def test_non_existing_target(self):
     '''Test expected behaviour on an non-existing target'''
     sergrp = ServiceGroup('group1')
     sergrp.fromdict({
         'services': {
             'svc1': {
                 'actions': {
                     'start': {
                         'cmd': '/bin/True'
                     },
                 },
                 'target': '@none',
             }
         }
     })
     self.assertEqual(sergrp._subservices['svc1'].target, NodeSet())
Example #15
0
    def test_servicegroup_with_nodeset_like_actions_with_one_decl(self):
        '''Test a service group with several group with nodeset-like names'''
        sergrp = ServiceGroup('group1')
        sergrp.fromdict({
            'services': {
                'da[1-3]': {
                    'actions': {'start': {'cmd': '/bin/True'}}
                },
            }})

        self.assertEqual(len(sergrp._subservices), 3)
        self.assertTrue(sergrp.has_subservice('da1'))
        self.assertTrue(sergrp.has_subservice('da2'))
        self.assertTrue(sergrp.has_subservice('da3'))
        self.assertEqual(len(sergrp._subservices['da1']._actions), 1)
        self.assertEqual(len(sergrp._subservices['da2']._actions), 1)
        self.assertEqual(len(sergrp._subservices['da3']._actions), 1)
Example #16
0
 def test_variable_with_escaping_pattern(self):
     """fromdict() should not resolve variables"""
     grp = ServiceGroup('grp')
     grp.fromdict({
         'services': {
             'svc': {
                 'variables': {
                     'foo': 'nice'
                 },
                 'actions': {
                     'start': {'cmd': 'shine config -O %%host %foo'}
                 }
             }
         }
     })
     action = grp._subservices['svc']._actions['start']
     self.assertEqual(action.command, 'shine config -O %%host %foo')
Example #17
0
 def test_fromdict2(self):
     '''
     Test instanciation of a service group with dependencies between
     subservices.
     '''
     sergrp = ServiceGroup('S1')
     sergrp.fromdict(
         {'services':
             {'hpss_nfs':
                 {'target': 'localhost',
                  'require': ['lustre', 'test'],
                  'actions':
                     {'start': {'cmd': '/bin/True'},
                     'stop': {'cmd': '/bin/False'}},
                     'desc': "I'm the service hpss_nfs"
                  },
              'lustre':
                  {'target': 'localhost',
                   'actions':
                     {'start': {'cmd':'/bin/True'},
                      'stop': {'cmd': '/bin/False'}},
                   'desc': "I'm the service lustre"},
             'test':
                  {'target': 'localhost',
                   'actions':
                     {'start': {'cmd':'/bin/True'},
                      'stop': {'cmd': '/bin/False'}},
                   'desc': "I'm a test suite"}},
         'variables':{'LUSTRE_FS_LIST': 'store0,work0'},
         'desc': "I'm the service S1",
         'target': 'localhost',
     })
     self.assertTrue(sergrp.has_subservice('hpss_nfs'))
     self.assertTrue(sergrp.has_subservice('lustre'))
     self.assertTrue(sergrp.has_subservice('test'))
     self.assertFalse(
         sergrp._subservices['hpss_nfs'].has_parent_dep('sink'))
     self.assertTrue(
         sergrp._subservices['hpss_nfs'].has_child_dep('source'))
     self.assertTrue(
         sergrp._subservices['lustre'].has_parent_dep('sink'))
     self.assertFalse(
         sergrp._subservices['test'].has_child_dep('source'))
     self.assertTrue(
         sergrp._subservices['test'].has_parent_dep('sink'))
Example #18
0
 def test_resolve_all_local_variable(self):
     """Variable resolution in 'require' with a local variable."""
     svcgrp = ServiceGroup('group')
     svcgrp.fromdict({
                     'services': {
                         'dep1': {
                                  'actions': {'start': {'cmd': '/bin/True'}}
                         },
                         'dep2': {
                                  'variables': {'foo': ['dep1']},
                                  'require': "%foo",
                                  'actions': {'start': {'cmd': '/bin/True'}}
                         },
                     }
                     })
     svcgrp.resolve_all()
     service = svcgrp._subservices['dep2']
     self.assertTrue('dep1' in service.deps())
Example #19
0
    def test_group_with_weak_dep_error(self):
        """A group with a weak dep error runs fine."""

        dep1 = Service('dep1')
        dep1.add_action(Action('stop', command='/bin/false'))

        grp = ServiceGroup('group')
        grp.fromdict({
            'services': {
                'svc1': {
                    'actions': {
                        'stop': { 'cmd': "/bin/true" },
                    }
                }
            }
        })

        grp.add_dep(dep1, sgth=REQUIRE_WEAK)
        grp.run('stop')

        self.assertEqual(grp.status, DONE)
Example #20
0
    def test_fromdict1(self):
        '''Test instanciation of a service group from a dictionnary'''
        sergrp = ServiceGroup('S1')
        sergrp.fromdict(
           {'services':
                {'hpss_nfs':
                    {'target': 'localhost',
                     'actions':
                        {'start': {'cmd': '/bin/True'},
                        'stop': {'cmd': '/bin/False'}},
                        'desc': "I'm the service hpss_nfs"
                     },
                 'lustre':
                     {'target': 'localhost',
                      'actions':
                        {'start': {'cmd':'/bin/True'},
                         'stop': {'cmd': '/bin/False'}},
                      'desc': "I'm the service lustre"}},
            'desc': "I'm the service S1",
            'target': 'localhost',
            'variables':{
                'var1': 'toto',
                'var2': 'titi'
            },
        })

        self.assertEqual(len(sergrp.variables), 2)
        self.assertTrue('var1' in sergrp.variables)
        self.assertTrue('var2' in sergrp.variables)
        self.assertTrue(sergrp.has_subservice('hpss_nfs'))
        self.assertTrue(sergrp.has_subservice('lustre'))
        self.assertTrue(
            sergrp._subservices['hpss_nfs'].has_parent_dep('sink'))
        self.assertTrue(
            sergrp._subservices['hpss_nfs'].has_child_dep('source'))
        self.assertTrue(
            sergrp._subservices['lustre'].has_parent_dep('sink'))
        self.assertTrue(
            sergrp._subservices['lustre'].has_child_dep('source'))
Example #21
0
    def test_servicegroup_with_nodeset_like_actions_with_one_decl(self):
        '''Test a service group with several group with nodeset-like names'''
        sergrp = ServiceGroup('group1')
        sergrp.fromdict({
            'services': {
                'da[1-3]': {
                    'actions': {
                        'start': {
                            'cmd': '/bin/True'
                        }
                    }
                },
            }
        })

        self.assertEqual(len(sergrp._subservices), 3)
        self.assertTrue(sergrp.has_subservice('da1'))
        self.assertTrue(sergrp.has_subservice('da2'))
        self.assertTrue(sergrp.has_subservice('da3'))
        self.assertEqual(len(sergrp._subservices['da1']._actions), 1)
        self.assertEqual(len(sergrp._subservices['da2']._actions), 1)
        self.assertEqual(len(sergrp._subservices['da3']._actions), 1)
Example #22
0
 def test_resolve_target_from_parent(self):
     """resolve target using a variable declared in parent service group"""
     # 'target' property is resolved very early and not in resolve_all()
     data = {
         'services': {
             'mygroup': {
                 'variables': {
                     'targets': 'foo',
                 },
                 'services': {
                     'svc': {
                         'target': '%targets',
                         'actions': {'start': {'cmd': '/bin/true'}}
                     }
                 }
             }
         }
     }
     grp = ServiceGroup('grp')
     grp.fromdict(data)
     svc = grp._subservices['mygroup']._subservices['svc']
     self.assertEqual(str(svc.target), 'foo')
Example #23
0
    def test_subservices_with_different_actions(self):
        '''Test a service group with subservices with different actions'''
        sergrp = ServiceGroup('group1')
        sergrp.fromdict(
            {
            'services': {
                'svc1': {
                    'actions': {
                          'start': {'cmd': '/bin/True'},
                          'status': {'cmd': '/bin/True'},
                          'stop': {'cmd': '/bin/True'},
                    }
                },
                'svc2': {
                    'require': [ 'svc1' ],
                    'actions': {
                          'start': {'cmd': '/bin/True'},
                          'stop': {'cmd': '/bin/True'},
                          'status': {'cmd': '/bin/True'},
                    }
                },
                'svc3': {
                    'require': [ 'svc1' ],
                    'actions': {
                          'start': {'cmd': '/bin/True'},
                          'stop': {'cmd': '/bin/True'},
                          'status': {'cmd': '/bin/True'},
                    }
                },
            }})

        self.assertEqual(len(sergrp._subservices), 3)
        self.assertTrue(sergrp.has_subservice('svc1'))
        self.assertTrue(sergrp.has_subservice('svc2'))
        self.assertTrue(sergrp.has_subservice('svc3'))
        self.assertEqual(len(sergrp._subservices['svc1']._actions), 3)
        self.assertEqual(len(sergrp._subservices['svc2']._actions), 3)
        self.assertEqual(len(sergrp._subservices['svc3']._actions), 3)
Example #24
0
 def test_inheritance(self):
     '''Test properties inherited from ServiceGroup to Service and Action'''
     sergrp = ServiceGroup('groupinit')
     sergrp.fromdict(
         {'services':
             {'svcA':
                 {'require': ['subgroup'],
                 'actions':
                     {'start': {'cmd': '/bin/True'},
                     'stop': {'cmd': '/bin/False'}},
                     'desc': 'I am the subservice $NAME'},
             'subgroup':
                 {'services':
                     {'svcB':
                         {'require_weak':['svcC'],
                         'actions':
                             {'start': {'cmd': '/bin/True'},
                         '   stop': {'cmd': '/bin/False'}},
                         'desc': 'I am the subservice $NAME'},
                     'svcC':
                         {'actions':
                             {'start': {'cmd': '/bin/True'},
                             'stop': {'cmd': '/bin/False'}},
                             'desc': 'I am the subservice $NAME'}},
                     'target': '127.0.0.1',
                     'desc': "I'm the service $NAME"}},
         'desc': 'I am a group',
         'target': 'localhost',
     })
     self.assertEqual(
         sergrp._subservices['svcA'].target, NodeSet('localhost'))
     self.assertEqual(
         sergrp._subservices['subgroup'].target, NodeSet('127.0.0.1'))
     subgroup = sergrp._subservices['subgroup']
     self.assertEqual(
         subgroup._subservices['svcB'].target, NodeSet('127.0.0.1'))
     self.assertEqual(
         subgroup._subservices['svcC'].target, NodeSet('127.0.0.1'))
Example #25
0
    def test_group_with_weak_dep_error(self):
        """A group with a weak dep error runs fine."""

        dep1 = Service('dep1')
        dep1.add_action(Action('stop', command='/bin/false'))

        grp = ServiceGroup('group')
        grp.fromdict({
            'services': {
                'svc1': {
                    'actions': {
                        'stop': {
                            'cmd': "/bin/true"
                        },
                    }
                }
            }
        })

        grp.add_dep(dep1, sgth=REQUIRE_WEAK)
        grp.run('stop')

        self.assertEqual(grp.status, DONE)
Example #26
0
 def test_fromdict_after(self):
     """Test 'after' as an alias of 'require_weak'"""
     grp = ServiceGroup('grp')
     grp.fromdict({
         'services': {
             'svc1': {
                 'actions': {
                     'start': {
                         'cmd': '/bin/true'
                     }
                 }
             },
             'svc2': {
                 'after': ['svc1'],
                 'actions': {
                     'start': {
                         'cmd': '/bin/true'
                     }
                 }
             }
         }
     })
     svc1 = grp._subservices['svc2'].parents['svc1']
     self.assertEqual(svc1.dep_type, REQUIRE_WEAK)
Example #27
0
    def _build_services(self):
        '''
        Instanciate services, variables and service group. This methods
        also populate the service manager.
        '''
        # Get back the manager
        manager = service_manager_self()
        dependencies = {}

        # Go through data registred within flow
        for data in self._flow:
            for elem, subelems in data.items():
                # Parse variables
                if elem == 'variables':
                    for (varname, value) in subelems.items():
                        # Variables could have been already defined on command
                        # line through defines, and they have priority.
                        # If several 'variables' section are defined, the first
                        # ones will have priority, and it is fine are there is
                        # no ordering guarantee.
                        if varname not in manager.variables:
                            manager.add_var(varname, value)
                # Parse service
                elif elem == 'service' and 'actions' in subelems:
                    ser = Service(subelems['name'])
                    ser.fromdict(subelems)
                    wrap = self._parse_deps(subelems)
                    wrap.source = ser
                    dependencies[ser.name] = wrap
                # Parse service group
                elif elem == 'service' and 'services' in subelems:
                    ser = ServiceGroup(subelems['name'])
                    ser.fromdict(subelems)
                    wrap = self._parse_deps(subelems)
                    wrap.source = ser
                    dependencies[ser.name] = wrap
                # Support for new style syntax to declare services
                # This is a simple mode, for compatibility, with old-style
                # syntax.
                elif elem == 'services':
                    for names, props in subelems.items():
                        for svcname in NodeSet(names):

                            service = None
                            if 'services' in props:
                                service = ServiceGroup(svcname)
                            else:
                                service = Service(svcname)

                            service.fromdict(props)
                            wrap = self._parse_deps(props)
                            wrap.source = service
                            dependencies[service.name] = wrap

                else:
                    raise ConfigurationError("Bad rule '%s'" % elem)

        # Build relations between services
        for wrap in dependencies.values():
            for (dtype, values) in wrap.deps.items():
                for dep in values:
                    if dep not in dependencies:
                        raise UnknownDependencyError(dep)
                    wrap.source.add_dep(
                        target=dependencies[dep].source, sgth=dtype.upper())
        # Populate the manager and set up inheritance
        for wrap in dependencies.values():
            manager.register_service(wrap.source)
Example #28
0
    def _build_services(self):
        '''
        Instanciate services, variables and service group. This methods
        also populate the service manager.
        '''
        # Get back the manager
        manager = service_manager_self()
        dependencies = {}

        # Go through data registred within flow
        for data in self._flow:
            for elem, subelems in data.items():
                # Parse variables
                if elem == 'variables':
                    for (varname, value) in subelems.items():
                        # Variables could have been already defined on command
                        # line through defines, and they have priority.
                        # If several 'variables' section are defined, the first
                        # ones will have priority, and it is fine are there is
                        # no ordering guarantee.
                        if varname not in manager.variables:
                            manager.add_var(varname, value)
                # Parse service
                elif elem == 'service' and 'actions' in subelems:
                    ser = Service(subelems['name'])
                    ser.fromdict(subelems)
                    wrap = self._parse_deps(subelems)
                    wrap.source = ser
                    dependencies[ser.name] = wrap
                # Parse service group
                elif elem == 'service' and 'services' in subelems:
                    ser = ServiceGroup(subelems['name'])
                    ser.fromdict(subelems)
                    wrap = self._parse_deps(subelems)
                    wrap.source = ser
                    dependencies[ser.name] = wrap
                # Support for new style syntax to declare services
                # This is a simple mode, for compatibility, with old-style
                # syntax.
                elif elem == 'services':
                    for names, props in subelems.items():
                        for svcname in NodeSet(names):

                            service = None
                            if 'services' in props:
                                service = ServiceGroup(svcname)
                            else:
                                service = Service(svcname)

                            service.fromdict(props)
                            wrap = self._parse_deps(props)
                            wrap.source = service
                            dependencies[service.name] = wrap

                else:
                    raise ConfigurationError("Bad rule '%s'" % elem)

        # Build relations between services
        for wrap in dependencies.values():
            for (dtype, values) in wrap.deps.items():
                for dep in values:
                    if dep not in dependencies:
                        raise UnknownDependencyError(dep)
                    wrap.source.add_dep(target=dependencies[dep].source,
                                        sgth=dtype.upper())
        # Populate the manager and set up inheritance
        for wrap in dependencies.values():
            manager.register_service(wrap.source)
Example #29
0
    def _build_services(self):
        '''
        Instanciate services, variables and service group. This methods
        also populate the service manager.
        '''
        # Get back the manager
        manager = service_manager_self()
        dependencies = {}

        # We need to parse variables first to be sure that variables used
        # in services are already parsed (see #15)
        for data in self._flow:
            # Parse variables
            if 'variables' in data:
                for varname, value in data['variables'].items():
                    if varname not in manager.variables:
                        manager.add_var(varname, value)

        # Go through data registred within flow
        for data in self._flow:
            for elem, subelems in data.items():
                # Parse service
                if elem == 'service' and 'actions' in subelems:
                    ser = Service(subelems['name'])
                    ser.fromdict(subelems)
                    wrap = self._parse_deps(subelems)
                    wrap.source = ser
                    dependencies[ser.name] = wrap
                # Parse service group
                elif elem == 'service' and 'services' in subelems:
                    ser = ServiceGroup(subelems['name'])
                    ser.fromdict(subelems)
                    wrap = self._parse_deps(subelems)
                    wrap.source = ser
                    dependencies[ser.name] = wrap
                # Support for new style syntax to declare services
                # This is a simple mode, for compatibility, with old-style
                # syntax.
                elif elem == 'services':
                    for names, props in subelems.items():
                        for svcname in NodeSet(names):

                            service = None
                            if 'services' in props:
                                service = ServiceGroup(svcname)
                            else:
                                service = Service(svcname)

                            service.fromdict(props)
                            wrap = self._parse_deps(props)
                            wrap.source = service
                            dependencies[service.name] = wrap

                elif elem != 'variables':
                    raise ConfigurationError("Bad rule '%s'" % elem)

        # Build relations between services
        for wrap in dependencies.values():
            for (dtype, values) in wrap.deps.items():
                for dep in values:
                    if dep not in dependencies:
                        raise UnknownDependencyError(dep)
                    wrap.source.add_dep(
                        target=dependencies[dep].source, sgth=dtype.upper())
        # Populate the manager and set up inheritance
        for wrap in dependencies.values():
            manager.register_service(wrap.source)
Example #30
0
 def test_fromdict2(self):
     '''
     Test instanciation of a service group with dependencies between
     subservices.
     '''
     sergrp = ServiceGroup('S1')
     sergrp.fromdict({
         'services': {
             'hpss_nfs': {
                 'target': 'localhost',
                 'require': ['lustre', 'test'],
                 'actions': {
                     'start': {
                         'cmd': '/bin/True'
                     },
                     'stop': {
                         'cmd': '/bin/False'
                     }
                 },
                 'desc': "I'm the service hpss_nfs"
             },
             'lustre': {
                 'target': 'localhost',
                 'actions': {
                     'start': {
                         'cmd': '/bin/True'
                     },
                     'stop': {
                         'cmd': '/bin/False'
                     }
                 },
                 'desc': "I'm the service lustre"
             },
             'test': {
                 'target': 'localhost',
                 'actions': {
                     'start': {
                         'cmd': '/bin/True'
                     },
                     'stop': {
                         'cmd': '/bin/False'
                     }
                 },
                 'desc': "I'm a test suite"
             }
         },
         'variables': {
             'LUSTRE_FS_LIST': 'store0,work0'
         },
         'desc': "I'm the service S1",
         'target': 'localhost',
     })
     self.assertTrue(sergrp.has_subservice('hpss_nfs'))
     self.assertTrue(sergrp.has_subservice('lustre'))
     self.assertTrue(sergrp.has_subservice('test'))
     self.assertFalse(
         sergrp._subservices['hpss_nfs'].has_parent_dep('sink'))
     self.assertTrue(
         sergrp._subservices['hpss_nfs'].has_child_dep('source'))
     self.assertTrue(sergrp._subservices['lustre'].has_parent_dep('sink'))
     self.assertFalse(sergrp._subservices['test'].has_child_dep('source'))
     self.assertTrue(sergrp._subservices['test'].has_parent_dep('sink'))