Ejemplo n.º 1
0
 def _create_repo(self, repo_name):
     repo_dir = sh.joinpths(self.anvil_repo_dir, repo_name)
     src_repo_dir = sh.joinpths(self.anvil_repo_dir, self.SRC_REPOS[repo_name])
     for a_dir in (repo_dir, src_repo_dir):
         if not sh.isdir(a_dir):
             sh.mkdirslist(a_dir, tracewriter=self.tracewriter)
         cmdline = ["createrepo", a_dir]
         LOG.info("Creating repo at %s", a_dir)
         sh.execute(cmdline)
     repo_filename = sh.joinpths(self.anvil_repo_dir, "%s.repo" % repo_name)
     LOG.info("Writing %s", repo_filename)
     (_fn, content) = utils.load_template("packaging", "common.repo")
     params = {
         "repo_name": repo_name,
         "baseurl_bin": "file://%s" % repo_dir,
         "baseurl_src": "file://%s" % src_repo_dir,
     }
     sh.write_file(repo_filename, utils.expand_template(content, params),
                   tracewriter=self.tracewriter)
     # Install *.repo file so that anvil deps will be available
     # when building OpenStack
     system_repo_filename = sh.joinpths(self.YUM_REPO_DIR, "%s.repo" % repo_name)
     sh.copy(repo_filename, system_repo_filename)
     LOG.info("Copying to %s", system_repo_filename)
     self.tracewriter.file_touched(system_repo_filename)
Ejemplo n.º 2
0
 def run_tests(self):
     app_dir = self.get_option('app_dir')
     if not sh.isdir(app_dir):
         LOG.warn("Unable to find application directory at %s, can not run %s tests.",
                  colorizer.quote(app_dir), colorizer.quote(self.name))
         return
     pre_cmd = self._get_pre_test_command()
     cmd = self._get_test_command()
     if not cmd:
         LOG.warn("Unable to determine test command for %s, can not run tests.",
                  colorizer.quote(self.name))
         return
     env = self._get_env()
     try:
         if pre_cmd:
             LOG.info("Running test setup via: %s",
                      utils.truncate_text(" ".join(pre_cmd), 80))
             sh.execute(pre_cmd, stdout_fh=sys.stdout, stderr_fh=sys.stdout,
                        cwd=app_dir, env_overrides=env)
         LOG.info("Running tests via: %s",
                  utils.truncate_text(" ".join(cmd), 80))
         sh.execute(cmd, stdout_fh=sys.stdout, stderr_fh=sys.stdout,
                    cwd=app_dir, env_overrides=env)
     except excp.ProcessExecutionError as e:
         if self.ignore_test_failures:
             LOG.warn("Ignoring test failure of component %s: %s", colorizer.quote(self.name), e)
         else:
             raise
Ejemplo n.º 3
0
 def stop(self):
     if self.status()[0].status != comp.STATUS_STOPPED:
         stop_cmd = self.distro.get_command('apache', 'stop')
         sh.execute(*stop_cmd, run_as_root=True, check_exit_code=True)
         return 1
     else:
         return 0
Ejemplo n.º 4
0
 def _setup_vol_groups(self):
     LOG.info("Attempting to setup volume groups for nova volume management.")
     mp = dict()
     backing_file = self.cfg.getdefaulted('nova', 'volume_backing_file',
                    sh.joinpths(self.installer.get_option('app_dir'), 'nova-volumes-backing-file'))
     vol_group = self.cfg.getdefaulted('nova', 'volume_group', 'nova-volumes')
     backing_file_size = utils.to_bytes(self.cfg.getdefaulted('nova', 'volume_backing_file_size', '2052M'))
     mp['VOLUME_GROUP'] = vol_group
     mp['VOLUME_BACKING_FILE'] = backing_file
     mp['VOLUME_BACKING_FILE_SIZE'] = backing_file_size
     try:
         utils.execute_template(*VG_CHECK_CMD, params=mp)
         LOG.warn("Volume group already exists: %r" % (vol_group))
     except exceptions.ProcessExecutionError as err:
         # Check that the error from VG_CHECK is an expected error
         if err.exit_code != 5:
             raise
         LOG.info("Need to create volume group: %r" % (vol_group))
         sh.touch_file(backing_file, die_if_there=False, file_size=backing_file_size)
         vg_dev_result = utils.execute_template(*VG_DEV_CMD, params=mp)
         if vg_dev_result and vg_dev_result[0]:
             LOG.debug("VG dev result: %s" % (vg_dev_result))
             # Strip the newlines out of the stdout (which is in the first
             # element of the first (and only) tuple in the response
             (sysout, _) = vg_dev_result[0]
             mp['DEV'] = sysout.replace('\n', '')
             utils.execute_template(*VG_CREATE_CMD, params=mp)
     # One way or another, we should have the volume group, Now check the
     # logical volumes
     self._process_lvs(mp)
     # Finish off by restarting tgt, and ignore any errors
     cmdrestart = self.distro.get_command('iscsi', 'restart', quiet=True)
     if cmdrestart:
         sh.execute(*cmdrestart, run_as_root=True, check_exit_code=False)
Ejemplo n.º 5
0
 def _create_repo(self, repo_name):
     repo_dir = sh.joinpths(self.anvil_repo_dir, repo_name)
     src_repo_dir = sh.joinpths(self.anvil_repo_dir,
                                self.SRC_REPOS[repo_name])
     for a_dir in (repo_dir, src_repo_dir):
         if not sh.isdir(a_dir):
             sh.mkdirslist(a_dir, tracewriter=self.tracewriter)
         cmdline = ["createrepo", a_dir]
         LOG.info("Creating repo at %s", a_dir)
         sh.execute(cmdline)
     repo_filename = sh.joinpths(self.anvil_repo_dir, "%s.repo" % repo_name)
     LOG.info("Writing %s", repo_filename)
     (_fn, content) = utils.load_template("packaging", "common.repo")
     params = {
         "repo_name": repo_name,
         "baseurl_bin": "file://%s" % repo_dir,
         "baseurl_src": "file://%s" % src_repo_dir,
     }
     sh.write_file(repo_filename,
                   utils.expand_template(content, params),
                   tracewriter=self.tracewriter)
     # NOTE(harlowja): Install *.repo file so that anvil deps will be available
     # when building openstack core project packages.
     system_repo_filename = sh.joinpths(self.YUM_REPO_DIR,
                                        "%s.repo" % repo_name)
     sh.copy(repo_filename,
             system_repo_filename,
             tracewriter=self.tracewriter)
     LOG.info("Copied to %s", system_repo_filename)
Ejemplo n.º 6
0
 def run_tests(self):
     app_dir = self.get_option('app_dir')
     if not sh.isdir(app_dir):
         LOG.warn(
             "Unable to find application directory at %s, can not run %s tests.",
             colorizer.quote(app_dir), colorizer.quote(self.name))
         return
     cmd = self._get_test_command()
     env = self._get_env()
     with open(os.devnull, 'wb') as null_fh:
         if self.get_bool_option("verbose", default_value=False):
             null_fh = None
         try:
             sh.execute(cmd,
                        stdout_fh=None,
                        stderr_fh=null_fh,
                        cwd=app_dir,
                        env_overrides=env)
         except excp.ProcessExecutionError as e:
             if self.get_bool_option("ignore-test-failures",
                                     default_value=False):
                 LOG.warn("Ignoring test failure of component %s: %s",
                          colorizer.quote(self.name), e)
             else:
                 raise e
Ejemplo n.º 7
0
 def _remove(self, pip):
     root_cmd = self._get_pip_command()
     # Versions don't seem to matter here...
     name = self._make_pip_name(pip['name'], None)
     LOG.audit("Uninstalling python package %r using pip command %s" % (name, root_cmd))
     cmd = [root_cmd] + ['uninstall'] + PIP_UNINSTALL_CMD_OPTS + [name]
     sh.execute(*cmd, run_as_root=True)
Ejemplo n.º 8
0
 def _add_bridge(self, name):
     cmd_template = self.distro.get_command('openvswitch', 'add_bridge')
     cmd = utils.expand_template_deep(cmd_template, {'NAME': name})
     try:
         sh.execute(cmd)
     except excp.ProcessExecutionError:
         LOG.warn("Failed to create '%s' openvswitch bridge." % name)
Ejemplo n.º 9
0
 def start(self):
     if self._status() != constants.STATUS_STARTED:
         start_cmd = self.distro.get_command('apache', 'start')
         sh.execute(*start_cmd, run_as_root=True, check_exit_code=True)
         return 1
     else:
         return 0
Ejemplo n.º 10
0
 def status_app(self, program):
     status_cmd = self.get_command("status", program)
     try:
         sh.execute(status_cmd, shell=True)
     except excp.ProcessExecutionError:
         return False
     return True
Ejemplo n.º 11
0
 def run_tests(self):
     app_dir = self.get_option('app_dir')
     if not sh.isdir(app_dir):
         LOG.warn("Unable to find application directory at %s, can not run %s tests.",
                  colorizer.quote(app_dir), colorizer.quote(self.name))
         return
     pre_cmd = self._get_pre_test_command()
     cmd = self._get_test_command()
     if not cmd:
         LOG.warn("Unable to determine test command for %s, can not run tests.",
                  colorizer.quote(self.name))
         return
     env = self._get_env()
     try:
         if pre_cmd:
             LOG.info("Running test setup via: %s",
                      utils.truncate_text(" ".join(pre_cmd), 80))
             sh.execute(pre_cmd, stdout_fh=sys.stdout, stderr_fh=sys.stdout,
                        cwd=app_dir, env_overrides=env)
         LOG.info("Running tests via: %s",
                  utils.truncate_text(" ".join(cmd), 80))
         sh.execute(cmd, stdout_fh=sys.stdout, stderr_fh=sys.stdout,
                    cwd=app_dir, env_overrides=env)
     except excp.ProcessExecutionError as e:
         if self.ignore_test_failures:
             LOG.warn("Ignoring test failure of component %s: %s", colorizer.quote(self.name), e)
         else:
             raise
Ejemplo n.º 12
0
 def stop(self):
     if self.status()[0].status != comp.STATUS_STOPPED:
         stop_cmd = self._get_run_actions('stop', excp.StopException)
         sh.execute(*stop_cmd, run_as_root=True, check_exit_code=True)
         return 1
     else:
         return 0
Ejemplo n.º 13
0
 def stop(self):
     if self._status() != constants.STATUS_STOPPED:
         stop_cmd = self.distro.get_command('qpid', 'stop')
         sh.execute(*stop_cmd, run_as_root=True, check_exit_code=True)
         return 1
     else:
         return 0
Ejemplo n.º 14
0
 def restart(self):
     LOG.info("Restarting your database.")
     restartcmd = self._get_run_actions('restart', excp.RestartException)
     sh.execute(*restartcmd, run_as_root=True, check_exit_code=True)
     LOG.info("Please wait %s seconds while it restarts." % self.wait_time)
     sh.sleep(self.wait_time)
     return 1
Ejemplo n.º 15
0
def download(distro, uri, target_dir, **kwargs):
    puri = urlparse(uri)
    scheme = puri.scheme.lower()
    path = puri.path
    if scheme in ['git'] or path.find('.git') != -1:
        dirs_made = sh.mkdirslist(target_dir)
        downloader = GitDownloader(distro, uri, target_dir)
        downloader.download()
        return dirs_made
    if scheme in ['http', 'https']:
        dirs_made = []
        with utils.tempdir() as tdir:
            fn = sh.basename(path)
            downloader = UrlLibDownloader(uri, sh.joinpths(tdir, fn))
            downloader.download()
            if fn.endswith('.tar.gz'):
                dirs_made = sh.mkdirslist(target_dir)
                cmd = ['tar', '-xzvf', sh.joinpths(tdir, fn), '-C', target_dir]
                sh.execute(*cmd)
            elif fn.endswith('.zip'):
                # TODO(harlowja) this might not be 100% right...
                # we might have to move the finished directory...
                dirs_made = sh.mkdirslist(target_dir)
                cmd = ['unzip', sh.joinpths(tdir, fn), '-d', target_dir]
                sh.execute(*cmd)
            else:
                raise excp.DownloadException("Unable to extract %s downloaded from %s" % (fn, uri))
        return dirs_made
    else:
        raise excp.DownloadException("Unknown scheme %s, unable to download from %s" % (scheme, uri))
Ejemplo n.º 16
0
 def status_app(self, program):
     status_cmd = self.get_command("status", program)
     try:
         sh.execute(status_cmd, shell=True)
     except excp.ProcessExecutionError:
         return False
     return True
Ejemplo n.º 17
0
 def stop(self):
     if self.status()[0].status != comp.STATUS_STOPPED:
         stop_cmd = self.distro.get_command('apache', 'stop')
         sh.execute(*stop_cmd, run_as_root=True, check_exit_code=True)
         return 1
     else:
         return 0
Ejemplo n.º 18
0
 def _add_bridge(self, name):
     cmd_template = self.distro.get_command('openvswitch', 'add_bridge')
     cmd = utils.expand_template_deep(cmd_template, {'NAME': name})
     try:
         sh.execute(cmd)
     except excp.ProcessExecutionError:
         LOG.warn("Failed to create '%s' openvswitch bridge." % name)
Ejemplo n.º 19
0
 def restart(self):
     LOG.info("Restarting your qpid daemon.")
     restart_cmd = self.distro.get_command('qpid', 'restart')
     sh.execute(*restart_cmd, run_as_root=True, check_exit_code=True)
     LOG.info("Please wait %s seconds while it restarts." % self.wait_time)
     sh.sleep(self.wait_time)
     return 1
Ejemplo n.º 20
0
 def _clean_it(self):
     cleaner_fn = sh.joinpths(self.get_option("app_dir"), BIN_DIR, CLEANER_DATA_CONF)
     if sh.isfile(cleaner_fn):
         LOG.info("Cleaning up your system by running nova cleaner script: %s", colorizer.quote(cleaner_fn))
         # These environment additions are important
         # in that they eventually affect how this script runs
         env = {"ENABLED_SERVICES": ",".join(self.subsystems.keys())}
         sh.execute(cleaner_fn, run_as_root=True, env_overrides=env)
Ejemplo n.º 21
0
 def _install_build_requirements():
     build_requires = self.requirements["build-requires"]
     if build_requires:
         utils.log_iterable(sorted(build_requires),
                            header=("Installing %s build requirements" % len(build_requires)),
                            logger=LOG)
         cmdline = ["yum", "install", "-y"] + list(build_requires)
         sh.execute(cmdline)
Ejemplo n.º 22
0
 def pre_uninstall(self):
     try:
         self.runtime.restart()
         LOG.info("Attempting to reset the rabbit-mq guest password to: %s", colorizer.quote(RESET_BASE_PW))
         cmd = self.distro.get_command('rabbit-mq', 'change_password') + [RESET_BASE_PW]
         sh.execute(*cmd, run_as_root=True)
     except IOError:
         LOG.warn(("Could not reset the rabbit-mq password. You might have to manually "
                   "reset the password to %s before the next install"), colorizer.quote(RESET_BASE_PW))
Ejemplo n.º 23
0
 def start(self):
     if self._status() != constants.STATUS_STARTED:
         start_cmd = self.distro.get_command('qpid', 'start')
         sh.execute(*start_cmd, run_as_root=True, check_exit_code=True)
         LOG.info("Please wait %s seconds while it starts up." % self.wait_time)
         sh.sleep(self.wait_time)
         return 1
     else:
         return 0
Ejemplo n.º 24
0
 def start(self):
     if self._status() != constants.STATUS_STARTED:
         startcmd = self._get_run_actions('start', excp.StartException)
         sh.execute(*startcmd, run_as_root=True, check_exit_code=True)
         LOG.info("Please wait %s seconds while it starts up." % self.wait_time)
         sh.sleep(self.wait_time)
         return 1
     else:
         return 0
Ejemplo n.º 25
0
 def _setup_pw(self):
     user_id = self.cfg.get('rabbit', 'rabbit_userid')
     LOG.info("Setting up your rabbit-mq %s password.", colorizer.quote(user_id))
     self.runtime.restart()
     passwd = self.cfg.get_password("rabbit", PW_USER_PROMPT)
     cmd = self.distro.get_command('rabbit-mq', 'change_password') + [user_id, passwd]
     sh.execute(*cmd, run_as_root=True)
     LOG.info("Restarting so that your rabbit-mq password is reflected.")
     self.runtime.restart()
Ejemplo n.º 26
0
 def run_tests(self):
     app_dir = self.get_option('app_dir')
     if not sh.isdir(app_dir):
         LOG.warn("Unable to find application directory at %s, can not run %s tests.", 
                  colorizer.quote(app_dir), colorizer.quote(self.name))
         return
     cmd = self._get_test_command()
     env = self._get_env()
     sh.execute(*cmd, stdout_fh=None, stderr_fh=None, cwd=app_dir, env_overrides=env)
Ejemplo n.º 27
0
 def _write_python_tarball(self, pkg_dir):
     cmdline = [
         sys.executable,
         "setup.py",
         "sdist",
         "--formats", "gztar",
         "--dist-dir", self.rpm_sources_dir,
     ]
     sh.execute(cmdline, cwd=pkg_dir)
Ejemplo n.º 28
0
 def _execute_pip(self, cmd):
     pip_cmd = self._get_pip_command()
     if not isinstance(pip_cmd, (list, tuple)):
         pip_cmd = [pip_cmd]
     pip_cmd = pip_cmd + cmd
     try:
         sh.execute(*pip_cmd, run_as_root=True)
     finally:
         # The known packages installed is probably not consistent anymore so uncache it
         pip_helper.uncache()
Ejemplo n.º 29
0
 def configure(self):
     files = self._configure_files()
     conf_dir = "/etc/%s" % self.name
     if sh.isdir(conf_dir):
         sh.execute(
             ["chown", "-R",
              "%s:%s" % (self.name, self.name),
              conf_dir],
             check_exit_code=False)
     return files
Ejemplo n.º 30
0
 def _execute_pip(self, cmd):
     pip_cmd = self._get_pip_command()
     if not isinstance(pip_cmd, (list, tuple)):
         pip_cmd = [pip_cmd]
     pip_cmd = pip_cmd + cmd
     try:
         sh.execute(*pip_cmd, run_as_root=True)
     finally:
         # The known packages installed is probably not consistent anymore so uncache it
         pip_helper.uncache()
Ejemplo n.º 31
0
 def stop_app(self, program):
     LOG.info("Stopping program %s under component %s.",
              colorizer.quote(program), self.name)
     stop_cmd = self.get_command("stop", program)
     try:
         sh.execute(stop_cmd, shell=True)
     except excp.ProcessExecutionError:
         LOG.error("Failed to stop program %s under component %s.",
                   colorizer.quote(program), self.name)
         return False
     return True
Ejemplo n.º 32
0
 def _setup_pw(self):
     user_id = self.get_option('user_id')
     LOG.info("Setting up your rabbit-mq %s password.", colorizer.quote(user_id))
     self.runtime.start()
     self.runtime.wait_active()
     cmd = list(self.distro.get_command('rabbit-mq', 'change_password'))
     cmd += [user_id, self.get_password('rabbit')]
     sh.execute(cmd)
     LOG.info("Restarting so that your rabbit-mq password is reflected.")
     self.runtime.restart()
     self.runtime.wait_active()
Ejemplo n.º 33
0
 def _setup_pw(self):
     user_id = self.get_option("user_id")
     LOG.info("Setting up your rabbit-mq %s password.", colorizer.quote(user_id))
     self.runtime.start()
     self.runtime.wait_active()
     cmd = list(self.distro.get_command("rabbit-mq", "change_password"))
     cmd += [user_id, rhelper.get_shared_passwords(self)["pw"]]
     sh.execute(*cmd, run_as_root=True)
     LOG.info("Restarting so that your rabbit-mq password is reflected.")
     self.runtime.restart()
     self.runtime.wait_active()
Ejemplo n.º 34
0
 def stop_app(self, program):
     LOG.info("Stopping program %s under component %s.",
              colorizer.quote(program), self.name)
     stop_cmd = self.get_command("stop", program)
     try:
         sh.execute(stop_cmd, shell=True)
     except excp.ProcessExecutionError:
         LOG.error("Failed to stop program %s under component %s.",
              colorizer.quote(program), self.name)
         return False
     return True
Ejemplo n.º 35
0
 def _clean_it(self):
     # These environment additions are important
     # in that they eventually affect how this script runs
     env = dict()
     env["ENABLED_SERVICES"] = ",".join(self._filter_subsystems())
     env["BIN_DIR"] = sh.joinpths(self.get_option("app_dir"), BIN_DIR)
     env["VOLUME_NAME_PREFIX"] = self.cfg.getdefaulted("nova", "volume_name_prefix", DEF_VOL_PREFIX)
     cleaner_fn = sh.joinpths(sh.joinpths(self.get_option("app_dir"), BIN_DIR), CLEANER_DATA_CONF)
     if sh.isfile(cleaner_fn):
         LOG.info("Cleaning up your system by running nova cleaner script: %s", colorizer.quote(cleaner_fn))
         cmd = [cleaner_fn]
         sh.execute(*cmd, run_as_root=True, env_overrides=env)
Ejemplo n.º 36
0
 def _setup_pw(self):
     user_id = self.get_option('user_id')
     LOG.info("Setting up your rabbit-mq %s password.",
              colorizer.quote(user_id))
     self.runtime.start()
     self.runtime.wait_active()
     cmd = list(self.distro.get_command('rabbit-mq', 'change_password'))
     cmd += [user_id, self.get_password('rabbit')]
     sh.execute(cmd)
     LOG.info("Restarting so that your rabbit-mq password is reflected.")
     self.runtime.restart()
     self.runtime.wait_active()
Ejemplo n.º 37
0
 def _setup_pw(self):
     user_id = self.get_option('user_id')
     LOG.info("Setting up your rabbit-mq %s password.",
              colorizer.quote(user_id))
     self.runtime.start()
     self.runtime.wait_active()
     cmd = list(self.distro.get_command('rabbit-mq', 'change_password'))
     cmd += [user_id, rhelper.get_shared_passwords(self)['pw']]
     sh.execute(*cmd, run_as_root=True)
     LOG.info("Restarting so that your rabbit-mq password is reflected.")
     self.runtime.restart()
     self.runtime.wait_active()
Ejemplo n.º 38
0
 def _clean_it(self):
     cleaner_fn = sh.joinpths(self.get_option('app_dir'), BIN_DIR,
                              CLEANER_DATA_CONF)
     if sh.isfile(cleaner_fn):
         LOG.info(
             "Cleaning up your system by running nova cleaner script: %s",
             colorizer.quote(cleaner_fn))
         # These environment additions are important
         # in that they eventually affect how this script runs
         env = {
             'ENABLED_SERVICES': ",".join(self.subsystems.keys()),
         }
         sh.execute(cleaner_fn, run_as_root=True, env_overrides=env)
Ejemplo n.º 39
0
def apply_patches(patch_files, working_dir):
    apply_files = expand_patches(patch_files)
    if not len(apply_files):
        return
    if not sh.isdir(working_dir):
        LOG.warn("Can only apply %s patches 'inside' a directory and not '%s'", len(apply_files), working_dir)
        return
    with utils.chdir(working_dir):
        for p in apply_files:
            LOG.debug("Applying patch %s in directory %s", p, working_dir)
            patch_contents = sh.load_file(p)
            if len(patch_contents):
                sh.execute(*PATCH_CMD, process_input=patch_contents)
Ejemplo n.º 40
0
 def run_tests(self):
     app_dir = self.get_option('app_dir')
     if not sh.isdir(app_dir):
         LOG.warn("Unable to find application directory at %s, can not run %s tests.",
                  colorizer.quote(app_dir), colorizer.quote(self.name))
         return
     cmd = self._get_test_command()
     env = self._get_env()
     with open(os.devnull, 'wb') as null_fh:
         if self.get_bool_option("tests_verbose", default_value=False):
             null_fh = None
         sh.execute(*cmd, stdout_fh=None, stderr_fh=null_fh,
                    cwd=app_dir, env_overrides=env)
Ejemplo n.º 41
0
 def pre_uninstall(self):
     try:
         LOG.debug("Attempting to reset the rabbit-mq guest password to: %s", colorizer.quote(RESET_BASE_PW))
         self.runtime.start()
         self.runtime.wait_active()
         cmd = self.distro.get_command('rabbit-mq', 'change_password') + [RESET_BASE_PW]
         sh.execute(cmd)
         LOG.info("Restarting so that your rabbit-mq password is reflected.")
         self.runtime.restart()
         self.runtime.wait_active()
     except IOError:
         LOG.warn(("Could not reset the rabbit-mq password. You might have to manually "
                   "reset the password to %s before the next install"), colorizer.quote(RESET_BASE_PW))
Ejemplo n.º 42
0
 def run_tests(self):
     app_dir = self.get_option('app_dir')
     if not sh.isdir(app_dir):
         LOG.warn(
             "Unable to find application directory at %s, can not run %s tests.",
             colorizer.quote(app_dir), colorizer.quote(self.name))
         return
     cmd = self._get_test_command()
     env = self._get_env()
     sh.execute(*cmd,
                stdout_fh=None,
                stderr_fh=None,
                cwd=app_dir,
                env_overrides=env)
Ejemplo n.º 43
0
    def install(self):
        super(YumDependencyHandler, self).install()
        repo_filename = sh.joinpths(self.YUM_REPO_DIR, self.REPO_FN)

        # Ensure we copy the local repo file name to the main repo so that
        # yum will find it when installing packages.
        sh.write_file(repo_filename,
                      sh.load_file(self.anvil_repo_filename),
                      tracewriter=self.tracewriter)

        # Erase it if its been previously installed.
        cmdline = []
        if self.helper.is_installed(self.OPENSTACK_DEPS_PACKAGE_NAME):
            cmdline.append(self.OPENSTACK_DEPS_PACKAGE_NAME)
        for p in self.nopackages:
            if self.helper.is_installed(p):
                cmdline.append(p)

        if cmdline:
            cmdline = ["yum", "erase", "-y"] + cmdline
            sh.execute(cmdline, stdout_fh=sys.stdout, stderr_fh=sys.stderr)

        cmdline = ["yum", "clean", "all"]
        sh.execute(cmdline)

        cmdline = ["yum", "install", "-y", self.OPENSTACK_DEPS_PACKAGE_NAME]
        sh.execute(cmdline, stdout_fh=sys.stdout, stderr_fh=sys.stderr)

        rpm_names = self._convert_names_python2rpm(self.python_names)
        if rpm_names:
            cmdline = ["yum", "install", "-y"] + rpm_names
            sh.execute(cmdline, stdout_fh=sys.stdout, stderr_fh=sys.stderr)
Ejemplo n.º 44
0
def apply_patches(patch_files, working_dir):
    apply_files = expand_patches(patch_files)
    if not len(apply_files):
        return
    if not sh.isdir(working_dir):
        LOG.warn("Can only apply %s patches 'inside' a directory and not '%s'",
                 len(apply_files), working_dir)
        return
    with utils.chdir(working_dir):
        for p in apply_files:
            LOG.debug("Applying patch %s in directory %s", p, working_dir)
            patch_contents = sh.load_file(p)
            if len(patch_contents):
                sh.execute(PATCH_CMD, process_input=patch_contents)
Ejemplo n.º 45
0
 def _uninstall_python(self):
     py_listing = self.tracereader.py_listing()
     if py_listing:
         py_listing_dirs = set()
         for (_name, where) in py_listing:
             py_listing_dirs.add(where)
         utils.log_iterable(py_listing_dirs, logger=LOG,
                            header="Uninstalling %s python setups" % (len(py_listing_dirs)))
         unsetup_cmd = self.distro.get_command('python', 'unsetup')
         for where in py_listing_dirs:
             if sh.isdir(where):
                 sh.execute(*unsetup_cmd, cwd=where, run_as_root=True)
             else:
                 LOG.warn("No python directory found at %s - skipping", colorizer.quote(where, quote_color='red'))
Ejemplo n.º 46
0
 def configure(self):
     configs_made = nova.NovaInstaller.configure(self)
     driver_canon = utils.canon_virt_driver(self.get_option('virt_driver'))
     if driver_canon == 'libvirt':
         # Create a libvirtd user group
         if not sh.group_exists('libvirtd'):
             cmd = ['groupadd', 'libvirtd']
             sh.execute(cmd)
         if not sh.isfile(LIBVIRT_POLICY_FN):
             contents = self._get_policy(self._get_policy_users())
             sh.mkdirslist(sh.dirname(LIBVIRT_POLICY_FN))
             sh.write_file(LIBVIRT_POLICY_FN, contents)
             configs_made += 1
     return configs_made
Ejemplo n.º 47
0
 def post_install(self):
     binstall.PkgInstallComponent.post_install(self)
     user_name = self.get_option('user_id')
     try:
         LOG.debug(
             "Attempting to create the qpid user '%s' and their associated password.",
             user_name)
         cmd_template = self.distro.get_command('qpid', 'create_user')
         cmd = utils.expand_template_deep(cmd_template, {'USER': user_name})
         if cmd:
             sh.execute(cmd, process_input=self.get_password('qpid'))
     except IOError:
         LOG.warn((
             "Could not create the user/password. You might have to manually "
             "create the user/password before running."))
Ejemplo n.º 48
0
 def details(self):
     base = super(PythonPackager, self).details
     if self._extended_details is None:
         ext_dets = {
             'automatic_dependencies': False,
         }
         setup_cmd = ['python', self._setup_fn]
         replacements = {
             'version': '--version',
             'license': '--license',
             'name': '--name',
             'vendor': '--author',
             'url': '--url',
         }
         for (key, opt) in replacements.items():
             cmd = setup_cmd + [opt]
             (stdout, _stderr) = sh.execute(*cmd, run_as_root=True, cwd=self.get_option('app_dir'))
             stdout = stdout.strip()
             if stdout:
                 ext_dets[key] = stdout
         description = self._description()
         if description:
             ext_dets['description'] = "\n".join(description)
             ext_dets['summary'] = utils.truncate_text("\n".join(description[0:1]), 50)
         ext_dets['changelog'] = self._build_changelog()
         self._extended_details = ext_dets
     extended_dets = dict(base)
     extended_dets.update(self._extended_details)
     return extended_dets
Ejemplo n.º 49
0
 def _get_python_names(package_dirs):
     python_names = []
     for pkg_dir in package_dirs:
         cmdline = ["python", "setup.py", "--name"]
         python_names.append(
             sh.execute(cmdline, cwd=pkg_dir)[0].splitlines()[-1].strip())
     return python_names
Ejemplo n.º 50
0
 def _call_multipip(self, requirements,
                    requires_files=None, ignore_requirements=None):
     cmdline = [self._multipip_executable]
     if requires_files:
         cmdline.append("-r")
         cmdline.extend(requires_files)
     if ignore_requirements:
         cmdline.append("--ignore-package")
         cmdline.extend(ignore_requirements)
     if requirements:
         cmdline.append("--")
         cmdline.extend(requirements)
     (stdout, stderr) = sh.execute(cmdline, check_exit_code=False)
     compatibles = list(utils.splitlines_not_empty(stdout))
     incompatibles = collections.defaultdict(list)
     current_name = ''
     for line in stderr.strip().splitlines():
         if line.endswith(": incompatible requirements"):
             current_name = line.split(":", 1)[0].lower().strip()
             if current_name not in incompatibles:
                 incompatibles[current_name] = []
         else:
             incompatibles[current_name].append(line)
     cleaned_incompatibles = dict()
     for (requirement, lines) in six.iteritems(incompatibles):
         requirement = requirement.strip()
         if not requirement:
             continue
         if not lines:
             continue
         cleaned_incompatibles[requirement] = lines
     incompatibles = cleaned_incompatibles
     return (compatibles, incompatibles)
Ejemplo n.º 51
0
 def pre_install(self):
     # Check if network namespaces are supported.
     if self.get_option("use_namespaces", default_value=True):
         try:
             # "ip netns" command is used for network namespace management.
             # We are trying to execute this command and if it was executed
             # successfully then network namespaces support is enabled.
             sh.execute(["ip", "netns"])
         except exceptions.ProcessExecutionError:
             raise exceptions.InstallException(
                 "Network namespaces are not supported in your system. "
                 "Please, install kernel and iproute with network "
                 "namespaces support. To install them from RDO you can "
                 "use the following script: "
                 "./tools/install-neutron-ns-packages.sh")
     super(NeutronInstaller, self).pre_install()
Ejemplo n.º 52
0
 def post_uninstall(self):
     binstall.PkgUninstallComponent.post_uninstall(self)
     user_name = self.get_option('user_id')
     if user_name in NO_DELETE:
         return
     try:
         LOG.debug(
             "Attempting to delete the qpid user '%s' and their associated password.",
             user_name)
         cmd_template = self.distro.get_command('qpid', 'delete_user')
         cmd = utils.expand_template_deep(cmd_template, {'USER': user_name})
         if cmd:
             sh.execute(cmd)
     except IOError:
         LOG.warn((
             "Could not delete the user/password. You might have to manually "
             "reset the user/password before the next install."))
Ejemplo n.º 53
0
 def _run_action(self, action, check_exit_code=True):
     cmd = self._get_command(action)
     if not cmd:
         raise NotImplementedError(
             "No distro command provided to perform action %r" % (action))
     return sh.execute(*cmd,
                       run_as_root=True,
                       check_exit_code=check_exit_code)
Ejemplo n.º 54
0
 def _service_status(self):
     cmd = self.distro.get_command('libvirt', 'status')
     (stdout, stderr) = sh.execute(cmd, check_exit_code=False)
     combined = (stdout + stderr)
     if combined.lower().find("running") != -1 or combined.lower().find(
             'start') != -1:
         return (_ALIVE, combined)
     else:
         return (_DEAD, combined)
Ejemplo n.º 55
0
    def uninstall(self):
        super(YumDependencyHandler, self).uninstall()
        if self.tracereader.exists():
            for f in self.tracereader.files_touched():
                sh.unlink(f)
            for d in self.tracereader.dirs_made():
                sh.deldir(d)
            sh.unlink(self.tracereader.filename())
            self.tracereader = None

        rpm_names = []
        for name in self._convert_names_python2rpm(self.python_names):
            if self.helper.is_installed(name):
                rpm_names.append(name)

        if rpm_names:
            cmdline = ["yum", "remove", "--remove-leaves", "-y"] + rpm_names
            sh.execute(cmdline, stdout_fh=sys.stdout, stderr_fh=sys.stderr)
Ejemplo n.º 56
0
 def _get_commit_detail(self, commit, field, am=1):
     detail_cmd = ['git', 'log', '--color=never', '-%s' % (am), "--pretty=format:%s" % (field), commit]
     (stdout, _stderr) = sh.execute(*detail_cmd, cwd=self.wkdir)
     ret = stdout.strip('\n').splitlines()
     if len(ret) == 1:
         ret = ret[0]
     else:
         ret = filter(lambda x: x.strip() != '', ret)
         ret = "\n".join(ret)
     return ret
Ejemplo n.º 57
0
 def pre_uninstall(self):
     try:
         LOG.debug(
             "Attempting to reset the rabbit-mq guest password to: %s",
             colorizer.quote(RESET_BASE_PW))
         self.runtime.start()
         self.runtime.wait_active()
         cmd = self.distro.get_command('rabbit-mq',
                                       'change_password') + [RESET_BASE_PW]
         sh.execute(cmd)
         LOG.info(
             "Restarting so that your rabbit-mq password is reflected.")
         self.runtime.restart()
         self.runtime.wait_active()
     except IOError:
         LOG.warn((
             "Could not reset the rabbit-mq password. You might have to manually "
             "reset the password to %s before the next install"),
                  colorizer.quote(RESET_BASE_PW))
Ejemplo n.º 58
0
    def status_app(self, program):
        status_cmd = self.get_command("status", program)
        try:
            output = sh.execute(status_cmd, shell=True)[0]
        except excp.ProcessExecutionError:
            return False

        if utils.has_any(output, "is not running"):
            return False
        return True
Ejemplo n.º 59
0
 def _install_python_setups(self):
     py_dirs = self.python_directories
     if py_dirs:
         real_dirs = {}
         for (name, wkdir) in py_dirs.items():
             real_dirs[name] = wkdir
             if not real_dirs[name]:
                 real_dirs[name] = self.get_option('app_dir')
         utils.log_iterable(real_dirs.values(), logger=LOG,
                            header="Setting up %s python directories" % (len(real_dirs)))
         setup_cmd = self.distro.get_command('python', 'setup')
         for (name, working_dir) in real_dirs.items():
             sh.mkdirslist(working_dir, tracewriter=self.tracewriter)
             setup_fn = sh.joinpths(self.get_option('trace_dir'), "%s.python.setup" % (name))
             sh.execute(*setup_cmd, cwd=working_dir, run_as_root=True,
                        stderr_fn='%s.stderr' % (setup_fn),
                        stdout_fn='%s.stdout' % (setup_fn),
                        tracewriter=self.tracewriter)
             self.tracewriter.py_installed(name, working_dir)