Add tests for assign_node_to_cluster

Change-Id: Iafa1baa6a1ca4d701ec89e49dd9d6f969804c82e
This commit is contained in:
Anastasiya 2016-08-01 15:47:13 +03:00
parent 8573c98921
commit b3ce0d348c
2 changed files with 53 additions and 3 deletions

View File

@ -58,13 +58,17 @@ class NailgunClusterAdapter(object):
def editable_attrs(self):
return self.cluster.attributes.editable
@editable_attrs.setter
def editable_attrs(self, attrs):
self.cluster.attributes.editable = attrs
@property
def network_template(self):
return self.cluster.network_config.configuration_template
@editable_attrs.setter
def editable_attrs(self, attrs):
self.cluster.attributes.editable = attrs
@network_template.setter
def network_template(self, template):
self.cluster.network_config.configuration_template = template
def get_create_data(self):
return objects.Cluster.get_create_data(self.cluster)
@ -177,6 +181,10 @@ class NailgunNodeAdapter(object):
def status(self):
return self.node.status
@property
def nic_interfaces(self):
return self.node.nic_interfaces
@property
def error_type(self):
return self.node.error_type

View File

@ -20,6 +20,7 @@ import six
from nailgun import consts
from nailgun.extensions.network_manager.objects.serializers import \
network_configuration
from nailgun.test.base import fake_tasks
from .. import upgrade
from . import base as base_tests
@ -239,3 +240,44 @@ class TestUpgradeHelperCloneCluster(base_tests.BaseCloneClusterTest):
self.helper.change_env_settings(self.src_cluster, new_cluster)
self.assertEqual('image',
attrs['editable']['provision']['method']['value'])
def get_assigned_nets(self, node):
assigned_nets = {}
for iface in node.nic_interfaces:
nets = [net.name for net in iface.assigned_networks_list]
assigned_nets[iface.name] = nets
return assigned_nets
@fake_tasks()
def assign_node_to_cluster(self, template=None):
new_cluster = self.helper.clone_cluster(self.src_cluster, self.data)
node = adapters.NailgunNodeAdapter(self.src_cluster.cluster.nodes[0])
orig_assigned_nets = self.get_assigned_nets(node)
if template:
net_template = self.env.read_fixtures(['network_template_80'])[0]
new_cluster.network_template = net_template
orig_assigned_nets = {
'eth0': ['fuelweb_admin'], 'eth1': ['public', 'management']
}
self.helper.assign_node_to_cluster(node, new_cluster, node.roles, [])
self.db.refresh(new_cluster.cluster)
self.assertEqual(node.cluster_id, new_cluster.id)
self.env.clusters.append(new_cluster.cluster)
task = self.env.launch_provisioning_selected(cluster_id=new_cluster.id)
self.assertEqual(task.status, consts.TASK_STATUSES.ready)
for n in new_cluster.cluster.nodes:
self.assertEqual(consts.NODE_STATUSES.provisioned, n.status)
new_assigned_nets = self.get_assigned_nets(node)
self.assertEqual(orig_assigned_nets, new_assigned_nets)
def test_assign_node_to_cluster(self):
self.assign_node_to_cluster()
def test_assign_node_to_cluster_with_template(self):
self.assign_node_to_cluster(template=True)