def emcxtremioblockdeviceapi_for_test(test_case):
    """
    Create a ``EMCXtremIOBlockDeviceAPI`` instance for use in tests.
    :returns: A ``EMCCinderBlockDeviceAPI`` instance
    """
    user_id = os.getuid()
    if user_id != 0:
        raise SkipTest(
            "``EMCXtremIOBlockDeviceAPI`` queries for iSCSI initiator name which is owned by root, "
            "Required UID: 0, Found UID: {!r}".format(user_id))
    xio = tidy_xio_client_for_test(test_case)
    return xio
    def test_parse_descriptors_parseExtraInfoFiles_benchmark_10000_bridges(self):
        """Benchmark test for ``b.p.descriptors.parseExtraInfoFiles``.
        The algorithm should grow linearly in the number of duplicates.
        """
        raise SkipTest(("This test can take several minutes to complete. "
                        "Run it on your own free time."))

        print()
        for i in range(1, 6):
            descFiles = self.createDuplicatesForBenchmark(b=10000, n=i)
            with Benchmarker():
                routers = descriptors.parseExtraInfoFiles(*descFiles)
Beispiel #3
0
 def wrapper(*a, **kw):
     try:
         func(*a, **kw)
     except FailTest as e:
         if e.args[0].startswith("'Failed to get object inventory from "):
             raise SkipTest(
                 (
                     "This test is prone to intermittent network errors. "
                     "See ticket 8753. Exception was: {!r}"
                 ).format(e)
             )
         raise
Beispiel #4
0
    def setUp(self):
        if not os.environ.get("CI"):
            raise SkipTest(("The mechanize tests cannot handle self-signed  "
                            "TLS certificates, and thus require opening "
                            "another port for running a plaintext HTTP-only "
                            "BridgeDB webserver. Because of this, these tests "
                            "are only run on CI servers."))

        if not PID or not processExists(PID):
            raise FailTest("Could not start BridgeDB process on CI server!")

        self.br = None
Beispiel #5
0
def get_ibm_storage_backend_from_environment(cluster_id):
    """
    :returns: An instance of IBMStorageBlockDeviceAPI
    """
    config_file_path = os.environ.get(messages.ENV_NAME_YML_FILE)
    if config_file_path is not None:
        config_file = open(config_file_path)
    else:
        raise SkipTest(messages.MISSING_ENV_FILE_FOR_TESTING)

    config = yaml.load(config_file.read())
    return get_ibm_storage_backend_by_conf(cluster_id, config['ibm'])
Beispiel #6
0
 def wrapper(*args, **kwargs):
     client = DockerClient()
     docker_version = LooseVersion(client._client.version()['Version'])
     if docker_version < minimum_docker_version:
         raise SkipTest('Minimum required Docker version: {}. '
                        'Actual Docker version: {}. '
                        'Details: {}'.format(
                            minimum_docker_version,
                            docker_version,
                            message,
                        ))
     return wrapped(*args, **kwargs)
Beispiel #7
0
 def ioctl(self, *args, **kwargs):
     """
     Attempt an ioctl, but translate permission denied errors into
     L{SkipTest} so that tests that require elevated system privileges and
     do not have them are skipped instead of failed.
     """
     try:
         return super(TestRealSystem, self).ioctl(*args, **kwargs)
     except IOError as e:
         if EPERM == e.errno:
             raise SkipTest("Permission to configure device denied")
         raise
Beispiel #8
0
    def test_get_obfs4_ipv4_publickey(self):
        """Ask for obfs4 bridges and check that there is an 'public-key' PT
        argument in the bridge lines.
        """
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest(
                    "Could not start BridgeDB process on CI server!")
        else:
            raise SkipTest(("The mechanize tests cannot handle self-signed  "
                            "TLS certificates, and thus require opening "
                            "another port for running a plaintext HTTP-only "
                            "BridgeDB webserver. Because of this, these tests "
                            "are only run on CI servers."))

        self.openBrowser()
        self.goToOptionsPage()

        PT = 'obfs4'

        try:
            soup = self.submitOptions(transport=PT,
                                      ipv6=False,
                                      captchaResponse=CAPTCHA_RESPONSE)
        except ValueError as error:
            if 'non-disabled' in str(error):
                raise SkipTest(
                    "Pluggable Transport obfs4 is currently disabled.")

        bridges = self.getBridgeLinesFromSoup(soup, fieldsPerBridge=6)
        for bridge in bridges:
            ptArgs = bridge[-3:]
            hasPublicKey = False
            for arg in ptArgs:
                if 'public-key' in arg:
                    hasPublicKey = True

            self.assertTrue(
                hasPublicKey,
                "obfs4 bridge line is missing 'public-key' PT arg.")
Beispiel #9
0
 def buildReactor(self):
     """
     Create and return a reactor using C{self.reactorFactory}.
     """
     try:
         from twisted.internet.cfreactor import CFReactor
         from twisted.internet import reactor as globalReactor
     except ImportError:
         pass
     else:
         if (isinstance(globalReactor, CFReactor)
             and self.reactorFactory is CFReactor):
             raise SkipTest(
                 "CFReactor uses APIs which manipulate global state, "
                 "so it's not safe to run its own reactor-builder tests "
                 "under itself")
     try:
         reactor = self.reactorFactory()
     except:
         # Unfortunately, not all errors which result in a reactor
         # being unusable are detectable without actually
         # instantiating the reactor.  So we catch some more here
         # and skip the test if necessary.  We also log it to aid
         # with debugging, but flush the logged error so the test
         # doesn't fail.
         log.err(None, "Failed to install reactor")
         self.flushLoggedErrors()
         raise SkipTest(Failure().getErrorMessage())
     else:
         if self.requiredInterfaces is not None:
             missing = filter(
                  lambda required: not required.providedBy(reactor),
                  self.requiredInterfaces)
             if missing:
                 self.unbuildReactor(reactor)
                 raise SkipTest("%s does not provide %s" % (
                     fullyQualifiedName(reactor.__class__),
                     ",".join([fullyQualifiedName(x) for x in missing])))
     self.addCleanup(self.unbuildReactor, reactor)
     return reactor
Beispiel #10
0
            def connectionMade(self):
                if not ITLSTransport.providedBy(self.transport):
                    # Functionality isn't available to be tested.
                    finished = self.factory.finished
                    self.factory.finished = None
                    finished.errback(SkipTest("No ITLSTransport support"))
                    return

                # Switch the transport to TLS.
                self.transport.startTLS(self.factory.context)
                # Force TLS to really get negotiated.  If nobody talks, nothing
                # will happen.
                self.transport.write("x")
Beispiel #11
0
 def test_component_start_error(self):
     ComponentTesterUpdate('test_pause_c1')
     yield component.start(['test_pause_c1'])
     yield component.pause(['test_pause_c1'])
     test_comp = component.get('test_pause_c1')
     try:
         result = self.failureResultOf(test_comp._component_start())
     except AttributeError:
         raise SkipTest(
             'This test requires trial failureResultOf() in Twisted version >= 13'
         )
     self.assertEqual(result.check(component.ComponentException),
                      component.ComponentException)
Beispiel #12
0
def daterablockdeviceapi_for_test(test_case):
    """
    Create a ``DateraBlockDeviceAPI`` instance for use in tests.
    :returns: A ``DateraBlockDeviceAPI`` instance
    """
    user_id = os.getuid()
    if user_id != 0:
        raise SkipTest(
            "``DateraBlockDeviceAPI`` queries for iSCSI initiator name \
                           which is owned by root, "
            "Required UID: 0, Found UID: {!r}".format(user_id))
    dfs = cleanup_for_test(test_case)
    return dfs
    def test_parse_descriptors_parseExtraInfoFiles_benchmark_1000_bridges(
            self):
        """Benchmark test for ``b.p.descriptors.parseExtraInfoFiles``."""
        raise SkipTest(("This test can take several minutes to complete. "
                        "Run it on your own free time."))

        print()
        for i in range(1, 6):
            descFiles = self.createDuplicatesForBenchmark(b=1000, n=i)
            with Benchmarker():
                routers = descriptors.parseExtraInfoFiles(*descFiles)
            for descFile in descFiles:
                self.assertTrue(self.removeTestDescriptorsFile(descFile))
Beispiel #14
0
def api_factory(test_case):
    """
    :param test: A twisted.trial.unittest.TestCase instance
    """
    flocker_functional_test = environ.get('FLOCKER_FUNCTIONAL_TEST')
    if flocker_functional_test is None:
        raise SkipTest(
            'Please set FLOCKER_FUNCTIONAL_TEST environment variable to '
            'run storage backend functional tests.')
    api = rbd_from_configuration("flocker", "client.admin",
                                 "/etc/ceph/ceph.conf", "rbd")
    test_case.addCleanup(api.destroy_all_flocker_volumes)
    return api
Beispiel #15
0
def cinder_volume_manager():
    """
    Get an ``ICinderVolumeManager`` configured to work on this environment.

    XXX: It will not automatically clean up after itself. See FLOC-1824.
    """
    try:
        config = get_blockdevice_config(ProviderType.openstack)
    except InvalidConfig as e:
        raise SkipTest(str(e))
    region = get_openstack_region_for_test()
    session = get_keystone_session(**config)
    return get_cinder_v1_client(session, region).volumes
Beispiel #16
0
    def test_noCompatibilityLayer(self):
        """
        If no compatibility layer is present, imports of gobject and friends
        are disallowed.

        We do this by running a process where we make sure gi.pygtkcompat
        isn't present.
        """
        if _PY3:
            raise SkipTest("Python3 always has the compatibility layer.")

        from twisted.internet import reactor
        if not IReactorProcess.providedBy(reactor):
            raise SkipTest("No process support available in this reactor.")

        result = Deferred()

        class Stdout(ProcessProtocol):
            data = b""

            def errReceived(self, err):
                print(err)

            def outReceived(self, data):
                self.data += data

            def processExited(self, reason):
                result.callback(self.data)

        path = FilePath(__file__).sibling(b"process_gireactornocompat.py").path
        pyExe = FilePath(sys.executable)._asBytesPath()
        # Pass in a PYTHONPATH that is the test runner's os.path, to make sure
        # we're running from a checkout
        reactor.spawnProcess(Stdout(),
                             pyExe, [pyExe, path],
                             env={"PYTHONPATH": ":".join(os.path)})
        result.addCallback(self.assertEqual, b"success")
        return result
Beispiel #17
0
    def test_badContext(self):
        """
        If the context factory passed to L{ITCPTransport.startTLS} raises an
        exception from its C{getContext} method, that exception is raised by
        L{ITCPTransport.startTLS}.
        """
        reactor = self.buildReactor()

        brokenFactory = BrokenContextFactory()
        results = []

        serverFactory = ServerFactory()
        serverFactory.protocol = Protocol

        port = reactor.listenTCP(0, serverFactory, interface=self.interface)
        endpoint = self.endpoints.client(reactor, port.getHost())

        clientFactory = ClientFactory()
        clientFactory.protocol = Protocol
        connectDeferred = endpoint.connect(clientFactory)

        def connected(protocol):
            if not ITLSTransport.providedBy(protocol.transport):
                results.append("skip")
            else:
                results.append(
                    self.assertRaises(ValueError, protocol.transport.startTLS,
                                      brokenFactory))

        def connectFailed(failure):
            results.append(failure)

        def whenRun():
            connectDeferred.addCallback(connected)
            connectDeferred.addErrback(connectFailed)
            connectDeferred.addBoth(lambda ign: reactor.stop())

        needsRunningReactor(reactor, whenRun)

        self.runReactor(reactor)

        self.assertEqual(len(results), 1,
                         "more than one callback result: %s" % (results, ))

        if isinstance(results[0], Failure):
            # self.fail(Failure)
            results[0].raiseException()
        if results[0] == "skip":
            raise SkipTest("Reactor does not support ITLSTransport")
        self.assertEqual(BrokenContextFactory.message, str(results[0]))
Beispiel #18
0
    def test_bridgedb_SIGHUP_assignments_log(self):
        """Test that BridgeDB creates a new ``assignments.log`` file after
        receiving a SIGHUP.
        """
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest("Could not start BridgeDB process on CI server!")
        if not self.pid or not processExists(self.pid):
            raise SkipTest("Can't run test: no BridgeDB process running.")

        os.unlink(self.assignmentsFile)
        os.kill(self.pid, signal.SIGHUP)
        self.doSleep()
        self.assertTrue(os.path.isfile(self.assignmentsFile))
Beispiel #19
0
    def testUpgrade(self):
        try:
            from PIL import Image
        except ImportError:
            raise SkipTest('PIL is not available')

        m = self.store.findUnique(Mugshot)
        p = self.store.findUnique(Person)

        self.assertIdentical(m.person, p)
        self.assertEqual(p.name, 'Bob')

        img = Image.open(m.smallerBody.open())
        self.assertEqual(img.size, (m.smallerSize, m.smallerSize))
Beispiel #20
0
def client_from_environment():
    """
    Search the process environment for a DigitalOcean v2 API token and use it
    to build an API client instance.

    :returns: A ``pyocean.DigitalOcean`` client instance.
    """
    token = os.environ.get('DIGITALOCEAN_TOKEN')
    if token is None:
        raise SkipTest(
            'A DIGITALOCEAN_TOKEN environment variable is required to run '
            'these tests.')

    return pyocean.DigitalOcean(token)
Beispiel #21
0
 def test_verify_false(self):
     """
     With the peer_verify field set to False, connection to the
     OpenStack servers always succeeds.
     """
     try:
         config = get_blockdevice_config(ProviderType.openstack)
     except InvalidConfig as e:
         raise SkipTest(str(e))
     config['peer_verify'] = False
     session = get_keystone_session(**config)
     region = get_openstack_region_for_test()
     cinder_client = get_cinder_v1_client(session, region)
     self.assertTrue(self._authenticates_ok(cinder_client))
Beispiel #22
0
    def setUp(self):
        if not ssh:
            raise SkipTest('Crypto requirements missing. Skipping Test.')

        self.pub_key_file_name = self.mktemp()
        self.pub_key_file = open(self.pub_key_file_name, 'w')
        self.pub_key_file.write(public_key.toString('OPENSSH'))
        self.pub_key_file.flush()

        self._middlewares = []
        self._client_sockets = []

        self.mw = self.get_middleware(
            {'authorized_keys': [self.pub_key_file.name]})
Beispiel #23
0
 def check_missing_messages(reason):
     reason.trap(RemoteFileNotFound)
     # XXX It would be better to predict this case based on what we know
     # about the OS the cluster is running.  We don't currently have
     # easy access to that information, though.
     #
     # Doing it this way is subject to incorrect skips if we happen to
     # make a mistaken assumption about /var/log/messages (eg if we
     # misspell the name or if it just hasn't been written *quite* yet
     # at the time we check).
     #
     # Currently, CentOS and Ubuntu are supported and CentOS is expected
     # to have this log file and Ubuntu is expected not to.
     raise SkipTest("{} not found".format(reason.value))
Beispiel #24
0
 def buildReactor(self):
     """
     Create and return a reactor using C{self.reactorFactory}.
     """
     try:
         reactor = self.reactorFactory()
     except:
         # Unfortunately, not all errors which result in a reactor being
         # unusable are detectable without actually instantiating the
         # reactor.  So we catch some more here and skip the test if
         # necessary.
         raise SkipTest(Failure().getErrorMessage())
     self.addCleanup(self.unbuildReactor, reactor)
     return reactor
Beispiel #25
0
def loopbackblockdeviceapi_for_test(test_case):
    """
    :returns: A ``LoopbackBlockDeviceAPI`` with a temporary root directory
        created for the supplied ``test_case``.
    """
    user_id = os.getuid()
    if user_id != 0:
        raise SkipTest("``LoopbackBlockDeviceAPI`` uses ``losetup``, "
                       "which requires root privileges. "
                       "Required UID: 0, Found UID: {!r}".format(user_id))

    root_path = test_case.mktemp()
    test_case.addCleanup(losetup_detach_all, FilePath(root_path))
    return LoopbackBlockDeviceAPI.from_path(root_path=root_path)
Beispiel #26
0
 def open(self, filename, *args, **kwargs):
     """
     Attempt an open, but if the file is /dev/net/tun and it does not exist,
     translate the error into L{SkipTest} so that tests that require
     platform support for tuntap devices are skipped instead of failed.
     """
     try:
         return super(TestRealSystem, self).open(filename, *args, **kwargs)
     except OSError as e:
         # The device file may simply be missing.  The device file may also
         # exist but be unsupported by the kernel.
         if e.errno in (ENOENT, ENODEV) and filename == b"/dev/net/tun":
             raise SkipTest("Platform lacks /dev/net/tun")
         raise
Beispiel #27
0
    def getListeningPort(self,
                         reactor,
                         protocol,
                         port=0,
                         interface='',
                         maxPacketSize=8192):
        """
        Get a UDP port from a reactor, wrapping an already-initialized file
        descriptor.

        @param reactor: A reactor used to build the returned
            L{IListeningPort} provider.
        @type reactor: L{twisted.internet.interfaces.IReactorSocket}

        @param port: A port number to which the adopted socket will be
            bound.
        @type port: C{int}

        @param interface: The local IPv4 or IPv6 address to which the
            adopted socket will be bound.  defaults to '', ie all IPv4
            addresses.
        @type interface: C{str}

        @see: L{twisted.internet.IReactorSocket.adoptDatagramPort} for other
            argument and return types.
        """
        if IReactorSocket.providedBy(reactor):
            if ':' in interface:
                domain = socket.AF_INET6
                address = socket.getaddrinfo(interface, port)[0][4]
            else:
                domain = socket.AF_INET
                address = (interface, port)
            portSock = socket.socket(domain, socket.SOCK_DGRAM)
            portSock.bind(address)
            portSock.setblocking(False)
            try:
                return reactor.adoptDatagramPort(portSock.fileno(),
                                                 portSock.family, protocol,
                                                 maxPacketSize)
            finally:
                # The socket should still be open; fileno will raise if it is
                # not.
                portSock.fileno()
                # Now clean it up, because the rest of the test does not need
                # it.
                portSock.close()
        else:
            raise SkipTest("Reactor does not provide IReactorSocket")
Beispiel #28
0
    def test_stopStartReading(self):
        """
        This test verifies transport socket read state after multiple
        pause/resumeProducing calls.
        """
        sf = ServerFactory()
        reactor = sf.reactor = self.buildReactor()

        skippedReactors = ["Glib2Reactor", "Gtk2Reactor"]
        reactorClassName = reactor.__class__.__name__
        if reactorClassName in skippedReactors and platform.isWindows():
            raise SkipTest("This test is broken on gtk/glib under Windows.")

        sf.protocol = StopStartReadingProtocol
        sf.ready = Deferred()
        sf.stop = Deferred()
        p = reactor.listenTCP(0, sf)
        port = p.getHost().port

        def proceed(protos, port):
            """
            Send several IOCPReactor's buffers' worth of data.
            """
            self.assertTrue(protos[0])
            self.assertTrue(protos[1])
            protos = protos[0][1], protos[1][1]
            protos[0].transport.write('x' * (2 * 4096) + 'y' * (2 * 4096))
            return (sf.stop.addCallback(
                cleanup, protos, port).addCallback(lambda ign: reactor.stop()))

        def cleanup(data, protos, port):
            """
            Make sure IOCPReactor didn't start several WSARecv operations
            that clobbered each other's results.
            """
            self.assertEquals(data, 'x' * (2 * 4096) + 'y' * (2 * 4096),
                              'did not get the right data')
            return DeferredList([
                maybeDeferred(protos[0].transport.loseConnection),
                maybeDeferred(protos[1].transport.loseConnection),
                maybeDeferred(port.stopListening)
            ])

        cc = TCP4ClientEndpoint(reactor, '127.0.0.1', port)
        cf = ClientFactory()
        cf.protocol = Protocol
        d = DeferredList([cc.connect(cf), sf.ready]).addCallback(proceed, p)
        self.runReactor(reactor)
        return d
Beispiel #29
0
    def setUp(self):
        """
        Add our example directory to the path and record which modules are
        currently loaded.
        """
        self.originalPath = sys.path[:]
        self.originalModules = sys.modules.copy()

        # Python usually expects native strs to be written to sys.stdout/stderr
        self.fakeErr = NativeStringIO()
        self.patch(sys, 'stderr', self.fakeErr)
        self.fakeOut = NativeStringIO()
        self.patch(sys, 'stdout', self.fakeOut)

        # Get documentation root
        try:
            here = FilePath(os.environ['TOX_INI_DIR']).child('docs')
        except KeyError:
            raise SkipTest(
                "Examples not found ($TOX_INI_DIR unset) - cannot test",
            )

        # Find the example script within this branch
        for childName in self.exampleRelativePath.split('/'):
            here = here.child(childName)
            if not here.exists():
                raise SkipTest(
                    "Examples (%s) not found - cannot test" % (here.path,))
        self.examplePath = here

        # Add the example parent folder to the Python path
        sys.path.append(self.examplePath.parent().path)

        # Import the example as a module
        moduleName = self.examplePath.basename().split('.')[0]
        self.example = __import__(moduleName)
Beispiel #30
0
 def buildReactor(self):
     """
     Create and return a reactor using C{self.reactorFactory}.
     """
     try:
         reactor = self.reactorFactory()
     except:
         # Unfortunately, not all errors which result in a reactor
         # being unusable are detectable without actually
         # instantiating the reactor.  So we catch some more here
         # and skip the test if necessary.  We also log it to aid
         # with debugging, but flush the logged error so the test
         # doesn't fail.
         log.err(None, "Failed to install reactor")
         self.flushLoggedErrors()
         raise SkipTest(Failure().getErrorMessage())
     else:
         if self.requiredInterface is not None:
             if not self.requiredInterface.providedBy(reactor):
                 self.unbuildReactor(reactor)
                 raise SkipTest("%r does not provide %r" %
                                (reactor, self.requiredInterface))
     self.addCleanup(self.unbuildReactor, reactor)
     return reactor