本文整理汇总了Python中neutron.common.utils.get_rand_name函数的典型用法代码示例。如果您正苦于以下问题:Python get_rand_name函数的具体用法?Python get_rand_name怎么用?Python get_rand_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_rand_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_db_find_column_type_list
def test_db_find_column_type_list(self):
"""Fixate output for vsctl/native ovsdb_interface.
Makes sure that db_find search queries give the same result for both
implementations.
"""
bridge_name = utils.get_rand_name(prefix=net_helpers.BR_PREFIX)
self.addCleanup(self.ovs.delete_bridge, bridge_name)
br = self.ovs.add_bridge(bridge_name)
port_name = utils.get_rand_name(prefix=net_helpers.PORT_PREFIX)
br.add_port(port_name)
self.ovs.set_db_attribute('Port', port_name, 'tag', 42)
# wrap list/find in transaction so we get a single isolated snapshot
with self.ovs.ovsdb.transaction(check_error=True) as txn:
tags = txn.add(self.ovs.ovsdb.db_list('Port', columns=['tag']))
len_0_list = txn.add(self.ovs.ovsdb.db_find(
'Port', ('tag', '!=', []), columns=['tag']))
single_value = txn.add(self.ovs.ovsdb.db_find(
'Port', ('tag', '=', 42), columns=['tag']))
# Make sure that there is data to query.
# It should be, but let's be a little paranoid here as otherwise
# the test has no sense
tags_present = [t for t in tags.result if t['tag'] != []]
self.assertTrue(tags_present)
tags_42 = [t for t in tags_present if t['tag'] == 42]
self.assertEqual(tags_42, single_value.result)
self.assertItemsEqual(len_0_list.result, tags_present)
示例2: generate_device_details
def generate_device_details(self, name=None, ip_cidrs=None,
mac_address=None, namespace=None):
return Device(name or utils.get_rand_name(),
ip_cidrs or ["%s/24" % TEST_IP],
mac_address or
net.get_random_mac('fa:16:3e:00:00:00'.split(':')),
namespace or utils.get_rand_name())
示例3: create_ovs_vif_port
def create_ovs_vif_port(self, iface_id=None, mac=None,
iface_field='iface-id'):
if iface_id is None:
iface_id = utils.get_rand_name()
if mac is None:
mac = utils.get_rand_name()
attrs = ('external_ids', {iface_field: iface_id, 'attached-mac': mac})
port_name, ofport = self.create_ovs_port(attrs)
return ovs_lib.VifPort(port_name, ofport, iface_id, mac, self.br)
示例4: test_macvtap_exists
def test_macvtap_exists(self):
namespace = self.useFixture(net_helpers.NamespaceFixture())
src_dev_name = utils.get_rand_name()
src_dev = namespace.ip_wrapper.add_dummy(src_dev_name)
self.addCleanup(self._safe_delete_device, src_dev)
dev_name = utils.get_rand_name()
device = namespace.ip_wrapper.add_macvtap(dev_name, src_dev_name)
self.addCleanup(self._safe_delete_device, device)
self._check_for_device_name(namespace.ip_wrapper, dev_name, True)
device.link.delete()
self._check_for_device_name(namespace.ip_wrapper, dev_name, False)
示例5: _setUp
def _setUp(self):
self.user = common_utils.get_rand_name(prefix='user')
self.password = common_utils.get_rand_name(prefix='pass')
self.vhost = common_utils.get_rand_name(prefix='vhost')
self._execute('add_user', self.user, self.password)
self.addCleanup(self._execute, 'delete_user', self.user)
self._execute('add_vhost', self.vhost)
self.addCleanup(self._execute, 'delete_vhost', self.vhost)
self._execute('set_permissions', '-p', self.vhost, self.user,
'.*', '.*', '.*')
示例6: create_resource
def create_resource(prefix, creation_func, *args, **kwargs):
"""Create a new resource that does not already exist.
If prefix isn't 'max_length' in size, a random suffix is concatenated to
ensure it is random. Otherwise, 'prefix' is used as is.
:param prefix: The prefix for a randomly generated name
:param creation_func: A function taking the name of the resource
to be created as it's first argument. An error is assumed
to indicate a name collision.
:param *args *kwargs: These will be passed to the create function.
"""
# Don't generate a random name if prefix is already full-length.
if len(prefix) == n_const.DEVICE_NAME_MAX_LEN:
return creation_func(prefix, *args, **kwargs)
while True:
name = utils.get_rand_name(
max_length=n_const.DEVICE_NAME_MAX_LEN,
prefix=prefix)
try:
return creation_func(name, *args, **kwargs)
except RuntimeError:
pass
示例7: create_security_group
def create_security_group(self, tenant_id, name=None):
resource_type = 'security_group'
name = name or utils.get_rand_name(prefix=resource_type)
spec = {'tenant_id': tenant_id, 'name': name}
return self._create_resource(resource_type, spec)
示例8: test_do_main_default_options
def test_do_main_default_options(self):
int_br = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
self.conf.set_override("ovs_integration_bridge", int_br.br_name)
self.conf.set_override("ovs_all_ports", False)
noskip = collections.defaultdict(list)
skip = collections.defaultdict(list)
# add two vifs, one skipped, and a non-vif port to int_br
for collection in (noskip, skip):
collection[int_br].append(
self.useFixture(net_helpers.OVSPortFixture(int_br)).port.name)
# set skippable vif to be skipped
int_br.ovsdb.db_set(
'Interface', skip[int_br][0],
('external_ids', {constants.SKIP_CLEANUP: "True"})
).execute(check_error=True)
device_name = utils.get_rand_name()
skip[int_br].append(device_name)
int_br.add_port(device_name, ('type', 'internal'))
# sanity check
for collection in (noskip, skip):
for bridge, ports in collection.items():
port_list = bridge.get_port_name_list()
for port in ports:
self.assertIn(port, port_list)
ovs_cleanup.do_main(self.conf)
ports = int_br.get_port_name_list()
for vif in noskip[int_br]:
self.assertNotIn(vif, ports)
for port in skip[int_br]:
self.assertIn(port, ports)
示例9: test_plug_with_namespace_sets_mtu_higher_than_bridge
def test_plug_with_namespace_sets_mtu_higher_than_bridge(self):
device_mtu = 1450
# Create a new OVS bridge
ovs_bridge = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
self.assertFalse(ovs_bridge.get_port_name_list())
# Add a new linuxbridge port with reduced MTU to OVS bridge
lb_bridge = self.useFixture(
net_helpers.LinuxBridgeFixture()).bridge
lb_bridge_port = self.useFixture(
net_helpers.LinuxBridgePortFixture(lb_bridge))
lb_bridge_port.port.link.set_mtu(device_mtu - 1)
ovs_bridge.add_port(lb_bridge_port.port.name)
# Now plug a device with intended MTU that is higher than for the port
# above and validate that its MTU is not reduced to the least MTU on
# the bridge
device_name = utils.get_rand_name()
mac_address = utils.get_random_mac('fa:16:3e:00:00:00'.split(':'))
namespace = self.useFixture(net_helpers.NamespaceFixture()).name
self.interface.plug(network_id=uuidutils.generate_uuid(),
port_id=uuidutils.generate_uuid(),
device_name=device_name,
mac_address=mac_address,
bridge=ovs_bridge.br_name,
namespace=namespace,
mtu=device_mtu)
self.assertIn(device_name, ovs_bridge.get_port_name_list())
self.assertTrue(ip_lib.device_exists(device_name, namespace))
self.assertEqual(
device_mtu,
ip_lib.IPDevice(device_name, namespace=namespace).link.mtu
)
示例10: create_network
def create_network(self, tenant_id, name=None, external=False):
resource_type = 'network'
name = name or utils.get_rand_name(prefix=resource_type)
spec = {'tenant_id': tenant_id, 'name': name}
spec['router:external'] = external
return self._create_resource(resource_type, spec)
示例11: test_db_add_to_new_object
def test_db_add_to_new_object(self):
ovsdb = self.ovs.ovsdb
brname = utils.get_rand_name(prefix=net_helpers.BR_PREFIX)
br = ovs_lib.OVSBridge(brname) # doesn't create
self.addCleanup(br.destroy)
with ovsdb.transaction(check_error=True) as txn:
txn.add(ovsdb.add_br(brname))
txn.add(ovsdb.db_add('Bridge', brname, 'protocols', 'OpenFlow10'))
示例12: test_bridge_lifecycle_baseovs
def test_bridge_lifecycle_baseovs(self):
name = utils.get_rand_name(prefix=net_helpers.BR_PREFIX)
self.addCleanup(self.ovs.delete_bridge, name)
br = self.ovs.add_bridge(name)
self.assertEqual(br.br_name, name)
self.assertTrue(self.ovs.bridge_exists(name))
self.ovs.delete_bridge(name)
self.assertFalse(self.ovs.bridge_exists(name))
示例13: test_set_link_alias
def test_set_link_alias(self):
attr = self.generate_device_details()
device = self.manage_device(attr)
alias = utils.get_rand_name()
device.link.set_alias(alias)
self.assertEqual(alias, device.link.alias)
示例14: test_set_mtu
def test_set_mtu(self):
device_name = utils.get_rand_name()
namespace = self.useFixture(net_helpers.NamespaceFixture()).name
self._test_mtu_set_after_action(
device_name, self.bridge_name, namespace,
functools.partial(
self.interface.set_mtu,
device_name=device_name, namespace=namespace))
示例15: setUp
def setUp(self):
super(TestKeepalivedStateChange, self).setUp()
self.conf_fixture = self.useFixture(fixture_config.Config())
kd.register_l3_agent_keepalived_opts(self.conf_fixture)
self.router_id = uuidutils.generate_uuid()
self.conf_dir = self.get_default_temp_dir().path
self.cidr = '169.254.128.1/24'
self.interface_name = utils.get_rand_name()
self.monitor = keepalived_state_change.MonitorDaemon(
self.get_temp_file_path('monitor.pid'),
self.router_id,
1,
2,
utils.get_rand_name(),
self.conf_dir,
self.interface_name,
self.cidr)
mock.patch.object(self.monitor, 'notify_agent').start()
self.line = '1: %s inet %s' % (self.interface_name, self.cidr)