def test_extract_action_type(self): LOG.debug('Test extract action type') # Test setup spec_list = mock_sync.simple_host_generators( zone_num=1, host_num=1, snapshot_events=1, snap_vals={'sync_mode': SyncMode.SNAPSHOT}) hosts_events = mock_sync.generate_random_events_list(spec_list) host_transformer = HostTransformer(self.transformers) # Test action action = host_transformer._extract_action_type(hosts_events[0]) # Test assertion self.assertEqual(EventAction.UPDATE, action) # Test setup spec_list = mock_sync.simple_host_generators( zone_num=1, host_num=1, snapshot_events=1, snap_vals={'sync_mode': SyncMode.INIT_SNAPSHOT}) hosts_events = mock_sync.generate_random_events_list(spec_list) host_transformer = HostTransformer(self.transformers) # Test action action = host_transformer._extract_action_type(hosts_events[0]) # Test assertions self.assertEqual(EventAction.CREATE, action)
def test_snapshot_transform(self): LOG.debug('Nova host transformer test: transform entity event') # Test setup spec_list = mock_sync.simple_host_generators( zone_num=2, host_num=4, snapshot_events=5) host_events = mock_sync.generate_random_events_list(spec_list) for event in host_events: # Test action wrapper = HostTransformer(self.transformers).transform(event) # Test assertions self._validate_vertex_props(wrapper.vertex, event) neighbors = wrapper.neighbors self.assertEqual(1, len(neighbors)) self._validate_zone_neighbor(neighbors[0], event) if SyncMode.SNAPSHOT == event['sync_mode']: self.assertEqual(EventAction.UPDATE, wrapper.action) else: self.assertEqual(EventAction.CREATE, wrapper.action)
def _create_mock_events(): gen_list = mock_sync.simple_zone_generators( 2, 4, snapshot_events=2, snap_vals={'sync_mode': 'init_snapshot'}) gen_list += mock_sync.simple_host_generators( 2, 4, 4, snap_vals={'sync_mode': 'init_snapshot'}) gen_list += mock_sync.simple_instance_generators( 4, 15, 15, snap_vals={'sync_mode': 'init_snapshot'}) return mock_sync.generate_sequential_events_list(gen_list)