Пример #1
0
    def run(self):
        LOG.info('Getting Stats for Scale...')
        with SSHInterface(device=self.device, timeout=TIMEOUT) as sshifc:
            try:
                # Create directory for stats
                device_dir = self.device.get_address() + "-" + self.device.alias

                stat_dir = os.path.join(self.session.path, DIRECTORY,
                                        device_dir)
                stat_dir = os.path.expanduser(stat_dir)
                stat_dir = os.path.expandvars(stat_dir)
                if not os.path.exists(stat_dir):
                    os.makedirs(stat_dir)

                # Create directory for logs.
                log_dir = os.path.join(self.session.path, DIRECTORY,
                                       device_dir, 'log')
                log_dir = os.path.expanduser(log_dir)
                log_dir = os.path.expandvars(log_dir)
                if not os.path.exists(log_dir):
                    os.makedirs(log_dir)

                # Collect specific files
                for log in LOGS:
                    ret = sshifc.api.run('ls -1 %s | wc -l' % log)
                    if not ret.status and int(ret.stdout):
                        SCMD.ssh.scp_get(ifc=sshifc, source=log,
                                         destination=log_dir)

                context = ContextHelper(__name__)
                r = context.get_icontrol_rest(device=self.device).api
                output = r.get('/mgmt/shared/diagnostics')
                with open(os.path.join(stat_dir, 'diagnostics'), 'wt') as f:
                    json.dump(output, f, indent=4)

                if SCMD.ssh.file_exists(ifc=sshifc, filename=FILE):
                    SCMD.ssh.scp_get(ifc=sshifc, source=FILE,
                                     destination=stat_dir)

                # Collect stats
                for stat in STATS:
                    output = SCMD.ssh.generic(stat, ifc=sshifc)
                    with open(os.path.join(stat_dir, stat.split()[0]), 'wt') as f:
                        f.write(output.stdout)

                java_pid = SCMD.ssh.generic("cat /service/restjavad/supervise/pid",
                                            ifc=sshifc).stdout
                output = SCMD.ssh.generic('lsof -p %s' % java_pid, ifc=sshifc)
                with open(os.path.join(stat_dir, 'lsof'), 'wt') as f:
                    f.write(output.stdout)

            except SSHTimeoutError:
                LOG.warning('Could not complete collecting log and stats on %s',
                            self.device)
Пример #2
0
    def setup(self):
        super(HAPromoteStage, self).setup()
        LOG.info('Promotion stage for: %s', self.default)

        self.default.specs.default = False
        self.peer.specs.default = True

        LOG.info("old default = %s", self.default)
        LOG.info("new default = %s", self.peer)

        # if this is active/standby, promote, otherwise, not needed.
        if self.ha_passive:
            # Prepare command to send to promote
            payload = Options()
            payload.command = 'SET_PRIMARY'

            LOG.info("Picking up the list of peers from the new primary")
            context = ContextHelper(__name__)
            rest = context.get_icontrol_rest(device=self.peer).api
            resp = rest.get(DeviceResolver.DEVICES_URI %
                            DEFAULT_ALLBIGIQS_GROUP)

            # Look for the machine id of the peer to promote
            for item in resp['items']:
                if item.address == self.peer.get_discover_address():
                    payload.machineId = item.machineId
                    LOG.info("Promoting peer to primary from peer")
                    rest.post(FailoverState.URI, payload=payload)

            # wait for restjavad to go down...
            wait(lambda: rest.get(DeviceResolver.DEVICES_URI %
                                  DEFAULT_ALLBIGIQS_GROUP)['items'],
                 negated=True,
                 progress_cb=lambda ret:
                 'Waiting for restjavad on {0} to go down.'.format(self.default
                                                                   ))
            # wait for it to come back up
            RCMD.system.wait_restjavad([self.peer])