本文整理汇总了Python中tempest.common.fixed_network.set_networks_kwarg函数的典型用法代码示例。如果您正苦于以下问题:Python set_networks_kwarg函数的具体用法?Python set_networks_kwarg怎么用?Python set_networks_kwarg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_networks_kwarg函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_list_servers_filter_by_exist_host
def test_list_servers_filter_by_exist_host(self):
# Filter the list of servers by existent host
name = data_utils.rand_name('server')
flavor = self.flavor_ref
image_id = self.image_ref
network = self.get_tenant_network()
network_kwargs = fixed_network.set_networks_kwarg(network)
test_server = self.client.create_server(name=name, imageRef=image_id,
flavorRef=flavor,
**network_kwargs)['server']
self.addCleanup(self.client.delete_server, test_server['id'])
waiters.wait_for_server_status(self.client,
test_server['id'], 'ACTIVE')
server = self.client.show_server(test_server['id'])['server']
self.assertEqual(server['status'], 'ACTIVE')
hostname = server[self._host_key]
params = {'host': hostname}
body = self.client.list_servers(**params)
servers = body['servers']
nonexistent_params = {'host': 'nonexistent_host'}
nonexistent_body = self.client.list_servers(**nonexistent_params)
nonexistent_servers = nonexistent_body['servers']
self.assertIn(test_server['id'], map(lambda x: x['id'], servers))
self.assertNotIn(test_server['id'],
map(lambda x: x['id'], nonexistent_servers))
示例2: nova_boot
def nova_boot(self):
name = data_utils.rand_name("scenario-server")
flavor_id = CONF.compute.flavor_ref
# Explicitly create secgroup to avoid cleanup at the end of testcases.
# Since no traffic is tested, we don't need to actually add rules to
# secgroup
secgroup = self.security_groups_client.create_security_group(
name="secgroup-%s" % name, description="secgroup-desc-%s" % name
)
self.addCleanupClass(self.security_groups_client.delete_security_group, secgroup["id"])
create_kwargs = {"min_count": CONF.scenario.large_ops_number, "security_groups": [{"name": secgroup["name"]}]}
network = self.get_tenant_network()
create_kwargs = fixed_network.set_networks_kwarg(network, create_kwargs)
self.servers_client.create_server(name, self.image, flavor_id, **create_kwargs)
# needed because of bug 1199788
params = {"name": name}
server_list = self.servers_client.list_servers(**params)
self.servers = server_list["servers"]
for server in self.servers:
# after deleting all servers - wait for all servers to clear
# before cleanup continues
self.addCleanupClass(waiters.wait_for_server_termination, self.servers_client, server["id"])
for server in self.servers:
self.addCleanupClass(self.servers_client.delete_server, server["id"])
self._wait_for_server_status("ACTIVE")
示例3: create_server
def create_server(cls, name, **kwargs):
network = cls.get_tenant_network()
network_kwargs = fixed_network.set_networks_kwarg(network, kwargs)
return cls.servers_client.create_server(name,
cls.image_ref,
cls.flavor_ref,
**network_kwargs)
示例4: resource_setup
def resource_setup(cls):
super(ListServerFiltersTestJSON, cls).resource_setup()
# Check to see if the alternate image ref actually exists...
images_client = cls.images_client
images = images_client.list_images()
if cls.image_ref != cls.image_ref_alt and \
any([image for image in images
if image['id'] == cls.image_ref_alt]):
cls.multiple_images = True
else:
cls.image_ref_alt = cls.image_ref
# Do some sanity checks here. If one of the images does
# not exist, fail early since the tests won't work...
try:
cls.images_client.get_image(cls.image_ref)
except lib_exc.NotFound:
raise RuntimeError("Image %s (image_ref) was not found!" %
cls.image_ref)
try:
cls.images_client.get_image(cls.image_ref_alt)
except lib_exc.NotFound:
raise RuntimeError("Image %s (image_ref_alt) was not found!" %
cls.image_ref_alt)
network = cls.get_tenant_network()
if network:
if network.get('name'):
cls.fixed_network_name = network['name']
else:
cls.fixed_network_name = None
else:
cls.fixed_network_name = None
network_kwargs = fixed_network.set_networks_kwarg(network)
cls.s1_name = data_utils.rand_name(cls.__name__ + '-instance')
cls.s1 = cls.create_test_server(name=cls.s1_name,
wait_until='ACTIVE',
**network_kwargs)
cls.s2_name = data_utils.rand_name(cls.__name__ + '-instance')
cls.s2 = cls.create_test_server(name=cls.s2_name,
image_id=cls.image_ref_alt,
wait_until='ACTIVE')
cls.s3_name = data_utils.rand_name(cls.__name__ + '-instance')
cls.s3 = cls.create_test_server(name=cls.s3_name,
flavor=cls.flavor_ref_alt,
wait_until='ACTIVE')
示例5: boot_instance
def boot_instance(self):
create_kwargs = {
'key_name': self.keypair['name']
}
# create server start
network = self.get_tenant_network()
create_kwargs = fixed_network.set_networks_kwarg(network,
create_kwargs)
if hasattr(self, 'config_drive'):
create_kwargs['config_drive'] = self.config_drive
LOG.debug("Creating a server (name: %s, image: %s, flavor: %s)",
self.instance_name, self.obj_user_image, self.obj_flavor['id'])
self.instance = self.servers_client.create_server(
self.instance_name,
self.obj_user_image,
self.obj_flavor['id'],
**create_kwargs)
# self.addCleanup(self.servers_client.wait_for_server_termination, self.instance['id'])
self.addCleanup_with_wait(
waiter_callable=self.servers_client.wait_for_server_termination,
thing_id=self.instance['id'], thing_id_param='server_id',
cleanup_callable=self.delete_wrapper,
cleanup_args=[self.servers_client.delete_server, self.instance['id']])
# create server end
self.wait_node(self.instance['id'])
self.node = self.get_node(instance_id=self.instance['id'])
self.wait_power_state(self.node['uuid'], BaremetalPowerStates.POWER_ON)
self.wait_provisioning_state(
self.node['uuid'],
[BaremetalProvisionStates.DEPLOYWAIT,
BaremetalProvisionStates.ACTIVE],
timeout=300)
self.wait_provisioning_state(self.node['uuid'],
BaremetalProvisionStates.ACTIVE,
timeout=CONF.baremetal.active_timeout)
self.servers_client.wait_for_server_status(self.instance['id'],
'ACTIVE')
self.node = self.get_node(instance_id=self.instance['id'])
self.instance = self.servers_client.get_server(self.instance['id'])
self.assertEqual(self.instance['name'], self.instance_name)
示例6: test_list_servers_filter_by_exist_host
def test_list_servers_filter_by_exist_host(self):
# Filter the list of servers by existent host
name = data_utils.rand_name(self.__class__.__name__ + "-server")
network = self.get_tenant_network()
network_kwargs = fixed_network.set_networks_kwarg(network)
# We need to create the server as an admin, so we can't use
# self.create_test_server() here as this method creates the server
# in the "primary" (i.e non-admin) tenant.
test_server, _ = compute.create_test_server(self.os_adm, wait_until="ACTIVE", name=name, **network_kwargs)
self.addCleanup(self.client.delete_server, test_server["id"])
server = self.client.show_server(test_server["id"])["server"]
self.assertEqual(server["status"], "ACTIVE")
hostname = server[self._host_key]
params = {"host": hostname}
body = self.client.list_servers(**params)
servers = body["servers"]
nonexistent_params = {"host": "nonexistent_host"}
nonexistent_body = self.client.list_servers(**nonexistent_params)
nonexistent_servers = nonexistent_body["servers"]
self.assertIn(test_server["id"], map(lambda x: x["id"], servers))
self.assertNotIn(test_server["id"], map(lambda x: x["id"], nonexistent_servers))
示例7: create_test_server
def create_test_server(cls, **kwargs):
"""Wrapper utility that returns a test server."""
name = data_utils.rand_name(cls.__name__ + "-instance")
if 'name' in kwargs:
name = kwargs.pop('name')
flavor = kwargs.get('flavor', cls.flavor_ref)
image_id = kwargs.get('image_id', cls.image_ref)
kwargs = fixed_network.set_networks_kwarg(
cls.get_tenant_network(), kwargs) or {}
body = cls.servers_client.create_server(
name, image_id, flavor, **kwargs)
# handle the case of multiple servers
servers = [body]
if 'min_count' in kwargs or 'max_count' in kwargs:
# Get servers created which name match with name param.
b = cls.servers_client.list_servers()
servers = [s for s in b['servers'] if s['name'].startswith(name)]
if 'wait_until' in kwargs:
for server in servers:
try:
cls.servers_client.wait_for_server_status(
server['id'], kwargs['wait_until'])
except Exception:
with excutils.save_and_reraise_exception():
if ('preserve_server_on_error' not in kwargs
or kwargs['preserve_server_on_error'] is False):
for server in servers:
try:
cls.servers_client.delete_server(
server['id'])
except Exception:
pass
cls.servers.extend(servers)
return body
示例8: nova_boot
def nova_boot(self, image):
name = data_utils.rand_name('scenario-server')
flavor_id = CONF.compute.flavor_ref
# Explicitly create secgroup to avoid cleanup at the end of testcases.
# Since no traffic is tested, we don't need to actually add rules to
# secgroup
secgroup = self.compute_security_groups_client.create_security_group(
name='secgroup-%s' % name,
description='secgroup-desc-%s' % name)['security_group']
self.addCleanupClass(
self.compute_security_groups_client.delete_security_group,
secgroup['id'])
create_kwargs = {
'min_count': CONF.scenario.large_ops_number,
'security_groups': [{'name': secgroup['name']}]
}
network = self.get_tenant_network()
create_kwargs = fixed_network.set_networks_kwarg(network,
create_kwargs)
self.servers_client.create_server(
name=name,
imageRef=image,
flavorRef=flavor_id,
**create_kwargs)
# needed because of bug 1199788
params = {'name': name}
server_list = self.servers_client.list_servers(**params)
self.servers = server_list['servers']
for server in self.servers:
# after deleting all servers - wait for all servers to clear
# before cleanup continues
self.addCleanupClass(waiters.wait_for_server_termination,
self.servers_client,
server['id'])
for server in self.servers:
self.addCleanupClass(self.servers_client.delete_server,
server['id'])
self._wait_for_server_status('ACTIVE')
示例9: create_test_server
def create_test_server(clients, validatable=False, validation_resources=None,
tenant_network=None, wait_until=None, **kwargs):
"""Common wrapper utility returning a test server.
This method is a common wrapper returning a test server that can be
pingable or sshable.
:param clients: Client manager which provides Openstack Tempest clients.
:param validatable: Whether the server will be pingable or sshable.
:param validation_resources: Resources created for the connection to the
server. Include a keypair, a security group and an IP.
:param tenant_network: Tenant network to be used for creating a server.
:param wait_until: Server status to wait for the server to reach after
its creation.
:returns a tuple
"""
# TODO(jlanoux) add support of wait_until PINGABLE/SSHABLE
if 'name' in kwargs:
name = kwargs.pop('name')
else:
name = data_utils.rand_name(__name__ + "-instance")
flavor = kwargs.get('flavor', CONF.compute.flavor_ref)
image_id = kwargs.get('image_id', CONF.compute.image_ref)
kwargs = fixed_network.set_networks_kwarg(
tenant_network, kwargs) or {}
if CONF.validation.run_validation and validatable:
# As a first implementation, multiple pingable or sshable servers will
# not be supported
if 'min_count' in kwargs or 'max_count' in kwargs:
msg = ("Multiple pingable or sshable servers not supported at "
"this stage.")
raise ValueError(msg)
if 'security_groups' in kwargs:
kwargs['security_groups'].append(
{'name': validation_resources['security_group']['name']})
else:
try:
kwargs['security_groups'] = [
{'name': validation_resources['security_group']['name']}]
except KeyError:
LOG.debug("No security group provided.")
if 'key_name' not in kwargs:
try:
kwargs['key_name'] = validation_resources['keypair']['name']
except KeyError:
LOG.debug("No key provided.")
if CONF.validation.connect_method == 'floating':
if wait_until is None:
wait_until = 'ACTIVE'
body = clients.servers_client.create_server(name, image_id, flavor,
**kwargs)
# handle the case of multiple servers
servers = [body]
if 'min_count' in kwargs or 'max_count' in kwargs:
# Get servers created which name match with name param.
body_servers = clients.servers_client.list_servers()
servers = \
[s for s in body_servers['servers'] if s['name'].startswith(name)]
# The name of the method to associate a floating IP to as server is too
# long for PEP8 compliance so:
assoc = clients.floating_ips_client.associate_floating_ip_to_server
if wait_until:
for server in servers:
try:
waiters.wait_for_server_status(
clients.servers_client, server['id'], wait_until)
# Multiple validatable servers are not supported for now. Their
# creation will fail with the condition above (l.58).
if CONF.validation.run_validation and validatable:
if CONF.validation.connect_method == 'floating':
assoc(floating_ip=validation_resources[
'floating_ip']['ip'],
server_id=servers[0]['id'])
except Exception:
with excutils.save_and_reraise_exception():
if ('preserve_server_on_error' not in kwargs
or kwargs['preserve_server_on_error'] is False):
for server in servers:
try:
clients.servers_client.delete_server(
server['id'])
except Exception:
LOG.exception('Deleting server %s failed'
% server['id'])
return body, servers
示例10: create_test_server
def create_test_server(
clients,
validatable=False,
validation_resources=None,
tenant_network=None,
wait_until=None,
volume_backed=False,
**kwargs
):
"""Common wrapper utility returning a test server.
This method is a common wrapper returning a test server that can be
pingable or sshable.
:param clients: Client manager which provides OpenStack Tempest clients.
:param validatable: Whether the server will be pingable or sshable.
:param validation_resources: Resources created for the connection to the
server. Include a keypair, a security group and an IP.
:param tenant_network: Tenant network to be used for creating a server.
:param wait_until: Server status to wait for the server to reach after
its creation.
:param volume_backed: Whether the instance is volume backed or not.
:returns a tuple
"""
# TODO(jlanoux) add support of wait_until PINGABLE/SSHABLE
if "name" in kwargs:
name = kwargs.pop("name")
else:
name = data_utils.rand_name(__name__ + "-instance")
flavor = kwargs.pop("flavor", CONF.compute.flavor_ref)
image_id = kwargs.pop("image_id", CONF.compute.image_ref)
kwargs = fixed_network.set_networks_kwarg(tenant_network, kwargs) or {}
if CONF.validation.run_validation and validatable:
# As a first implementation, multiple pingable or sshable servers will
# not be supported
if "min_count" in kwargs or "max_count" in kwargs:
msg = "Multiple pingable or sshable servers not supported at " "this stage."
raise ValueError(msg)
if "security_groups" in kwargs:
kwargs["security_groups"].append({"name": validation_resources["security_group"]["name"]})
else:
try:
kwargs["security_groups"] = [{"name": validation_resources["security_group"]["name"]}]
except KeyError:
LOG.debug("No security group provided.")
if "key_name" not in kwargs:
try:
kwargs["key_name"] = validation_resources["keypair"]["name"]
except KeyError:
LOG.debug("No key provided.")
if CONF.validation.connect_method == "floating":
if wait_until is None:
wait_until = "ACTIVE"
if volume_backed:
volume_name = data_utils.rand_name("volume")
volumes_client = clients.volumes_v2_client
if CONF.volume_feature_enabled.api_v1:
volumes_client = clients.volumes_client
volume = volumes_client.create_volume(display_name=volume_name, imageRef=image_id)
volumes_client.wait_for_volume_status(volume["volume"]["id"], "available")
bd_map_v2 = [
{
"uuid": volume["volume"]["id"],
"source_type": "volume",
"destination_type": "volume",
"boot_index": 0,
"delete_on_termination": True,
}
]
kwargs["block_device_mapping_v2"] = bd_map_v2
# Since this is boot from volume an image does not need
# to be specified.
image_id = ""
body = clients.servers_client.create_server(name=name, imageRef=image_id, flavorRef=flavor, **kwargs)
# handle the case of multiple servers
servers = []
if "min_count" in kwargs or "max_count" in kwargs:
# Get servers created which name match with name param.
body_servers = clients.servers_client.list_servers()
servers = [s for s in body_servers["servers"] if s["name"].startswith(name)]
else:
body = service_client.ResponseBody(body.response, body["server"])
servers = [body]
# The name of the method to associate a floating IP to as server is too
# long for PEP8 compliance so:
assoc = clients.floating_ips_client.associate_floating_ip_to_server
#.........这里部分代码省略.........
示例11: create_test_server
def create_test_server(clients, validatable, validation_resources=None, tenant_network=None, **kwargs):
"""Common wrapper utility returning a test server.
This method is a common wrapper returning a test server that can be
pingable or sshable.
:param clients: Client manager which provides Openstack Tempest clients.
:param validatable: Whether the server will be pingable or sshable.
:param validation_resources: Resources created for the connection to the
server. Include a keypair, a security group and an IP.
:returns a tuple
"""
# TODO(jlanoux) add support of wait_until PINGABLE/SSHABLE
if "name" in kwargs:
name = kwargs.pop("name")
else:
name = data_utils.rand_name(__name__ + "-instance")
flavor = kwargs.get("flavor", CONF.compute.flavor_ref)
image_id = kwargs.get("image_id", CONF.compute.image_ref)
kwargs = fixed_network.set_networks_kwarg(tenant_network, kwargs) or {}
if CONF.validation.run_validation and validatable:
# As a first implementation, multiple pingable or sshable servers will
# not be supported
if "min_count" in kwargs or "max_count" in kwargs:
msg = "Multiple pingable or sshable servers not supported at " "this stage."
raise ValueError(msg)
if "security_groups" in kwargs:
kwargs["security_groups"].append({"name": validation_resources["security_group"]["name"]})
else:
try:
kwargs["security_groups"] = [{"name": validation_resources["security_group"]["name"]}]
except KeyError:
LOG.debug("No security group provided.")
if "key_name" not in kwargs:
try:
kwargs["key_name"] = validation_resources["keypair"]["name"]
except KeyError:
LOG.debug("No key provided.")
if CONF.validation.connect_method == "floating":
if "wait_until" not in kwargs:
kwargs["wait_until"] = "ACTIVE"
body = clients.servers_client.create_server(name, image_id, flavor, **kwargs)
# handle the case of multiple servers
servers = [body]
if "min_count" in kwargs or "max_count" in kwargs:
# Get servers created which name match with name param.
body_servers = clients.servers_client.list_servers()
servers = [s for s in body_servers["servers"] if s["name"].startswith(name)]
# The name of the method to associate a floating IP to as server is too
# long for PEP8 compliance so:
assoc = clients.floating_ips_client.associate_floating_ip_to_server
if "wait_until" in kwargs:
for server in servers:
try:
clients.servers_client.wait_for_server_status(server["id"], kwargs["wait_until"])
# Multiple validatable servers are not supported for now. Their
# creation will fail with the condition above (l.58).
if CONF.validation.run_validation and validatable:
if CONF.validation.connect_method == "floating":
assoc(floating_ip=validation_resources["floating_ip"]["ip"], server_id=servers[0]["id"])
except Exception:
with excutils.save_and_reraise_exception():
if "preserve_server_on_error" not in kwargs or kwargs["preserve_server_on_error"] is False:
for server in servers:
try:
clients.servers_client.delete_server(server["id"])
except Exception:
LOG.exception("Deleting server %s failed" % server["id"])
return body, servers