예제 #1
0
 def test_start_shoud_run_start(self, mock_subprocess, *args):
     """Start valid package."""
     sm = WinSvcManagerNSSM(svc_conf=CONF_STUB)
     sm.start()
     cmd = 'command start the_displayname'
     mock_subprocess.assert_called_once_with(cmd,
                                             **RUN_COMMAND_DEFAULT_KWARGS)
예제 #2
0
파일: command.py 프로젝트: pcrews/dcos
    def execute(self):
        """Execute command."""
        msg_src = self.__class__.__name__

        for pkg_manifest in self.config.inst_storage.get_pkgactive():
            pkg_id = pkg_manifest.pkg_id
            LOG.debug(f'{msg_src}: Execute: Manifest: {pkg_manifest.body}')
            svc_conf = cfp.ConfigParser()
            svc_conf.read_dict(pkg_manifest.svc_conf)
            cluster_conf = cfp.ConfigParser()
            cluster_conf.read_dict(self.config.cluster_conf)
            svc_manager = WinSvcManagerNSSM(
                svc_conf=svc_conf, cluster_conf=cluster_conf
            )

            try:
                ret_code, stdout, stderr = svc_manager.status()
            except svcm_exc.ServiceManagerCommandError as e:
                err_msg = (f'Execute: Get service status (initial):'
                           f' {pkg_id.pkg_name}: {e}')
                raise cr_exc.StartCommandError(err_msg)
            else:
                LOG.debug(
                    f'{msg_src}: Execute: Get service status (initial):'
                    f' {pkg_id.pkg_name}: stdout[{stdout}] stderr[{stderr}]'
                )
                svc_status = str(stdout).strip().rstrip('\n')

            if svc_status == SVC_STATUS.STOPPED:
                try:
                    svc_manager.start()
                    ret_code, stdout, stderr = svc_manager.status()
                    LOG.debug(
                        f'{msg_src}: Execute: Get service status (final):'
                        f' {pkg_id.pkg_name}: stdout[{stdout}]'
                        f' stderr[{stderr}]'
                    )
                    svc_status = str(stdout).strip().rstrip('\n')
                    if svc_status != SVC_STATUS.RUNNING:
                        err_msg = (f'Execute: Service failed to start:'
                                   f' {pkg_id.pkg_name}: {svc_status}')
                        raise cr_exc.StartCommandError(err_msg)
                except svcm_exc.ServiceManagerCommandError as e:
                    err_msg = (f'Execute: Get service status (final):'
                               f' {pkg_id.pkg_name}: {e}')
                    raise cr_exc.StartCommandError(err_msg)
            elif svc_status == SVC_STATUS.RUNNING:
                LOG.warning(f'{msg_src}: Execute: Service is already running:'
                            f' {pkg_id.pkg_name}')
            else:
                err_msg = (f'Execute: Invalid service status:'
                           f' {pkg_id.pkg_name}: {svc_status}')
                raise cr_exc.StartCommandError(err_msg)