Beispiel #1
0
    def test_create_vm(self):
        expected_goldimage_name = NameUtil.goldimage_vmdisk_name(
            "ubuntu1604-x86_64", "os")
        vm_name = NameUtil.goldimage_vm_name(self.scenario, "ubuntu1604")

        datastore_name = self.cluster._mgmt_server_info.prism_container_id
        node_id = self.cluster.nodes()[0].node_id()
        vm = self.cluster.create_vm(self.scenario.goldimages_directory,
                                    "ubuntu1604",
                                    vm_name,
                                    vcpus=1,
                                    ram_mb=1024,
                                    node_id=node_id,
                                    datastore_name=datastore_name,
                                    data_disks=[10, 20, 30])
        vms = self.cluster.find_vms([vm_name])
        assert len(vms) == 1, "Too many VMs found for %s" % vm_name
        assert vms[0].vm_name() == vm_name, "VM found %s wasn't %s" % (
            vms[0].vm_name(), vm_name)
        assert isinstance(vms[0],
                          AcropolisVm), ("VM is %s instead of AcropolisVm" %
                                         str(type(vms[0])))

        found_images = self.__get_image_names()
        assert expected_goldimage_name in found_images, \
          "Goldimage disk wasn't found in image service."

        self.scenario.cluster.cleanup()

        found_images = self.__get_image_names()
        assert expected_goldimage_name not in found_images, \
          "Goldimage disk wasn't found in image service."
Beispiel #2
0
    def deploy_goldimage_image_service(self, goldimages_directory,
                                       goldimage_name):
        """
    Deploy a gold image to the image service.

    Args:
      goldimage_name (str): Name of the gold image to deploy.

    Returns:
      str: ID of the created disk image.
    """
        arch = self.get_cluster_architecture()
        # Select a vdisk format to use. Currently PPC64LE goldimages are only built
        # using qcow2 format and the x86_64 in vmdk. We could have the manager
        # perform a conversion, but acropolis can already do the image conversion
        # for us.
        if arch == GoldImageManager.ARCH_PPC64LE:
            disk_format = GoldImageManager.FORMAT_QCOW2
        else:
            disk_format = GoldImageManager.FORMAT_VMDK

        # Use the GoldImage manager to get a path to our appropriate goldimage
        goldimage_manager = GoldImageManager(goldimages_directory)
        goldimage_path = goldimage_manager.get_goldimage_path(
            goldimage_name, format_str=disk_format, arch=arch)
        log.debug("Deploying %s to cluster", goldimage_path)

        # Deploy the image to service
        disk_name = os.path.splitext(os.path.basename(goldimage_path))[0]
        img_uuid, tid, _ = self._prism_client.images_create(
            NameUtil.goldimage_vmdisk_name(disk_name, "os"), goldimage_path,
            self._container_id)
        TaskPoller.execute_parallel_tasks(tasks=PrismTask.from_task_id(
            self._prism_client, tid),
                                          timeout_secs=3600)

        # NB: Required due to possible AHV bug. See XRAY-225.
        num_images_get_retries = 5
        for attempt_num in xrange(num_images_get_retries):
            images_get_data = self._prism_client.images_get(image_id=img_uuid)
            image_state = images_get_data["image_state"]
            if image_state.lower() == "active":
                # Return the disk image
                return images_get_data["vm_disk_id"]
            else:
                log.info(
                    "Waiting for created image to become active "
                    "(imageState: %s, retry %d of %d)", image_state,
                    attempt_num + 1, num_images_get_retries)
                log.debug(images_get_data)
                time.sleep(1)
        else:
            raise CurieException(
                CurieError.kInternalError,
                "Created image failed to become active within "
                "%d attempts" % num_images_get_retries)