Exemplo n.º 1
0
    def test_transfer_file(self):
        """Test the transfer file method of the subscription token transfer task."""
        with tempfile.TemporaryDirectory() as sysroot:
            task = TransferSubscriptionTokensTask(
                sysroot=sysroot, transfer_subscription_tokens=True)
            task._copy_file = Mock()
            task._copy_file.return_value = True
            task._transfer_file("/etc/foo.conf", "config for FOO")
            sysroot_path = util.join_paths(sysroot, "/etc/foo.conf")
            task._copy_file.assert_called_once_with("/etc/foo.conf",
                                                    sysroot_path)

        # simulate the file not existing
        # - this is a critical error and should raise an exception
        with tempfile.TemporaryDirectory() as sysroot:
            task = TransferSubscriptionTokensTask(
                sysroot=sysroot, transfer_subscription_tokens=True)
            task._copy_file = Mock()
            task._copy_file.return_value = False
            with self.assertRaises(SubscriptionTokenTransferError):
                task._transfer_file("/etc/foo.conf", "config for FOO")
Exemplo n.º 2
0
    def test_no_transfer(self):
        """Test transfer_tokens being False is handled correctly for token transfer task."""

        # if transfer_subscription_tokens is False, only system purpose tokens should be
        # transferred and others ignored

        with tempfile.TemporaryDirectory() as sysroot:
            task = TransferSubscriptionTokensTask(
                sysroot=sysroot, transfer_subscription_tokens=False)
            task._transfer_system_purpose = Mock()
            task._transfer_entitlement_keys = Mock()
            task._transfer_file = Mock()
            # run the task
            task.run()
            # only the system purpose transfer method should have been called
            task._transfer_system_purpose.assert_called_once()
            task._transfer_entitlement_keys.assert_not_called()
            task._transfer_file.assert_not_called()
Exemplo n.º 3
0
    def test_transfer(self):
        """Test transfer_tokens being True is handled correctly for token transfer task."""

        # If transfer_subscription_tokens is True, all token should be transferred.
        # As we test each transfer method individually we just check here that all
        # expected method are called.

        with tempfile.TemporaryDirectory() as sysroot:
            task = TransferSubscriptionTokensTask(
                sysroot=sysroot, transfer_subscription_tokens=True)
            task._transfer_system_purpose = Mock()
            task._transfer_entitlement_keys = Mock()
            task._transfer_file = Mock()
            # run the task
            task.run()
            # all the transfer operations should have been done
            task._transfer_system_purpose.assert_called_once()
            task._transfer_entitlement_keys.assert_called_once()
            task._transfer_file.assert_has_calls([
                call('/etc/pki/consumer/key.pem', 'RHSM consumer key'),
                call('/etc/pki/consumer/cert.pem', 'RHSM consumer cert'),
                call('/etc/yum.repos.d/redhat.repo', 'RHSM repo file'),
                call('/etc/rhsm/rhsm.conf', 'RHSM config file')
            ])