Ejemplo n.º 1
0
 def test_track_universe_actions(self):
     # When AIM is the current state, created objects are in ACI form,
     # deleted objects are in AIM form
     reset_limit = self.universe.reset_retry_limit
     purge_limit = self.universe.purge_retry_limit
     old_backoff_time = self.universe.max_backoff_time
     self.assertEqual(2 * self.universe.max_create_retry, reset_limit)
     self.assertEqual(2 * reset_limit, purge_limit)
     self.assertTrue(self.universe.max_create_retry > 0)
     self.universe.retry_cooldown = -1
     self.universe.max_backoff_time = 0
     actions = {
         'create': [
             self._get_example_aci_object('fvBD', 'uni/tn-t1/BD-b'),
             self._get_example_aci_object('fvBD', 'uni/tn-t1/BD-b'),
         ],
         'delete': []
     }
     reset, purge, skip = self.universe._track_universe_actions(actions,
                                                                'tn-t1')
     self.assertEqual(False, reset)
     self.assertEqual([], purge)
     # 1 roots
     self.assertEqual(1, len(self.universe._sync_log['tn-t1']['create']))
     # BD counted only once
     self.assertEqual(
         0, list(self.universe._sync_log['tn-t1']['create'].values())[0][
             'retries'])
     actions = {
         'create': [
             self._get_example_aci_object('fvCtx', 'uni/tn-t2/ctx-c'),
         ],
         'delete': []
     }
     self.universe._track_universe_actions(actions, 'tn-t2')
     # 2 roots
     self.assertEqual(1, len(self.universe._sync_log['tn-t2']['create']))
     ctrl = resource.VMMController(domain_type='OpenStack',
                                   domain_name='os', name='ctrl')
     actions = {
         'create': [],
         'delete': [ctrl]
     }
     reset, purge, skip = self.universe._track_universe_actions(
         actions, 'vmmp-OpenStack')
     self.assertEqual(False, reset)
     self.assertEqual([], purge)
     self.universe._track_universe_actions({'create': [], 'delete': []},
                                           'tn-t2')
     actions = {
         'create': [self._get_example_aci_object('fvBD', 'uni/tn-t1/BD-b')],
         'delete': []
     }
     reset, purge, skip = self.universe._track_universe_actions(actions,
                                                                'tn-t1')
     # BD count increased
     self.assertEqual(
         1, list(self.universe._sync_log['tn-t1']['create'].values())[0][
             'retries'])
     self.assertEqual(
         0, list(self.universe._sync_log[ctrl.root]['delete'].values())[0][
             'retries'])
     # Retry the above until t1 needs reset
     for _ in range(reset_limit - 1):
         reset, purge, skip = self.universe._track_universe_actions(
             actions, 'tn-t1')
         self.assertEqual(False, reset)
         self.assertEqual([], purge)
     reset, purge, skip = self.universe._track_universe_actions(actions,
                                                                'tn-t1')
     self.assertEqual(True, reset)
     self.assertEqual([], purge)
     # with the next run, reset is not required for t1 anymore, but pure
     # countdown starts
     reset, purge, skip = self.universe._track_universe_actions(actions,
                                                                'tn-t1')
     self.assertEqual([], purge)
     for _ in range(purge_limit - reset_limit - 2):
         reset, purge, skip = self.universe._track_universe_actions(actions,
                                                                    'tn-t1')
         self.assertEqual(False, reset)
         self.assertEqual([], purge)
     reset, purge, skip = self.universe._track_universe_actions(actions,
                                                                'tn-t1')
     self.assertEqual(False, reset)
     self.assertEqual(1, len(purge))
     self.assertEqual('create', purge[0][0])
     self.assertEqual('uni/tn-t1/BD-b', purge[0][1].dn)
     self.universe.max_backoff_time = old_backoff_time
Ejemplo n.º 2
0
 def test_track_universe_actions(self):
     # When AIM is the current state, created objects are in ACI form,
     # deleted objects are in AIM form
     old_cooldown = self.universe.retry_cooldown
     reset_limit = self.universe.reset_retry_limit
     purge_limit = self.universe.purge_retry_limit
     self.assertEqual(2 * self.universe.max_create_retry, reset_limit)
     self.assertEqual(2 * reset_limit, purge_limit)
     self.assertTrue(self.universe.max_create_retry > 0)
     self.universe.retry_cooldown = -1
     actions = {
         'create': [
             self._get_example_aci_object('fvBD', 'uni/tn-t1/BD-b'),
             self._get_example_aci_object('fvBD', 'uni/tn-t1/BD-b'),
             self._get_example_aci_object('fvCtx', 'uni/tn-t2/ctx-c'),
         ],
         'delete': []
     }
     reset, purge = self.universe._track_universe_actions(actions)
     self.assertEqual(set(), reset)
     self.assertEqual([], purge)
     # 2 roots
     self.assertEqual(2, len(self.universe._action_cache['create']))
     # BD counted only once
     self.assertEqual(
         0, self.universe._action_cache['create']['tn-t1'].values()[0]
         ['retries'])
     ctrl = resource.VMMController(domain_type='OpenStack',
                                   domain_name='os',
                                   name='ctrl')
     actions = {
         'create': [
             self._get_example_aci_object('fvBD', 'uni/tn-t1/BD-b'),
         ],
         'delete': [ctrl]
     }
     reset, purge = self.universe._track_universe_actions(actions)
     self.assertEqual(set(), reset)
     self.assertEqual([], purge)
     # Tenant t2 is off the hook
     self.assertTrue('tn-t2' not in self.universe._action_cache['create'])
     self.assertTrue('tn-t2' not in self.universe._action_cache['delete'])
     # BD count increased
     self.assertEqual(
         1, self.universe._action_cache['create']['tn-t1'].values()[0]
         ['retries'])
     self.assertEqual(
         0, self.universe._action_cache['delete'][ctrl.root].values()[0]
         ['retries'])
     # Retry the above until t1 needs reset
     for _ in range(reset_limit - 1):
         reset, purge = self.universe._track_universe_actions(actions)
         self.assertEqual(set(), reset)
         self.assertEqual([], purge)
     reset, purge = self.universe._track_universe_actions(actions)
     self.assertEqual({'tn-t1'}, reset)
     self.assertEqual([], purge)
     # with the next run, reset is not required for t1 anymore, but pure
     # countdown starts
     reset, purge = self.universe._track_universe_actions(actions)
     self.assertEqual({ctrl.root}, reset)
     self.assertEqual([], purge)
     for _ in range(purge_limit - reset_limit - 2):
         reset, purge = self.universe._track_universe_actions(actions)
         self.assertEqual(set(), reset)
         self.assertEqual([], purge)
     reset, purge = self.universe._track_universe_actions(actions)
     self.assertEqual(set(), reset)
     self.assertEqual(1, len(purge))
     self.assertEqual('create', purge[0][0])
     self.assertEqual('uni/tn-t1/BD-b', purge[0][1].dn)
     reset, purge = self.universe._track_universe_actions(actions)
     self.assertEqual(set(), reset)
     self.assertEqual(1, len(purge))
     self.assertEqual(ctrl.dn, purge[0][1].dn)
     self.universe.retry_cooldown = old_cooldown