def test__doesnt_move_paths_with_more_levels_into_ubuntu_dir(self): storage_dir = self.make_dir() self.configure_storage(storage_dir) # Extra directory level, this is what it looks like after upgrade. osystems = [factory.make_name('arch') for _ in range(3)] arches = [factory.make_name('arch') for _ in range(3)] subarches = [factory.make_name('subarch') for _ in range(3)] releases = [factory.make_name('release') for _ in range(3)] labels = [factory.make_name('label') for _ in range(3)] for osystem, arch, subarch, release, label in product( osystems, arches, subarches, releases, labels): os.makedirs( os.path.join(storage_dir, 'current', osystem, arch, subarch, release, label)) move_arch = factory.make_name('arch') os.makedirs( os.path.join(storage_dir, 'current', move_arch, factory.make_name('subarch'), factory.make_name('release'), factory.make_name('label'))) self.patch(upgrade_cluster, 'update_targets_conf') upgrade_cluster.migrate_architectures_into_ubuntu_directory() self.assertItemsEqual([move_arch], list_subdirs( os.path.join(storage_dir, 'current', 'ubuntu')))
def test_doesnt_move_paths_with_fewer_levels_into_ubuntu_dir(self): storage_dir = self.make_dir() self.configure_storage(storage_dir) arches = [factory.make_name("arch") for _ in range(3)] subarches = [factory.make_name("subarch") for _ in range(3)] releases = [factory.make_name("release") for _ in range(3)] # Labels directory is missing, causing none of the folders to move for arch, subarch, release in product(arches, subarches, releases): os.makedirs( os.path.join(storage_dir, "current", arch, subarch, release) ) move_arch = factory.make_name("arch") os.makedirs( os.path.join( storage_dir, "current", move_arch, factory.make_name("subarch"), factory.make_name("release"), factory.make_name("label"), ) ) self.patch(upgrade_cluster, "update_targets_conf") upgrade_cluster.migrate_architectures_into_ubuntu_directory( self.current_dir ) self.assertItemsEqual( [move_arch], list_subdirs(os.path.join(storage_dir, "current", "ubuntu")), )
def test_doesnt_create_ubuntu_dir_when_no_valid_directories(self): storage_dir = self.make_dir() self.configure_storage(storage_dir) upgrade_cluster.migrate_architectures_into_ubuntu_directory( self.current_dir) self.assertFalse( os.path.exists(os.path.join(storage_dir, "current", "ubuntu")))
def test__calls_update_targets_conf_with_current_dir(self): storage_dir = self.setup_working_migration_scenario() mock_update = self.patch(upgrade_cluster, 'update_targets_conf') upgrade_cluster.migrate_architectures_into_ubuntu_directory() self.assertThat( mock_update, MockCalledOnceWith(os.path.join(storage_dir, 'current')))
def test__exits_early_if_current_dir_does_not_exist(self): # Patch list_subdirs, if it gets called then the method did not # exit early. self.patch(upgrade_cluster, 'list_subdirs') storage_dir = self.make_dir() self.configure_storage(storage_dir, make_current_dir=False) upgrade_cluster.migrate_architectures_into_ubuntu_directory() self.assertThat(upgrade_cluster.list_subdirs, MockNotCalled())
def test__list_subdirs_under_current_directory(self): self.patch(upgrade_cluster, 'list_subdirs').return_value = ['ubuntu'] storage_dir = self.make_dir() self.configure_storage(storage_dir) upgrade_cluster.migrate_architectures_into_ubuntu_directory() self.assertThat( upgrade_cluster.list_subdirs, MockCalledOnceWith(os.path.join(storage_dir, "current")))
def test__exits_early_if_ubuntu_dir_exist(self): # Patch drill_down, if it gets called then the method did not # exit early. self.patch(upgrade_cluster, 'drill_down') storage_dir = self.make_dir() self.configure_storage(storage_dir) os.mkdir(os.path.join(storage_dir, 'current', 'ubuntu')) upgrade_cluster.migrate_architectures_into_ubuntu_directory() self.assertThat(upgrade_cluster.drill_down, MockNotCalled())
def test_exits_early_if_boot_resources_dir_does_not_exist(self): # Patch list_subdirs, if it gets called then the method did not # exit early. self.patch(upgrade_cluster, "list_subdirs") storage_dir = os.path.join(self.make_dir(), factory.make_name("none")) self.configure_storage(storage_dir, make_current_dir=False) upgrade_cluster.migrate_architectures_into_ubuntu_directory( self.current_dir) self.assertThat(upgrade_cluster.list_subdirs, MockNotCalled())
def test__moves_paths_with_correct_levels_into_ubuntu_dir(self): storage_dir = self.make_dir() self.configure_storage(storage_dir) arches = [factory.make_name('arch') for _ in range(3)] subarches = [factory.make_name('subarch') for _ in range(3)] releases = [factory.make_name('release') for _ in range(3)] labels = [factory.make_name('label') for _ in range(3)] for arch, subarch, release, label in product(arches, subarches, releases, labels): os.makedirs( os.path.join(storage_dir, 'current', arch, subarch, release, label)) self.patch(upgrade_cluster, 'update_targets_conf') upgrade_cluster.migrate_architectures_into_ubuntu_directory() self.assertItemsEqual( arches, list_subdirs(os.path.join(storage_dir, 'current', 'ubuntu')))
def test_moves_paths_with_correct_levels_into_ubuntu_dir(self): storage_dir = self.make_dir() self.configure_storage(storage_dir) arches = [factory.make_name("arch") for _ in range(3)] subarches = [factory.make_name("subarch") for _ in range(3)] releases = [factory.make_name("release") for _ in range(3)] labels = [factory.make_name("label") for _ in range(3)] for arch, subarch, release, label in product(arches, subarches, releases, labels): os.makedirs( os.path.join(storage_dir, "current", arch, subarch, release, label)) self.patch(upgrade_cluster, "update_targets_conf") upgrade_cluster.migrate_architectures_into_ubuntu_directory( self.current_dir) self.assertItemsEqual( arches, list_subdirs(os.path.join(storage_dir, "current", "ubuntu")), )