Python exceptions.RuntimeError() Examples

The following are 9 code examples of exceptions.RuntimeError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module exceptions , or try the search function .
Example #1
Source File: silverstripe.py    From droopescan with GNU Affero General Public License v3.0 6 votes vote down vote up
def update_version(self):
        """
            @return: updated VersionsFile
        """
        fw_gr, versions_file, new_tags = ua.github_repo_new(self._repo_framework,
                'silverstripe/framework', self.versions_file, self.update_majors)
        cms_gr, _, _ = ua.github_repo_new(self._repo_cms,
                'silverstripe/cms', self.versions_file, self.update_majors)

        hashes = {}
        for version in new_tags:
            fw_gr.tag_checkout(version)
            try:
                cms_gr.tag_checkout(version)
            except exceptions.RuntimeError:
                print("Version %s does not exist on `cms` branch. Skipping.")
                continue

            hashes[version] = ua.hashes_get(versions_file, './.update-workspace/silverstripe/')

        versions_file.update(hashes)
        return versions_file 
Example #2
Source File: redefine_in_handler.py    From python-netsurv with MIT License 5 votes vote down vote up
def some_function():
    """A function."""
    exc = None

    try:
        {}["a"]
    except KeyError, exceptions.RuntimeError: # [redefine-in-handler]
        pass 
Example #3
Source File: redefine_in_handler.py    From python-netsurv with MIT License 5 votes vote down vote up
def some_function():
    """A function."""
    exc = None

    try:
        {}["a"]
    except KeyError, exceptions.RuntimeError: # [redefine-in-handler]
        pass 
Example #4
Source File: mixing.py    From MJHMC with GNU General Public License v2.0 5 votes vote down vote up
def sg(sampler):
    """returns the spectral gap
    t: transition matrix
    """
    while True:
        try:
            t = sampler.get_empirical_transition_matrix()
            w,v = eig(t)
            w_ord = np.sort(w)[::-1]
            if np.around(np.real_if_close(w_ord[0]), decimals=5) != 1:
                raise Exception("no eval with value 1")
            return 1 - np.absolute(w_ord[1])
        except RuntimeError:
            sampler.sample(1000) 
Example #5
Source File: virtsetup.py    From transperf with Apache License 2.0 5 votes vote down vote up
def ip_numeric(ip, ip_mode):
        """Returns numerical value from IP address."""
        if ip_mode == socket.AF_INET:
            # Returns numerical value from IPv4 address (dotted string).
            return struct.unpack('!I', socket.inet_pton(socket.AF_INET, ip))[0]
        elif ip_mode == socket.AF_INET6:
            return int(binascii.hexlify(socket.inet_pton(socket.AF_INET6, ip)),
                       16)
        else:
            raise exceptions.RuntimeError('Invalid IP mode %s' % ip_mode) 
Example #6
Source File: virtsetup.py    From transperf with Apache License 2.0 5 votes vote down vote up
def numeric_ip(numeric, ip_mode):
        """Returns IP address from numerical value."""
        if ip_mode == socket.AF_INET:
            # Returns IPv4 address (dotted string) from numerical value.
            return socket.inet_ntop(socket.AF_INET, struct.pack('!I', numeric))
        elif ip_mode == socket.AF_INET6:
            # pad=32 is to 0-pad all 128 bits.
            hex_form = '{value:0{pad}x}'.format(value=numeric, pad=32)
            return socket.inet_ntop(socket.AF_INET6,
                                    binascii.unhexlify(hex_form))
        else:
            raise exceptions.RuntimeError('Invalid IP mode %s' % ip_mode) 
Example #7
Source File: virtsetup.py    From transperf with Apache License 2.0 5 votes vote down vote up
def verify_iface_cfg(iface_cfg, ip_mode):
        """Verifies interface exists with configured address."""
        iface = iface_cfg['name']
        cmd = 'ip addr show dev {iface}'.format(iface=iface)
        out, err, _ = Utils.run(cmd)
        lines = out.splitlines()
        errlines = err.splitlines()
        # Verify iface exists.
        assert lines, 'No output for %s' % cmd
        assert (not errlines or
                'does not exist' not in errlines[0]), ('Device %s '
                                                       'does not exist.' %
                                                       iface)
        # Verify address.
        matcher = 'inet6' if ip_mode == socket.AF_INET6 else 'inet'
        for line in lines:
            splits = line.split()
            if not splits:
                continue
            if splits[0] != matcher:
                continue
            addr = splits[1]
            if addr == iface_cfg['address'][ip_mode]:
                return
        error = 'Unable to verify interface: %s' % iface_cfg
        LOG.error(error)
        raise RuntimeError(error) 
Example #8
Source File: virtsetup.py    From transperf with Apache License 2.0 4 votes vote down vote up
def setup_container_environment(self):
        """Setup container environment for experiment.

        Performs the following actions:
        1. Delete existing node containers and bridge device, as well as all
           interfaces connected to bridge device. Unmounts /etc/hosts if needed.
           (We temporarily bind mount per transperf run for node addresses).
        2. Creates virtual bridge and rootns veth pair for contacting nodes in
           namespace (ROOT_TRANSPERF_ADDR/TRANSPERF_SUBNET) with stp off.
        3. Remounts (--make-private, --bind) mount namespace dir.
        4. Creates a container per node with these persistent namespaces:
           uts: <outdir>/uts/<container>
           mount: <outdir>/mntns/<container>
           netns: /var/run/netns/<container>
           with a running 'screen' session as the initial process.
           Creates per-node directories and performs necessary mount ops.

        NB: This method does *not* connect the containers to the bridge
        (see: container.setup_all_container_interfaces() instead).
        It also does not create a custom /etc/hosts file (only orch.py can do
        that since it can vary from config file to config file).
        It also does not handle custom /etc/hosts file bind-mounting
        (see: initialization code in recv.py/send.py/orch.py instead).

        Raises:
            RuntimeError if an operation fails during container setup.

        """
        # Ensures bonding module is loaded.
        IfUtils.ensure_bonding_available()

        # Delete existing bridge.
        IfUtils.delete_bridge(self.brdev)

        # Prepare to create namespaces.
        self.__prepare_ns_dirs()

        # Cleanup existing nodes as necessary.
        for node in self.nodes:
            net_ns = node
            cmd = 'ip netns del {ns}'.format(ns=net_ns)
            Utils.run(cmd)
            # NB: We do not clean up the node processes, however.

        # Create bridge.
        IfUtils.create_bridge(self.brdev)
        assert IfUtils.br_exists(self.brdev), ('Cannot create '
                                               'bridge %s' % self.brdev)

        # Create root veth pair and attach to bridge.
        IfUtils.setup_root_veth(self.brdev, self.ip_mode)
        IfUtils.verify_iface_cfg(Constants.ROOT_TRANSPERF_IFACE, self.ip_mode)
        IfUtils.verify_iface_on_br(self.brdev,
                                   Constants.ROOT_TRANSPERF_IFACE['br-pair'])

        # Create node containers.
        for node in self.nodes:
            self.__create_node_container(node) 
Example #9
Source File: virtsetup.py    From transperf with Apache License 2.0 4 votes vote down vote up
def setup_all_container_interfaces(self, node_cfg_dict):
        """Assigns addresses and creates interfaces for all nodes.

        Performs the following actions:
        1. For each node, assign an address, >= 1 + ROOT_TRANSPERF_ADDR.
        2. For each node, setup the container interfaces with the assigned
           address.

        Args:
            node_cfg_dict: A per-node configuration for interfaces.

        Return:
            Nothing.

        Raises:
            RuntimeError: if an operation fails.
        """
        base = Utils.ip_numeric(Constants.ROOT_TRANSPERF_ADDR[self.ip_mode],
                                self.ip_mode)
        nextval = base + 1
        mask = Constants.TRANSPERF_SUBNET[self.ip_mode]
        node_dns = []

        # Check if we have too many nodes.
        max_nodes = Constants.MAX_NODES[self.ip_mode]
        if len(self.nodes) >= max_nodes:
            raise RuntimeError('Too many nodes (%d given, max %d)' %
                               (len(self.nodes), max_nodes))

        # IFB device module is not virtualized by netns. Need to setup IFBs in
        # root namespace and move into the per-node namespaces.
        self.__setup_node_ifbs(node_cfg_dict)

        # Assign subsequent nodes the next available IP address.
        for node in self.nodes:
            val = nextval
            nextval += 1
            node_addr = '{ip}/{mask}'.format(ip=Utils.numeric_ip(val,
                                                                 self.ip_mode),
                                             mask=mask)
            # Get per-node cfg and setup interfaces for node.
            node_cfg = self.__get_node_cfg(node, node_cfg_dict)
            self.__setup_container_interfaces(node, node_addr, node_cfg)
            # DNS entry for augmented /etc/hosts file.
            dns = '{addr} {node}'.format(addr=node_addr.split('/')[0],
                                         node=node)
            node_dns.append(dns)

        # Add nodes to hosts file and bind-mount it on top of regular file.
        new_hosts = os.path.join(self.out_dir, 'hosts')
        with open(new_hosts, 'w') as new_file:
            for dns in node_dns:
                new_file.write('%s\n' % dns)
            new_file.close()