<s> import copy <EOL> import six <EOL> from nailgun import consts <EOL> from nailgun . extensions . network_manager . objects . serializers import network_configuration <EOL> from . import base as base_tests <EOL> from . . objects import adapters <EOL> from . . objects import relations <EOL> class TestUpgradeHelperCloneCluster ( base_tests . BaseCloneClusterTest ) : <EOL> def setUp ( self ) : <EOL> super ( TestUpgradeHelperCloneCluster , self ) . setUp ( ) <EOL> self . orig_net_manager = self . src_cluster . get_network_manager ( ) <EOL> self . serialize_nets = network_configuration . NeutronNetworkConfigurationSerializer . serialize_for_cluster <EOL> self . public_net_data = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ [ "<STR_LIT>" , "<STR_LIT>" ] ] , <EOL> } <EOL> def test_create_cluster_clone ( self ) : <EOL> new_cluster = self . helper . create_cluster_clone ( self . src_cluster , <EOL> self . data ) <EOL> src_cluster_data = self . src_cluster . get_create_data ( ) <EOL> new_cluster_data = new_cluster . get_create_data ( ) <EOL> for key , value in src_cluster_data . items ( ) : <EOL> if key in ( "<STR_LIT:name>" , "<STR_LIT>" ) : <EOL> continue <EOL> self . assertEqual ( value , new_cluster_data [ key ] ) <EOL> def test_copy_attributes ( self ) : <EOL> new_cluster = self . helper . create_cluster_clone ( self . src_cluster , <EOL> self . data ) <EOL> self . assertNotEqual ( self . src_cluster . generated_attrs , <EOL> new_cluster . generated_attrs ) <EOL> attrs = copy . deepcopy ( self . src_cluster . editable_attrs ) <EOL> attrs [ "<STR_LIT>" ] [ "<STR_LIT:user>" ] [ "<STR_LIT:value>" ] = "<STR_LIT>" <EOL> attrs [ "<STR_LIT>" ] [ "<STR_LIT:password>" ] [ "<STR_LIT:value>" ] = "<STR_LIT>" <EOL> self . src_cluster . editable_attrs = attrs <EOL> self . helper . copy_attributes ( self . src_cluster , new_cluster ) <EOL> self . assertEqual ( self . src_cluster . generated_attrs , <EOL> new_cluster . generated_attrs ) <EOL> editable_attrs = self . src_cluster . editable_attrs <EOL> for section , params in six . iteritems ( new_cluster . editable_attrs ) : <EOL> if section == "<STR_LIT>" : <EOL> continue <EOL> for key , value in six . iteritems ( params ) : <EOL> if key == "<STR_LIT>" : <EOL> continue <EOL> self . assertEqual ( editable_attrs [ section ] [ key ] [ "<STR_LIT:value>" ] , <EOL> value [ "<STR_LIT:value>" ] ) <EOL> def update_public_net_params ( self , networks ) : <EOL> pub_net = self . _get_pub_net ( networks ) <EOL> pub_net . update ( self . public_net_data ) <EOL> self . orig_net_manager . update ( networks ) <EOL> def _get_pub_net ( self , networks ) : <EOL> return next ( net for net in networks [ '<STR_LIT>' ] if <EOL> net [ '<STR_LIT:name>' ] == consts . NETWORKS . public ) <EOL> def test_copy_network_config ( self ) : <EOL> new_cluster = self . helper . create_cluster_clone ( self . src_cluster , <EOL> self . data ) <EOL> nets = self . serialize_nets ( self . src_cluster . cluster ) <EOL> self . update_public_net_params ( nets ) <EOL> self . helper . copy_network_config ( self . src_cluster , new_cluster ) <EOL> new_nets = self . serialize_nets ( new_cluster . cluster ) <EOL> public_net = self . _get_pub_net ( new_nets ) <EOL> self . assertEqual ( public_net [ '<STR_LIT>' ] , self . public_net_data [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( public_net [ '<STR_LIT>' ] , <EOL> self . public_net_data [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( public_net [ '<STR_LIT>' ] , <EOL> self . public_net_data [ '<STR_LIT>' ] ) <EOL> def test_copy_vips ( self ) : <EOL> orig_nets = self . serialize_nets ( self . src_cluster . cluster ) <EOL> new_cluster = self . helper . clone_cluster ( self . src_cluster , self . data ) <EOL> node = adapters . NailgunNodeAdapter ( self . src_cluster . cluster . nodes [ <NUM_LIT:0> ] ) <EOL> self . helper . assign_node_to_cluster ( node , new_cluster , node . roles , [ ] ) <EOL> self . helper . copy_vips ( self . src_cluster , new_cluster ) <EOL> new_nets = self . serialize_nets ( new_cluster . cluster ) <EOL> self . assertEqual ( orig_nets [ "<STR_LIT>" ] , <EOL> new_nets [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( orig_nets [ "<STR_LIT>" ] , <EOL> new_nets [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( orig_nets [ "<STR_LIT>" ] , <EOL> new_nets [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( orig_nets [ "<STR_LIT>" ] , <EOL> new_nets [ "<STR_LIT>" ] ) <EOL> def test_clone_cluster ( self ) : <EOL> self . orig_net_manager . assign_vips_for_net_groups ( ) <EOL> new_cluster = self . helper . clone_cluster ( self . src_cluster , self . data ) <EOL> relation = relations . UpgradeRelationObject . get_cluster_relation ( <EOL> self . src_cluster . id ) <EOL> self . assertEqual ( relation . orig_cluster_id , self . src_cluster . id ) <EOL> self . assertEqual ( relation . seed_cluster_id , new_cluster . id ) </s>
