Exemple #1
0
    def _reconnect(self, steps, timeout, sleep_disconnect=30):
        """Disconnect and reconnect to router within given timeout.

        Args:
          Mandatory:
            steps (`obj`) : Step object to represent each step taken.
            timeout (`obj`) : 
                max_time (int): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (int): Wait time between iterations when looping is needed,
                                in second. Default: 15
          Optional:
            sleep_disconnect (`int`) : Break between issue the command and the
                                       HA action really take place,
                                       in second. Default: 30

        Returns:
            AETEST Step Result


        Raises:
            None

        Example:
            >>> _reconnect(steps=ats.aetest.Steps(),
                           timeout=genie.utils.timeout.Timeout(
                             max_time=180,
                             interval=15))
        """
        with steps.start('Disconnecting device {}'.format(self.device.name),
                         continue_=True) as step:
            disconnect_device(self.device)
            time.sleep(sleep_disconnect)

        with steps.start('Reconnecting to device {}'.format(self.device.name),
                         continue_=True) as step:
            temp = TempResult(container=step)
            while timeout.iterate():
                try:
                    connect_device(self.device)
                except Exception as e:
                    temp.failed('Could not reconnect to the device',
                                from_exception=e)
                    # incase console is existed but cannot enable the device.
                    # conf mode is not active when standby RP is coming up
                    try:
                        disconnect_device(self.device)
                    except:
                        pass
                    timeout.sleep()
                    continue
                temp.passed('Reconnected to the device')
                break
            temp.result()
Exemple #2
0
    def _reconnect(self, steps, timeout):
        '''Reconnect to the device if needed'''
        if self.process in self.reconnect:

            ha = self.abstract.sdk.libs.abstracted_libs.ha.HA(
                device=self.device)
            with steps.start(
                    'The device is reloading when restarting this process',
                    continue_=True) as step:
                disconnect_device(self.device)
                time.sleep(30)
                temp = TempResult(container=step)
                while timeout.iterate():
                    try:
                        connect_device(self.device)
                    except Exception as e:
                        temp.failed('Could not reconnect to the device',
                                    from_exception=e)
                        timeout.sleep()
                        continue
                    temp.passed('Reconnected to the device')
                    break
                temp.result()

            # check show module
            with steps.start('Check module status after reconnection',
                             continue_=True) as step:

                temp = TempResult(container=step)
                while timeout.iterate():
                    try:
                        ha.check_module()
                    except AttributeError as e:
                        temp.failed(
                            'Could not find mandatory information from show module',
                            from_exception=e)
                        continue
                    except AssertionError as e:
                        temp.failed('Modules are not ready', from_exception=e)
                        timeout.sleep()
                        continue

                    temp.passed('Modules are ready')
                    break

                temp.result()