On Fri, Sep 27, 2013 at 3:35 PM, Raffa Santi <[email protected]> wrote:
> Add the "access" parameter to the RBD configuration, plus generate a > list of valid access combinations. Fix tests broken by this change. > > Signed-off-by: Raffa Santi <[email protected]> > --- > lib/constants.py | 14 ++++++++++++-- > lib/objects.py | 1 + > src/Ganeti/HsConstants.hs | 23 +++++++++++++++++++++++ > src/Ganeti/Types.hs | 26 ++++++++++++++++++++++++++ > test/py/cmdlib/cluster_unittest.py | 6 ++++-- > 5 files changed, 66 insertions(+), 4 deletions(-) > > diff --git a/lib/constants.py b/lib/constants.py > index 218e937..6458bd4 100644 > --- a/lib/constants.py > +++ b/lib/constants.py > @@ -519,6 +519,10 @@ LDS_DRBD = compat.UniqueFrozenset([DT_DRBD8]) > DISK_RDONLY = _constants.DISK_RDONLY > DISK_RDWR = _constants.DISK_RDWR > DISK_ACCESS_SET = _constants.DISK_ACCESS_SET > +DISK_USERSPACE = _constants.DISK_USERSPACE > +DISK_KERNELSPACE = _constants.DISK_KERNELSPACE > +DISK_VALID_ACCESS_PROTOCOLS = _constants.DISK_VALID_ACCESS_PROTOCOLS > +DISK_VALID_ACCESS_COMBINATIONS = _constants.DISK_VALID_ACCESS_COMBINATIONS > > # disk replacement mode > REPLACE_DISK_PRI = "replace_on_primary" # replace disks on primary > @@ -1103,6 +1107,7 @@ LDP_DELAY_TARGET = "c-delay-target" > LDP_MAX_RATE = "c-max-rate" > LDP_MIN_RATE = "c-min-rate" > LDP_POOL = "pool" > +LDP_ACCESS = "access" > DISK_LD_TYPES = { > LDP_RESYNC_RATE: VTYPE_INT, > LDP_STRIPES: VTYPE_INT, > @@ -1119,6 +1124,7 @@ DISK_LD_TYPES = { > LDP_MAX_RATE: VTYPE_INT, > LDP_MIN_RATE: VTYPE_INT, > LDP_POOL: VTYPE_STRING, > + LDP_ACCESS: VTYPE_STRING, > } > DISK_LD_PARAMETERS = frozenset(DISK_LD_TYPES.keys()) > > @@ -1141,6 +1147,7 @@ DRBD_MAX_RATE = "c-max-rate" > DRBD_MIN_RATE = "c-min-rate" > LV_STRIPES = "stripes" > RBD_POOL = "pool" > +RBD_ACCESS = "access" > DISK_DT_TYPES = { > DRBD_RESYNC_RATE: VTYPE_INT, > DRBD_DATA_STRIPES: VTYPE_INT, > @@ -1159,6 +1166,7 @@ DISK_DT_TYPES = { > DRBD_MIN_RATE: VTYPE_INT, > LV_STRIPES: VTYPE_INT, > RBD_POOL: VTYPE_STRING, > + RBD_ACCESS: VTYPE_STRING, > } > > DISK_DT_PARAMETERS = frozenset(DISK_DT_TYPES.keys()) > @@ -1952,7 +1960,8 @@ DISK_LD_DEFAULTS = { > DT_SHARED_FILE: {}, > DT_BLOCK: {}, > DT_RBD: { > - LDP_POOL: "rbd" > + LDP_POOL: "rbd", > + LDP_ACCESS: DISK_KERNELSPACE, > }, > DT_EXT: {}, > } > @@ -1987,7 +1996,8 @@ DISK_DT_DEFAULTS = { > DT_SHARED_FILE: {}, > DT_BLOCK: {}, > DT_RBD: { > - RBD_POOL: DISK_LD_DEFAULTS[DT_RBD][LDP_POOL] > + RBD_POOL: DISK_LD_DEFAULTS[DT_RBD][LDP_POOL], > + RBD_ACCESS: DISK_LD_DEFAULTS[DT_RBD][LDP_ACCESS], > }, > DT_EXT: {}, > } > diff --git a/lib/objects.py b/lib/objects.py > index aba3734..406988b 100644 > --- a/lib/objects.py > +++ b/lib/objects.py > @@ -897,6 +897,7 @@ class Disk(ConfigObject): > elif disk_template == constants.DT_RBD: > > result.append(FillDict(constants.DISK_LD_DEFAULTS[constants.DT_RBD], { > constants.LDP_POOL: dt_params[constants.RBD_POOL], > + constants.LDP_ACCESS: dt_params[constants.RBD_ACCESS], > })) > > elif disk_template == constants.DT_EXT: > diff --git a/src/Ganeti/HsConstants.hs b/src/Ganeti/HsConstants.hs > index fd56b27..eee7573 100644 > --- a/src/Ganeti/HsConstants.hs > +++ b/src/Ganeti/HsConstants.hs > @@ -1381,3 +1381,26 @@ statFile = "/proc/stat" > -- | Mond's variable for periodical data collection > mondTimeInterval :: Int > mondTimeInterval = 5 > + > +-- * Disk access protocols > + > +diskUserspace :: String > +diskUserspace = Types.diskAccessProtocolToRaw DiskUserspace > + > +diskKernelspace :: String > +diskKernelspace = Types.diskAccessProtocolToRaw DiskKernelspace > + > +diskValidAccessProtocols :: FrozenSet String > +diskValidAccessProtocols = > + ConstantUtils.mkSet $ map Types.diskAccessProtocolToRaw [minBound..] > + > +-- Hypervisor / Template / Access > +diskValidAccessCombinations :: FrozenSet (Hypervisor, > + DiskTemplate, > + DiskAccessProtocol) > +diskValidAccessCombinations = > + ConstantUtils.mkSet [ (hv, disk, proto) | > + hv <- [minBound..], > + disk <- [minBound..], > Our shortcut for disk templates is 'dt' usually, disk is usually for an individual disk. > + proto <- [minBound..], > + isValidAccessCombination hv disk proto ] > diff --git a/src/Ganeti/Types.hs b/src/Ganeti/Types.hs > index ba9dea7..c2b8602 100644 > --- a/src/Ganeti/Types.hs > +++ b/src/Ganeti/Types.hs > @@ -141,6 +141,9 @@ module Ganeti.Types > , adminStateToRaw > , StorageField(..) > , storageFieldToRaw > + , DiskAccessProtocol(..) > I would rather speak about a DiskAccessMode than a DiskAccessProtocol. The protocol spoken with RBD is always the same, it's just who (kernel module or QEMU) speak is different... This comment applies to all occurrences of 'protocol'. > + , diskAccessProtocolToRaw > + , isValidAccessCombination > This name is rather generic, given that it's in Types.hs one wouldn't think at all about disk access to hypervisor combinations. Please choose a > ) where > > import Control.Monad (liftM) > @@ -282,6 +285,9 @@ $(THH.declareLADT ''String "DiskTemplate" > ]) > $(THH.makeJSONInstance ''DiskTemplate) > > +instance THH.PyValue DiskTemplate where > + showValue = show . diskTemplateToRaw > + > instance HasStringRepr DiskTemplate where > fromStringRepr = diskTemplateFromRaw > toStringRepr = diskTemplateToRaw > @@ -406,6 +412,9 @@ $(THH.declareLADT ''String "Hypervisor" > ]) > $(THH.makeJSONInstance ''Hypervisor) > > +instance THH.PyValue Hypervisor where > + showValue = show . hypervisorToRaw > + > -- | Oob command type. > $(THH.declareLADT ''String "OobCommand" > [ ("OobHealth", "health") > @@ -758,3 +767,20 @@ $(THH.declareLADT ''String "StorageField" > , ( "SFSize", "size") > ]) > $(THH.makeJSONInstance ''StorageField) > + > +-- * Disk access protocol > + > +$(THH.declareLADT ''String "DiskAccessProtocol" > + [ ( "DiskUserspace", "userspace") > + , ( "DiskKernelspace", "kernelspace") > + ]) > +$(THH.makeJSONInstance ''DiskAccessProtocol) > + > +instance THH.PyValue DiskAccessProtocol where > + showValue = show . diskAccessProtocolToRaw > + > +isValidAccessCombination :: Hypervisor -> DiskTemplate -> > + DiskAccessProtocol -> Bool > +isValidAccessCombination _ _ DiskKernelspace = True > +isValidAccessCombination Kvm DTRbd DiskUserspace = True > +isValidAccessCombination _ _ _ = False > diff --git a/test/py/cmdlib/cluster_unittest.py > b/test/py/cmdlib/cluster_unittest.py > index 5b8f2e1..e8438a3 100644 > --- a/test/py/cmdlib/cluster_unittest.py > +++ b/test/py/cmdlib/cluster_unittest.py > @@ -425,13 +425,15 @@ class TestLUClusterSetParams(CmdlibTestCase): > > def testInvalidDiskparams(self): > for diskparams in [{constants.DT_DISKLESS: {constants.LV_STRIPES: 0}}, > - {constants.DT_DRBD8: {constants.RBD_POOL: > "pool"}}]: > + {constants.DT_DRBD8: {constants.RBD_POOL: "pool"}}, > + {constants.DT_DRBD8: {constants.RBD_ACCESS: > "bunny"}}]: > self.ResetMocks() > op = opcodes.OpClusterSetParams(diskparams=diskparams) > self.ExecOpCodeExpectOpPrereqError(op, "verify diskparams") > > def testValidDiskparams(self): > - diskparams = {constants.DT_RBD: {constants.RBD_POOL: "mock_pool"}} > + diskparams = {constants.DT_RBD: {constants.RBD_POOL: "mock_pool", > + constants.RBD_ACCESS: "kernelspace"}} > op = opcodes.OpClusterSetParams(diskparams=diskparams) > self.ExecOpCode(op) > self.assertEqual(diskparams[constants.DT_RBD], > -- > 1.7.10.4 > > -- Thomas Thrainer | Software Engineer | [email protected] | Google Germany GmbH Dienerstr. 12 80331 München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores
