def test_generate_configdrive(self, get, create, required): get.return_value = '/test/tmp/fake_uuid' create.return_value = '/test/cfgdrive.tgz' required.return_value = True ctxt = context.RequestContext('fake_user', 'fake_project') instance = fake_instance.fake_instance_obj(ctxt) file = zvmutils.generate_configdrive('context', instance, 'injected_files', 'network_info', 'admin_password') required.assert_called_once_with(instance) create.assert_called_once_with('context', '/test/tmp/fake_uuid', instance, 'injected_files', 'network_info', 'admin_password') self.assertEqual('/test/cfgdrive.tgz', file)
def test_generate_configdrive(self, get, create, required): get.return_value = '/test/tmp/fake_uuid' create.return_value = '/test/cfgdrive.tgz' required.return_value = True ctxt = context.RequestContext('fake_user', 'fake_project') instance = fake_instance.fake_instance_obj(ctxt) file = zvmutils.generate_configdrive('context', instance, 'injected_files', 'network_info', 'admin_password') required.assert_called_once_with(instance) create.assert_called_once_with('context', '/test/tmp/fake_uuid', instance, 'injected_files', 'network_info', 'admin_password') self.assertEqual('/test/cfgdrive.tgz', file)
def spawn(self, context, instance, image_meta, injected_files, admin_password, allocations, network_info=None, block_device_info=None, power_on=True): LOG.info("Spawning new instance %s on zVM hypervisor", instance.name, instance=instance) if self._hypervisor.guest_exists(instance): raise exception.InstanceExists(name=instance.name) os_distro = image_meta.properties.get('os_distro') if os_distro is None or len(os_distro) == 0: reason = _("The `os_distro` image metadata property is required") raise exception.InvalidInput(reason=reason) try: spawn_start = time.time() transportfiles = zvmutils.generate_configdrive( context, instance, injected_files, network_info, admin_password) spawn_image_name = self._get_image_info(context, image_meta.id, os_distro) disk_list, eph_list = self._set_disk_list(instance, spawn_image_name, block_device_info) # Create the guest vm self._hypervisor.guest_create(instance.name, instance.vcpus, instance.memory_mb, disk_list) # Deploy image to the guest vm self._hypervisor.guest_deploy(instance.name, spawn_image_name, transportfiles=transportfiles) # Handle ephemeral disks if eph_list: self._hypervisor.guest_config_minidisks( instance.name, eph_list) # Setup network for z/VM instance self._wait_vif_plug_events(instance.name, os_distro, network_info, instance) self._hypervisor.guest_start(instance.name) spawn_time = time.time() - spawn_start LOG.info("Instance spawned successfully in %s seconds", spawn_time, instance=instance) except Exception as err: with excutils.save_and_reraise_exception(): LOG.error( "Deploy instance %(instance)s " "failed with reason: %(err)s", { 'instance': instance.name, 'err': err }, instance=instance) try: self.destroy(context, instance, network_info, block_device_info) except Exception: LOG.exception("Failed to destroy instance", instance=instance)
def spawn(self, context, instance, image_meta, injected_files, admin_password, allocations, network_info=None, block_device_info=None): LOG.info("Spawning new instance %s on zVM hypervisor", instance.name, instance=instance) if self._hypervisor.guest_exists(instance): raise exception.InstanceExists(name=instance.name) os_distro = image_meta.properties.get('os_distro') if os_distro is None or len(os_distro) == 0: reason = _("The `os_distro` image metadata property is required") raise exception.InvalidInput(reason=reason) try: spawn_start = time.time() transportfiles = zvmutils.generate_configdrive(context, instance, injected_files, network_info, admin_password) spawn_image_name = self._get_image_info(context, image_meta.id, os_distro) disk_list, eph_list = self._set_disk_list(instance, spawn_image_name, block_device_info) # Create the guest vm self._hypervisor.guest_create(instance.name, instance.vcpus, instance.memory_mb, disk_list) # Deploy image to the guest vm self._hypervisor.guest_deploy(instance.name, spawn_image_name, transportfiles=transportfiles) # Handle ephemeral disks if eph_list: self._hypervisor.guest_config_minidisks(instance.name, eph_list) # Setup network for z/VM instance self._wait_vif_plug_events(instance.name, os_distro, network_info, instance) self._hypervisor.guest_start(instance.name) spawn_time = time.time() - spawn_start LOG.info("Instance spawned successfully in %s seconds", spawn_time, instance=instance) except Exception as err: with excutils.save_and_reraise_exception(): LOG.error("Deploy instance %(instance)s " "failed with reason: %(err)s", {'instance': instance.name, 'err': err}, instance=instance) try: self.destroy(context, instance, network_info, block_device_info) except Exception as err: LOG.exception("Failed to destroy instance", instance=instance)