def test_link(self): Storage().link_home(self.storage_dir) self.assertTrue(os.path.islink(paths.HOME)) self.assertEqual(os.path.realpath(paths.HOME), self.storage_dir) self.assertThat(paths.HOME, HasOwnership(123, 123)) # Second run paths.HOME is a link Storage().link_home(self.storage_dir) self.assertTrue(os.path.islink(paths.HOME)) self.assertEqual(os.path.realpath(paths.HOME), self.storage_dir) self.assertThat(paths.HOME, HasOwnership(123, 123))
def test_unlink(self): with open(os.path.join(self.storage_dir, "touched"), 'w') as f: f.write("touched") Storage().link_home(self.storage_dir) Storage().unlink_home() self.assertFalse(os.path.islink(paths.HOME)) self.assertThat(paths.HOME, HasOwnership(123, 123)) # Second run is a no-op Storage().unlink_home() self.assertFalse(os.path.islink(paths.HOME)) self.assertThat(paths.HOME, HasOwnership(123, 123))
def set_jenkins_dir(storage_dir=paths.HOME): status_set("maintenance", "Configuring Jenkins storage") jenkins_installed = get_state("apt.installed.jenkins") if jenkins_installed: service_stop('jenkins') if storage_dir is paths.HOME: log("Setting Jenkins to use local storage") Storage().unlink_home() else: log("Setting Jenkins to use storage at {}".format(storage_dir)) Storage().link_home(storage_dir) if jenkins_installed: status_set("maintenance", "Restarting Jenkins") service_start('jenkins') Service().check_ready() if get_state('jenkins.bootstrapped'): # JENKINS_HOME just changed trigger bootstrap again remove_state("jenkins.bootstrapped") bootstrap_jenkins() else: status_set('active', 'Ready')
def test_unlink_no_backup(self): Storage().link_home(self.storage_dir) Storage().unlink_home() self.assertFalse(os.path.islink(paths.HOME)) self.assertThat(paths.HOME, HasOwnership(123, 123))
def test_link_existing_backup(self): with open(os.path.join(self.storage_dir, "touched"), 'w') as f: f.write("touched") os.mkdir(Storage()._backup_dir) self.assertRaises(RuntimeError, lambda: Storage().link_home(self.storage_dir))