Beispiel #1
0
    def choose_from_multiple_cdroms_test(self, proxy_getter, mount_mock,
                                         unmount_mock, valid_mock):
        """Test CD-ROM Source setup installation source task run - choice from multiple CD-ROMs.

        Fake four CD-ROM devices: First fails to mount, second has nothing useful, third has what
        we want so is left mounted, fourth is entirely skipped.
        The other two tests below are needed only to test the exit when nothing is found.
        """
        device_tree = self.set_up_device_tree(4)
        proxy_getter.return_value = device_tree

        mount_mock.side_effect = \
            [PayloadSetupError("Mocked failure"), DEFAULT, DEFAULT, DEFAULT]

        # only for devices 2-4; the expected first call is prevented by the exception from mount
        valid_mock.side_effect = [False, True, False]

        task = SetUpCdromSourceTask(self.mount_location)
        task.run()

        # 3/4 devices tried, 1/4 untried
        self.assert_resolve_and_mount_calls(device_tree, mount_mock, 3, 1)

        # Only 2 & 3 were mounted
        self.assertEqual(valid_mock.call_count, 2)
        # It makes no sense to check how validation was called because all mounting is to the same
        # path.

        #  #1 died earlier, #2 was unmounted, #3 was left mounted, #4 never got mounted
        unmount_mock.assert_called_once_with(self.mount_location)
    def failure_to_mount_test(self, proxy_getter, mount_mock, unmount_mock,
                              valid_mock):
        """Test CD-ROM Source setup installation source task run - mount failure.

        Mocks one disk which fails to mount, expect exception.
        """
        device_tree = self.set_up_device_tree(1)
        proxy_getter.return_value = device_tree

        mount_mock.side_effect = PayloadSetupError("Mocked failure")
        valid_mock.return_value = True

        with self.assertRaises(SourceSetupError) as cm:
            task = SetUpCdromSourceTask(self.mount_location)
            task.run()

        # 1/1 devices tried, 0 untried
        self.assert_resolve_and_mount_calls(device_tree, mount_mock, 1, 0)
        # neither validation nor unmounting could not have been reached
        valid_mock.assert_not_called()
        unmount_mock.assert_not_called()
        # no device was selected
        self.assertFalse(task._device_name)
        # exception happened due to no disk
        self.assertEqual(str(cm.exception), "Found no CD-ROM")
Beispiel #3
0
    def test_priority_stage2_not_optical_media_cdrom(self, proxy_getter,
                                                     mount_mock, unmount_mock,
                                                     valid_mock,
                                                     kernel_arguments_mock):
        """Test CD-ROM Source setup installation source task run - stage2 is not optical media.

        We should not pick stage2 device if it is not an optical_media which means type iso9660.
        """
        kernel_arguments_mock.get.return_value = "hd:LABEL=correct-device"
        device_tree = self.set_up_device_tree(1)
        device_tree.ResolveDevice.return_value = "not-optical-media"
        proxy_getter.return_value = device_tree
        valid_mock.return_value = True

        task = SetUpCdromSourceTask(self.mount_location)
        result = task.run()

        device_tree.ResolveDevice.assert_called_once_with(
            "LABEL=correct-device")

        self._check_if_device_was_not_tried(device_tree, mount_mock,
                                            "correct-device")

        # 1/2 devices tried, 1/2 untried
        self.assert_resolve_and_mount_calls(device_tree, mount_mock, 1, 1)

        # Only first was mounted
        assert valid_mock.call_count == 1

        #  First device was used no unmount should be called
        unmount_mock.assert_not_called()

        # Test device name returned
        assert result == "test0"
Beispiel #4
0
    def test_priority_stage2_cant_be_resolved_source_cdrom(
            self, proxy_getter, mount_mock, unmount_mock, valid_mock,
            kernel_arguments_mock):
        """Test CD-ROM Source setup installation source task run - can't resolve stage2 device.

        Stage2 device can't be resolved. This should not happen but let's make sure the code works.
        """
        kernel_arguments_mock.get.return_value = "hd:LABEL=my-cool-dvd"
        device_tree = self.set_up_device_tree(1)
        proxy_getter.return_value = device_tree
        # When device can't be resolved it returns an empty string.
        device_tree.ResolveDevice.return_value = ""
        valid_mock.return_value = True

        task = SetUpCdromSourceTask(self.mount_location)
        result = task.run()

        self._check_if_device_was_not_tried(device_tree, mount_mock, "")

        # 1/2 devices tried, 1/2 untried
        self.assert_resolve_and_mount_calls(device_tree, mount_mock, 1, 1)

        # Only first was mounted
        assert valid_mock.call_count == 1

        #  First device was used no unmount should be called
        unmount_mock.assert_not_called()

        # Test device name returned
        assert result == "test0"
Beispiel #5
0
    def test_priority_stage2_not_hdd_source_cdrom(self, proxy_getter,
                                                  mount_mock, unmount_mock,
                                                  valid_mock,
                                                  kernel_arguments_mock):
        """Test CD-ROM Source setup installation source task run - stage2 is not HDD source.

        We are testing HDD because DVD ISOs are created with inst.stage2=hd: . We want to change
        this behavior on master so let's change this test too then.

        TODO: Change this test when DVD ISOs will use cdrom:<device> instead of inst.stage2=hd:...
        """
        kernel_arguments_mock.get.return_value = "nfs:test.org:/super/cool/path"
        device_tree = self.set_up_device_tree(1)
        proxy_getter.return_value = device_tree
        valid_mock.return_value = True

        task = SetUpCdromSourceTask(self.mount_location)
        result = task.run()

        device_tree.ResolveDevice.assert_not_called()

        # 1/2 devices tried, 1/2 untried
        self.assert_resolve_and_mount_calls(device_tree, mount_mock, 1, 1)

        # Only first was mounted
        assert valid_mock.call_count == 1

        #  First device was used no unmount should be called
        unmount_mock.assert_not_called()

        # Test device name returned
        assert result == "test0"
Beispiel #6
0
    def test_priority_stage2_unrecognized_source_cdrom(self, proxy_getter,
                                                       mount_mock,
                                                       unmount_mock,
                                                       valid_mock,
                                                       kernel_arguments_mock):
        """Test CD-ROM Source setup installation source task run - unrecognized stage2 source.

        This should not happen but when we have the code there let's check it.
        """
        kernel_arguments_mock.get.return_value = "wrong source!"
        device_tree = self.set_up_device_tree(1)
        proxy_getter.return_value = device_tree
        valid_mock.return_value = True

        task = SetUpCdromSourceTask(self.mount_location)
        result = task.run()

        device_tree.ResolveDevice.assert_not_called()

        # 1/2 devices tried, 1/2 untried
        self.assert_resolve_and_mount_calls(device_tree, mount_mock, 1, 1)

        # Only first was mounted
        assert valid_mock.call_count == 1

        #  First device was used no unmount should be called
        unmount_mock.assert_not_called()

        # Test device name returned
        assert result == "test0"
Beispiel #7
0
    def test_priority_stage2_cdrom(self, proxy_getter, mount_mock,
                                   unmount_mock, valid_mock,
                                   kernel_arguments_mock):
        """Test CD-ROM Source setup installation source task run - prioritize inst.stage2 CD-ROMs.

        Add valid stage2 CDROM device and it has to be tested first.
        """
        kernel_arguments_mock.get.return_value = "hd:LABEL=my-cool-dvd"
        device_tree = self.set_up_device_tree(2)
        device_tree.ResolveDevice.return_value = "test1"
        proxy_getter.return_value = device_tree
        valid_mock.return_value = True

        task = SetUpCdromSourceTask(self.mount_location)
        result = task.run()

        # Only one device was checked
        device_tree.ResolveDevice.assert_called_once_with("LABEL=my-cool-dvd")

        self._check_if_device_was_tried(device_tree, mount_mock, "test1")
        self._check_if_device_was_not_tried(device_tree, mount_mock, "test0")

        # First device (stage2 device) is valid one
        valid_mock.assert_called_once()

        # First device works so no unmount is called here
        unmount_mock.assert_not_called()

        # Test device name returned
        assert result == "test1"
Beispiel #8
0
    def no_cdrom_with_valid_source_test(self, proxy_getter, mount_mock, unmount_mock, valid_mock):
        """Test CD-ROM Source setup installation source task run - no valid source CD-ROMs.

        Mocks one CD-ROM device which has nothing useful, expect exception.
        """
        device_tree = self.set_up_device_tree(1)
        proxy_getter.return_value = device_tree

        valid_mock.return_value = False

        with self.assertRaises(SourceSetupError) as cm:
            task = SetUpCdromSourceTask(self.mount_location)
            task.run()

        # 1/1 devices tried, 0 untried
        self.assert_resolve_and_mount_calls(device_tree, mount_mock, 1, 0)
        # neither validation nor unmounting could not have been reached
        valid_mock.assert_called_once()
        unmount_mock.assert_called_once()
        # exception happened due to no disk
        self.assertEqual(str(cm.exception), "Found no CD-ROM")
    def test_failure_to_mount(self, proxy_getter, mount_mock, unmount_mock,
                              valid_mock, kernel_arguments_mock):
        """Test CD-ROM Source setup installation source task run - mount failure.

        Mocks one disk which fails to mount, expect exception.
        """
        kernel_arguments_mock.get.return_value = None
        device_tree = self.set_up_device_tree(1)
        proxy_getter.return_value = device_tree
        mount_mock.side_effect = OSError("Mocked failure")
        valid_mock.return_value = True

        with pytest.raises(SourceSetupError) as cm:
            task = SetUpCdromSourceTask(self.mount_location)
            task.run()

        # 1/1 devices tried, 0 untried
        self.assert_resolve_and_mount_calls(device_tree, mount_mock, 1, 0)
        # neither validation nor unmounting could not have been reached
        valid_mock.assert_not_called()
        unmount_mock.assert_not_called()
        # exception happened due to no disk
        assert str(cm.value) == "Found no CD-ROM"