示例#1
0
 def _check_payload_type(self, payload_type, kickstart):
     """Check the payload type for the given kickstart."""
     specification = PayloadKickstartSpecification
     handler = KickstartSpecificationHandler(specification)
     parser = KickstartSpecificationParser(handler, specification)
     parser.readKickstartFromString(kickstart)
     self.assertEqual(payload_type, PayloadFactory.get_type_for_kickstart(handler))
示例#2
0
    def _test_kickstart(self, ks_in, ks_out):
        """Simulate the kickstart test.

        FIXME: This is a temporary workaround.
        """
        spec = AnacondaKickstartSpecification

        # Parse a kickstart string.
        ks_in = dedent(ks_in).strip()
        handler = KickstartSpecificationHandler(spec)
        parser = KickstartSpecificationParser(handler, spec)
        parser.readKickstartFromString(ks_in)

        self.repositories = list(
            map(convert_ks_repo_to_repo_data, handler.repo.dataList()))

        # Verify the DBus data.
        RepoConfigurationData.to_structure_list(self.repositories)

        # Generate a kickstart string.
        ks_out = dedent(ks_out).strip()
        handler = KickstartSpecificationHandler(spec)

        for repo_data in self.repositories:
            ks_repo = convert_repo_data_to_ks_repo(repo_data)
            handler.repo.dataList().append(ks_repo)

        ks_generated = str(handler).strip()
        assert ks_generated == ks_out
 def _check_method(self, method, kickstart):
     """Check the partitioning method of the given kickstart."""
     specification = StorageKickstartSpecification
     handler = KickstartSpecificationHandler(specification)
     parser = KickstartSpecificationParser(handler, specification)
     parser.readKickstartFromString(kickstart)
     self.assertEqual(method, PartitioningFactory.get_method_for_kickstart(handler))
示例#4
0
    def parse_kickstart(self, specification, kickstart_input, kickstart_output=None):
        """Parse a kickstart string using the given specification."""
        handler = KickstartSpecificationHandler(specification)
        parser = KickstartSpecificationParser(handler, specification)
        parser.readKickstartFromString(dedent(kickstart_input))

        if kickstart_output is not None:
            self.assertEqual(str(handler).strip(), dedent(kickstart_output).strip())

        return handler
示例#5
0
    def parser_test(self):
        """Check the specification parser."""
        for specification in self.SPECIFICATIONS:
            print("Checking specification {}...".format(specification.__name__))

            # Create the kickstart parser.
            handler = KickstartSpecificationHandler(specification)
            parser = KickstartSpecificationParser(handler, specification)

            # Read an empty string.
            parser.readKickstartFromString("")
    def parser_test(self):
        """Check the specification parser."""
        for specification in self.SPECIFICATIONS:
            print("Checking specification {}...".format(specification.__name__))

            # Create the kickstart parser.
            handler = KickstartSpecificationHandler(specification)
            parser = KickstartSpecificationParser(handler, specification)

            # Read an empty string.
            parser.readKickstartFromString("")
示例#7
0
    def get_kickstart_parser(self, handler):
        """Return a kickstart parser.

        :param handler: a kickstart handler
        :return: a kickstart parser
        """
        return KickstartSpecificationParser(handler, self.kickstart_specification)
 def parse_kickstart(self, specification, kickstart_input):
     """Parse a kickstart string using the given specification."""
     handler = KickstartSpecificationHandler(specification)
     parser = KickstartSpecificationParser(handler, specification)
     parser.readKickstartFromString(kickstart_input)
     return handler
示例#9
0
 def setUp(self):
     nvdimm_ks_spec = NvdimmKickstartSpecification()
     self.handler = KickstartSpecificationHandler(nvdimm_ks_spec)
     self.parser = KickstartSpecificationParser(self.handler, nvdimm_ks_spec)
示例#10
0
class UpdateNvdimmDataTestCase(unittest.TestCase):
    """Test updating of nvdimm command from UI.

    The update is done:
    - always by disk selection in UI.
    - optionally by reconfiguring NVDIMM in UI.
    """

    def setUp(self):
        nvdimm_ks_spec = NvdimmKickstartSpecification()
        self.handler = KickstartSpecificationHandler(nvdimm_ks_spec)
        self.parser = KickstartSpecificationParser(self.handler, nvdimm_ks_spec)

    def _read(self, input_ks):
        self.parser.readKickstartFromString(input_ks)

    def _use(self, namespaces):
        """Represents update for NVDIMM disks selected in UI."""
        nvdimm_update_ksdata_for_used_devices(self.handler,
                                              namespaces=namespaces)

    def _reconfigure(self, namespace, sectorsize):
        """Represents update for NVDIMM disk reconfigured in UI."""
        nvdimm_update_ksdata_after_reconfiguration(self.handler,
                                                   namespace=namespace,
                                                   mode=NVDIMM_MODE_SECTOR,
                                                   sectorsize=sectorsize)

    def _check(self, expected_ks):
        self.assertEqual(str(self.handler.nvdimm).strip(), dedent(expected_ks).strip())

    # Test setting use from UI

    def ksuse_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        """
        self._read(input_ks)
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksuse_use2_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        nvdimm use --namespace=namespace1.0
        """
        self._read(input_ks)
        self._use(["namespace0.0", "namespace1.0"])
        self._check(expected_ks)

    def ksuse_use_none_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        """
        self._read(input_ks)
        self._use([])
        self._check(expected_ks)

    def ksnone_use2_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        nvdimm use --namespace=namespace1.0
        """
        self._read(input_ks)
        self._use(["namespace0.0", "namespace1.0"])
        self._check(expected_ks)

    def ksnone_repeated_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        """
        self._read(input_ks)
        self._use(["namespace0.0"])
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksnone_use_none_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        """
        expected_ks = """
        """
        self._read(input_ks)
        self._use([])
        self._check(expected_ks)

    def ksnone_repeated_use_2_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace1.0
        """
        self._read(input_ks)
        self._use(["namespace0.0"])
        # Next use should override the previous
        self._use(["namespace1.0"])
        self._check(expected_ks)

    def ksuse_another_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace1.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        """
        self._read(input_ks)
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksuse_none_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace1.0
        """
        expected_ks = """
        """
        self._read(input_ks)
        self._use([])
        self._check(expected_ks)

    def ksreconfigure_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksreconfigure_use_none_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        # Even when not used, the reconfiguration should go to generated kicksart
        self._use([])
        self._check(expected_ks)

    def ksreconfigure_another_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm use --namespace=namespace1.0
        """
        self._read(input_ks)
        self._use(["namespace1.0"])
        self._check(expected_ks)

    def ksreconfigure_ksuse_another_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm use --namespace=namespace1.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksreconfigure_2_use_1_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._use(["namespace0.0"])
        self._check(expected_ks)

    # Test reconfigure and use in UI
    # (if _reconfigure is done in UI, _use is always done as well)

    def ksnone_reconfigure_use_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._reconfigure("namespace0.0", 512)
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksnone_repeated_reconfigure_use_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=4096
        """
        self._read(input_ks)
        self._reconfigure("namespace0.0", 512)
        self._reconfigure("namespace0.0", 4096)
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksnone_repeated_reconfigure_repeated_use_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._reconfigure("namespace0.0", 512)
        self._use(["namespace0.0"])
        self._reconfigure("namespace1.0", 512)
        # Even when not used, reconfiguration goes to generated ks
        self._use(["namespace1.0"])
        self._check(expected_ks)

    def ksuse_reconfigure_other_use_other_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._reconfigure("namespace1.0", 512)
        self._use(["namespace1.0"])
        self._check(expected_ks)

    def ksuse_2_reconfigure_1_use_2_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        nvdimm use --namespace=namespace1.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        nvdimm use --namespace=namespace0.0
        """
        self._read(input_ks)
        self._reconfigure("namespace1.0", 512)
        self._use(["namespace0.0", "namespace1.0"])
        self._check(expected_ks)

    def ksuse_reconfigure_other_use_none_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._reconfigure("namespace1.0", 512)
        # Even when not used, the reconfiguration should go to generated kicksart
        self._use([])
        print(self.handler.nvdimm)
        self._check(expected_ks)