Exemple #1
0
    def mount_block_volume(self):
        if not self.args.devices:
            return 0

        if len(self.args.devices) > 1 and\
                self.args.raidLevel.upper() == "NONE":
            raise plugin_exceptions.AgentPluginException(
                "Must specify a RAID volume with mounting multiple devices at "
                "once.")

        if len(self.args.devices) > 1:
            target_device = "md0"
        else:
            target_device = self.args.devices[0]

        _g_logger.debug("target device is " + target_device)

        td = target_device
        if self.args.encryptedFsEncryptionKey is not None:
            encrypted_device = "es" + target_device
            td = encrypted_device
            self._install_deps(_g_platform_dep_crypto_installer)

        device_mappings = utils.get_device_mappings(self.conf)
        for mapping in device_mappings:
            if mapping["device_id"] == td:
                return 0

        if len(self.args.devices) > 1:
            self.configure_raid(target_device)

        if self.args.formatVolume:
            if self.args.encryptedFsEncryptionKey:
                key_file_path = None
                try:
                    key_file_path = self.write_key_file(True)
                    self.setup_encryption(target_device, encrypted_device,
                                          key_file_path)
                    utils.open_encrypted_device(self.conf, target_device,
                                                encrypted_device,
                                                key_file_path)
                    target_device = encrypted_device
                finally:
                    if key_file_path:
                        utils.safe_delete(key_file_path)
            self.format(target_device)
        elif self.args.encryptedFsEncryptionKey:
            key_file_path = None
            try:
                key_file_path = self.write_key_file(True)
                utils.open_encrypted_device(self.conf, target_device,
                                            encrypted_device, key_file_path)
                target_device = encrypted_device
            finally:
                plugin_utils.safe_delete(key_file_path)
        utils.mount(self.conf, target_device, self.args.fileSystem,
                    self.args.mountPoint)
        return 0
Exemple #2
0
    def test_get_conf_files(self):
        osf, path = tempfile.mkstemp()
        osf, path2 = tempfile.mkstemp()
        os.environ["DCM_AGENT_CONF"] = path2

        try:
            file_list = config.get_config_files(conffile=path)
            self.assertIn(path, file_list)
            self.assertIn(path2, file_list)
        finally:
            utils.safe_delete(path)
            utils.safe_delete(path2)
Exemple #3
0
    def test_get_conf_files(self):
        osf, path = tempfile.mkstemp()
        osf, path2 = tempfile.mkstemp()
        os.environ["DCM_AGENT_CONF"] = path2

        try:
            file_list = config.get_config_files(conffile=path)
            self.assertIn(path, file_list)
            self.assertIn(path2, file_list)
        finally:
            utils.safe_delete(path)
            utils.safe_delete(path2)
Exemple #4
0
    def mount_block_volume(self):
        if not self.args.devices:
            return 0

        if len(self.args.devices) > 1 and self.args.raidLevel.upper() == "NONE":
            raise plugin_exceptions.AgentPluginException(
                "Must specify a RAID volume with mounting multiple devices at " "once."
            )

        if len(self.args.devices) > 1:
            target_device = "md0"
        else:
            target_device = self.args.devices[0]

        _g_logger.debug("target device is " + target_device)

        td = target_device
        if self.args.encryptedFsEncryptionKey is not None:
            encrypted_device = "es" + target_device
            td = encrypted_device
            self._install_deps(_g_platform_dep_crypto_installer)

        device_mappings = utils.get_device_mappings(self.conf)
        for mapping in device_mappings:
            if mapping["device_id"] == td:
                return 0

        if len(self.args.devices) > 1:
            self.configure_raid(target_device)

        if self.args.formatVolume:
            if self.args.encryptedFsEncryptionKey:
                key_file_path = None
                try:
                    key_file_path = self.write_key_file(True)
                    self.setup_encryption(target_device, encrypted_device, key_file_path)
                    utils.open_encrypted_device(self.conf, target_device, encrypted_device, key_file_path)
                    target_device = encrypted_device
                finally:
                    if key_file_path:
                        utils.safe_delete(key_file_path)
            self.format(target_device)
        elif self.args.encryptedFsEncryptionKey:
            key_file_path = None
            try:
                key_file_path = self.write_key_file(True)
                utils.open_encrypted_device(self.conf, target_device, encrypted_device, key_file_path)
                target_device = encrypted_device
            finally:
                plugin_utils.safe_delete(key_file_path)
        utils.mount(self.conf, target_device, self.args.fileSystem, self.args.mountPoint)
        return 0
Exemple #5
0
def safe_delete(fname):
    """Delete a file but do not thrown an error if the files is not there.

    :param fname: The path to the file to delete.
    :return: True if the fine no longer exists.  False if an error occured
             while trying to delete.
    """
    return agent_util.safe_delete(fname)
Exemple #6
0
def safe_delete(fname):
    """Delete a file but do not thrown an error if the files is not there.

    :param fname: The path to the file to delete.
    :return: True if the fine no longer exists.  False if an error occured
             while trying to delete.
    """
    return agent_util.safe_delete(fname)
Exemple #7
0
 def test_safe_delete_no_exists(self):
     # test non existent file
     rc = utils.safe_delete("no/such/file")
     self.assertTrue(rc)
Exemple #8
0
 def test_safe_delete_no_exists(self):
     # test non existent file
     rc = utils.safe_delete("no/such/file")
     self.assertTrue(rc)