How to use _assign_floating_ips method in tempest

Best Python code snippet using tempest_python

direct_engine.py

Source:direct_engine.py Github

copy

Full Screen

...43 {"status": "Waiting"})44 LOG.info(g.format_cluster_status(cluster))45 instances = g.get_instances(cluster)46 self._await_active(cluster, instances)47 self._assign_floating_ips(instances)48 self._await_networks(cluster, instances)49 cluster = conductor.cluster_get(ctx, cluster)50 # attach volumes51 volumes.attach(cluster)52 # prepare all instances53 cluster = conductor.cluster_update(ctx, cluster,54 {"status": "Preparing"})55 LOG.info(g.format_cluster_status(cluster))56 self._configure_instances(cluster)57 except Exception as ex:58 with excutils.save_and_reraise_exception():59 self._log_operation_exception(60 "Can't start cluster '%s' (reason: %s)", cluster, ex)61 cluster = conductor.cluster_update(62 ctx, cluster, {"status": "Error",63 "status_description": str(ex)})64 LOG.info(g.format_cluster_status(cluster))65 self._rollback_cluster_creation(cluster, ex)66 def scale_cluster(self, cluster, node_group_id_map):67 ctx = context.ctx()68 instance_ids = []69 try:70 instance_ids = self._scale_cluster_instances(cluster,71 node_group_id_map)72 cluster = conductor.cluster_get(ctx, cluster)73 g.clean_cluster_from_empty_ng(cluster)74 cluster = conductor.cluster_get(ctx, cluster)75 instances = g.get_instances(cluster, instance_ids)76 self._await_active(cluster, instances)77 self._assign_floating_ips(instances)78 self._await_networks(cluster, instances)79 cluster = conductor.cluster_get(ctx, cluster)80 volumes.attach_to_instances(81 g.get_instances(cluster, instance_ids))82 except Exception as ex:83 with excutils.save_and_reraise_exception():84 self._log_operation_exception(85 "Can't scale cluster '%s' (reason: %s)", cluster, ex)86 cluster = conductor.cluster_get(ctx, cluster)87 self._rollback_cluster_scaling(88 cluster, g.get_instances(cluster, instance_ids), ex)89 instance_ids = []90 cluster = conductor.cluster_get(ctx, cluster)91 g.clean_cluster_from_empty_ng(cluster)92 if cluster.status == 'Decommissioning':93 cluster = conductor.cluster_update(ctx, cluster,94 {"status": "Error"})95 else:96 cluster = conductor.cluster_update(ctx, cluster,97 {"status": "Active"})98 LOG.info(g.format_cluster_status(cluster))99 # we should be here with valid cluster: if instances creation100 # was not successful all extra-instances will be removed above101 if instance_ids:102 self._configure_instances(cluster)103 return instance_ids104 def _generate_anti_affinity_groups(self, cluster):105 aa_groups = {}106 for node_group in cluster.node_groups:107 for instance in node_group.instances:108 if instance.instance_id:109 for process in node_group.node_processes:110 if process in cluster.anti_affinity:111 aa_group = aa_groups.get(process, [])112 aa_group.append(instance.instance_id)113 aa_groups[process] = aa_group114 return aa_groups115 def _create_instances(self, cluster):116 ctx = context.ctx()117 aa_groups = {}118 for node_group in cluster.node_groups:119 count = node_group.count120 conductor.node_group_update(ctx, node_group, {'count': 0})121 for idx in six.moves.xrange(1, count + 1):122 self._run_instance(cluster, node_group, idx, aa_groups)123 def _scale_cluster_instances(self, cluster, node_group_id_map):124 ctx = context.ctx()125 aa_groups = self._generate_anti_affinity_groups(cluster)126 instances_to_delete = []127 node_groups_to_enlarge = []128 for node_group in cluster.node_groups:129 new_count = node_group_id_map[node_group.id]130 if new_count < node_group.count:131 instances_to_delete += node_group.instances[new_count:132 node_group.count]133 elif new_count > node_group.count:134 node_groups_to_enlarge.append(node_group)135 if instances_to_delete:136 cluster = conductor.cluster_update(137 ctx, cluster, {"status": "Deleting Instances"})138 LOG.info(g.format_cluster_status(cluster))139 for instance in instances_to_delete:140 self._shutdown_instance(instance)141 cluster = conductor.cluster_get(ctx, cluster)142 instances_to_add = []143 if node_groups_to_enlarge:144 cluster = conductor.cluster_update(ctx, cluster,145 {"status": "Adding Instances"})146 LOG.info(g.format_cluster_status(cluster))147 for node_group in node_groups_to_enlarge:148 count = node_group_id_map[node_group.id]149 for idx in six.moves.xrange(node_group.count + 1, count + 1):150 instance_id = self._run_instance(cluster, node_group, idx,151 aa_groups)152 instances_to_add.append(instance_id)153 return instances_to_add154 def _find_by_id(self, lst, id):155 for obj in lst:156 if obj.id == id:157 return obj158 return None159 def _run_instance(self, cluster, node_group, idx, aa_groups):160 """Create instance using nova client and persist them into DB."""161 ctx = context.ctx()162 name = '%s-%s-%03d' % (cluster.name, node_group.name, idx)163 userdata = self._generate_user_data_script(node_group, name)164 # aa_groups: node process -> instance ids165 aa_ids = []166 for node_process in node_group.node_processes:167 aa_ids += aa_groups.get(node_process) or []168 # create instances only at hosts w/ no instances169 # w/ aa-enabled processes170 hints = {'different_host': list(set(aa_ids))} if aa_ids else None171 if CONF.use_neutron:172 net_id = cluster.neutron_management_network173 nics = [{"net-id": net_id, "v4-fixed-ip": ""}]174 nova_instance = nova.client().servers.create(175 name, node_group.get_image_id(), node_group.flavor_id,176 scheduler_hints=hints, userdata=userdata,177 key_name=cluster.user_keypair_id,178 nics=nics)179 else:180 nova_instance = nova.client().servers.create(181 name, node_group.get_image_id(), node_group.flavor_id,182 scheduler_hints=hints, userdata=userdata,183 key_name=cluster.user_keypair_id)184 instance_id = conductor.instance_add(ctx, node_group,185 {"instance_id": nova_instance.id,186 "instance_name": name})187 # save instance id to aa_groups to support aa feature188 for node_process in node_group.node_processes:189 if node_process in cluster.anti_affinity:190 aa_group_ids = aa_groups.get(node_process, [])191 aa_group_ids.append(nova_instance.id)192 aa_groups[node_process] = aa_group_ids193 return instance_id194 def _assign_floating_ips(self, instances):195 for instance in instances:196 node_group = instance.node_group197 if node_group.floating_ip_pool:198 networks.assign_floating_ip(instance.instance_id,199 node_group.floating_ip_pool)200 def _await_active(self, cluster, instances):201 """Await all instances are in Active status and available."""202 if not instances:203 return204 active_ids = set()205 while len(active_ids) != len(instances):206 if not g.check_cluster_exists(instances[0].node_group.cluster):207 return208 for instance in instances:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful