QueryNetworks tries to find which instances are connected to which networks. The query mechanism in Haskell was written back when NICs referred to a network via its name and not its UUID. Fix luxi to comply with the current implementation (network slot of NIC object is a UUID).
Fix old style query mechanism to return a list of names instead of UUIDs for the instances that are connected to a network. Signed-off-by: Dimitris Aragiorgis <[email protected]> --- lib/cmdlib/network.py | 2 +- src/Ganeti/Query/Network.hs | 9 ++++----- test/hs/Test/Ganeti/Objects.hs | 2 +- test/hs/Test/Ganeti/Query/Network.hs | 11 ++++------- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/cmdlib/network.py b/lib/cmdlib/network.py index 8bfd0b4..5dc8771 100644 --- a/lib/cmdlib/network.py +++ b/lib/cmdlib/network.py @@ -465,7 +465,7 @@ class NetworkQuery(QueryBase): for instance in all_instances.values(): for nic in instance.nics: if nic.network in network_uuids: - network_to_instances[nic.network].append(instance.uuid) + network_to_instances[nic.network].append(instance.name) break if query.NETQ_STATS in self.requested_data: diff --git a/src/Ganeti/Query/Network.hs b/src/Ganeti/Query/Network.hs index b7487f4..edbb3b5 100644 --- a/src/Ganeti/Query/Network.hs +++ b/src/Ganeti/Query/Network.hs @@ -137,14 +137,13 @@ getNicLink nic_params = fromMaybe "-" (nicpLinkP nic_params) -- | Retrieves the network's instances' names. getInstances :: ConfigData -> String -> [String] getInstances cfg network_uuid = - map instName (filter (instIsConnected cfg network_uuid) + map instName (filter (instIsConnected network_uuid) ((Map.elems . fromContainer . configInstances) cfg)) -- | Helper function that checks if an instance is linked to the given network. -instIsConnected :: ConfigData -> String -> Instance -> Bool -instIsConnected cfg network_uuid inst = - network_uuid `elem` mapMaybe (getNetworkUuid cfg) - (mapMaybe nicNetwork (instNics inst)) +instIsConnected :: String -> Instance -> Bool +instIsConnected network_uuid inst = + network_uuid `elem` mapMaybe nicNetwork (instNics inst) -- | Helper function to look up a network's UUID by its name getNetworkUuid :: ConfigData -> String -> Maybe String diff --git a/test/hs/Test/Ganeti/Objects.hs b/test/hs/Test/Ganeti/Objects.hs index 05f2f44..a5498ca 100644 --- a/test/hs/Test/Ganeti/Objects.hs +++ b/test/hs/Test/Ganeti/Objects.hs @@ -166,7 +166,7 @@ enhanceInstWithNets inst nets = do uuid <- arbitrary -- generate some more networks than the given ones num_more_nets <- choose (0,3) - more_nets <- vectorOf num_more_nets genName + more_nets <- vectorOf num_more_nets genUUID let genNic net = PartialNic mac ip nicparams net name uuid partial_nics = map (genNic . Just) (List.nub (nets ++ more_nets)) diff --git a/test/hs/Test/Ganeti/Query/Network.hs b/test/hs/Test/Ganeti/Query/Network.hs index 64efa28..de6008a 100644 --- a/test/hs/Test/Ganeti/Query/Network.hs +++ b/test/hs/Test/Ganeti/Query/Network.hs @@ -33,7 +33,6 @@ module Test.Ganeti.Query.Network import Ganeti.JSON import Ganeti.Objects import Ganeti.Query.Network -import Ganeti.Types import Test.Ganeti.Objects import Test.Ganeti.TestCommon @@ -67,9 +66,8 @@ prop_instIsConnected :: ConfigData -> Property prop_instIsConnected cfg = let nets = (fromContainer . configNetworks) cfg net_keys = Map.keys nets - net_names = map (fromNonEmpty . networkName) (Map.elems nets) - in forAll (genInstWithNets net_names) $ \inst -> - True ==? all (\nk -> instIsConnected cfg nk inst) net_keys + in forAll (genInstWithNets net_keys) $ \inst -> + True ==? all (`instIsConnected` inst) net_keys -- | Tests whether instances that are not connected to a network are -- correctly classified as such. @@ -77,10 +75,9 @@ prop_instIsConnected_notFound :: ConfigData -> String -> Property prop_instIsConnected_notFound cfg network_uuid = let nets = (fromContainer . configNetworks) cfg net_keys = Map.keys nets - net_names = map (fromNonEmpty . networkName) (Map.elems nets) in notElem network_uuid net_keys ==> - forAll (genInstWithNets net_names) $ \inst -> - not (instIsConnected cfg network_uuid inst) + forAll (genInstWithNets net_keys) $ \inst -> + not (instIsConnected network_uuid inst) testSuite "Query_Network" [ 'prop_getGroupConnection -- 1.7.10.4
