예제 #1
0
    def __init__(self, disk):
        try:
            import guestfs
        except ImportError:
            install_cmd = "yum -y install python-libguestfs"
            try:
                process.run(install_cmd)
                import guestfs
            except Exception:
                raise exceptions.TestSkipError('We need python-libguestfs (or '
                                               'the equivalent for your '
                                               'distro) for this particular '
                                               'feature (modifying guest '
                                               'files with libguestfs)')

        self.g = guestfs.GuestFS()
        self.disk = disk
        self.g.add_drive(disk)
        libvirtd = SpecificServiceManager("libvirtd")
        libvirtd_status = libvirtd.status()
        if libvirtd_status is None:
            raise exceptions.TestError('libvirtd: service not found')
        if (not libvirtd_status) and (not libvirtd.start()):
            raise exceptions.TestError('libvirtd: failed to start')
        logging.debug("Launch the disk %s, wait..." % self.disk)
        self.g.launch()
예제 #2
0
    def __init__(self, disk):
        try:
            import guestfs
        except ImportError:
            install_cmd = "yum -y install python-libguestfs"
            try:
                process.run(install_cmd)
                import guestfs
            except Exception:
                raise exceptions.TestSkipError('We need python-libguestfs (or '
                                               'the equivalent for your '
                                               'distro) for this particular '
                                               'feature (modifying guest '
                                               'files with libguestfs)')

        self.g = guestfs.GuestFS()
        self.disk = disk
        self.g.add_drive(disk)
        libvirtd = SpecificServiceManager("libvirtd")
        libvirtd_status = libvirtd.status()
        if libvirtd_status is None:
            raise exceptions.TestError('libvirtd: service not found')
        if (not libvirtd_status) and (not libvirtd.start()):
            raise exceptions.TestError('libvirtd: failed to start')
        logging.debug("Launch the disk %s, wait..." % self.disk)
        self.g.launch()
예제 #3
0
    def __init__(self, disk, backend='direct'):
        """
        :params disk: target disk image.
        :params backend: let libguestfs creates/connects to backend daemon
                         by starting qemu directly, or using libvirt to manage
                         an appliance, running User-Mode Linux, or connecting
                         to an already running daemon.
                         'direct', 'appliance', 'libvirt', 'libvirt:null',
                         'libvirt:URI', 'uml', 'unix:path'.
        """
        try:
            import guestfs
        except ImportError:
            from virttest.utils_package import package_install
            if not package_install("python*-libguestfs"):
                raise exceptions.TestSkipError('We need python-libguestfs (or '
                                               'the equivalent for your '
                                               'distro) for this particular '
                                               'feature (modifying guest '
                                               'files with libguestfs)')
            try:
                import guestfs
            except ImportError:
                raise exceptions.TestError("Couldn't import guestfs")

        self.g = guestfs.GuestFS()
        self.disk = disk
        self.g.add_drive(disk)
        self.g.set_backend(backend)
        libvirtd = SpecificServiceManager("libvirtd")
        libvirtd_status = libvirtd.status()
        if libvirtd_status is None:
            raise exceptions.TestError('libvirtd: service not found')
        if (not libvirtd_status) and (not libvirtd.start()):
            raise exceptions.TestError('libvirtd: failed to start')
        logging.debug("Launch the disk %s, wait..." % self.disk)
        self.g.launch()
예제 #4
0
    def __init__(self, disk, backend='direct'):
        """
        :params disk: target disk image.
        :params backend: let libguestfs creates/connects to backend daemon
                         by starting qemu directly, or using libvirt to manage
                         an appliance, running User-Mode Linux, or connecting
                         to an already running daemon.
                         'direct', 'appliance', 'libvirt', 'libvirt:null',
                         'libvirt:URI', 'uml', 'unix:path'.
        """
        try:
            import guestfs
        except ImportError:
            install_cmd = "yum -y install python-libguestfs"
            try:
                process.run(install_cmd)
                import guestfs
            except Exception:
                raise exceptions.TestSkipError('We need python-libguestfs (or '
                                               'the equivalent for your '
                                               'distro) for this particular '
                                               'feature (modifying guest '
                                               'files with libguestfs)')

        self.g = guestfs.GuestFS()
        self.disk = disk
        self.g.add_drive(disk)
        self.g.set_backend(backend)
        libvirtd = SpecificServiceManager("libvirtd")
        libvirtd_status = libvirtd.status()
        if libvirtd_status is None:
            raise exceptions.TestError('libvirtd: service not found')
        if (not libvirtd_status) and (not libvirtd.start()):
            raise exceptions.TestError('libvirtd: failed to start')
        logging.debug("Launch the disk %s, wait..." % self.disk)
        self.g.launch()
    def test(self):
        detected_distro = distro.detect()
        parser = ConfigParser.ConfigParser()
        parser.read(self.get_data('services.cfg'))
        services_list = parser.get(detected_distro.name, 'services').split(',')

        smm = SoftwareManager()
        deps = []

        if detected_distro.name == 'SuSE':
            deps.extend(['ppc64-diag', 'libvirt-daemon'])
            if detected_distro.version >= 15:
                services_list.append('firewalld')
            else:
                services_list.append('SuSEfirewall2')

        for package in deps:
            if not smm.check_installed(package) and not smm.install(package):
                self.cancel(' %s is needed for the test to be run' % package)

        if 'PowerNV' in open('/proc/cpuinfo', 'r').read():
            services_list.extend(['opal_errd', 'opal-prd'])
            if os.path.exists('/proc/device-tree/bmc'):
                services_list.remove('opal_errd')
        else:
            services_list.extend(['rtas_errd'])
        if 'Ubuntu' in detected_distro.name:
            if detected_distro.version >= 17:
                services_list.remove('networking')
        services_failed = []
        runner = process.run

        for service in services_list:
            service_obj = SpecificServiceManager(service, runner)
            self.log.info("Checking %s service" % service)
            if service_obj.is_enabled() is False:
                self.log.info("%s service Not Found !!!" % service)
                services_failed.append(service)
                continue
            original_status = service_obj.status()
            if original_status is True:
                service_obj.stop()
                if not wait_for(lambda: not service_obj.status(), 10):
                    self.log.info("Fail to stop %s service" % service)
                    services_failed.append(service)
                    continue
                service_obj.start()
                wait_for(service_obj.status, 10)
            else:
                service_obj.start()
                if not wait_for(service_obj.status, 10):
                    self.log.info("Fail to start %s service" % service)
                    services_failed.append(service)
                    continue
                service_obj.stop()
                wait_for(lambda: not service_obj.status(), 10)
            if not service_obj.status() is original_status:
                self.log.info("Fail to restore original status of the %s"
                              "service" % service)
                services_failed.append(service)

        if services_failed:
            self.fail("List of services failed: %s" % services_failed)
        else:
            self.log.info("All Services Passed the ON/OFF test")
예제 #6
0
    def test(self):
        detected_distro = distro.detect()
        parser = ConfigParser.ConfigParser()
        config_file = self.datadir + '/services.cfg'
        parser.read(config_file)
        services_list = parser.get(detected_distro.name, 'services').split(',')
        services_failed = []
        runner = process.run

        for service in services_list:
            service_obj = SpecificServiceManager(service, runner)
            self.log.info("Checking %s service" % service)
            if service_obj.is_enabled() is False:
                self.log.info("%s service Not Found !!!" % service)
                services_failed.append(service)
                continue
            original_status = service_obj.status()
            if original_status is True:
                service_obj.stop()
                if not wait_for(lambda: not service_obj.status(), 10):
                    self.log.info("Fail to stop %s service" % service)
                    services_failed.append(service)
                    continue
                service_obj.start()
                wait_for(service_obj.status, 10)
            else:
                service_obj.start()
                if not wait_for(service_obj.status, 10):
                    self.log.info("Fail to start %s service" % service)
                    services_failed.append(service)
                    continue
                service_obj.stop()
                wait_for(lambda: not service_obj.status(), 10)
            if not service_obj.status() is original_status:
                self.log.info("Fail to restore original status of the %s"
                              "service" % service)
                services_failed.append(service)

        if services_failed:
            self.fail("List of services failed: %s" % services_failed)
        else:
            self.log.info("All Services Passed the ON/OFF test")
예제 #7
0
    def test(self):
        detected_distro = distro.detect()
        parser = ConfigParser.ConfigParser()
        config_file = self.datadir + '/services.cfg'
        parser.read(config_file)
        services_list = parser.get(detected_distro.name, 'services').split(',')
        if 'PowerNV' in open('/proc/cpuinfo', 'r').read():
            services_list.extend(['opal_errd', 'opal-prd'])
        else:
            services_list.extend(['rtas_errd'])
        services_failed = []
        runner = process.run

        for service in services_list:
            service_obj = SpecificServiceManager(service, runner)
            self.log.info("Checking %s service" % service)
            if service_obj.is_enabled() is False:
                self.log.info("%s service Not Found !!!" % service)
                services_failed.append(service)
                continue
            original_status = service_obj.status()
            if original_status is True:
                service_obj.stop()
                if not wait_for(lambda: not service_obj.status(), 10):
                    self.log.info("Fail to stop %s service" % service)
                    services_failed.append(service)
                    continue
                service_obj.start()
                wait_for(service_obj.status, 10)
            else:
                service_obj.start()
                if not wait_for(service_obj.status, 10):
                    self.log.info("Fail to start %s service" % service)
                    services_failed.append(service)
                    continue
                service_obj.stop()
                wait_for(lambda: not service_obj.status(), 10)
            if not service_obj.status() is original_status:
                self.log.info("Fail to restore original status of the %s"
                              "service" % service)
                services_failed.append(service)

        if services_failed:
            self.fail("List of services failed: %s" % services_failed)
        else:
            self.log.info("All Services Passed the ON/OFF test")
예제 #8
0
def run(test, params, env):
    """
    Logs guest's hostname.
    1) Decide whether use host/guest
    2) Check current service status
    3) Start (Stop) $service
    4) Check status of $service
    5) Stop (Start) $service
    6) Check service status

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    if params.get('test_on_guest') == "yes":
        # error_context.context() is common method to log test steps used to verify
        # what exactly was tested.
        error_context.context("Using guest.", logging.info)
        vm = env.get_vm(params["main_vm"])
        session = vm.wait_for_login()
        # RemoteRunner is object, which simulates the utils.run() behavior
        # on remote consoles
        runner = remote.RemoteRunner(session=session).run
    else:
        error_context.context("Using host", logging.info)
        runner = process.run

    error_context.context("Initialize service manager", logging.info)
    service = SpecificServiceManager(params["test_service"], runner)

    error_context.context("Testing service %s" % params["test_service"],
                          logging.info)
    original_status = service.status()
    logging.info("Original status=%s", original_status)

    if original_status is True:
        service.stop()
        time.sleep(5)
        if service.status() is not False:
            logging.error("Fail to stop service")
            service.start()
            raise exceptions.TestFail("Fail to stop service")
        service.start()
    else:
        service.start()
        time.sleep(5)
        if service.status() is not True:
            logging.error("Fail to start service")
            service.stop()
            raise exceptions.TestFail("Fail to start service")
        service.start()
    time.sleep(5)
    if not service.status() is original_status:
        raise exceptions.TestFail("Fail to restore original status of the %s "
                                  "service" % params["test_service"])
    def test(self):
        detected_distro = distro.detect()
        parser = ConfigParser.ConfigParser()
        parser.read(self.get_data('services.cfg'))
        services_list = parser.get(detected_distro.name, 'services').split(',')

        smm = SoftwareManager()
        deps = []

        if detected_distro.name == 'SuSE':
            deps.extend(['ppc64-diag', 'libvirt-daemon'])
            if detected_distro.version >= 15:
                services_list.append('firewalld')
            else:
                services_list.append('SuSEfirewall2')
        elif detected_distro.name == 'Ubuntu':
            deps.extend(['opal-prd'])
            if detected_distro.version >= 17:
                services_list.remove('networking')

        for package in deps:
            if not smm.check_installed(package) and not smm.install(package):
                self.cancel(' %s is needed for the test to be run' % package)

        if 'PowerNV' in open('/proc/cpuinfo', 'r').read():
            services_list.extend(['opal_errd', 'opal-prd'])
            if os.path.exists('/proc/device-tree/bmc'):
                services_list.remove('opal_errd')
        else:
            services_list.extend(['rtas_errd'])
        services_failed = []
        runner = process.run

        for service in services_list:
            service_obj = SpecificServiceManager(service, runner)
            self.log.info("Checking %s service" % service)
            if service_obj.is_enabled() is False:
                self.log.info("%s service Not Found !!!" % service)
                services_failed.append(service)
                continue
            original_status = service_obj.status()
            if original_status is True:
                service_obj.stop()
                if not wait_for(lambda: not service_obj.status(), 10):
                    self.log.info("Fail to stop %s service" % service)
                    services_failed.append(service)
                    continue
                service_obj.start()
                wait_for(service_obj.status, 10)
            else:
                service_obj.start()
                if not wait_for(service_obj.status, 10):
                    self.log.info("Fail to start %s service" % service)
                    services_failed.append(service)
                    continue
                service_obj.stop()
                wait_for(lambda: not service_obj.status(), 10)
            if not service_obj.status() is original_status:
                self.log.info("Fail to restore original status of the %s"
                              "service" % service)
                services_failed.append(service)

        if services_failed:
            self.fail("List of services failed: %s" % services_failed)
        else:
            self.log.info("All Services Passed the ON/OFF test")
예제 #10
0
파일: service.py 프로젝트: rbian/avocado-vt
def run(test, params, env):
    """
    Logs guest's hostname.
    1) Decide whether use host/guest
    2) Check current service status
    3) Start (Stop) $service
    4) Check status of $service
    5) Stop (Start) $service
    6) Check service status

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    if params.get('test_on_guest') == "yes":
        # error_context.context() is common method to log test steps used to verify
        # what exactly was tested.
        error_context.context("Using guest.", logging.info)
        vm = env.get_vm(params["main_vm"])
        session = vm.wait_for_login()
        # RemoteRunner is object, which simulates the utils.run() behavior
        # on remote consoles
        runner = remote.RemoteRunner(session=session).run
    else:
        error_context.context("Using host", logging.info)
        runner = process.run

    error_context.context("Initialize service manager", logging.info)
    service = SpecificServiceManager(params["test_service"], runner)

    error_context.context("Testing service %s" %
                          params["test_service"], logging.info)
    original_status = service.status()
    logging.info("Original status=%s", original_status)

    if original_status is True:
        service.stop()
        time.sleep(5)
        if service.status() is not False:
            logging.error("Fail to stop service")
            service.start()
            raise exceptions.TestFail("Fail to stop service")
        service.start()
    else:
        service.start()
        time.sleep(5)
        if service.status() is not True:
            logging.error("Fail to start service")
            service.stop()
            raise exceptions.TestFail("Fail to start service")
        service.start()
    time.sleep(5)
    if not service.status() is original_status:
        raise exceptions.TestFail("Fail to restore original status of the %s "
                                  "service" % params["test_service"])