def _lib(old_name): """Deprecate a function moved to neutron_lib.api.converters/validators.""" new_func = getattr(lib_validators, old_name, None) if not new_func: # Try non-private name (without leading underscore) new_func = getattr(lib_validators, old_name[1:], None) if not new_func: # If it isn't a validator, maybe it's a converter new_func = getattr(lib_converters, old_name, None) assert new_func return moves.moved_function(new_func, old_name, __name__, message='moved to neutron_lib', version='mitaka', removal_version='ocata')
self.firewall.security_group_updated('sg_member', [], updated_devices) # If a device is both in new and updated devices # avoid reprocessing it updated_devices = ((updated_devices | devices_to_refilter) - new_devices) if updated_devices: LOG.debug("Refreshing firewall for %d devices", len(updated_devices)) self.refresh_firewall(updated_devices) # TODO(armax): For bw compat with external dependencies; to be dropped in P. # NOTE(dasm): Should be already removed, but didn't have DeprecationWarning. SG_RPC_VERSION = moves.moved_function( securitygroups_rpc.SecurityGroupAgentRpcApiMixin.SG_RPC_VERSION, 'SG_RPC_VERSION', __name__, version='Liberty', removal_version='Pike' ) SecurityGroupServerRpcApi = moves.moved_class( securitygroups_rpc.SecurityGroupServerRpcApi, 'SecurityGroupServerRpcApi', old_module_name=__name__, version='Liberty', removal_version='Pike' ) SecurityGroupAgentRpcApiMixin = moves.moved_class( securitygroups_rpc.SecurityGroupAgentRpcApiMixin, 'SecurityGroupAgentRpcApiMixin', old_module_name=__name__, version='Liberty', removal_version='Pike' ) SecurityGroupAgentRpcCallbackMixin = moves.moved_class( securitygroups_rpc.SecurityGroupAgentRpcCallbackMixin, 'SecurityGroupAgentRpcCallbackMixin', old_module_name=__name__, version='Liberty', removal_version='Pike'
context_manager = enginefacade.transaction_context() _FACADE = None MAX_RETRIES = 10 def is_retriable(e): if _is_nested_instance(e, (db_exc.DBDeadlock, exc.StaleDataError)): return True # looking savepoints mangled by deadlocks. see bug/1590298 for details. return _is_nested_instance(e, db_exc.DBError) and '1305' in str(e) is_deadlock = moves.moved_function(is_retriable, 'is_deadlock', __name__, message='use "is_retriable" instead', version='newton', removal_version='ocata') retry_db_errors = oslo_db_api.wrap_db_retry( max_retries=MAX_RETRIES, retry_interval=0.1, inc_retry_interval=True, retry_on_request=True, exception_checker=is_retriable ) def _is_nested_instance(e, etypes): """Check if exception or its inner excepts are an instance of etypes.""" return (isinstance(e, etypes) or isinstance(e, exceptions.MultipleExceptions) and any(_is_nested_instance(i, etypes) for i in e.inner_exceptions))
from neutron.common import utils from neutron.tests.functional import base MARK_VALUE = '0x1' MARK_MASK = '0xffffffff' ICMP_MARK_RULE = ('-j MARK --set-xmark %(value)s/%(mask)s' % { 'value': MARK_VALUE, 'mask': MARK_MASK }) MARKED_BLOCK_RULE = '-m mark --mark %s -j DROP' % MARK_VALUE ICMP_BLOCK_RULE = '-p icmp -j DROP' get_rand_name = moves.moved_function( utils.get_rand_name, 'get_rand_name', __name__, message='use "neutron.common.utils.get_rand_name" instead', version='Newton', removal_version='Ocata') # Regarding MRO, it goes BaseOVSLinuxTestCase, WithScenarios, # BaseSudoTestCase, ..., UnitTest, object. setUp is not defined in # WithScenarios, so it will correctly be found in BaseSudoTestCase. class BaseOVSLinuxTestCase(testscenarios.WithScenarios, base.BaseSudoTestCase): scenarios = [ ('vsctl', dict(ovsdb_interface='vsctl')), ('native', dict(ovsdb_interface='native')), ] def setUp(self):
def etcdir(*p): return os.path.join(ETCDIR, *p) def fake_use_fatal_exceptions(*args): return True for _name in ('get_related_rand_names', 'get_rand_name', 'get_rand_device_name', 'get_related_rand_device_names'): setattr( sys.modules[__name__], _name, moves.moved_function(getattr(utils, _name), _name, __name__, message='use "neutron.common.utils.%s" instead' % _name, version='Newton', removal_version='Ocata')) def bool_from_env(key, strict=False, default=False): value = os.environ.get(key) return strutils.bool_from_string(value, strict=strict, default=default) def setup_test_logging(config_opts, log_dir, log_file_path_template): # Have each test log into its own log file config_opts.set_override('debug', True) fileutils.ensure_tree(log_dir, mode=0o755) log_file = sanitize_log_path(os.path.join(log_dir, log_file_path_template))
@removals.remove() def red_comet(): return True @removals.remove(category=PendingDeprecationWarning) def blue_comet(): return True def yellow_sun(): """Yellow.""" return True yellowish_sun = moves.moved_function(yellow_sun, 'yellowish_sun', __name__) @removals.remove() class EFSF(object): pass @removals.remove(category=PendingDeprecationWarning) class EFSF_2(object): pass @removals.removed_class("StarLord") class StarLord(object): def __init__(self):
msg = ("N328: Use assertTrue(observed) instead of " "assertEqual(True, observed)") yield (0, msg) if re.search(r"assertEqual\(\s*False,[^,]*(,[^,]*)?\)", logical_line): msg = ("N328: Use assertFalse(observed) instead of " "assertEqual(False, observed)") yield (0, msg) if re.search(r"assertEqual\([^,]*,\s*False(,[^,]*)?\)", logical_line): msg = ("N328: Use assertFalse(observed) instead of " "assertEqual(False, observed)") yield (0, msg) check_asserttrue = flake8ext( moves.moved_function( check_asserttruefalse, 'check_asserttrue', __name__, version='Newton', removal_version='Ocata')) check_assertfalse = flake8ext( moves.moved_function( check_asserttruefalse, 'check_assertfalse', __name__, version='Newton', removal_version='Ocata')) @flake8ext def no_mutable_default_args(logical_line): """N329 - Don't use mutable default arguments.""" msg = "N329: Method's default argument shouldn't be mutable!" if checks.mutable_default_args.match(logical_line): yield (0, msg)
# All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # TODO(dougwig) - remove this file at the beginning of N. from debtcollector import moves import neutron._i18n message = "moved to neutron._i18n; please migrate to local oslo_i18n " \ "usage, as defined in the devref and at " \ "http://docs.openstack.org/developer/oslo.i18n/usage.html" _ = moves.moved_function(neutron._i18n._, '_', __name__, message=message) _LI = moves.moved_function(neutron._i18n._LI, '_LI', __name__, message=message) _LW = moves.moved_function(neutron._i18n._LW, '_LW', __name__, message=message) _LE = moves.moved_function(neutron._i18n._LE, '_LE', __name__, message=message) _LC = moves.moved_function(neutron._i18n._LC, '_LC', __name__, message=message)
# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # TODO(amotoki): Remove this file at the beginning of Nxx cycle. from debtcollector import moves from neutronclient import _i18n message = ("moved to neutronclient._i18n; please migrate to local " "oslo_i18n usage, as defined at " "http://docs.openstack.org/developer/oslo.i18n/usage.html") _ = moves.moved_function(_i18n._, '_', __name__, message=message)
def etcdir(*p): return os.path.join(ETCDIR, *p) def fake_use_fatal_exceptions(*args): return True for _name in ('get_related_rand_names', 'get_rand_name', 'get_rand_device_name', 'get_related_rand_device_names'): setattr(sys.modules[__name__], _name, moves.moved_function( getattr(utils, _name), _name, __name__, message='use "neutron.common.utils.%s" instead' % _name, version='Newton', removal_version='Ocata')) def bool_from_env(key, strict=False, default=False): value = os.environ.get(key) return strutils.bool_from_string(value, strict=strict, default=default) def setup_test_logging(config_opts, log_dir, log_file_path_template): # Have each test log into its own log file config_opts.set_override('debug', True) utils.ensure_dir(log_dir) log_file = sanitize_log_path( os.path.join(log_dir, log_file_path_template)) config_opts.set_override('log_file', log_file)
class Psikit(object): def __init__(self, threads=4, memory=4, debug=False): import psi4 self.psi4 = psi4 self.psi4.set_memory("{} GB".format(memory)) #self.psi4.set_options({"save_jk": True}) # for JK calculation self.psi4.set_num_threads(threads) self.wfn = None self.mol = None self.debug = debug self.tempdir = mkdtemp() if self.debug: self.psi4.core.set_output_file("psikit_out.dat", True) else: self.psi4.core.be_quiet() def clean(self): rmtree(self.tempdir) def read_from_smiles(self, smiles_str, opt=True): self.mol = Chem.MolFromSmiles(smiles_str) if opt: self.rdkit_optimize() def read_from_molfile(self, molfile, opt=True, removeHs=False): self.mol = Chem.MolFromMolFile(molfile, removeHs=removeHs) if opt: self.rdkit_optimize() def rdkit_optimize(self, addHs=True): if addHs: self.mol = Chem.AddHs(self.mol) AllChem.EmbedMolecule(self.mol, useExpTorsionAnglePrefs=True,useBasicKnowledge=True) AllChem.UFFOptimizeMolecule(self.mol) def geometry(self, multiplicity=1): xyz = self.mol2xyz(multiplicity=multiplicity) self.psi4.geometry(xyz) def energy(self, basis_sets= "scf/6-31g**", return_wfn=True, multiplicity=1): self.geometry(multiplicity=multiplicity) scf_energy, wfn = self.psi4.energy(basis_sets, return_wfn=return_wfn) self.psi4.core.clean() self.wfn = wfn self.mol = self.xyz2mol() return scf_energy def optimize(self, basis_sets= "scf/6-31g**", return_wfn=True, name=None, multiplicity=1, maxiter=50): if not name: name = uuid.uuid4().hex self.psi4.core.IO.set_default_namespace(name) self.geometry(multiplicity=multiplicity) self.psi4.set_options({'GEOM_MAXITER':maxiter}) try: scf_energy, wfn = self.psi4.optimize(basis_sets, return_wfn=return_wfn) self.wfn = wfn except self.psi4.OptimizationConvergenceError as cError: print('Convergence error caught: {0}'.format(cError)) self.wfn = cError.wfn scf_energy = self.wfn.energy() self.psi4.core.clean() self.mol = self.xyz2mol() if not self.debug: self.psi4.core.opt_clean() # Seg fault will occured when the function is called before optimize. return scf_energy def set_options(self, **kwargs): """ http://www.psicode.org/psi4manual/1.2/psiapi.html IV. Analysis of Intermolecular Interactions and http://forum.psicode.org/t/how-can-i-change-max-iteration-in-energy-method/1238/2 """ self.psi4.set_options(kwargs) def mol2xyz(self, multiplicity=1): return mol2xyz(self.mol) def xyz2mol(self, confId=0): natom = self.wfn.molecule().natom() mol_array_bohr = self.wfn.molecule().geometry().to_array() mol_array = mol_array_bohr * 0.52917721092 nmol = Chem.Mol(self.mol) conf = nmol.GetConformer(confId) for i in range(natom): conf.SetAtomPosition(i, tuple(mol_array[i])) return nmol def clone_mol(self): return Chem.Mol(self.mol) def create_cube_files(self, gridspace=0.3): if self.wfn == None: print('wfn not found. run optimze()/energy()') return None else: a = self.wfn.nalpha() # H**O b = a + 1 # LUMO self.psi4.set_options({"cubeprop_tasks": ['ESP', 'FRONTIER_ORBITALS', 'Density', 'DUAL_DESCRIPTOR'], "cubic_grid_spacing": [gridspace, gridspace, gridspace], "cubeprop_filepath": self.tempdir }) Chem.MolToMolFile(self.mol, os.path.join(self.tempdir, 'target.mol')) self.psi4.cubeprop(self.wfn) getMOview = moves.moved_function(create_cube_files, 'getMOview', __name__) def view_on_pymol(self, target='FRONTIER', maprange=0.05, gridspace=0.3): self.create_cube_files(gridspace=gridspace) run_pymol_server(self.tempdir, target=target, maprange=maprange) def save_frontier(self, gridspace=0.3, isotype="isosurface"): self.create_cube_files(gridspace=gridspace) save_pyscript(self.tempdir, isotype=isotype) def save_fchk(self, filename="output.fchk"): fchk_writer = self.psi4.core.FCHKWriter(self.wfn) fchk_writer.write(filename) def save_cube(self): self.psi4.cubeprop(self.wfn) def calc_resp_charges(self): if self.wfn.molecule() == None: print('please run optimze() at first!') return None try: import resp except: print('please install resp at first') print('conda install -c psi4 resp') return None # https://www.cgl.ucsf.edu/chimerax/docs/user/radii.html options = {'N_VDW_LAYERS' : 4, 'VDW_SCALE_FACTOR' : 1.4, 'VDW_INCREMENT' : 0.2, 'VDW_POINT_DENSITY' : 1.0, 'resp_a' : 0.0005, 'RESP_B' : 0.1, 'RADIUS' : {'Br':1.98, 'I':2.09, } } charges = resp.resp([self.wfn.molecule()], [options]) atoms = self.mol.GetAtoms() for idx, atom in enumerate(atoms): atom.SetDoubleProp("EP", charges[0][0][idx]) atom.SetDoubleProp("RESP", charges[0][1][idx]) return charges[0][1] def calc_mulliken_charges(self): ''' Compute Mulliken Charges And return the results as numpy array. ''' if self.wfn.molecule() == None: print('please run optimze() at first!') return None self.psi4.oeprop(self.wfn, 'MULLIKEN_CHARGES') mulliken_acp = self.wfn.atomic_point_charges() atoms = self.mol.GetAtoms() for idx, atom in enumerate(atoms): atom.SetDoubleProp("MULLIKEN", mulliken_acp.np[idx]) return mulliken_acp.np def calc_lowdin_charges(self): ''' Compute Lowdin Charges And return the results as numpy array. ''' if self.wfn.molecule() == None: print('please run optimze() at first!') return None self.psi4.oeprop(self.wfn, 'LOWDIN_CHARGES') lowdin_acp = self.wfn.atomic_point_charges() atoms = self.mol.GetAtoms() for idx, atom in enumerate(atoms): atom.SetDoubleProp("LOWDIN", lowdin_acp.np[idx]) return lowdin_acp.np @property def dipolemoment(self, basis_sets="scf/6-31g**", return_wfn=True): # The three components of the SCF dipole [Debye] x = self.psi4.get_variable('SCF DIPOLE X') y = self.psi4.get_variable('SCF DIPOLE Y') z = self.psi4.get_variable('SCF DIPOLE Z') total = np.sqrt(x * x + y * y + z * z) return (x, y, z, total) @property def H**O(self): return self.wfn.epsilon_a_subset('AO', 'ALL').np[self.wfn.nalpha()-1] @property def LUMO(self): return self.wfn.epsilon_a_subset('AO', 'ALL').np[self.wfn.nalpha()] @property def coulomb_matrix(self): return self.wfn.jk().J[0].to_array() @property def exchange_matrix(self): return self.wfn.jk().K[0].to_array()
# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ NOTE: Do not use this module to add random utils. We want to avoid having a generic utils.py dumping ground. """ from debtcollector import moves from neutron_lib.api import attributes populate_project_info = moves.moved_function( attributes.populate_project_info, 'populate_project_info', __name__)
inc = n_bars - i for col in cols: df[f'{col}{i}'] = df[f'{col}{n_bars}'][inc:].append( pd.Series([np.nan] * inc)).reset_index(drop=True) # correct bar date (or datetime) if datetime_col is not None: df[datetime_col] = df[datetime_col][n_bars:].append( pd.Series([np.nan] * n_bars)).reset_index(drop=True) df = df.dropna() return df make_nbars = moves.moved_function(make_nbars_past, 'make_nbars', __name__) def make_nbars_future(df: pd.DataFrame, n_bars: int, cols: List[str] = ['Close'], datetime_col: Union[str, None] = 'Date') -> pd.DataFrame: """Make n bars dataframe seeing future n bars. The row size of `df` must be greater than or equal to `n_bars`, or raise ValueError. Args: df (DataFrame): target data frame. n_bars (int): number of bars. cols (List[str], optional): column names. Defaults to ['Close']. datetime_col (Union[str, None], optional): datetime column name. Defaults to 'Date'.
import testscenarios from neutron.common import utils from neutron.tests.functional import base MARK_VALUE = '0x1' MARK_MASK = '0xffffffff' ICMP_MARK_RULE = ('-j MARK --set-xmark %(value)s/%(mask)s' % {'value': MARK_VALUE, 'mask': MARK_MASK}) MARKED_BLOCK_RULE = '-m mark --mark %s -j DROP' % MARK_VALUE ICMP_BLOCK_RULE = '-p icmp -j DROP' get_rand_name = moves.moved_function( utils.get_rand_name, 'get_rand_name', __name__, message='use "neutron.common.utils.get_rand_name" instead', version='Newton', removal_version='Ocata') # Regarding MRO, it goes BaseOVSLinuxTestCase, WithScenarios, # BaseSudoTestCase, ..., UnitTest, object. setUp is not defined in # WithScenarios, so it will correctly be found in BaseSudoTestCase. class BaseOVSLinuxTestCase(testscenarios.WithScenarios, base.BaseSudoTestCase): scenarios = [ ('vsctl', dict(ovsdb_interface='vsctl')), ('native', dict(ovsdb_interface='native')), ] def setUp(self): super(BaseOVSLinuxTestCase, self).setUp() self.config(group='OVS', ovsdb_interface=self.ovsdb_interface)
def is_bsd(): """Return True on BSD-based systems.""" system = platform.system() if system == 'Darwin': return True if 'bsd' in system.lower(): return True return False def reset_random_seed(): # reset random seed to make sure other processes extracting values from RNG # don't get the same results (useful especially when you then use the # random values to allocate system resources from global pool, like ports # to listen). Use both current time and pid to make sure no tests started # at the same time get the same values from RNG seed = time.time() + os.getpid() random.seed(seed) def get_random_ipv6_mode(): return random.choice(constants.IPV6_MODES) import_modules_recursively = moves.moved_function( utils.import_modules_recursively, 'import_modules_recursively', __name__, version='Newton', removal_version='Ocata')
class Psikit(object): def __init__(self, threads=4, memory=4, debug=False): import psi4 self.psi4 = psi4 self.psi4.set_memory("{} GB".format(memory)) #self.psi4.set_options({"save_jk": True}) # for JK calculation self.psi4.set_num_threads(threads) self.wfn = None self.mol = None self.debug = debug if self.debug: self.psi4.core.set_output_file("psikit_out.dat", True) else: self.psi4.core.be_quiet() def read_from_smiles(self, smiles_str, opt=True): self.mol = Chem.MolFromSmiles(smiles_str) if opt: self.rdkit_optimize() def read_from_molfile(self, molfile, opt=True, removeHs=False): self.mol = Chem.MolFromMolFile(molfile, removeHs=removeHs) if opt: self.rdkit_optimize() def rdkit_optimize(self, addHs=True): if addHs: self.mol = Chem.AddHs(self.mol) AllChem.EmbedMolecule(self.mol, useExpTorsionAnglePrefs=True, useBasicKnowledge=True) AllChem.UFFOptimizeMolecule(self.mol) def geometry(self, multiplicity=1): xyz = self.mol2xyz(multiplicity=multiplicity) self.psi4.geometry(xyz) def energy(self, basis_sets="scf/6-31g**", return_wfn=True, multiplicity=1): self.geometry(multiplicity=multiplicity) scf_energy, wfn = self.psi4.energy(basis_sets, return_wfn=return_wfn) self.psi4.core.clean() self.wfn = wfn return scf_energy def optimize(self, basis_sets="scf/6-31g**", return_wfn=True, name=None, multiplicity=1, maxiter=50): if not name: name = uuid.uuid4().hex self.psi4.core.IO.set_default_namespace(name) self.geometry(multiplicity=multiplicity) self.psi4.set_options({'GEOM_MAXITER': maxiter}) try: scf_energy, wfn = self.psi4.optimize(basis_sets, return_wfn=return_wfn) self.wfn = wfn except self.psi4.OptimizationConvergenceError as cError: print('Convergence error caught: {0}'.format(cError)) self.wfn = cError.wfn scf_energy = self.wfn.energy() self.psi4.core.clean() self.mol = self.xyz2mol() if not self.debug: self.psi4.core.opt_clean( ) # Seg fault will occured when the function is called before optimize. return scf_energy def set_options(self, **kwargs): """ http://www.psicode.org/psi4manual/1.2/psiapi.html IV. Analysis of Intermolecular Interactions and http://forum.psicode.org/t/how-can-i-change-max-iteration-in-energy-method/1238/2 """ self.psi4.set_options(kwargs) def mol2xyz(self, multiplicity=1): charge = Chem.GetFormalCharge(self.mol) xyz_string = "\n{} {}\n".format(charge, multiplicity) for atom in self.mol.GetAtoms(): pos = self.mol.GetConformer().GetAtomPosition(atom.GetIdx()) xyz_string += "{} {} {} {}\n".format(atom.GetSymbol(), pos.x, pos.y, pos.z) # the "no_com" stops Psi4 from moving your molecule to its center of mass, # "no_reorient" stops it from spinning to align with axis of inertia xyz_string += "no_reorient\n" xyz_string += "no_com\n" xyz_string += "units angstrom\n" return xyz_string def xyz2mol(self, confId=0): natom = self.wfn.molecule().natom() mol_array_bohr = self.wfn.molecule().geometry().to_array() mol_array = mol_array_bohr * 0.52917721092 nmol = Chem.Mol(self.mol) conf = nmol.GetConformer(confId) for i in range(natom): conf.SetAtomPosition(i, tuple(mol_array[i])) return nmol def clone_mol(self): return Chem.Mol(self.mol) def create_cube_files(self, gridspace=0.3): if self.wfn == None: print('please run optimze()/energy() at first!') return None else: a = self.wfn.nalpha() # H**O b = a + 1 # LUMO self.psi4.set_options({ "cubeprop_tasks": ['ESP', 'FRONTIER_ORBITALS', 'Density', 'DUAL_DESCRIPTOR'], "cubic_grid_spacing": [gridspace, gridspace, gridspace] }) Chem.MolToMolFile(self.mol, 'target.mol') self.psi4.cubeprop(self.wfn) print('Done!') getMOview = moves.moved_function(create_cube_files, 'getMOview', __name__) def view_on_pymol(self, target='FRONTIER', maprange=0.05): ''' To use the function, user need to install pymol and run the pymol for server mode The command is pymol -R target ['ESP', 'FRONTIER', 'DUAL'] ''' targetlist = ['ESP', 'FRONTIER', 'DUAL'] if target not in targetlist: raise Exception(f'Please set target from ESP, FRONTIER, DENSITY!!') import sys import xmlrpc.client as xmlrpc filepath = os.getcwd() nalpha = self.wfn.nalpha() srv = xmlrpc.ServerProxy('http://localhost:9123') srv.do('delete *') srv.do('load ' + os.path.join(filepath, 'target.mol')) srv.do('as sticks, target') if target == 'FRONTIER': homof = glob.glob(f'Psi_a_{nalpha}*_HOMO.cube')[0] lumof = glob.glob(f'Psi_a_{nalpha+1}*_LUMO.cube')[0] srv.do('load ' + os.path.join(filepath, homof) + ',H**O') srv.do('load ' + os.path.join(filepath, lumof) + ',LUMO') srv.do(f'isosurface HOMO_A, H**O, -0.02') srv.do(f'isosurface HOMO_B, H**O, 0.02') srv.do(f'isosurface LUMO_A, LUMO, -0.02') srv.do(f'isosurface LUMO_B, LUMO, 0.02') srv.do('color blue, HOMO_A') srv.do('color red, HOMO_B') srv.do('color green, LUMO_A') srv.do('color yellow, LUMO_B') srv.do('set transparency, 0.2') srv.do('disable HOMO_A') srv.do('disable HOMO_B') abb = 'frontier_' elif target == 'ESP': srv.do('load ' + 'ESP.cube' + ', ESP') srv.do('show surface, target') srv.do(f'ramp_new cmap, ESP, [-{maprange}, {maprange}]') srv.do('color cmap, target') srv.do('set transparency, 0.2') abb = 'esp_' elif target == 'DUAL': dualf = glob.glob('DUAL*.cube')[0] srv.do('load ' + dualf + ', DUAL_DESC') srv.do('show surface, target') srv.do(f'ramp_new cmap, DUAL_DESC, [-{maprange}, {maprange}]') srv.do('color cmap, target') srv.do('set transparency, 0.2') abb = 'dual_' outputpath = os.path.join(filepath, abb + 'mo.pse') srv.do(f'save {outputpath}') print('finished !') def save_frontier(self, gridspace=0.15): if self.wfn == None: print('please run optimze()/energy() at first!') else: a = self.wfn.nalpha() # H**O b = a + 1 # LUMO self.psi4.set_options({ "cubeprop_tasks": ['orbitals'], "cubeprop_orbitals": [a, b, -a, -b], "cubic_grid_spacing": [gridspace, gridspace, gridspace] }) Chem.MolToMolFile(self.mol, 'target.mol') self.psi4.cubeprop(self.wfn) homo_a = "Psi_a_{0}_{0}-A".format(a) homo_b = "Psi_b_{0}_{0}-A".format(a) lumo_a = "Psi_a_{0}_{0}-A".format(b) lumo_b = "Psi_b_{0}_{0}-A".format(b) with open("frontier.py", "w") as f: f.write('from pymol import *\n') f.write('cmd.load("{0}.cube")\n'.format(homo_a)) f.write('cmd.load("{0}.cube")\n'.format(homo_b)) f.write('cmd.load("{0}.cube")\n'.format(lumo_a)) f.write('cmd.load("{0}.cube")\n'.format(lumo_b)) f.write('cmd.load("target.mol")\n') f.write('cmd.isomesh("HOMO_A", "{0}", -0.02)\n'.format(homo_a)) f.write('cmd.isomesh("HOMO_B", "{0}", 0.02)\n'.format(homo_b)) f.write('cmd.isomesh("LUMO_A", "{0}", 0.02)\n'.format(lumo_a)) f.write('cmd.isomesh("LUMO_B", "{0}", -0.02)\n'.format(lumo_b)) f.write('cmd.color("blue", "HOMO_A")\n') f.write('cmd.color("red", "HOMO_B")\n') f.write('cmd.color("blue", "LUMO_A")\n') f.write('cmd.color("red", "LUMO_B")\n') f.write('cmd.disable("LUMO_A")\n') f.write('cmd.disable("LUMO_B")\n') def save_fchk(self, filename="output.fchk"): fchk_writer = self.psi4.core.FCHKWriter(self.wfn) fchk_writer.write(filename) def save_cube(self): self.psi4.cubeprop(self.wfn) def calc_resp_charges(self): if self.wfn.molecule() == None: print('please run optimze() at first!') return None try: import resp except: print('please install resp at first') print('conda install -c psi4 resp') return None # https://www.cgl.ucsf.edu/chimerax/docs/user/radii.html options = { 'N_VDW_LAYERS': 4, 'VDW_SCALE_FACTOR': 1.4, 'VDW_INCREMENT': 0.2, 'VDW_POINT_DENSITY': 1.0, 'resp_a': 0.0005, 'RESP_B': 0.1, 'RADIUS': { 'Br': 1.98, 'I': 2.09, } } charges = resp.resp([self.wfn.molecule()], [options]) atoms = self.mol.GetAtoms() for idx, atom in enumerate(atoms): atom.SetDoubleProp("EP", charges[0][0][idx]) atom.SetDoubleProp("RESP", charges[0][1][idx]) return charges[0][1] def calc_mulliken_charges(self): ''' Compute Mulliken Charges And return the results as numpy array. ''' if self.wfn.molecule() == None: print('please run optimze() at first!') return None self.psi4.oeprop(self.wfn, 'MULLIKEN_CHARGES') mulliken_acp = self.wfn.atomic_point_charges() atoms = self.mol.GetAtoms() for idx, atom in enumerate(atoms): atom.SetDoubleProp("MULLIKEN", mulliken_acp.np[idx]) return mulliken_acp.np def calc_lowdin_charges(self): ''' Compute Lowdin Charges And return the results as numpy array. ''' if self.wfn.molecule() == None: print('please run optimze() at first!') return None self.psi4.oeprop(self.wfn, 'LOWDIN_CHARGES') lowdin_acp = self.wfn.atomic_point_charges() atoms = self.mol.GetAtoms() for idx, atom in enumerate(atoms): atom.SetDoubleProp("LOWDIN", lowdin_acp.np[idx]) return lowdin_acp.np @property def dipolemoment(self, basis_sets="scf/6-31g**", return_wfn=True): # The three components of the SCF dipole [Debye] x = self.psi4.get_variable('SCF DIPOLE X') y = self.psi4.get_variable('SCF DIPOLE Y') z = self.psi4.get_variable('SCF DIPOLE Z') total = np.sqrt(x * x + y * y + z * z) return (x, y, z, total) @property def H**O(self): return self.wfn.epsilon_a_subset('AO', 'ALL').np[self.wfn.nalpha() - 1] @property def LUMO(self): return self.wfn.epsilon_a_subset('AO', 'ALL').np[self.wfn.nalpha()] @property def coulomb_matrix(self): return self.wfn.jk().J[0].to_array() @property def exchange_matrix(self): return self.wfn.jk().K[0].to_array()
LOG = logging.getLogger(__name__) def is_retriable(e): if _is_nested_instance( e, (db_exc.DBDeadlock, exc.StaleDataError, db_exc.DBConnectionError, db_exc.DBDuplicateEntry, db_exc.RetryRequest)): return True # looking savepoints mangled by deadlocks. see bug/1590298 for details. return _is_nested_instance(e, db_exc.DBError) and '1305' in str(e) is_deadlock = moves.moved_function(is_retriable, 'is_deadlock', __name__, message='use "is_retriable" instead', version='newton', removal_version='ocata') _retry_db_errors = oslo_db_api.wrap_db_retry(max_retries=MAX_RETRIES, retry_interval=0.1, inc_retry_interval=True, exception_checker=is_retriable) def retry_db_errors(f): """Log retriable exceptions before retry to help debugging.""" @_retry_db_errors @six.wraps(f) def wrapped(*args, **kwargs): try: return f(*args, **kwargs)
from neutron._i18n import _LE from neutron.db.models import securitygroup as sg_models from neutron.db import models_v2 from neutron.db import segments_db from neutron.extensions import portbindings from neutron import manager from neutron.plugins.ml2 import models LOG = log.getLogger(__name__) # limit the number of port OR LIKE statements in one query MAX_PORTS_PER_QUERY = 500 # The API methods from segments_db add_network_segment = moves.moved_function( segments_db.add_network_segment, 'add_network_segment', __name__, version='Newton', removal_version='Ocata') get_network_segments = moves.moved_function( segments_db.get_network_segments, 'get_network_segments', __name__, version='Newton', removal_version='Ocata') get_networks_segments = moves.moved_function( segments_db.get_networks_segments, 'get_networks_segments', __name__, version='Newton', removal_version='Ocata') get_segment_by_id = moves.moved_function( segments_db.get_segment_by_id, 'get_segment_by_id', __name__, version='Newton', removal_version='Ocata') get_dynamic_segment = moves.moved_function(
@removals.remove() def red_comet(): return True @removals.remove(category=PendingDeprecationWarning) def blue_comet(): return True def yellow_sun(): """Yellow.""" return True yellowish_sun = moves.moved_function(yellow_sun, 'yellowish_sun', __name__) @removals.remove() class EFSF(object): pass @removals.remove(category=PendingDeprecationWarning) class EFSF_2(object): pass class ThingB(object): @removals.remove() def black_tristars(self):
if os.path.exists(disabled_ipv6_path): with open(disabled_ipv6_path, 'r') as f: disabled = f.read().strip() _IS_IPV6_ENABLED = disabled == "0" else: _IS_IPV6_ENABLED = False if not _IS_IPV6_ENABLED: LOG.info(_LI("IPv6 not present or configured not to bind to new " "interfaces on this system. Please ensure IPv6 is " "enabled and /proc/sys/net/ipv6/conf/default/" "disable_ipv6 is set to 1 to enable IPv6.")) return _IS_IPV6_ENABLED is_enabled = moves.moved_function(is_enabled_and_bind_by_default, 'is_enabled', __name__, version='Ocata', removal_version='Pike') def is_auto_address_subnet(subnet): """Check if subnet is an auto address subnet.""" modes = [const.IPV6_SLAAC, const.DHCPV6_STATELESS] return (subnet['ipv6_address_mode'] in modes or subnet['ipv6_ra_mode'] in modes) def is_eui64_address(ip_address): """Check if ip address is EUI64.""" ip = netaddr.IPAddress(ip_address) # '0xfffe' addition is used to build EUI-64 from MAC (RFC4291) # Look for it in the middle of the EUI-64 part of address
# Copyright (c) 2015 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import functools from debtcollector import moves from ovsdbapp.schema.open_vswitch import helpers from neutron.agent.common import utils _connection_to_manager_uri = moves.moved_function( helpers._connection_to_manager_uri, '_connection_to_manager_uri', __name__) enable_connection_uri = functools.partial(helpers.enable_connection_uri, execute=utils.execute, run_as_root=True, log_fail_as_error=False, check_exit_code=False)
"""Return True on BSD-based systems.""" system = platform.system() if system == 'Darwin': return True if 'bsd' in system.lower(): return True return False def reset_random_seed(): # reset random seed to make sure other processes extracting values from RNG # don't get the same results (useful especially when you then use the # random values to allocate system resources from global pool, like ports # to listen). Use both current time and pid to make sure no tests started # at the same time get the same values from RNG seed = time.time() + os.getpid() random.seed(seed) def get_random_ipv6_mode(): return random.choice(constants.IPV6_MODES) import_modules_recursively = moves.moved_function( utils.import_modules_recursively, 'import_modules_recursively', __name__, version='Newton', removal_version='Ocata')
from neutron.db.models import securitygroup as sg_models from neutron.db import models_v2 from neutron.db import segments_db from neutron.extensions import portbindings from neutron import manager from neutron.plugins.ml2 import models LOG = log.getLogger(__name__) # limit the number of port OR LIKE statements in one query MAX_PORTS_PER_QUERY = 500 # The API methods from segments_db add_network_segment = moves.moved_function(segments_db.add_network_segment, 'add_network_segment', __name__, version='Newton', removal_version='Ocata') get_network_segments = moves.moved_function(segments_db.get_network_segments, 'get_network_segments', __name__, version='Newton', removal_version='Ocata') get_networks_segments = moves.moved_function(segments_db.get_networks_segments, 'get_networks_segments', __name__, version='Newton', removal_version='Ocata')
class VolumesClient(base_client.BaseClient): """Client class to send CRUD Volume V2 API requests""" api_version = "v2" create_volume_transfer = moves.moved_function( transfers_client.TransfersClient.create_volume_transfer, 'VolumesClient.create_volume_transfer', __name__, message='Use create_volume_transfer from new location.', version='Pike', removal_version='Queens') show_volume_transfer = moves.moved_function( transfers_client.TransfersClient.show_volume_transfer, 'VolumesClient.show_volume_transfer', __name__, message='Use show_volume_transfer from new location.', version='Pike', removal_version='Queens') list_volume_transfers = moves.moved_function( transfers_client.TransfersClient.list_volume_transfers, 'VolumesClient.list_volume_transfers', __name__, message='Use list_volume_transfer from new location.', version='Pike', removal_version='Queens') delete_volume_transfer = moves.moved_function( transfers_client.TransfersClient.delete_volume_transfer, 'VolumesClient.delete_volume_transfer', __name__, message='Use delete_volume_transfer from new location.', version='Pike', removal_version='Queens') accept_volume_transfer = moves.moved_function( transfers_client.TransfersClient.accept_volume_transfer, 'VolumesClient.accept_volume_transfer', __name__, message='Use accept_volume_transfer from new location.', version='Pike', removal_version='Queens') def _prepare_params(self, params): """Prepares params for use in get or _ext_get methods. If params is a string it will be left as it is, but if it's not it will be urlencoded. """ if isinstance(params, six.string_types): return params return urllib.urlencode(params) def list_volumes(self, detail=False, params=None): """List all the volumes created. Params can be a string (must be urlencoded) or a dictionary. For a full list of available parameters, please refer to the official API reference: http://developer.openstack.org/api-ref/block-storage/v2/#list-volumes-with-details http://developer.openstack.org/api-ref/block-storage/v2/#list-volumes """ url = 'volumes' if detail: url += '/detail' if params: url += '?%s' % self._prepare_params(params) resp, body = self.get(url) body = json.loads(body) self.expected_success(200, resp.status) return rest_client.ResponseBody(resp, body) def show_volume(self, volume_id): """Returns the details of a single volume.""" url = "volumes/%s" % volume_id resp, body = self.get(url) body = json.loads(body) self.expected_success(200, resp.status) return rest_client.ResponseBody(resp, body) def create_volume(self, **kwargs): """Creates a new Volume. For a full list of available parameters, please refer to the official API reference: http://developer.openstack.org/api-ref/block-storage/v2/#create-volume """ post_body = json.dumps({'volume': kwargs}) resp, body = self.post('volumes', post_body) body = json.loads(body) self.expected_success(202, resp.status) return rest_client.ResponseBody(resp, body) def update_volume(self, volume_id, **kwargs): """Updates the Specified Volume. For a full list of available parameters, please refer to the official API reference: http://developer.openstack.org/api-ref/block-storage/v2/#update-volume """ put_body = json.dumps({'volume': kwargs}) resp, body = self.put('volumes/%s' % volume_id, put_body) body = json.loads(body) self.expected_success(200, resp.status) return rest_client.ResponseBody(resp, body) def delete_volume(self, volume_id, **params): """Deletes the Specified Volume. For a full list of available parameters, please refer to the official API reference: https://developer.openstack.org/api-ref/block-storage/v2/#delete-volume """ url = 'volumes/%s' % volume_id if params: url += '?%s' % urllib.urlencode(params) resp, body = self.delete(url) self.expected_success(202, resp.status) return rest_client.ResponseBody(resp, body) def upload_volume(self, volume_id, **kwargs): """Uploads a volume in Glance.""" post_body = json.dumps({'os-volume_upload_image': kwargs}) url = 'volumes/%s/action' % (volume_id) resp, body = self.post(url, post_body) body = json.loads(body) self.expected_success(202, resp.status) return rest_client.ResponseBody(resp, body) def attach_volume(self, volume_id, **kwargs): """Attaches a volume to a given instance on a given mountpoint. For a full list of available parameters, please refer to the official API reference: http://developer.openstack.org/api-ref/block-storage/v2/#attach-volume-to-server """ post_body = json.dumps({'os-attach': kwargs}) url = 'volumes/%s/action' % (volume_id) resp, body = self.post(url, post_body) self.expected_success(202, resp.status) return rest_client.ResponseBody(resp, body) def set_bootable_volume(self, volume_id, **kwargs): """Set a bootable flag for a volume - true or false. For a full list of available parameters, please refer to the official API reference: http://developer.openstack.org/api-ref/block-storage/v2/#update-volume-bootable-status """ post_body = json.dumps({'os-set_bootable': kwargs}) url = 'volumes/%s/action' % (volume_id) resp, body = self.post(url, post_body) self.expected_success(200, resp.status) return rest_client.ResponseBody(resp, body) def detach_volume(self, volume_id): """Detaches a volume from an instance.""" post_body = json.dumps({'os-detach': {}}) url = 'volumes/%s/action' % (volume_id) resp, body = self.post(url, post_body) self.expected_success(202, resp.status) return rest_client.ResponseBody(resp, body) def reserve_volume(self, volume_id): """Reserves a volume.""" post_body = json.dumps({'os-reserve': {}}) url = 'volumes/%s/action' % (volume_id) resp, body = self.post(url, post_body) self.expected_success(202, resp.status) return rest_client.ResponseBody(resp, body) def unreserve_volume(self, volume_id): """Restore a reserved volume .""" post_body = json.dumps({'os-unreserve': {}}) url = 'volumes/%s/action' % (volume_id) resp, body = self.post(url, post_body) self.expected_success(202, resp.status) return rest_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_volume(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'volume' def extend_volume(self, volume_id, **kwargs): """Extend a volume. For a full list of available parameters, please refer to the official API reference: http://developer.openstack.org/api-ref/block-storage/v2/#extend-volume-size """ post_body = json.dumps({'os-extend': kwargs}) url = 'volumes/%s/action' % (volume_id) resp, body = self.post(url, post_body) self.expected_success(202, resp.status) return rest_client.ResponseBody(resp, body) def reset_volume_status(self, volume_id, **kwargs): """Reset the Specified Volume's Status. For a full list of available parameters, please refer to the official API reference: http://developer.openstack.org/api-ref/block-storage/v2/#reset-volume-statuses """ post_body = json.dumps({'os-reset_status': kwargs}) resp, body = self.post('volumes/%s/action' % volume_id, post_body) self.expected_success(202, resp.status) return rest_client.ResponseBody(resp, body) def update_volume_readonly(self, volume_id, **kwargs): """Update the Specified Volume readonly.""" post_body = json.dumps({'os-update_readonly_flag': kwargs}) url = 'volumes/%s/action' % (volume_id) resp, body = self.post(url, post_body) self.expected_success(202, resp.status) return rest_client.ResponseBody(resp, body) def force_delete_volume(self, volume_id): """Force Delete Volume.""" post_body = json.dumps({'os-force_delete': {}}) resp, body = self.post('volumes/%s/action' % volume_id, post_body) self.expected_success(202, resp.status) return rest_client.ResponseBody(resp, body) def create_volume_metadata(self, volume_id, metadata): """Create metadata for the volume. For a full list of available parameters, please refer to the official API reference: http://developer.openstack.org/api-ref/block-storage/v2/#create-volume-metadata """ put_body = json.dumps({'metadata': metadata}) url = "volumes/%s/metadata" % volume_id resp, body = self.post(url, put_body) body = json.loads(body) self.expected_success(200, resp.status) return rest_client.ResponseBody(resp, body) def show_volume_metadata(self, volume_id): """Get metadata of the volume.""" url = "volumes/%s/metadata" % volume_id resp, body = self.get(url) body = json.loads(body) self.expected_success(200, resp.status) return rest_client.ResponseBody(resp, body) def update_volume_metadata(self, volume_id, metadata): """Update metadata for the volume. For a full list of available parameters, please refer to the official API reference: http://developer.openstack.org/api-ref/block-storage/v2/#update-volume-metadata """ put_body = json.dumps({'metadata': metadata}) url = "volumes/%s/metadata" % volume_id resp, body = self.put(url, put_body) body = json.loads(body) self.expected_success(200, resp.status) return rest_client.ResponseBody(resp, body) def show_volume_metadata_item(self, volume_id, id): """Show metadata item for the volume.""" url = "volumes/%s/metadata/%s" % (volume_id, id) resp, body = self.get(url) body = json.loads(body) self.expected_success(200, resp.status) return rest_client.ResponseBody(resp, body) def update_volume_metadata_item(self, volume_id, id, meta_item): """Update metadata item for the volume.""" put_body = json.dumps({'meta': meta_item}) url = "volumes/%s/metadata/%s" % (volume_id, id) resp, body = self.put(url, put_body) body = json.loads(body) self.expected_success(200, resp.status) return rest_client.ResponseBody(resp, body) def delete_volume_metadata_item(self, volume_id, id): """Delete metadata item for the volume.""" url = "volumes/%s/metadata/%s" % (volume_id, id) resp, body = self.delete(url) self.expected_success(200, resp.status) return rest_client.ResponseBody(resp, body) def retype_volume(self, volume_id, **kwargs): """Updates volume with new volume type. For a full list of available parameters, please refer to the official API reference: https://developer.openstack.org/api-ref/block-storage/v2/#retype-volume """ post_body = json.dumps({'os-retype': kwargs}) resp, body = self.post('volumes/%s/action' % volume_id, post_body) self.expected_success(202, resp.status) def force_detach_volume(self, volume_id, **kwargs): """Force detach a volume. For a full list of available parameters, please refer to the official API reference: https://developer.openstack.org/api-ref/block-storage/v2/#force-detach-volume """ post_body = json.dumps({'os-force_detach': kwargs}) url = 'volumes/%s/action' % volume_id resp, body = self.post(url, post_body) self.expected_success(202, resp.status) return rest_client.ResponseBody(resp, body) def update_volume_image_metadata(self, volume_id, **kwargs): """Update image metadata for the volume. For a full list of available parameters, please refer to the official API reference: http://developer.openstack.org/api-ref/block-storage/v2/#set-image-metadata-for-volume """ post_body = json.dumps({'os-set_image_metadata': {'metadata': kwargs}}) url = "volumes/%s/action" % (volume_id) resp, body = self.post(url, post_body) body = json.loads(body) self.expected_success(200, resp.status) return rest_client.ResponseBody(resp, body) def delete_volume_image_metadata(self, volume_id, key_name): """Delete image metadata item for the volume.""" post_body = json.dumps({'os-unset_image_metadata': {'key': key_name}}) url = "volumes/%s/action" % (volume_id) resp, body = self.post(url, post_body) self.expected_success(200, resp.status) return rest_client.ResponseBody(resp, body) @removals.remove(message="use list_pools from tempest.lib.services." "volume.v2.scheduler_stats_client") def show_pools(self, detail=False): # List all the volumes pools (hosts) url = 'scheduler-stats/get_pools' if detail: url += '?detail=True' resp, body = self.get(url) body = json.loads(body) self.expected_success(200, resp.status) return rest_client.ResponseBody(resp, body) @removals.remove(message="use show_backend_capabilities from tempest.lib." "services.volume.v2.capabilities_client") def show_backend_capabilities(self, host): """Shows capabilities for a storage back end. For a full list of available parameters, please refer to the official API reference: http://developer.openstack.org/api-ref/block-storage/v2/#show-back-end-capabilities """ url = 'capabilities/%s' % host resp, body = self.get(url) body = json.loads(body) self.expected_success(200, resp.status) return rest_client.ResponseBody(resp, body) def unmanage_volume(self, volume_id): """Unmanage volume. For a full list of available parameters, please refer to the official API reference: https://developer.openstack.org/api-ref/block-storage/v2/#unmanage-volume """ post_body = json.dumps({'os-unmanage': {}}) resp, body = self.post('volumes/%s/action' % volume_id, post_body) self.expected_success(202, resp.status) return rest_client.ResponseBody(resp, body)
disabled = f.read().strip() _IS_IPV6_ENABLED = disabled == "0" else: _IS_IPV6_ENABLED = False if not _IS_IPV6_ENABLED: LOG.info( _LI("IPv6 not present or configured not to bind to new " "interfaces on this system. Please ensure IPv6 is " "enabled and /proc/sys/net/ipv6/conf/default/" "disable_ipv6 is set to 1 to enable IPv6.")) return _IS_IPV6_ENABLED is_enabled = moves.moved_function(is_enabled_and_bind_by_default, 'is_enabled', __name__, version='Ocata', removal_version='Pike') def is_auto_address_subnet(subnet): """Check if subnet is an auto address subnet.""" modes = [const.IPV6_SLAAC, const.DHCPV6_STATELESS] return (subnet['ipv6_address_mode'] in modes or subnet['ipv6_ra_mode'] in modes) def is_eui64_address(ip_address): """Check if ip address is EUI64.""" ip = netaddr.IPAddress(ip_address) # '0xfffe' addition is used to build EUI-64 from MAC (RFC4291)
def etcdir(*p): return os.path.join(ETCDIR, *p) def fake_use_fatal_exceptions(*args): return True for _name in ("get_related_rand_names", "get_rand_name", "get_rand_device_name", "get_related_rand_device_names"): setattr( sys.modules[__name__], _name, moves.moved_function( getattr(utils, _name), _name, __name__, message='use "neutron.common.utils.%s" instead' % _name, version="Newton", removal_version="Ocata", ), ) def bool_from_env(key, strict=False, default=False): value = os.environ.get(key) return strutils.bool_from_string(value, strict=strict, default=default) def setup_test_logging(config_opts, log_dir, log_file_path_template): # Have each test log into its own log file config_opts.set_override("debug", True) fileutils.ensure_tree(log_dir, mode=0o755)
# Copyright (c) 2015 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import functools from debtcollector import moves from ovsdbapp.schema.open_vswitch import helpers from neutron.agent.common import utils _connection_to_manager_uri = moves.moved_function( helpers._connection_to_manager_uri, '_connection_to_manager_uri', __name__) enable_connection_uri = functools.partial( helpers.enable_connection_uri, execute=utils.execute, run_as_root=True, log_fail_as_error=False, check_exit_code=False)
"assertEqual(True, observed)") yield (0, msg) if re.search(r"assertEqual\(\s*False,[^,]*(,[^,]*)?", logical_line): msg = ("N328: Use assertFalse(observed) instead of " "assertEqual(False, observed)") yield (0, msg) if re.search(r"assertEqual\([^,]*,\s*False(,[^,]*)?", logical_line): msg = ("N328: Use assertFalse(observed) instead of " "assertEqual(False, observed)") yield (0, msg) check_asserttrue = flake8ext( moves.moved_function(check_asserttruefalse, 'check_asserttrue', __name__, version='Newton', removal_version='Ocata')) check_assertfalse = flake8ext( moves.moved_function(check_asserttruefalse, 'check_assertfalse', __name__, version='Newton', removal_version='Ocata')) @flake8ext def no_mutable_default_args(logical_line): """N329 - Don't use mutable default arguments.""" msg = "N329: Method's default argument shouldn't be mutable!"
# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # TODO(amotoki): Remove this file at the beginning of Nxx cycle. from debtcollector import moves from neutronclient import _i18n message = ( "moved to neutronclient._i18n; please migrate to local " "oslo_i18n usage, as defined at " "http://docs.openstack.org/developer/oslo.i18n/usage.html" ) _ = moves.moved_function(_i18n._, "_", __name__, message=message) _LC = moves.moved_function(_i18n._LC, "_LC", __name__, message=message) _LE = moves.moved_function(_i18n._LE, "_LE", __name__, message=message) _LW = moves.moved_function(_i18n._LW, "_LW", __name__, message=message) _LI = moves.moved_function(_i18n._LI, "_LI", __name__, message=message)