コード例 #1
0
    def test_invalid_image(self):
        """Test an invalid image."""
        configuration = LiveImageConfigurationData()
        configuration.url = "file:///my/invalid/path"

        task = SetUpLocalImageSourceTask(configuration)
        with pytest.raises(SourceSetupError) as cm:
            task.run()

        assert str(cm.value) == "File /my/invalid/path does not exist."
コード例 #2
0
    def invalid_image_test(self):
        """Test an invalid image."""
        configuration = LiveImageConfigurationData()
        configuration.url = "file:///my/invalid/path"

        task = SetUpLocalImageSourceTask(configuration)
        with self.assertRaises(SourceSetupError) as cm:
            task.run()

        self.assertEqual(str(cm.exception),
                         "File /my/invalid/path does not exist.")
コード例 #3
0
    def empty_image_test(self):
        """Test an empty image."""
        with tempfile.NamedTemporaryFile("w") as f:
            # Run the task.
            configuration = LiveImageConfigurationData()
            configuration.url = "file://" + f.name

            task = SetUpLocalImageSourceTask(configuration)
            result = task.run()

            # Check the result.
            self.assertIsInstance(result, SetupImageResult)
            self.assertEqual(result, SetupImageResult(None))
コード例 #4
0
    def test_empty_image(self, os_stat):
        """Test an empty image."""
        os_stat.return_value = Mock(st_blocks=0)

        with tempfile.NamedTemporaryFile("w") as f:
            # Run the task.
            configuration = LiveImageConfigurationData()
            configuration.url = "file://" + f.name

            task = SetUpLocalImageSourceTask(configuration)
            result = task.run()

            # Check the result.
            assert isinstance(result, SetupImageResult)
            assert result == SetupImageResult(None)
コード例 #5
0
    def test_failed_request(self, session_getter):
        """Test a request that fails to be send."""
        # Prepare the session.
        session = session_getter.return_value.__enter__.return_value
        session.head.side_effect = RequestException("Fake!")

        # Run the task.
        configuration = LiveImageConfigurationData()
        configuration.url = "http://my/fake/path"

        task = SetUpRemoteImageSourceTask(configuration)
        with pytest.raises(SourceSetupError) as cm:
            task.run()

        # Check the exception.
        assert str(cm.value) == "Error while handling a request: Fake!"
コード例 #6
0
    def SetConfiguration(self, data: Structure):
        """Set the source configuration.

        :param data: a structure of the type LiveImageConfigurationData
        """
        self.implementation.set_configuration(
            LiveImageConfigurationData.from_structure(data))
コード例 #7
0
    def Configuration(self) -> Structure:
        """The source configuration.

        :return: a structure of the type LiveImageConfigurationData
        """
        return LiveImageConfigurationData.to_structure(
            self.implementation.configuration)
コード例 #8
0
    def invalid_response_test(self, session_getter):
        """Test an invalid response."""
        # Prepare the session.
        session = session_getter.return_value.__enter__.return_value
        response = session.head.return_value
        response.status_code = 303

        # Run the task.
        configuration = LiveImageConfigurationData()
        configuration.url = "http://my/fake/path"

        task = SetUpRemoteImageSourceTask(configuration)
        with self.assertRaises(SourceSetupError) as cm:
            task.run()

        # Check the exception.
        self.assertEqual(str(cm.exception), "The request has failed: 303")
コード例 #9
0
    def fake_image_test(self):
        """Test a fake image."""
        with tempfile.NamedTemporaryFile("w") as f:
            # Create a fake image.
            f.write("MY FAKE IMAGE")
            f.flush()

            # Run the task.
            configuration = LiveImageConfigurationData()
            configuration.url = "file://" + f.name

            task = SetUpLocalImageSourceTask(configuration)
            result = task.run()

            # Check the result.
            self.assertIsInstance(result, SetupImageResult)
            self.assertGreater(result.required_space, 0)
コード例 #10
0
    def set_from_opts(self, opts):
        """Set the payload from the Anaconda cmdline options.

        :param opts: a namespace of options
        """
        source_proxy = self.get_source_proxy()
        source_data = LiveImageConfigurationData.from_structure(
            source_proxy.Configuration)

        if opts.proxy:
            source_data.proxy = opts.proxy

        if not conf.payload.verify_ssl:
            source_data.ssl_verification_enabled = conf.payload.verify_ssl

        source_proxy.Configuration = \
            LiveImageConfigurationData.to_structure(source_data)
コード例 #11
0
    def fake_request_test(self, session_getter):
        """Test a fake request."""
        # Prepare the session.
        session = session_getter.return_value.__enter__.return_value
        response = session.head.return_value

        response.status_code = 200
        response.headers = {'content-length': 1000}

        # Run the task.
        configuration = LiveImageConfigurationData()
        configuration.url = "http://my/fake/path"

        task = SetUpRemoteImageSourceTask(configuration)
        result = task.run()

        # Check the result.
        self.assertIsInstance(result, SetupImageResult)
        self.assertEqual(result, SetupImageResult(4000))
コード例 #12
0
    def missing_size_test(self, session_getter):
        """Test a request with a missing size."""
        # Prepare the session.
        session = session_getter.return_value.__enter__.return_value
        response = session.head.return_value

        response.status_code = 200
        response.headers = {}

        # Run the task.
        configuration = LiveImageConfigurationData()
        configuration.url = "http://my/fake/path"

        task = SetUpRemoteImageSourceTask(configuration)
        result = task.run()

        # Check the result.
        self.assertIsInstance(result, SetupImageResult)
        self.assertEqual(result, SetupImageResult(None))
コード例 #13
0
    def fake_image_test(self, os_stat):
        """Test a fake image."""
        os_stat.return_value = Mock(st_blocks=2)

        with tempfile.NamedTemporaryFile("w") as f:
            # Create a fake image.
            f.write("MY FAKE IMAGE")
            f.flush()

            # Run the task.
            configuration = LiveImageConfigurationData()
            configuration.url = "file://" + f.name

            task = SetUpLocalImageSourceTask(configuration)
            result = task.run()

            # Check the result.
            self.assertIsInstance(result, SetupImageResult)
            self.assertEqual(result, SetupImageResult(3072))
コード例 #14
0
 def process_kickstart(self, data):
     """Process the kickstart data."""
     configuration = LiveImageConfigurationData()
     configuration.url = data.liveimg.url or ""
     configuration.proxy = data.liveimg.proxy or ""
     configuration.checksum = data.liveimg.checksum or ""
     configuration.ssl_verification_enabled = not data.liveimg.noverifyssl
     self.set_configuration(configuration)
コード例 #15
0
 def setUp(self):
     self.data = LiveImageConfigurationData()
コード例 #16
0
 def setUp(self):
     """Set up the test."""
     self.data = LiveImageConfigurationData()
     self.directory = None
コード例 #17
0
    def __init__(self):
        super().__init__()
        self._configuration = LiveImageConfigurationData()
        self.configuration_changed = Signal()

        self._required_space = None