def destroy(self, skip=True):
        if skip:
            # We can skip in most cases since the nodes themselves will be
            # destroyed instead.
            return

        if settings.as_bool('_TEAR_DOWN_CLUSTER_CONFIRM'):
            common.handle_cleanup_input("pause before cleanup kubernetes")

        # TODO(jhesketh): Uninstall kubernetes
        logger.info(f"kube destroy on hardware {self.hardware}")
        pass
Esempio n. 2
0
    def destroy(self, skip=False):
        if settings.as_bool('_TEAR_DOWN_CLUSTER_CONFIRM'):
            handle_cleanup_input("pause before cleanup workspace")

        # This kills the SSH_AGENT_PID agent
        try:
            self.execute('ssh-agent -k', check=True)
        except subprocess.CalledProcessError:
            logger.warning(f'Killing ssh-agent with PID'
                           f' {self._ssh_agent_pid} failed')

        if skip:
            logger.warning("The workspace directory will not be removed!")
            logger.warning(f"Workspace left behind at {self.working_dir}")
            return

        if settings.as_bool('_REMOVE_WORKSPACE'):
            logger.info(f"Removing workspace {self.working_dir} from disk")
            # NOTE(jhesketh): go clones repos as read-only. We need to chmod
            #                 all the files back to writable (in particular,
            #                 the directories) so that we can remove them
            #                 without failures or warnings.
            for root, dirs, files in os.walk(self.working_dir):
                for folder in dirs:
                    path = os.path.join(root, folder)
                    try:
                        os.chmod(path, os.stat(path).st_mode | stat.S_IWUSR)
                    except (FileNotFoundError, PermissionError):
                        # Some path's might be broken symlinks.
                        # Some files may be owned by somebody else (eg qemu)
                        # but are still safe to remove so ignore the
                        # permissions issue.
                        pass
                for f in files:
                    path = os.path.join(root, f)
                    try:
                        os.chmod(path, os.stat(path).st_mode | stat.S_IWUSR)
                    except (FileNotFoundError, PermissionError):
                        # Some path's might be broken symlinks.
                        # Some files may be owned by somebody else (eg qemu)
                        # but are still safe to remove so ignore the
                        # permissions issue.
                        pass
            shutil.rmtree(self.working_dir)
        else:
            logger.info(f"Keeping workspace on disk at {self.working_dir}")
Esempio n. 3
0
    def destroy(self, skip=False):
        if skip:
            logger.warning("Hardware will not be removed!")
            logger.warning("The following nodes and their associated resources"
                           " (such as IP's and volumes) will remain:")
            for n in self.nodes.values():
                logger.warning(f"Leaving node {n.name} at ip {n.get_ssh_ip()}")
                logger.warning(f".. with volumes {n._disks}")
                # TODO(jhesketh): Neaten up how disks are handled
            return

        if settings.as_bool('_TEAR_DOWN_CLUSTER_CONFIRM'):
            handle_cleanup_input("pause before cleanup hardware")

        logger.info("Remove all nodes from Hardware")
        for n in list(self.nodes):
            self.node_remove(self.nodes[n])