示例#1
0
文件: utils_test.py 项目: vonion/salt
    def test_check_state_result(self):
        self.assertFalse(utils.check_state_result([]),
                         "Failed to handle an invalid data type.")
        self.assertFalse(utils.check_state_result(None),
                         "Failed to handle None as an invalid data type.")
        self.assertFalse(
            utils.check_state_result({'host1': []}),
            "Failed to handle an invalid data structure for a host")
        self.assertFalse(utils.check_state_result({}),
                         "Failed to handle an empty dictionary.")
        self.assertFalse(utils.check_state_result({'host1': []}),
                         "Failed to handle an invalid host data structure.")

        self.assertTrue(utils.check_state_result({'    _|-': {}}))

        test_valid_state = {
            'host1': {
                'test_state': {
                    'result': 'We have liftoff!'
                }
            }
        }
        self.assertTrue(utils.check_state_result(test_valid_state))

        test_valid_false_state = {'host1': {'test_state': {'result': False}}}
        self.assertFalse(utils.check_state_result(test_valid_false_state))
示例#2
0
    def test_check_state_result(self):
        self.assertFalse(utils.check_state_result([]), "Failed to handle an invalid data type.")
        self.assertFalse(utils.check_state_result(None), "Failed to handle None as an invalid data type.")
        self.assertFalse(utils.check_state_result({'host1': []}),
                         "Failed to handle an invalid data structure for a host")
        self.assertFalse(utils.check_state_result({}), "Failed to handle an empty dictionary.")
        self.assertFalse(utils.check_state_result({'host1': []}), "Failed to handle an invalid host data structure.")

        self.assertTrue(utils.check_state_result({'    _|-': {}}))

        test_valid_state = {'host1': {'test_state': {'result': 'We have liftoff!'}}}
        self.assertTrue(utils.check_state_result(test_valid_state))

        test_valid_false_state = {'host1': {'test_state': {'result': False}}}
        self.assertFalse(utils.check_state_result(test_valid_false_state))
示例#3
0
    def test_check_state_result(self):
        self.assertFalse(utils.check_state_result(None), "Failed to handle None as an invalid data type.")
        self.assertFalse(utils.check_state_result([]), "Failed to handle an invalid data type.")
        self.assertFalse(utils.check_state_result({}), "Failed to handle an empty dictionary.")
        self.assertFalse(utils.check_state_result({"host1": []}), "Failed to handle an invalid host data structure.")

        test_valid_state = {"host1": {"test_state": {"result": "We have liftoff!"}}}
        self.assertTrue(utils.check_state_result(test_valid_state))

        test_valid_false_state = {"host1": {"test_state": {"result": False}}}
        self.assertFalse(utils.check_state_result(test_valid_false_state))
示例#4
0
文件: utils_test.py 项目: Roche/salt
 def test_check_state_result(self):
     self.assertFalse(utils.check_state_result(None), "Failed to handle None as an invalid data type.")
     self.assertFalse(utils.check_state_result([]), "Failed to handle an invalid data type.")
     self.assertFalse(utils.check_state_result({}), "Failed to handle an empty dictionary.")
     self.assertFalse(utils.check_state_result({'host1': []}), "Failed to handle an invalid host data structure.")
     test_valid_state = {'host1': {'test_state': {'result': 'We have liftoff!'}}}
     self.assertTrue(utils.check_state_result(test_valid_state))
     test_valid_false_states = {
         'test1': OrderedDict([
             ('host1',
              OrderedDict([
                  ('test_state0', {'result':  True}),
                  ('test_state', {'result': False}),
              ])),
         ]),
         'test2': OrderedDict([
             ('host1',
              OrderedDict([
                  ('test_state0', {'result':  True}),
                  ('test_state', {'result': True}),
              ])),
             ('host2',
              OrderedDict([
                  ('test_state0', {'result':  True}),
                  ('test_state', {'result': False}),
              ])),
         ]),
         'test3': ['a'],
         'test4': OrderedDict([
             ('asup', OrderedDict([
                 ('host1',
                  OrderedDict([
                      ('test_state0', {'result':  True}),
                      ('test_state', {'result': True}),
                  ])),
                 ('host2',
                  OrderedDict([
                      ('test_state0', {'result':  True}),
                      ('test_state', {'result': False}),
                  ]))
             ]))
         ]),
         'test5': OrderedDict([
             ('asup', OrderedDict([
                 ('host1',
                  OrderedDict([
                      ('test_state0', {'result':  True}),
                      ('test_state', {'result': True}),
                  ])),
                 ('host2', [])
             ]))
         ])
     }
     for test, data in test_valid_false_states.items():
         self.assertFalse(
             utils.check_state_result(data),
             msg='{0} failed'.format(test))
     test_valid_true_states = {
         'test1': OrderedDict([
             ('host1',
              OrderedDict([
                  ('test_state0', {'result':  True}),
                  ('test_state', {'result': True}),
              ])),
         ]),
         'test3': OrderedDict([
             ('host1',
              OrderedDict([
                  ('test_state0', {'result':  True}),
                  ('test_state', {'result': True}),
              ])),
             ('host2',
              OrderedDict([
                  ('test_state0', {'result':  True}),
                  ('test_state', {'result': True}),
              ])),
         ]),
         'test4': OrderedDict([
             ('asup', OrderedDict([
                 ('host1',
                  OrderedDict([
                      ('test_state0', {'result':  True}),
                      ('test_state', {'result': True}),
                  ])),
                 ('host2',
                  OrderedDict([
                      ('test_state0', {'result':  True}),
                      ('test_state', {'result': True}),
                  ]))
             ]))
         ]),
         'test2': OrderedDict([
             ('host1',
              OrderedDict([
                  ('test_state0', {'result':  None}),
                  ('test_state', {'result': True}),
              ])),
             ('host2',
              OrderedDict([
                  ('test_state0', {'result':  True}),
                  ('test_state', {'result': 'abc'}),
              ]))
         ])
     }
     for test, data in test_valid_true_states.items():
         self.assertTrue(
             utils.check_state_result(data),
             msg='{0} failed'.format(test))
     test_valid_false_state = {'host1': {'test_state': {'result': False}}}
     self.assertFalse(utils.check_state_result(test_valid_false_state))
示例#5
0
 def test_check_state_result(self):
     self.assertFalse(utils.check_state_result(None), "Failed to handle None as an invalid data type.")
     self.assertFalse(utils.check_state_result([]), "Failed to handle an invalid data type.")
     self.assertFalse(utils.check_state_result({}), "Failed to handle an empty dictionary.")
     self.assertFalse(utils.check_state_result({'host1': []}), "Failed to handle an invalid host data structure.")
     test_valid_state = {'host1': {'test_state': {'result': 'We have liftoff!'}}}
     self.assertTrue(utils.check_state_result(test_valid_state))
     test_valid_false_states = {
         'test1': OrderedDict([
             ('host1',
              OrderedDict([
                  ('test_state0', {'result':  True}),
                  ('test_state', {'result': False}),
              ])),
         ]),
         'test2': OrderedDict([
             ('host1',
              OrderedDict([
                  ('test_state0', {'result':  True}),
                  ('test_state', {'result': True}),
              ])),
             ('host2',
              OrderedDict([
                  ('test_state0', {'result':  True}),
                  ('test_state', {'result': False}),
              ])),
         ]),
         'test3': ['a'],
         'test4': OrderedDict([
             ('asup', OrderedDict([
                 ('host1',
                  OrderedDict([
                      ('test_state0', {'result':  True}),
                      ('test_state', {'result': True}),
                  ])),
                 ('host2',
                  OrderedDict([
                      ('test_state0', {'result':  True}),
                      ('test_state', {'result': False}),
                  ]))
             ]))
         ]),
         'test5': OrderedDict([
             ('asup', OrderedDict([
                 ('host1',
                  OrderedDict([
                      ('test_state0', {'result':  True}),
                      ('test_state', {'result': True}),
                  ])),
                 ('host2', [])
             ]))
         ])
     }
     for test, data in test_valid_false_states.items():
         self.assertFalse(
             utils.check_state_result(data),
             msg='{0} failed'.format(test))
     test_valid_true_states = {
         'test1': OrderedDict([
             ('host1',
              OrderedDict([
                  ('test_state0', {'result':  True}),
                  ('test_state', {'result': True}),
              ])),
         ]),
         'test3': OrderedDict([
             ('host1',
              OrderedDict([
                  ('test_state0', {'result':  True}),
                  ('test_state', {'result': True}),
              ])),
             ('host2',
              OrderedDict([
                  ('test_state0', {'result':  True}),
                  ('test_state', {'result': True}),
              ])),
         ]),
         'test4': OrderedDict([
             ('asup', OrderedDict([
                 ('host1',
                  OrderedDict([
                      ('test_state0', {'result':  True}),
                      ('test_state', {'result': True}),
                  ])),
                 ('host2',
                  OrderedDict([
                      ('test_state0', {'result':  True}),
                      ('test_state', {'result': True}),
                  ]))
             ]))
         ]),
         'test2': OrderedDict([
             ('host1',
              OrderedDict([
                  ('test_state0', {'result':  None}),
                  ('test_state', {'result': True}),
              ])),
             ('host2',
              OrderedDict([
                  ('test_state0', {'result':  True}),
                  ('test_state', {'result': 'abc'}),
              ]))
         ])
     }
     for test, data in test_valid_true_states.items():
         self.assertTrue(
             utils.check_state_result(data),
             msg='{0} failed'.format(test))
     test_valid_false_state = {'host1': {'test_state': {'result': False}}}
     self.assertFalse(utils.check_state_result(test_valid_false_state))
示例#6
0
    def test_check_state_result(self):
        self.assertFalse(utils.check_state_result(None), "Failed to handle None as an invalid data type.")
        self.assertFalse(utils.check_state_result([]), "Failed to handle an invalid data type.")
        self.assertFalse(utils.check_state_result({}), "Failed to handle an empty dictionary.")
        self.assertFalse(utils.check_state_result({'host1': []}), "Failed to handle an invalid host data structure.")
        test_valid_state = {'host1': {'test_state': {'result': 'We have liftoff!'}}}
        self.assertTrue(utils.check_state_result(test_valid_state))
        test_valid_false_states = {
            'test1': OrderedDict([
                ('host1',
                 OrderedDict([
                     ('test_state0', {'result':  True}),
                     ('test_state', {'result': False}),
                 ])),
            ]),
            'test2': OrderedDict([
                ('host1',
                 OrderedDict([
                     ('test_state0', {'result':  True}),
                     ('test_state', {'result': True}),
                 ])),
                ('host2',
                 OrderedDict([
                     ('test_state0', {'result':  True}),
                     ('test_state', {'result': False}),
                 ])),
            ]),
            'test3': ['a'],
            'test4': OrderedDict([
                ('asup', OrderedDict([
                    ('host1',
                     OrderedDict([
                         ('test_state0', {'result':  True}),
                         ('test_state', {'result': True}),
                     ])),
                    ('host2',
                     OrderedDict([
                         ('test_state0', {'result':  True}),
                         ('test_state', {'result': False}),
                     ]))
                ]))
            ]),
            'test5': OrderedDict([
                ('asup', OrderedDict([
                    ('host1',
                     OrderedDict([
                         ('test_state0', {'result':  True}),
                         ('test_state', {'result': True}),
                     ])),
                    ('host2', OrderedDict([]))
                ]))
            ])
        }
        for test, data in six.iteritems(test_valid_false_states):
            self.assertFalse(
                utils.check_state_result(data),
                msg='{0} failed'.format(test))
        test_valid_true_states = {
            'test1': OrderedDict([
                ('host1',
                 OrderedDict([
                     ('test_state0', {'result':  True}),
                     ('test_state', {'result': True}),
                 ])),
            ]),
            'test3': OrderedDict([
                ('host1',
                 OrderedDict([
                     ('test_state0', {'result':  True}),
                     ('test_state', {'result': True}),
                 ])),
                ('host2',
                 OrderedDict([
                     ('test_state0', {'result':  True}),
                     ('test_state', {'result': True}),
                 ])),
            ]),
            'test4': OrderedDict([
                ('asup', OrderedDict([
                    ('host1',
                     OrderedDict([
                         ('test_state0', {'result':  True}),
                         ('test_state', {'result': True}),
                     ])),
                    ('host2',
                     OrderedDict([
                         ('test_state0', {'result':  True}),
                         ('test_state', {'result': True}),
                     ]))
                ]))
            ]),
            'test2': OrderedDict([
                ('host1',
                 OrderedDict([
                     ('test_state0', {'result':  None}),
                     ('test_state', {'result': True}),
                 ])),
                ('host2',
                 OrderedDict([
                     ('test_state0', {'result':  True}),
                     ('test_state', {'result': 'abc'}),
                 ]))
            ])
        }
        for test, data in six.iteritems(test_valid_true_states):
            self.assertTrue(
                utils.check_state_result(data),
                msg='{0} failed'.format(test))
        test_invalid_true_ht_states = {
            'test_onfail_simple2': (
                OrderedDict([
                    ('host1',
                     OrderedDict([
                         ('test_vstate0', {'result':  False}),
                         ('test_vstate1', {'result': True}),
                     ])),
                ]),
                {
                    'test_vstate0': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                'run',
                                {'order': 10002}]},
                    'test_vstate1': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                OrderedDict([
                                    ('onfail_stop', True),
                                    ('onfail',
                                     [OrderedDict([('cmd', 'test_vstate0')])])
                                ]),
                                'run',
                                {'order': 10004}]},
                }
            ),
            'test_onfail_integ2': (
                OrderedDict([
                    ('host1',
                     OrderedDict([
                         ('t_|-test_ivstate0_|-echo_|-run', {
                             'result':  False}),
                         ('cmd_|-test_ivstate0_|-echo_|-run', {
                             'result':  False}),
                         ('cmd_|-test_ivstate1_|-echo_|-run', {
                             'result': False}),
                     ])),
                ]),
                {
                    'test_ivstate0': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                'run',
                                {'order': 10002}],
                        't': [OrderedDict([('name', '/bin/true')]),
                              'run',
                              {'order': 10002}]},
                    'test_ivstate1': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                OrderedDict([
                                    ('onfail_stop', False),
                                    ('onfail',
                                     [OrderedDict([('cmd', 'test_ivstate0')])])
                                ]),
                                'run',
                                {'order': 10004}]},
                }
            ),
            'test_onfail_integ3': (
                OrderedDict([
                    ('host1',
                     OrderedDict([
                         ('t_|-test_ivstate0_|-echo_|-run', {
                             'result':  True}),
                         ('cmd_|-test_ivstate0_|-echo_|-run', {
                             'result': False}),
                         ('cmd_|-test_ivstate1_|-echo_|-run', {
                             'result': False}),
                     ])),
                ]),
                {
                    'test_ivstate0': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                'run',
                                {'order': 10002}],
                        't': [OrderedDict([('name', '/bin/true')]),
                              'run',
                              {'order': 10002}]},
                    'test_ivstate1': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                OrderedDict([
                                    ('onfail_stop', False),
                                    ('onfail',
                                     [OrderedDict([('cmd', 'test_ivstate0')])])
                                ]),
                                'run',
                                {'order': 10004}]},
                }
            ),
            'test_onfail_integ4': (
                OrderedDict([
                    ('host1',
                     OrderedDict([
                         ('t_|-test_ivstate0_|-echo_|-run', {
                             'result':  False}),
                         ('cmd_|-test_ivstate0_|-echo_|-run', {
                             'result': False}),
                         ('cmd_|-test_ivstate1_|-echo_|-run', {
                             'result': True}),
                     ])),
                ]),
                {
                    'test_ivstate0': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                'run',
                                {'order': 10002}],
                        't': [OrderedDict([('name', '/bin/true')]),
                              'run',
                              {'order': 10002}]},
                    'test_ivstate1': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                OrderedDict([
                                    ('onfail_stop', False),
                                    ('onfail',
                                     [OrderedDict([('cmd', 'test_ivstate0')])])
                                ]),
                                'run',
                                {'order': 10004}]},
                    'test_ivstate2': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                OrderedDict([
                                    ('onfail_stop', True),
                                    ('onfail',
                                     [OrderedDict([('cmd', 'test_ivstate0')])])
                                ]),
                                'run',
                                {'order': 10004}]},
                }
            ),
            'test_onfail': (
                OrderedDict([
                    ('host1',
                     OrderedDict([
                         ('test_state0', {'result':  False}),
                         ('test_state', {'result': True}),
                     ])),
                ]),
                None
            ),
            'test_onfail_d': (
                OrderedDict([
                    ('host1',
                     OrderedDict([
                         ('test_state0', {'result':  False}),
                         ('test_state', {'result': True}),
                     ])),
                ]),
                {}
            )
        }
        for test, testdata in six.iteritems(test_invalid_true_ht_states):
            data, ht = testdata
            for t_ in [a for a in data['host1']]:
                tdata = data['host1'][t_]
                if '_|-' in t_:
                    t_ = t_.split('_|-')[1]
                tdata['__id__'] = t_
            self.assertFalse(
                utils.check_state_result(data, highstate=ht),
                msg='{0} failed'.format(test))

        test_valid_true_ht_states = {
            'test_onfail_integ': (
                OrderedDict([
                    ('host1',
                     OrderedDict([
                         ('cmd_|-test_ivstate0_|-echo_|-run', {
                             'result':  False}),
                         ('cmd_|-test_ivstate1_|-echo_|-run', {
                             'result': True}),
                     ])),
                ]),
                {
                    'test_ivstate0': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                'run',
                                {'order': 10002}]},
                    'test_ivstate1': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                OrderedDict([
                                    ('onfail_stop', False),
                                    ('onfail',
                                     [OrderedDict([('cmd', 'test_ivstate0')])])
                                ]),
                                'run',
                                {'order': 10004}]},
                }
            ),
            'test_onfail_intega3': (
                OrderedDict([
                    ('host1',
                     OrderedDict([
                         ('t_|-test_ivstate0_|-echo_|-run', {
                             'result':  True}),
                         ('cmd_|-test_ivstate0_|-echo_|-run', {
                             'result': False}),
                         ('cmd_|-test_ivstate1_|-echo_|-run', {
                             'result': True}),
                     ])),
                ]),
                {
                    'test_ivstate0': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                'run',
                                {'order': 10002}],
                        't': [OrderedDict([('name', '/bin/true')]),
                              'run',
                              {'order': 10002}]},
                    'test_ivstate1': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                OrderedDict([
                                    ('onfail_stop', False),
                                    ('onfail',
                                     [OrderedDict([('cmd', 'test_ivstate0')])])
                                ]),
                                'run',
                                {'order': 10004}]},
                }
            ),
            'test_onfail_simple': (
                OrderedDict([
                    ('host1',
                     OrderedDict([
                         ('test_vstate0', {'result':  False}),
                         ('test_vstate1', {'result': True}),
                     ])),
                ]),
                {
                    'test_vstate0': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                'run',
                                {'order': 10002}]},
                    'test_vstate1': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                OrderedDict([
                                    ('onfail_stop', False),
                                    ('onfail',
                                     [OrderedDict([('cmd', 'test_vstate0')])])
                                ]),
                                'run',
                                {'order': 10004}]},
                }
            ),  # order is different
            'test_onfail_simple_rev': (
                OrderedDict([
                    ('host1',
                     OrderedDict([
                         ('test_vstate0', {'result':  False}),
                         ('test_vstate1', {'result': True}),
                     ])),
                ]),
                {
                    'test_vstate0': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                'run',
                                {'order': 10002}]},
                    'test_vstate1': {
                        '__env__': 'base',
                        '__sls__': u'a',
                        'cmd': [OrderedDict([('name', '/bin/true')]),
                                OrderedDict([
                                    ('onfail',
                                     [OrderedDict([('cmd', 'test_vstate0')])])
                                ]),
                                OrderedDict([('onfail_stop', False)]),
                                'run',
                                {'order': 10004}]},
                }
            )
        }
        for test, testdata in six.iteritems(test_valid_true_ht_states):
            data, ht = testdata
            for t_ in [a for a in data['host1']]:
                tdata = data['host1'][t_]
                if '_|-' in t_:
                    t_ = t_.split('_|-')[1]
                tdata['__id__'] = t_
            self.assertTrue(
                utils.check_state_result(data, highstate=ht),
                msg='{0} failed'.format(test))
        test_valid_false_state = {'host1': {'test_state': {'result': False}}}
        self.assertFalse(utils.check_state_result(test_valid_false_state))