示例#1
0
class PlaybookContext(object):

    STATUS_READY = 'ready'
    STATUS_STARTED = 'started'
    STATUS_FINISHED = 'finished'

    STATE_RUNNING = 'running'
    STATE_SUCCEEDED = 'succeeded'
    STATE_FAILED = 'failed'
    #     STATE_ABORTED = 'aborted'
    #     STATE_KILLED = 'killed'
    STATES = (STATE_RUNNING, STATE_SUCCEEDED, STATE_FAILED)

    def __init__(self,
                 runid: str,
                 ansible_ws_config: AnsibleWebServiceConfig = None) -> None:
        self.logger = logging.getLogger(self.__class__.__name__)
        self.ansible_ws_config = AnsibleWebServiceConfig(
        ) if ansible_ws_config is None else ansible_ws_config
        self.runs_dir = self.ansible_ws_config.get('ansible.runs_dir')
        self.agent_path = self.ansible_ws_config.get("agent.path")
        self.agent_id = self.ansible_ws_config.get("agent.id")
        self.runid = runid
        self.folder = os.path.join(self.runs_dir, self.runid)
        self.logger.debug(self.folder)
        self.file_output = os.path.join(self.folder, 'run.out')
        self.file_error = os.path.join(self.folder, 'run.err')
        self.file_desc = os.path.join(self.folder, 'run.desc')
        self.file_status = os.path.join(self.folder, 'run.status')
        self._description = None

    @property
    def description(self):
        if self._description is None:
            with open(self.file_desc) as run_desc:
                self._description = json.load(run_desc)
        return self._description

    @property
    def out(self):
        if os.path.isfile(self.file_output):
            with open(self.file_output) as out:
                run_out = out.read()
        else:
            run_out = None
        return run_out

    @property
    def status(self):
        with open(self.file_status) as run_status:
            # self.logger.debug(f'read {self.file_status}')
            status = json.load(run_status)
        return status
示例#2
0
 def test(self):
     config = AnsibleWebServiceConfig()
     value = config.get('unittest.unittest.unittest')
     self.assertEqual(value, 'unittest')