def app_test_environmenterror_repr(): import exceptions as ex e = ex.EnvironmentError("hello") assert str(e) == "hello" e = ex.EnvironmentError(1, "hello") assert str(e) == "[Errno 1] hello" e = ex.EnvironmentError(1, "hello", "world") assert str(e) == "[Errno 1] hello: 'world'"
def run(self, **kwargs): search_opts = kwargs.get('search_opts_tenant', {}) network_resource = self.cloud.resources[utils.NETWORK_RESOURCE] networks_info = network_resource.read_info(**search_opts) external_networks = [] for subnet_info in networks_info['subnets']: if subnet_info['external']: external_networks.append(ipaddr.IPNetwork(subnet_info['cidr'])) if len(external_networks) == 0: return compute_resource = self.cloud.resources[utils.COMPUTE_RESOURCE] computes_info = compute_resource.read_info(**search_opts) instance_names = [] for compute_info in computes_info['instances'].values(): for interface in compute_info['instance']['interfaces']: addr = ipaddr.IPAddress(interface['ip']) for network in external_networks: if network.Contains(addr): instance_names.append(compute_info['instance']['name']) if len(instance_names) > 0: raise exceptions.EnvironmentError( "Instances %s spawned " "in external network directly. CloudFerry can't " "migrate it." % ", ".join(instance_names))
def add_url(self, func): if not hasattr(func, '__method__'): return key = '{}{}'.format(func.__method__, func.__route__).lower() if not self.urls.has_key(key): self.urls[key] = func else: # print 'you has double view functions:{}'.format(key) raise exceptions.EnvironmentError('regist url functions error')
def current_necessitas(): global _necessitas if _necessitas == None: for path in _necessitas_guess_paths(): if os.path.exists(path): _necessitas = path return _necessitas # early return err_str = "Automatic recognition of Necessitas failed " err_str += "please install it or set the " err_str += "'NECESSITAS' environment variable" raise exceptions.EnvironmentError(err_str) else: return _necessitas
def lcd(self, path): path = os.path.normpath(path) if not os.path.exists(path): raise exceptions.EnvironmentError( "Path '%s' does not exist on the local system" % path) os.chdir(path)