@@ -2238,57 +2238,71 @@ def setUp(self):
22382238
22392239 def test_archive_deleted_rows (self ):
22402240 admin_context = context .get_admin_context (read_deleted = 'yes' )
2241- # Boot a server to cell1
2242- server_ids = {}
2243- server = self ._build_server (az = 'nova:host1' )
2244- created_server = self .api .post_server ({'server' : server })
2245- self ._wait_for_state_change (created_server , 'ACTIVE' )
2246- server_ids ['cell1' ] = created_server ['id' ]
2247- # Boot a server to cell2
2248- server = self ._build_server (az = 'nova:host2' )
2249- created_server = self .api .post_server ({'server' : server })
2250- self ._wait_for_state_change (created_server , 'ACTIVE' )
2251- server_ids ['cell2' ] = created_server ['id' ]
2252- # Boot a server to cell0 (cause ERROR state prior to schedule)
2253- server = self ._build_server ()
2254- # Flavor m1.xlarge cannot be fulfilled
2255- server ['flavorRef' ] = 'http://fake.server/5'
2256- created_server = self .api .post_server ({'server' : server })
2257- self ._wait_for_state_change (created_server , 'ERROR' )
2258- server_ids ['cell0' ] = created_server ['id' ]
2241+ server_ids_by_cell = collections .defaultdict (list )
2242+ # Create two servers per cell to make sure archive for table iterates
2243+ # at least once.
2244+ for i in range (2 ):
2245+ # Boot a server to cell1
2246+ server = self ._build_server (az = 'nova:host1' )
2247+ created_server = self .api .post_server ({'server' : server })
2248+ self ._wait_for_state_change (created_server , 'ACTIVE' )
2249+ server_ids_by_cell ['cell1' ].append (created_server ['id' ])
2250+ # Boot a server to cell2
2251+ server = self ._build_server (az = 'nova:host2' )
2252+ created_server = self .api .post_server ({'server' : server })
2253+ self ._wait_for_state_change (created_server , 'ACTIVE' )
2254+ server_ids_by_cell ['cell2' ].append (created_server ['id' ])
2255+ # Boot a server to cell0 (cause ERROR state prior to schedule)
2256+ server = self ._build_server ()
2257+ # Flavor m1.xlarge cannot be fulfilled
2258+ server ['flavorRef' ] = 'http://fake.server/5'
2259+ created_server = self .api .post_server ({'server' : server })
2260+ self ._wait_for_state_change (created_server , 'ERROR' )
2261+ server_ids_by_cell ['cell0' ].append (created_server ['id' ])
2262+
22592263 # Verify all the servers are in the databases
2260- for cell_name , server_id in server_ids .items ():
2261- with context .target_cell (admin_context ,
2262- self .cell_mappings [cell_name ]) as cctxt :
2263- objects .Instance .get_by_uuid (cctxt , server_id )
2264+ for cell_name , server_ids in server_ids_by_cell .items ():
2265+ for server_id in server_ids :
2266+ with context .target_cell (
2267+ admin_context ,
2268+ self .cell_mappings [cell_name ]
2269+ ) as cctxt :
2270+ objects .Instance .get_by_uuid (cctxt , server_id )
22642271 # Delete the servers
2265- for cell_name in server_ids .keys ():
2266- self .api .delete_server (server_ids [cell_name ])
2272+ for cell_name , server_ids in server_ids_by_cell .items ():
2273+ for server_id in server_ids :
2274+ self .api .delete_server (server_id )
22672275 # Verify all the servers are in the databases still (as soft deleted)
2268- for cell_name , server_id in server_ids .items ():
2269- with context .target_cell (admin_context ,
2270- self .cell_mappings [cell_name ]) as cctxt :
2271- objects .Instance .get_by_uuid (cctxt , server_id )
2276+ for cell_name , server_ids in server_ids_by_cell .items ():
2277+ for server_id in server_ids :
2278+ with context .target_cell (
2279+ admin_context ,
2280+ self .cell_mappings [cell_name ]
2281+ ) as cctxt :
2282+ objects .Instance .get_by_uuid (cctxt , server_id )
22722283 # Archive the deleted rows
22732284 self .cli .archive_deleted_rows (verbose = True , all_cells = True )
2274- # Three instances should have been archived (cell0, cell1, cell2)
2285+ # 6 instances should have been archived (cell0, cell1, cell2)
22752286 self .assertRegex (self .output .getvalue (),
2276- r"| cell0\.instances.*\| 1.* " )
2287+ r"\ | cell0\.instances\s+\| 2 " )
22772288 self .assertRegex (self .output .getvalue (),
2278- r"| cell1\.instances.*\| 1.* " )
2289+ r"\ | cell1\.instances\s+\| 2 " )
22792290 self .assertRegex (self .output .getvalue (),
2280- r"| cell2\.instances.*\| 1.* " )
2291+ r"\ | cell2\.instances\s+\| 2 " )
22812292 self .assertRegex (self .output .getvalue (),
2282- r"| API_DB\.instance_mappings.*\| 3.* " )
2293+ r"\ | API_DB\.instance_mappings\s+\| 6 " )
22832294 self .assertRegex (self .output .getvalue (),
2284- r"| API_DB\.request_specs.*\| 3.* " )
2295+ r"\ | API_DB\.request_specs\s+\| 6 " )
22852296 # Verify all the servers are gone from the cell databases
2286- for cell_name , server_id in server_ids .items ():
2287- with context .target_cell (admin_context ,
2288- self .cell_mappings [cell_name ]) as cctxt :
2289- self .assertRaises (exception .InstanceNotFound ,
2290- objects .Instance .get_by_uuid ,
2291- cctxt , server_id )
2297+ for cell_name , server_ids in server_ids_by_cell .items ():
2298+ for server_id in server_ids :
2299+ with context .target_cell (
2300+ admin_context ,
2301+ self .cell_mappings [cell_name ]
2302+ ) as cctxt :
2303+ self .assertRaises (exception .InstanceNotFound ,
2304+ objects .Instance .get_by_uuid ,
2305+ cctxt , server_id )
22922306
22932307
22942308class TestDBArchiveDeletedRowsMultiCellTaskLog (
0 commit comments