Пример #1
0
class EnableNetworkInterfaceHost(TestStepBase):
    """
    Implements a Test Step to enable a network interface on the host pc
    """

    def run(self, context):
        """
        Enable a network interface on the host pc

        :type context: TestStepContext
        :param context: test case context
        """
        TestStepBase.run(self, context)

        # Get parameters
        self._hostpc = EquipmentManager().get_computer(eqt_name="COMPUTER1")
        self._timeout = self._pars.dhcp_timeout_sec
        self._interface = self._pars.interface

        # Bring up the specified network interface
        if 'Linux' in self._hostpc.get_os():
            primaryAddress =  str(self._hostpc.get_eqt_dict().get_param_value("IP", ""))
            username =  str(self._hostpc.get_eqt_dict().get_param_value("username", ""))

            if os.system('ssh {0}@{1} ifconfig {2} up'.format(username, primaryAddress, self._interface)) != 0:
                msg = "Failed to bring the {0} network interface up".format(self._interface)
                raise DeviceException(DeviceException.OPERATION_FAILED, msg)

            # Configure the tethered network interface on the host using DHCP
            network_interface_start_time = time.time()
            network_interface_available = False
            while (time.time() - network_interface_start_time < self._timeout) and network_interface_available == False:
                time.sleep(1)

                try:
                    self._hostpc.dhclient(self._interface)
                    network_interface_available = True
                except Exception, e:
                    network_interface_available = False
                    msg = "Failed to allocate IP address to {0} : {1}".format(self._interface, e)
                    self._logger.info(msg)

            if network_interface_available == False:
                msg = "DHCP time out occurred while allocating IP address to {0}. Aborting TestStep execution".format(self._interface)
                raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        else:
Пример #2
0
class DisableNetworkInterfaceHost(TestStepBase):
    """
    Implements a Test Step to disable a network interface on the host pc
    """
    def run(self, context):
        """
        Disable a network interface on the host pc

        :type context: TestStepContext
        :param context: test case context
        """
        TestStepBase.run(self, context)

        # Get parameters
        self._hostpc = EquipmentManager().get_computer(eqt_name="COMPUTER1")
        self._interface = self._pars.interface

        # Bring down the specified network interface
        if 'Linux' in self._hostpc.get_os():
            primaryAddress = str(self._hostpc.get_eqt_dict().get_param_value(
                "IP", ""))
            username = str(self._hostpc.get_eqt_dict().get_param_value(
                "username", ""))

            if os.system('ssh {0}@{1} ifconfig {2} down'.format(
                    username, primaryAddress, self._interface)) != 0:
                msg = "Failed to bring the {0} network interface up".format(
                    self._interface)
                raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        else:
            if os.system(
                    'netsh interface set interface name="{0}" admin="disabled"'
                    .format(self._interface)) != 0:
                msg = "Failed to bring the {0} network interface down".format(
                    self._interface)
                raise DeviceException(DeviceException.OPERATION_FAILED, msg)