Commit 96092119 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Helga Velroyen

Fix QueryNetworks wrt instances

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: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent a37549ea
......@@ -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:
......
......@@ -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
......
......@@ -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))
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment