prepare_net_info only if info contains quantum_settings

Nailgun changed API:

It returned list of nodes and everyone of them contain common
information (for example quantum_settings)

Now it returns list of all nodes without common settings and common
settings dict

Change-Id: I15154c93c83bcfcd5107c7dd253fc8232506c092
Closses-bug: 1623854
This commit is contained in:
Sergey Abramov 2016-09-15 15:36:02 +03:00
parent 5e6953bc93
commit 55d0836681
4 changed files with 55 additions and 6 deletions

View File

@ -30,12 +30,12 @@ LOG = logging.getLogger(__name__)
def isolate(nodes, env):
nodes.sort(key=lambda node: node.id, reverse=True)
hub = nodes[0]
deployment_info = env.get_default_facts(
'deployment', nodes=[hub.data['id']])
deployment_info = env_util.get_node_default_facts(
env, nodes=[hub.data['id']])
network.create_bridges(hub, env, deployment_info)
for node in nodes[1:]:
deployment_info = env.get_default_facts(
'deployment', nodes=[node.data['id']])
deployment_info = env_util.get_node_default_facts(
env, nodes=[node.data['id']])
network.setup_isolation(hub, node, env, deployment_info)
for node in nodes:
network.flush_arp(node)

View File

@ -31,7 +31,7 @@ class ControllerUpgrade(upgrade.UpgradeHandler):
self.gateway = None
def predeploy(self):
default_info = self.env.get_default_facts('deployment')
default_info = env_util.get_node_default_facts(self.env)
deployment_info = []
network_data = self.env.get_network_data()
gw_admin = transformations.get_network_gw(network_data,

View File

@ -316,3 +316,35 @@ def test_wait_for_node_stopped(mocker):
) in excinfo.args)
sleep.assert_called_once_with(60)
time.assert_has_calls((mock.call(), mock.call()))
@pytest.mark.parametrize("api,modified", [
([], []),
(
[
{'uid': 'common', 'common_key': 'common_value'},
{'uid': 'master'},
{'uid': 'node-1', 'common_key': 'uncommon_value'},
],
[
{'uid': 'master', 'common_key': 'common_value'},
{'uid': 'node-1', 'common_key': 'uncommon_value'},
]
),
(
[
{'uid': 'master', 'common_key': 'common_value'},
{'uid': 'node-1', 'common_key': 'uncommon_value'},
],
[
{'uid': 'master', 'common_key': 'common_value'},
{'uid': 'node-1', 'common_key': 'uncommon_value'},
]
),
])
@pytest.mark.parametrize("nodes", [None, [1, 2, 3]])
def test_util_env(mocker, api, modified, nodes):
env = mock.Mock()
env.get_default_facts.return_value = api
assert modified == env_util.get_node_default_facts(env, nodes)
env.get_default_facts.assert_called_once_with('deployment', nodes=nodes)

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
import json
import logging
import os.path
@ -237,6 +238,8 @@ def deploy_changes(env, nodes):
def prepare_net_info(info):
if "quantum_settings" not in info:
return
quantum_settings = info["quantum_settings"]
pred_nets = quantum_settings["predefined_networks"]
phys_nets = quantum_settings["L2"]["phys_nets"]
@ -259,8 +262,22 @@ def get_admin_password(env, node=None):
return get_astute_yaml(env, node)['access']['password']
def get_node_default_facts(env, nodes=None):
facts = env.get_default_facts('deployment', nodes=nodes)
common = None
node_facts = []
for fact in facts:
if fact.get("uid") == "common":
common = fact
else:
node_facts.append(fact)
if not common:
return node_facts
return [helpers.merge_dicts(copy.deepcopy(common), n) for n in node_facts]
def update_deployment_info(env, isolated):
default_info = env.get_default_facts('deployment')
default_info = get_node_default_facts(env)
network_data = env.get_network_data()
gw_admin = transformations.get_network_gw(network_data,
"fuelweb_admin")