def _process_network_info(self, network_info): if not network_info: raise exception.BuildAbortException('Network info missing') network_interfaces = [] for net_info in network_info: gce_network_name = 'net-' + net_info['network']['id'] gce_subnet_name = 'subnet-' + net_info['details']['subnet_id'] ip_address = net_info['details']['ip_address'] compute, project = self.gce_svc, self.gce_project gce_network_details = gceutils.get_network(compute, project, gce_network_name) for subnet_link in gce_network_details['subnetworks']: if gce_subnet_name in subnet_link: gce_subnet_link = subnet_link break network_interfaces.append({ 'network': gce_network_details['selfLink'], 'subnetwork': gce_subnet_link, 'networkIP': ip_address, }) # yapf:disable return network_interfaces
def test_build_abort_exception(self): self.mox.StubOutWithMock(self.compute, '_build_and_run_instance') self.mox.StubOutWithMock(self.compute, '_set_instance_error_state') self.mox.StubOutWithMock(self.compute.compute_task_api, 'build_instances') self.mox.StubOutWithMock(self.compute.conductor_api, 'action_event_start') self.mox.StubOutWithMock(self.compute.conductor_api, 'action_event_finish') self.compute._build_and_run_instance( self.context, self.instance, self.image, self.injected_files, self.admin_pass, self.node, self.limits).AndRaise( exception.BuildAbortException( reason='', instance_uuid=self.instance['uuid'])) self.compute._set_instance_error_state(self.context, self.instance['uuid']) self.compute.conductor_api.action_event_start(self.context, mox.IgnoreArg()) self.compute.conductor_api.action_event_finish(self.context, mox.IgnoreArg()) self.mox.ReplayAll() self.compute.build_and_run_instance(self.context, self.instance, self.image, request_spec={}, filter_properties=[], injected_files=self.injected_files, admin_password=self.admin_pass, node=self.node, limits=self.limits)
def create_lpar(adapter, host_wrapper, instance, nvram=None, slot_mgr=None): """Create an LPAR based on the host based on the instance :param adapter: The adapter for the pypowervm API :param host_wrapper: The host wrapper :param instance: The nova instance. :param nvram: The NVRAM to set on the LPAR. :param slot_mgr: NovaSlotManager to restore/save the maximum number of virtual slots. If omitted, the default is used. :return: The LPAR response from the API. """ try: lpar_b = VMBuilder( host_wrapper, adapter, slot_mgr=slot_mgr).lpar_builder(instance) pending_lpar_w = lpar_b.build() vldn.LPARWrapperValidator(pending_lpar_w, host_wrapper).validate_all() if nvram is not None: pending_lpar_w.nvram = nvram lpar_w = pending_lpar_w.create(parent=host_wrapper) if slot_mgr is not None: slot_mgr.register_max_vslots(lpar_w.io_config.max_virtual_slots) return lpar_w except lpar_bldr.LPARBuilderException as e: # Raise the BuildAbortException since LPAR failed to build raise exception.BuildAbortException(instance_uuid=instance.uuid, reason=e) except pvm_exc.HttpError as he: # Raise the API exception LOG.exception("PowerVM HttpError creating LPAR.", instance=instance) raise nvex.PowerVMAPIFailed(inst_name=instance.name, reason=he)
def test_with_failing_middle_cells(self): data = [{'id': 'foo-%i' % i} for i in range(0, 100)] cells = [objects.CellMapping(uuid=getattr(uuids, 'cell%i' % i), name='cell%i' % i) for i in range(0, 3)] lister = FailureLister(data, [], [], cells=cells) # One cell will succeed and then time out, one will fail immediately, # and the last will always work lister.set_fails(uuids.cell0, [None, context.did_not_respond_sentinel]) # Note that BuildAbortException will never appear during instance # listing, the aim is to only simulate a situation where there could # be some type of exception arising. lister.set_fails(uuids.cell1, exception.BuildAbortException( instance_uuid='fake', reason='fake')) ctx = context.RequestContext() result = lister.get_records_sorted(ctx, {}, 50, None, batch_size=5) # We should still have 50 results since there are enough from the # good cells to fill our limit. self.assertEqual(50, len(list(result))) # Make sure the counts line up self.assertEqual(1, len(lister.cells_responded)) self.assertEqual(1, len(lister.cells_failed)) self.assertEqual(1, len(lister.cells_timed_out))
def spawn(self, context, instance, image_meta, injected_files, admin_password, network_info=None, block_device_info=None): raise exception.BuildAbortException(instance_uuid=instance.uuid, reason='FakeBuildAbortDriver')
def _get_network_profile(self, network_info): if not network_info: raise exception.BuildAbortException('Network info missing') network_profile = {'network_interfaces': []} for net_info in network_info: nic_name = 'nic-' + net_info['id'] nic = utils.get_nic(self.network_client, drv_conf.resource_group, nic_name) network_profile['network_interfaces'].append({'id': nic.id}) return network_profile
def test_spawn_with_image_error(self): self._create_instance() self._create_network() with contextlib.nested( mock.patch.object(EC2Driver, '_get_image_ami_id_from_meta'), mock.patch.object(EC2Driver, '_process_network_info'), mock.patch.object(EC2Driver, '_get_instance_sec_grps'), ) as (mock_image, mock_network, mock_secgrp): mock_image.side_effect = exception.BuildAbortException('fake') mock_network.return_value = ('subnet-1234abc', '192.168.10.5', None, None) mock_secgrp.return_value = [] self.assertRaises(exception.BuildAbortException, self._create_nova_vm) self.reset()
def _get_image_ami_id_from_meta(self, context, image_lacking_meta): """Pulls the Image AMI ID from the location attribute of Image Meta :param image_meta: :return: ami_id """ image_api = glance.get_default_image_service() image_meta = image_api._client.call(context, 2, 'get', image_lacking_meta.id) LOG.info("Calling _get_image_ami_id_from_meta Meta: %s" % image_meta) try: return image_meta['aws_image_id'] except Exception as e: LOG.error("Error in parsing Image Id: %s" % e) raise exception.BuildAbortException("Invalid or Non-Existent Image" " ID Error")
def test_build_abort_exception(self): self.mox.StubOutWithMock(self.compute, '_build_and_run_instance') self.mox.StubOutWithMock(self.compute, '_set_instance_error_state') self.mox.StubOutWithMock(self.compute.compute_task_api, 'build_instances') self.compute._build_and_run_instance( self.context, self.instance, self.image, self.injected_files, self.admin_pass).AndRaise( exception.BuildAbortException( reason='', instance_uuid=self.instance['uuid'])) self.compute._set_instance_error_state(self.context, self.instance['uuid']) self.mox.ReplayAll() self.compute.build_and_run_instance(self.context, self.instance, self.image, request_spec={}, filter_properties=[], injected_files=self.injected_files, admin_password=self.admin_pass)
def create_lpar(adapter, host_w, instance): """Create an LPAR based on the host based on the instance. :param adapter: The adapter for the pypowervm API. :param host_w: The host's System wrapper. :param instance: The nova instance. :return: The LPAR wrapper response from the API. """ try: # Translate the nova flavor into a PowerVM Wrapper Object. lpar_b = VMBuilder(host_w, adapter).lpar_builder(instance) pending_lpar_w = lpar_b.build() # Run validation against it. This is just for nice(r) error messages. pvm_vldn.LPARWrapperValidator(pending_lpar_w, host_w).validate_all() # Create it. The API returns a new wrapper with the actual system data. return pending_lpar_w.create(parent=host_w) except lpar_bldr.LPARBuilderException as e: # Raise the BuildAbortException since LPAR failed to build raise exc.BuildAbortException(instance_uuid=instance.uuid, reason=e) except pvm_exc.HttpError as he: # Raise the API exception LOG.exception("PowerVM HttpError creating LPAR.", instance=instance) raise exc.PowerVMAPIFailed(inst_name=instance.name, reason=he)
def throw_error(*args, **kwargs): raise exception.BuildAbortException(reason='', instance_uuid='fake')
def spawn(self, context, instance, image_meta, injected_files, admin_password, network_info=None, block_device_info=None): """Create a new instance/VM/domain on the virtualization platform. Once this successfully completes, the instance should be running (power_state.RUNNING). If this fails, any partial instance should be completely cleaned up, and the virtualization platform should be in the state that it was before this call began. :param context: security context <Not Yet Implemented> :param instance: nova.objects.instance.Instance This function should use the data there to guide the creation of the new instance. :param image_meta: image object returned by nova.image.glance that defines the image from which to boot this instance :param injected_files: User files to inject into instance. :param admin_password: set in instance. <Not Yet Implemented> :param network_info: :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info` :param block_device_info: Information about block devices to be attached to the instance. """ image_ami_id = self._get_image_ami_id_from_meta(context, image_meta) subnet_id, fixed_ip, port_id, network_id = self._process_network_info( network_info) if subnet_id is None or fixed_ip is None: raise exception.BuildAbortException("Network configuration " "failure") security_groups = self._get_instance_sec_grps(context, port_id, network_id) # Flavor flavor_dict = instance['flavor'] flavor_type = flavor_dict['name'] # SSH Keys if (instance['key_name'] is not None and instance['key_data'] is not None): self._add_ssh_keys(instance['key_name'], instance['key_data']) # Creating the EC2 instance user_data = None # Passing user_data from the openstack instance which is Base64 encoded # after decoding it. if 'user_data' in instance and instance['user_data'] is not None: user_data = instance['user_data'] user_data = base64.b64decode(user_data) try: reservation = self.ec2_conn.run_instances( instance_type=flavor_type, key_name=instance['key_name'], image_id=image_ami_id, user_data=user_data, subnet_id=subnet_id, private_ip_address=fixed_ip, security_group_ids=security_groups) ec2_instance = reservation.instances ec2_instance_obj = ec2_instance[0] ec2_id = ec2_instance[0].id self._wait_for_state(instance, ec2_id, "running", power_state.RUNNING) instance['metadata'].update({'ec2_id': ec2_id}) ec2_instance_obj.add_tag("Name", instance['display_name']) ec2_instance_obj.add_tag("openstack_id", instance['uuid']) ec2_instance_obj.add_tag("openstack_project_id", context.project_id) ec2_instance_obj.add_tag("openstack_user_id", context.user_id) self._uuid_to_ec2_instance[instance.uuid] = ec2_instance_obj # Fetch Public IP of the instance if it has one instances = self.ec2_conn.get_only_instances(instance_ids=[ec2_id]) if len(instances) > 0: public_ip = instances[0].ip_address if public_ip is not None: instance['metadata'].update( {'public_ip_address': public_ip}) except EC2ResponseError as ec2_exception: actual_exception = Ec2ExceptionHandler.get_processed_exception( ec2_exception) LOG.info("Error in starting instance %s" % (actual_exception)) raise exception.BuildAbortException(actual_exception.message)