示例#1
0
def test_duplicate_add(api, distro_collection):
    # Arrange
    name = "duplicate_name"
    item1 = distro.Distro(api)
    item1.name = name
    distro_collection.add(item1)
    item2 = distro.Distro(api)
    item2.name = name

    # Act & Assert
    with pytest.raises(CX):
        distro_collection.add(item2, check_for_duplicate_names=True)
示例#2
0
文件: distros.py 项目: maduhu/cobbler
 def factory_produce(self, collection_mgr, item_dict):
     """
     Return a Distro forged from item_dict
     """
     new_distro = distro.Distro(collection_mgr)
     new_distro.from_dict(item_dict)
     return new_distro
示例#3
0
 def factory_produce(self, api, item_dict):
     """
     Return a Distro forged from item_dict
     """
     new_distro = distro.Distro(api)
     new_distro.from_dict(item_dict)
     return new_distro
示例#4
0
def test_collection_add(api, distro_collection):
    # Arrange
    name = "collection_add"
    item1 = distro.Distro(api)
    item1.name = name

    # Act
    distro_collection.add(item1)

    # Assert
    assert name in distro_collection.listing
示例#5
0
def test_to_list(api, distro_collection):
    # Arrange
    name = "test_to_list"
    item1 = distro.Distro(api)
    item1.name = name
    distro_collection.add(item1)

    # Act
    result = distro_collection.to_list()

    # Assert
    assert len(result) == 1
    assert result[0].get("name") == name
示例#6
0
def test_get(api, distro_collection):
    # Arrange
    name = "test_get"
    item1 = distro.Distro(api)
    item1.name = name
    distro_collection.add(item1)

    # Act
    item = distro_collection.get(name)

    # Assert
    assert isinstance(item, distro.Distro)
    assert item.name == name
示例#7
0
def test_to_string(api, distro_collection):
    # Arrange
    name = "to_string"
    item1 = distro.Distro(api)
    item1.name = name
    distro_collection.add(item1)

    # Act
    result = distro_collection.to_string()

    # Assert
    print(result)
    assert False
示例#8
0
def test_remove(api, distro_collection):
    # Arrange
    name = "to_be_removed"
    item1 = distro.Distro(api)
    item1.name = name
    distro_collection.add(item1)
    assert name in distro_collection.listing

    # Act
    distro_collection.remove(name)

    # Assert
    assert name not in distro_collection.listing
示例#9
0
def test_find(api, distro_collection):
    # Arrange
    name = "test_find"
    item1 = distro.Distro(api)
    item1.name = name
    distro_collection.add(item1)

    # Act
    result = distro_collection.find(name, True, True)

    # Assert
    assert isinstance(result, list)
    assert len(result) == 1
    assert result[0].name == name
示例#10
0
def test_rename(api, distro_collection):
    # Arrange
    name = "to_be_renamed"
    item1 = distro.Distro(api)
    item1.name = name
    distro_collection.add(item1)

    # Act
    new_name = "new_name"
    distro_collection.rename(item1, new_name)

    # Assert
    assert new_name in distro_collection.listing
    assert distro_collection.listing.get(new_name).name == new_name
示例#11
0
def test_copy(api, distro_collection, create_kernel_initrd, fk_initrd, fk_kernel):
    # Arrange
    folder = create_kernel_initrd(fk_kernel, fk_initrd)
    name = "test_copy"
    item1 = distro.Distro(api)
    item1.name = name
    item1.initrd = os.path.join(folder, fk_initrd)
    item1.kernel = os.path.join(folder, fk_kernel)
    distro_collection.add(item1)

    # Act
    new_item_name = "test_copy_successful"
    distro_collection.copy(item1, new_item_name)

    # Assert
    assert len(distro_collection.listing) == 2
    assert name in distro_collection.listing
    assert new_item_name in distro_collection.listing
示例#12
0
    def add_entry(self, dirname: str, kernel, initrd):
        """
        When we find a directory with a valid kernel/initrd in it, create the distribution objects as appropriate and
        save them. This includes creating xen and rescue distros/profiles if possible.

        :param dirname: Unkown what this currently does.
        :param kernel: Unkown what this currently does.
        :param initrd: Unkown what this currently does.
        :return: Unkown what this currently does.
        """

        # build a proposed name based on the directory structure
        proposed_name = self.get_proposed_name(dirname, kernel)

        # build a list of arches found in the packages directory
        archs = self.learn_arch_from_tree()
        if not archs and self.arch:
            archs.append(self.arch)
        else:
            if self.arch and self.arch not in archs:
                utils.die("Given arch (%s) not found on imported tree %s" %
                          (self.arch, self.path))

        if len(archs) == 0:
            self.logger.error(
                "No arch could be detected in %s, and none was specified via the --arch option"
                % dirname)
            return []
        elif len(archs) > 1:
            self.logger.warning("- Warning : Multiple archs found : %s" %
                                archs)

        distros_added = []
        for pxe_arch in archs:
            name = proposed_name + "-" + pxe_arch
            existing_distro = self.distros.find(name=name)

            if existing_distro is not None:
                self.logger.warning(
                    "skipping import, as distro name already exists: %s" %
                    name)
                continue
            else:
                self.logger.info("creating new distro: %s" % name)
                new_distro = distro.Distro(self.collection_mgr)

            if name.find("-autoboot") != -1:
                # this is an artifact of some EL-3 imports
                continue

            new_distro.set_name(name)
            new_distro.set_kernel(kernel)
            new_distro.set_initrd(initrd)
            new_distro.set_arch(pxe_arch)
            new_distro.set_breed(self.breed)
            new_distro.set_os_version(self.os_version)
            new_distro.set_kernel_options(
                self.signature.get("kernel_options", ""))
            new_distro.set_kernel_options_post(
                self.signature.get("kernel_options_post", ""))
            new_distro.set_template_files(
                self.signature.get("template_files", ""))
            supported_distro_boot_loaders = utils.get_supported_distro_boot_loaders(
                new_distro, self.api)
            new_distro.set_supported_boot_loaders(
                supported_distro_boot_loaders)
            new_distro.set_boot_loader(supported_distro_boot_loaders[0])

            boot_files = ''
            for boot_file in self.signature["boot_files"]:
                boot_files += '$local_img_path/%s=%s/%s ' % (
                    boot_file, self.path, boot_file)
            new_distro.set_boot_files(boot_files.strip())

            self.configure_tree_location(new_distro)

            self.distros.add(new_distro, save=True)
            distros_added.append(new_distro)

            # see if the profile name is already used, if so, skip it and
            # do not modify the existing profile

            existing_profile = self.profiles.find(name=name)

            if existing_profile is None:
                self.logger.info("creating new profile: %s" % name)
                new_profile = profile.Profile(self.collection_mgr)
            else:
                self.logger.info(
                    "skipping existing profile, name already exists: %s" %
                    name)
                continue

            new_profile.set_name(name)
            new_profile.set_distro(name)
            new_profile.set_autoinstall(self.autoinstall_file)

            # depending on the name of the profile we can
            # define a good virt-type for usage with koan
            if name.find("-xen") != -1:
                new_profile.set_virt_type("xenpv")
            elif name.find("vmware") != -1:
                new_profile.set_virt_type("vmware")
            else:
                new_profile.set_virt_type("kvm")

            self.profiles.add(new_profile, save=True)

        return distros_added
示例#13
0
 def new_distro(self, is_subobject=False):
     self.log("new_distro", [is_subobject])
     return distro.Distro(self._collection_mgr, is_subobject=is_subobject)
示例#14
0
    def add_entry(self, dirname: str, kernel, initrd):
        """
        When we find a directory with a valid kernel/initrd in it, create the distribution objects as appropriate and
        save them. This includes creating xen and rescue distros/profiles if possible.

        :param dirname: Unkown what this currently does.
        :param kernel: Unkown what this currently does.
        :param initrd: Unkown what this currently does.
        :return: Unkown what this currently does.
        """

        # build a proposed name based on the directory structure
        proposed_name = self.get_proposed_name(dirname, kernel)

        # build a list of arches found in the packages directory
        archs = self.learn_arch_from_tree()
        if not archs and self.arch:
            archs.append(self.arch)
        else:
            if self.arch and self.arch not in archs:
                utils.die("Given arch (%s) not found on imported tree %s" %
                          (self.arch, self.path))

        if len(archs) == 0:
            self.logger.error(
                "No arch could be detected in %s, and none was specified via the --arch option"
                % dirname)
            return []
        elif len(archs) > 1:
            self.logger.warning("- Warning : Multiple archs found : %s" %
                                archs)

        distros_added = []
        for pxe_arch in archs:
            name = proposed_name + "-" + pxe_arch
            existing_distro = self.distros.find(name=name)

            if existing_distro is not None:
                self.logger.warning(
                    "skipping import, as distro name already exists: %s" %
                    name)
                continue
            else:
                self.logger.info("creating new distro: %s" % name)
                new_distro = distro.Distro(self.api)

            if name.find("-autoboot") != -1:
                # this is an artifact of some EL-3 imports
                continue

            new_distro.name = name
            new_distro.kernel = kernel
            new_distro.initrd = initrd
            new_distro.arch = pxe_arch
            new_distro.breed = self.breed
            new_distro.os_version = self.os_version
            new_distro.kernel_options = self.signature.get(
                "kernel_options", "")
            new_distro.kernel_options_post = self.signature.get(
                "kernel_options_post", "")
            new_distro.template_files = self.signature.get(
                "template_files", "")

            boot_files: Dict[str, str] = {}
            for boot_file in self.signature["boot_files"]:
                boot_files['$local_img_path/%s' %
                           boot_file] = '%s/%s' % (self.path, boot_file)
            new_distro.boot_files = boot_files

            self.configure_tree_location(new_distro)

            self.distros.add(new_distro, save=True)
            distros_added.append(new_distro)

            # see if the profile name is already used, if so, skip it and
            # do not modify the existing profile

            existing_profile = self.profiles.find(name=name)

            if existing_profile is None:
                self.logger.info("creating new profile: %s" % name)
                new_profile = profile.Profile(self.api)
            else:
                self.logger.info(
                    "skipping existing profile, name already exists: %s" %
                    name)
                continue

            new_profile.name = name
            new_profile.distro = name
            new_profile.autoinstall = self.autoinstall_file

            # depending on the name of the profile we can
            # define a good virt-type for usage with koan
            if name.find("-xen") != -1:
                new_profile.virt_type = enums.VirtType.XENPV
            elif name.find("vmware") != -1:
                new_profile.virt_type = enums.VirtType.VMWARE
            else:
                new_profile.virt_type = enums.VirtType.KVM

            if self.breed == "windows":
                dest_path = os.path.join(self.path, "boot")
                bootmgr_path = os.path.join(dest_path, "bootmgr.exe")
                bcd_path = os.path.join(dest_path, "bcd")
                winpe_path = os.path.join(dest_path, "winpe.wim")
                if os.path.exists(bootmgr_path) and os.path.exists(
                        bcd_path) and os.path.exists(winpe_path):
                    new_profile.autoinstall_meta = {
                        "kernel": os.path.basename(kernel),
                        "bootmgr": "bootmgr.exe",
                        "bcd": "bcd",
                        "winpe": "winpe.wim",
                        "answerfile": "autounattended.xml"
                    }

            self.profiles.add(new_profile, save=True)

        return distros_added