def test_reformat_idempotency(self):
        """
        Test that if a volume format passes its initial check for existing filesystems,
        then it will format successfully even if the initial format operation is stopped
        and restarted.  To do that it has to pass reformat=True the second time
        """

        path = self.mgt.managedtargetmount_set.get().volume_node.path
        try:
            MockAgentRpc.fail_commands = [('format_target', {
                'device': path,
                'target_types': 'mgs',
                'backfstype': 'ldiskfs',
                'device_type': 'linux',
                'target_name': 'MGS'
            })]

            command = self.set_and_assert_state(self.mgt.managedtarget_ptr,
                                                'formatted',
                                                check=False)
            self.assertEqual(freshen(command).complete, True)
            self.assertEqual(freshen(command).errored, True)
        finally:
            MockAgentRpc.fail_commands = []

        # Check that the initial format did not pass the reformat flag
        self.assertEqual(MockAgentRpc.skip_calls(['device_plugin']),
                         ('format_target', {
                             'device': path,
                             'target_types': 'mgs',
                             'backfstype': 'ldiskfs',
                             'device_type': 'linux',
                             'target_name': 'MGS'
                         }))

        # This one should succeed
        self.set_and_assert_state(self.mgt.managedtarget_ptr,
                                  'formatted',
                                  check=True)

        # Check that it passed the reformat flag
        self.assertEqual(
            MockAgentRpc.skip_calls(['device_plugin', 'export_target']),
            ('format_target', {
                'device': path,
                'target_types': 'mgs',
                'backfstype': 'ldiskfs',
                'device_type': 'linux',
                'target_name': 'MGS',
                'reformat': True
            }))
    def test_ost_override(self):
        import settings

        self.create_simple_filesystem(self.host, start=False)
        self.mgt.managedtarget_ptr = self.set_and_assert_state(self.mgt.managedtarget_ptr, "mounted")

        settings.LUSTRE_MKFS_OPTIONS_OST = "-E block_size=2048"
        self.mgt.managedtarget_ptr = self.set_and_assert_state(self.ost.managedtarget_ptr, "formatted")

        cmd, args = MockAgentRpc.skip_calls(["device_plugin", "export_target"])
        self.assertEqual(cmd, "format_target")
        self.assertDictContainsSubset({"mkfsoptions": settings.LUSTRE_MKFS_OPTIONS_OST}, args)
    def test_ost_override(self):
        import settings

        self.create_simple_filesystem(self.host, start=False)
        self.mgt.managedtarget_ptr = self.set_and_assert_state(
            self.mgt.managedtarget_ptr, 'mounted')

        settings.LUSTRE_MKFS_OPTIONS_OST = '-E block_size=2048'
        self.mgt.managedtarget_ptr = self.set_and_assert_state(
            self.ost.managedtarget_ptr, 'formatted')

        cmd, args = MockAgentRpc.skip_calls(['device_plugin', 'export_target'])
        self.assertEqual(cmd, 'format_target')
        self.assertDictContainsSubset(
            {'mkfsoptions': settings.LUSTRE_MKFS_OPTIONS_OST}, args)
    def test_reformat_idempotency(self):
        """
        Test that if a volume format passes its initial check for existing filesystems,
        then it will format successfully even if the initial format operation is stopped
        and restarted.  To do that it has to pass reformat=True the second time
        """

        path = self.mgt.managedtargetmount_set.get().volume_node.path
        try:
            MockAgentRpc.fail_commands = [
                (
                    "format_target",
                    {
                        "device": path,
                        "target_types": "mgs",
                        "backfstype": "ldiskfs",
                        "device_type": "linux",
                        "target_name": "MGS",
                    },
                )
            ]

            command = self.set_and_assert_state(self.mgt.managedtarget_ptr, "formatted", check=False)
            self.assertEqual(freshen(command).complete, True)
            self.assertEqual(freshen(command).errored, True)
        finally:
            MockAgentRpc.fail_commands = []

        # Check that the initial format did not pass the reformat flag
        self.assertEqual(
            MockAgentRpc.skip_calls(["device_plugin"]),
            (
                "format_target",
                {
                    "device": path,
                    "target_types": "mgs",
                    "backfstype": "ldiskfs",
                    "device_type": "linux",
                    "target_name": "MGS",
                },
            ),
        )

        # This one should succeed
        self.set_and_assert_state(self.mgt.managedtarget_ptr, "formatted", check=True)

        # Check that it passed the reformat flag
        self.assertEqual(
            MockAgentRpc.skip_calls(["device_plugin", "export_target"]),
            (
                "format_target",
                {
                    "device": path,
                    "target_types": "mgs",
                    "backfstype": "ldiskfs",
                    "device_type": "linux",
                    "target_name": "MGS",
                    "reformat": True,
                },
            ),
        )
Beispiel #5
0
 def invoke(self, cmd, args={}, auth_args=None):
     host = ManagedHost(address=self.address)
     return MockAgentRpc._call(host, cmd, args)