def test_restore_state_on_new_distro_release_livecd(self, mock_lowlevel): """ test lucid -> maverick apt-clone-ugprade as if it will be used from a live cd based upgrader """ # setup mock for dpkg -i mock_lowlevel.install_debs.return_value = True # create target dir targetdir = self.tempdir # status file from maverick (to simulate running on a maverick live-cd) with open("./data/dpkg-status/dpkg-status-ubuntu-maverick", "rb") as fp: s = fp.read().decode("utf8") s = s.replace( "Architecture: i386", "Architecture: %s" % apt_pkg.config.find("Apt::Architecture")) path = os.path.join(targetdir, "var/lib/dpkg", "status") with open(path, "wb",) as fp: fp.write(s.encode("utf-8")) # test upgrade clone from lucid system to maverick clone = AptClone(cache_cls=MockAptCache) clone.restore_state( "./data/apt-state-ubuntu-lucid.tar.gz", targetdir, new_distro="maverick") sources_list = os.path.join(targetdir, "etc","apt","sources.list") self.assertTrue(os.path.exists(sources_list)) with open(sources_list) as fp: self.assertTrue("maverick" in fp.read()) with open(sources_list) as fp: self.assertFalse("lucid" in fp.read())
def test_restore_state_on_new_distro_release_livecd(self, mock_lowlevel): """ test lucid -> maverick apt-clone-ugprade as if it will be used from a live cd based upgrader """ # setup mock for dpkg -i mock_lowlevel.install_debs.return_value = True # create target dir targetdir = self.tempdir # status file from maverick (to simulate running on a maverick live-cd) with open("./data/dpkg-status/dpkg-status-ubuntu-maverick", "rb") as fp: s = fp.read().decode("utf8") s = s.replace( "Architecture: i386", "Architecture: %s" % apt_pkg.config.find("Apt::Architecture")) path = os.path.join(targetdir, "var/lib/dpkg", "status") with open( path, "wb", ) as fp: fp.write(s.encode("utf-8")) # test upgrade clone from lucid system to maverick clone = AptClone(cache_cls=MockAptCache) clone.restore_state("./data/apt-state-ubuntu-lucid.tar.gz", targetdir, new_distro="maverick") sources_list = os.path.join(targetdir, "etc", "apt", "sources.list") self.assertTrue(os.path.exists(sources_list)) with open(sources_list) as fp: self.assertTrue("maverick" in fp.read()) with open(sources_list) as fp: self.assertFalse("lucid" in fp.read())
def test_restore_state(self, mock_lowlevel): # setup mock mock_lowlevel.install_debs.return_value = True targetdir = self.tempdir # test clone = AptClone(cache_cls=MockAptCache) clone.restore_state( "./data/apt-state_chroot_with_vim.tar.gz", targetdir) self.assertTrue( os.path.exists(os.path.join(targetdir, "etc","apt","sources.list")))
def test_restore_state_with_not_downloadable_debs(self, mock_lowlevel): # setup mock mock_lowlevel.install_debs.return_value = True targetdir = self.tempdir # test clone = AptClone(cache_cls=MockAptCache) clone.restore_state( "./data/apt-state_with_not_downloadable_debs.tar.gz", targetdir) self.assertTrue( os.path.exists( os.path.join(targetdir, "var", "lib", "apt-clone", "debs", "foo.deb")))
def test_restore_state(self, mock_lowlevel): # setup mock mock_lowlevel.install_debs.return_value = True targetdir = self.tempdir # test clone = AptClone(cache_cls=MockAptCache) clone.restore_state("./data/apt-state_chroot_with_vim.tar.gz", targetdir) self.assertTrue( os.path.exists( os.path.join(targetdir, "etc", "apt", "sources.list")))
def test_real(self): if os.getuid() != 0: print("Skipping because uid != 0") return # do it target = "./test-chroot" if not os.path.exists(target): os.mkdir(target) subprocess.call(["debootstrap", "--arch=i386", "maverick", target]) # force i386 with open(os.path.join(target, "etc/apt/apt.conf"), "w") as fp: fp.write('APT::Architecture "i386";') # restore clone = AptClone() clone.restore_state( "./data/apt-state_chroot_with_vim.tar.gz", target, "maverick")