def create_repository(session): ''' Create some Repository to play with for the tests ''' item = model.Repository( name='pub/fedora/linux/updates/testing/25/x86_64', prefix='updates-testing-f25', category_id=1, version_id=5, arch_id=3, directory_id=7, disabled=True ) session.add(item) item = model.Repository( name='pub/fedora/linux/updates/testing/26/x86_64', prefix='updates-testing-f26', category_id=1, version_id=1, arch_id=3, directory_id=8, disabled=False ) session.add(item) item = model.Repository( name='pub/fedora/linux/updates/testing/27/x86_64', prefix='updates-testing-f27', category_id=1, version_id=3, arch_id=3, directory_id=9, disabled=False ) session.add(item) session.commit()
def test_mdtr(self): """ Test the mdtr script. """ command = self.command[:] # Fill the DB a little bit tests.create_base_items(self.session) tests.create_directory(self.session) tests.create_category(self.session) tests.create_categorydirectory(self.session) tests.create_version(self.session) item = model.Directory( name='pub/fedora/linux/releases/26/Everything/x86_64/os', readable=True, ) self.session.add(item) item = model.Directory( name='pub/fedora/linux/releases/26/Everything/armhfp/os', readable=True, ) self.session.add(item) item = model.Directory( name='pub/fedora-secondary/releases/26/Everything/ppc64le/os', readable=True, ) self.session.add(item) item = model.Directory( name='pub/fedora-secondary/releases/26/Everything/sources/os', readable=True, ) self.session.add(item) item = model.Directory( name='pub/fedora/linux/development/27/Everything/x86_64/os', readable=True, ) self.session.add(item) item = model.Directory( name='pub/fedora/linux/releases/27/Everything/x86_64/os', readable=True, ) self.session.add(item) item = model.Repository( name='pub/fedora/linux/development/27/Everything/x86_64/os', prefix='fedora-27', version_id=3, arch_id=3, directory_id=14, category_id=1, ) self.session.add(item) item = model.Repository( name='pub/fedora/linux/releases/26/Everything/x86_64/os', prefix=None, version_id=1, arch_id=3, directory_id=10, category_id=1, ) self.session.add(item) item = model.Category( name='Fedora Secondary Arches', product_id=2, canonicalhost='http://download.fedora.redhat.com', topdir_id=1, publiclist=True) self.session.add(item) self.session.commit() # Check before running the script results = mirrormanager2.lib.get_repositories(self.session) self.assertEqual(len(results), 2) results = mirrormanager2.lib.get_directories(self.session) # create_directory creates 9 directories # we create 6 more here, 9+6=15 self.assertEqual(len(results), 15) self.assertEqual(results[9].name, 'pub/fedora/linux/releases/26/Everything/x86_64/os') self.assertEqual(results[10].name, 'pub/fedora/linux/releases/26/Everything/armhfp/os') self.assertEqual( results[11].name, 'pub/fedora-secondary/releases/26/Everything/ppc64le/os') self.assertEqual( results[12].name, 'pub/fedora-secondary/releases/26/Everything/sources/os') self.assertEqual( results[13].name, 'pub/fedora/linux/development/27/Everything/x86_64/os') self.assertEqual(results[14].name, 'pub/fedora/linux/releases/27/Everything/x86_64/os') # Run the script process = subprocess.Popen(args=command[:], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) stdout, stderr = process.communicate() self.assertEqual( stdout, 'pub/fedora/linux/development/27/Everything/x86_64/os ' '=> pub/fedora/linux/releases/27/Everything/x86_64/os\n') self.assertEqual(stderr, '') # Check after running the script results = mirrormanager2.lib.get_repositories(self.session) self.assertEqual(len(results), 2) res = results[0] self.assertEqual(res.prefix, 'fedora-27') self.assertEqual(res.name, 'pub/fedora/linux/releases/27/Everything/x86_64/os') self.assertEqual(res.category.name, 'Fedora Linux') self.assertEqual(res.version.name, '27') self.assertEqual(res.arch.name, 'x86_64') self.assertEqual(res.directory.name, 'pub/fedora/linux/releases/27/Everything/x86_64/os') res = results[1] self.assertEqual(res.prefix, None) self.assertEqual(res.name, 'pub/fedora/linux/releases/26/Everything/x86_64/os') self.assertEqual(res.category.name, 'Fedora Linux') self.assertEqual(res.version.name, '26') self.assertEqual(res.arch.name, 'x86_64') self.assertEqual(res.directory.name, 'pub/fedora/linux/releases/26/Everything/x86_64/os') results = mirrormanager2.lib.get_directories(self.session) # create_directory creates 9 directories # we create 6 more here, 9+6=15 self.assertEqual(len(results), 15) self.assertEqual(results[9].name, 'pub/fedora/linux/releases/26/Everything/x86_64/os') self.assertEqual(results[10].name, 'pub/fedora/linux/releases/26/Everything/armhfp/os') self.assertEqual( results[11].name, 'pub/fedora-secondary/releases/26/Everything/ppc64le/os') self.assertEqual( results[12].name, 'pub/fedora-secondary/releases/26/Everything/sources/os') self.assertEqual( results[13].name, 'pub/fedora/linux/development/27/Everything/x86_64/os') self.assertEqual(results[14].name, 'pub/fedora/linux/releases/27/Everything/x86_64/os') # Check non-existing version command = ('%s -c %s --version=24 ' '--category=' % (self.script, self.configfile)).split() command[-1] += 'Fedora Linux' process = subprocess.Popen(args=command[:], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) stdout, stderr = process.communicate() self.assertEqual(stdout, 'Version 24 not found for product Fedora\n') self.assertEqual(stderr, '') # Check after running the script results = mirrormanager2.lib.get_repositories(self.session) self.assertEqual(len(results), 2) res = results[0] self.assertEqual(res.prefix, 'fedora-27') self.assertEqual(res.name, 'pub/fedora/linux/releases/27/Everything/x86_64/os') self.assertEqual(res.category.name, 'Fedora Linux') self.assertEqual(res.version.name, '27') self.assertEqual(res.arch.name, 'x86_64') self.assertEqual(res.directory.name, 'pub/fedora/linux/releases/27/Everything/x86_64/os') res = results[1] self.assertEqual(res.prefix, None) self.assertEqual(res.name, 'pub/fedora/linux/releases/26/Everything/x86_64/os') self.assertEqual(res.category.name, 'Fedora Linux') self.assertEqual(res.version.name, '26') self.assertEqual(res.arch.name, 'x86_64') self.assertEqual(res.directory.name, 'pub/fedora/linux/releases/26/Everything/x86_64/os') results = mirrormanager2.lib.get_directories(self.session) # create_directory creates 9 directories # we create 6 more here, 9+6=15 self.assertEqual(len(results), 15) self.assertEqual(results[9].name, 'pub/fedora/linux/releases/26/Everything/x86_64/os') self.assertEqual(results[10].name, 'pub/fedora/linux/releases/26/Everything/armhfp/os') self.assertEqual( results[11].name, 'pub/fedora-secondary/releases/26/Everything/ppc64le/os') self.assertEqual( results[12].name, 'pub/fedora-secondary/releases/26/Everything/sources/os') self.assertEqual( results[13].name, 'pub/fedora/linux/development/27/Everything/x86_64/os') self.assertEqual(results[14].name, 'pub/fedora/linux/releases/27/Everything/x86_64/os')
def test_mdtr(self): """ Test the mdtr script. """ command = self.command[:] # Fill the DB a little bit tests.create_base_items(self.session) tests.create_directory(self.session) tests.create_category(self.session) tests.create_categorydirectory(self.session) tests.create_version(self.session) item = model.Directory( name='pub/fedora/linux/releases/20/Fedora/x86_64/os', readable=True, ) self.session.add(item) item = model.Directory( name='pub/fedora/linux/releases/20/Fedora/i386/os', readable=True, ) self.session.add(item) item = model.Directory( name='pub/fedora-secondary/releases/20/Fedora/ppc/os', readable=True, ) self.session.add(item) item = model.Directory( name='pub/fedora-secondary/releases/20/Fedora/sources/os', readable=True, ) self.session.add(item) item = model.Directory( name='pub/fedora/linux/development/21/x86_64/os', readable=True, ) self.session.add(item) item = model.Directory( name='pub/fedora/linux/releases/21/Fedora/x86_64/os', readable=True, ) self.session.add(item) item = model.Directory( name='pub/fedora/linux/releases/21/Everything/x86_64/os', readable=True, ) self.session.add(item) item = model.Repository( name='pub/fedora/linux/development/21/x86_64/os', prefix='fedora-21', version_id=3, arch_id=3, directory_id=14, category_id=1, ) self.session.add(item) item = model.Repository( name='pub/fedora/linux/releases/21/Everything/x86_64/os', prefix=None, version_id=3, arch_id=3, directory_id=16, category_id=1, ) self.session.add(item) item = model.Category( name='Fedora Secondary Arches', product_id=2, canonicalhost='http://download.fedora.redhat.com', topdir_id=1, publiclist=True ) self.session.add(item) self.session.commit() # Check before running the script results = mirrormanager2.lib.get_repositories(self.session) self.assertEqual(len(results), 2) results = mirrormanager2.lib.get_directories(self.session) # create_directory creates 9 directories # we create 7 more here, 9+7=16 self.assertEqual(len(results), 16) self.assertEqual( results[9].name, 'pub/fedora/linux/releases/20/Fedora/x86_64/os') self.assertEqual( results[10].name, 'pub/fedora/linux/releases/20/Fedora/i386/os') self.assertEqual( results[11].name, 'pub/fedora-secondary/releases/20/Fedora/ppc/os') self.assertEqual( results[12].name, 'pub/fedora-secondary/releases/20/Fedora/sources/os') self.assertEqual( results[13].name, 'pub/fedora/linux/development/21/x86_64/os') self.assertEqual( results[14].name, 'pub/fedora/linux/releases/21/Fedora/x86_64/os') self.assertEqual( results[15].name, 'pub/fedora/linux/releases/21/Everything/x86_64/os') # Run the script process = subprocess.Popen( args=command[:] + ['--test'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = process.communicate() self.assertEqual( stdout, 'updating fedora-install-20 repo for arch i386\n' 'updating fedora-install-20 repo for arch ppc\n' 'updating fedora-install-20 repo for arch x86_64\n' ) self.assertEqual(stderr, '') # Check after running the script results = mirrormanager2.lib.get_repositories(self.session) self.assertEqual(len(results), 5) res = results[0] self.assertEqual(res.prefix, 'fedora-21') self.assertEqual( res.name, 'pub/fedora/linux/development/21/x86_64/os') self.assertEqual(res.category.name, 'Fedora Linux') self.assertEqual(res.version.name, '21') self.assertEqual(res.arch.name, 'x86_64') self.assertEqual( res.directory.name, 'pub/fedora/linux/development/21/x86_64/os') res = results[1] self.assertEqual(res.prefix, None) self.assertEqual( res.name, 'pub/fedora/linux/releases/21/Everything/x86_64/os') self.assertEqual(res.category.name, 'Fedora Linux') self.assertEqual(res.version.name, '21') self.assertEqual(res.arch.name, 'x86_64') self.assertEqual( res.directory.name, 'pub/fedora/linux/releases/21/Everything/x86_64/os') res = results[2] self.assertEqual(res.prefix, 'fedora-install-20') self.assertEqual( res.name, 'pub/fedora/linux/releases/20/Fedora/i386/os') self.assertEqual(res.category.name, 'Fedora Linux') self.assertEqual(res.version.name, '20') self.assertEqual(res.arch.name, 'i386') self.assertEqual( res.directory.name, 'pub/fedora/linux/releases/20/Fedora/i386/os') res = results[3] self.assertEqual(res.prefix, 'fedora-install-20') self.assertEqual( res.name, 'pub/fedora-secondary/releases/20/Fedora/ppc/os') self.assertEqual(res.category.name, 'Fedora Secondary Arches') self.assertEqual(res.version.name, '20') self.assertEqual(res.arch.name, 'ppc') self.assertEqual( res.directory.name, 'pub/fedora-secondary/releases/20/Fedora/ppc/os') res = results[4] self.assertEqual(res.prefix, 'fedora-install-20') self.assertEqual( res.name, 'pub/fedora/linux/releases/20/Fedora/x86_64/os') self.assertEqual(res.category.name, 'Fedora Linux') self.assertEqual(res.version.name, '20') self.assertEqual(res.arch.name, 'x86_64') self.assertEqual( res.directory.name, 'pub/fedora/linux/releases/20/Fedora/x86_64/os') results = mirrormanager2.lib.get_directories(self.session) # create_directory creates 9 directories # we create 7 more here, 9+7=16 self.assertEqual(len(results), 16) self.assertEqual( results[9].name, 'pub/fedora/linux/releases/20/Fedora/x86_64/os') self.assertEqual( results[10].name, 'pub/fedora/linux/releases/20/Fedora/i386/os') self.assertEqual( results[11].name, 'pub/fedora-secondary/releases/20/Fedora/ppc/os') self.assertEqual( results[12].name, 'pub/fedora-secondary/releases/20/Fedora/sources/os') self.assertEqual( results[13].name, 'pub/fedora/linux/development/21/x86_64/os') self.assertEqual( results[14].name, 'pub/fedora/linux/releases/21/Fedora/x86_64/os') self.assertEqual( results[15].name, 'pub/fedora/linux/releases/21/Everything/x86_64/os') # Update F21 command = ('%s -c %s --version=21 '\ '--category=' % (self.script, self.configfile)).split() command[-1] += 'Fedora Linux' process = subprocess.Popen( args=command[:] + ['--test'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = process.communicate() print stdout self.assertEqual( stdout, 'pub/fedora/linux/development/21/x86_64/os => ' 'pub/fedora/linux/releases/21/Everything/x86_64/os\n' 'directory pub/fedora/linux/releases/21/Fedora/i386/os exists ' 'on disk, but not in the database yet, skipping creation of a ' 'repository there until after the next UMDL run.\n' 'directory pub/fedora-secondary/releases/21/Fedora/ppc/os exists ' 'on disk, but not in the database yet, skipping creation of a ' 'repository there until after the next UMDL run.\n' 'updating fedora-install-21 repo for arch x86_64\n' ) self.assertEqual(stderr, '') # Check after running the script results = mirrormanager2.lib.get_repositories(self.session) self.assertEqual(len(results), 6) res = results[0] self.assertEqual(res.prefix, 'fedora-21') self.assertEqual( res.name, 'pub/fedora/linux/development/21/x86_64/os') self.assertEqual(res.category.name, 'Fedora Linux') self.assertEqual(res.version.name, '21') self.assertEqual(res.arch, None) self.assertEqual( res.directory.name, 'pub/fedora/linux/development/21/x86_64/os') res = results[1] self.assertEqual(res.prefix, 'fedora-21') self.assertEqual( res.name, 'pub/fedora/linux/releases/21/Everything/x86_64/os') self.assertEqual(res.category.name, 'Fedora Linux') self.assertEqual(res.version.name, '21') self.assertEqual(res.arch.name, 'x86_64') self.assertEqual( res.directory.name, 'pub/fedora/linux/releases/21/Everything/x86_64/os') res = results[2] self.assertEqual(res.prefix, 'fedora-install-20') self.assertEqual( res.name, 'pub/fedora/linux/releases/20/Fedora/i386/os') self.assertEqual(res.category.name, 'Fedora Linux') self.assertEqual(res.version.name, '20') self.assertEqual(res.arch.name, 'i386') self.assertEqual( res.directory.name, 'pub/fedora/linux/releases/20/Fedora/i386/os') res = results[3] self.assertEqual(res.prefix, 'fedora-install-20') self.assertEqual( res.name, 'pub/fedora-secondary/releases/20/Fedora/ppc/os') self.assertEqual(res.category.name, 'Fedora Secondary Arches') self.assertEqual(res.version.name, '20') self.assertEqual(res.arch.name, 'ppc') self.assertEqual( res.directory.name, 'pub/fedora-secondary/releases/20/Fedora/ppc/os') res = results[4] self.assertEqual(res.prefix, 'fedora-install-20') self.assertEqual( res.name, 'pub/fedora/linux/releases/20/Fedora/x86_64/os') self.assertEqual(res.category.name, 'Fedora Linux') self.assertEqual(res.version.name, '20') self.assertEqual(res.arch.name, 'x86_64') self.assertEqual( res.directory.name, 'pub/fedora/linux/releases/20/Fedora/x86_64/os') res = results[5] self.assertEqual(res.prefix, 'fedora-install-21') self.assertEqual( res.name, 'pub/fedora/linux/releases/21/Fedora/x86_64/os') self.assertEqual(res.category.name, 'Fedora Linux') self.assertEqual(res.version.name, '21') self.assertEqual(res.arch.name, 'x86_64') self.assertEqual( res.directory.name, 'pub/fedora/linux/releases/21/Fedora/x86_64/os') results = mirrormanager2.lib.get_directories(self.session) # create_directory creates 9 directories # we create 7 more here, 9+7=16 self.assertEqual(len(results), 16) self.assertEqual( results[9].name, 'pub/fedora/linux/releases/20/Fedora/x86_64/os') self.assertEqual( results[10].name, 'pub/fedora/linux/releases/20/Fedora/i386/os') self.assertEqual( results[11].name, 'pub/fedora-secondary/releases/20/Fedora/ppc/os') self.assertEqual( results[12].name, 'pub/fedora-secondary/releases/20/Fedora/sources/os') self.assertEqual( results[13].name, 'pub/fedora/linux/development/21/x86_64/os') self.assertEqual( results[14].name, 'pub/fedora/linux/releases/21/Fedora/x86_64/os') self.assertEqual( results[15].name, 'pub/fedora/linux/releases/21/Everything/x86_64/os')