<s> from nose . plugins . attrib import attr <EOL> from manager_rest import storage_manager <EOL> from manager_rest . test import base_test <EOL> @ attr ( client_min_version = <NUM_LIT:1> , client_max_version = base_test . LATEST_API_VERSION ) <EOL> class NodesTest ( base_test . BaseServerTestCase ) : <EOL> def test_get_nonexisting_node ( self ) : <EOL> response = self . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> def test_get_node ( self ) : <EOL> self . put_node_instance ( <EOL> instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' , <EOL> runtime_properties = { <EOL> '<STR_LIT:key>' : '<STR_LIT:value>' <EOL> } <EOL> ) <EOL> response = self . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertEqual ( '<STR_LIT>' , response . json [ '<STR_LIT:id>' ] ) <EOL> self . assertTrue ( '<STR_LIT>' in response . json ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( response . json [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( '<STR_LIT:value>' , response . json [ '<STR_LIT>' ] [ '<STR_LIT:key>' ] ) <EOL> def test_bad_patch_node ( self ) : <EOL> response = self . patch ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> response = self . patch ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' } ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> response = self . patch ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:version>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> def test_patch_node ( self ) : <EOL> self . put_node_instance ( <EOL> instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' , <EOL> runtime_properties = { <EOL> '<STR_LIT:key>' : '<STR_LIT:value>' <EOL> } <EOL> ) <EOL> update = { <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:value>' } , <EOL> '<STR_LIT:version>' : <NUM_LIT:2> } <EOL> response = self . patch ( '<STR_LIT>' , update ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( response . json [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> response . json [ '<STR_LIT>' ] [ '<STR_LIT:key>' ] ) <EOL> self . assertEqual ( '<STR_LIT:value>' , <EOL> response . json [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> response = self . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( response . json [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> response . json [ '<STR_LIT>' ] [ '<STR_LIT:key>' ] ) <EOL> self . assertEqual ( '<STR_LIT:value>' , <EOL> response . json [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def test_patch_node_runtime_props_update ( self ) : <EOL> self . put_node_instance ( <EOL> instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' , <EOL> runtime_properties = { <EOL> '<STR_LIT:key>' : '<STR_LIT:value>' <EOL> } <EOL> ) <EOL> response = self . patch ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT:version>' : <NUM_LIT:2> } ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertEqual ( '<STR_LIT>' , response . json [ '<STR_LIT:id>' ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( response . json [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( '<STR_LIT>' , response . json [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def test_patch_node_runtime_props_overwrite ( self ) : <EOL> self . put_node_instance ( <EOL> instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' , <EOL> runtime_properties = { <EOL> '<STR_LIT:key>' : '<STR_LIT:value>' <EOL> } <EOL> ) <EOL> response = self . patch ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' } , <EOL> '<STR_LIT:version>' : <NUM_LIT:2> } ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertEqual ( '<STR_LIT>' , response . json [ '<STR_LIT:id>' ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( response . json [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( '<STR_LIT>' , response . json [ '<STR_LIT>' ] [ '<STR_LIT:key>' ] ) <EOL> def test_patch_node_runtime_props_cleanup ( self ) : <EOL> self . put_node_instance ( <EOL> instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' , <EOL> runtime_properties = { <EOL> '<STR_LIT:key>' : '<STR_LIT:value>' <EOL> } <EOL> ) <EOL> response = self . patch ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:version>' : <NUM_LIT:2> } ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertEqual ( '<STR_LIT>' , response . json [ '<STR_LIT:id>' ] ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( response . json [ '<STR_LIT>' ] ) ) <EOL> def test_partial_patch_node ( self ) : <EOL> self . put_node_instance ( <EOL> instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' , <EOL> runtime_properties = { <EOL> '<STR_LIT:key>' : '<STR_LIT:value>' <EOL> } <EOL> ) <EOL> response = self . patch ( '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT:version>' : <NUM_LIT:2> <EOL> } ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertEqual ( '<STR_LIT>' , response . json [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , response . json [ '<STR_LIT:state>' ] ) <EOL> response = self . patch ( '<STR_LIT>' , { '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT:version>' : <NUM_LIT:3> } ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertEqual ( '<STR_LIT>' , response . json [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , response . json [ '<STR_LIT:state>' ] ) <EOL> response = self . patch ( '<STR_LIT>' , { '<STR_LIT:version>' : <NUM_LIT:4> } ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertEqual ( '<STR_LIT>' , response . json [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , response . json [ '<STR_LIT:state>' ] ) <EOL> response = self . patch ( '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT:version>' : <NUM_LIT:5> <EOL> } ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertEqual ( '<STR_LIT>' , response . json [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , response . json [ '<STR_LIT:state>' ] ) <EOL> def test_patch_node_conflict ( self ) : <EOL> sm = storage_manager . _get_instance ( ) <EOL> from manager_rest import manager_exceptions <EOL> prev_update_node_func = sm . update_node_instance <EOL> try : <EOL> def conflict_update_node_func ( node ) : <EOL> raise manager_exceptions . ConflictError ( ) <EOL> sm . update_node_instance = conflict_update_node_func <EOL> self . put_node_instance ( <EOL> instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' , <EOL> runtime_properties = { <EOL> '<STR_LIT:key>' : '<STR_LIT:value>' <EOL> } <EOL> ) <EOL> response = self . patch ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' } , <EOL> '<STR_LIT:version>' : <NUM_LIT:2> } ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> finally : <EOL> sm . update_node_instance = prev_update_node_func <EOL> @ attr ( client_min_version = <NUM_LIT:2> , <EOL> client_max_version = base_test . LATEST_API_VERSION ) <EOL> def test_list_node_instances_multiple_value_filter ( self ) : <EOL> self . put_node_instance ( node_id = '<STR_LIT:1>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> self . put_node_instance ( node_id = '<STR_LIT:1>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> self . put_node_instance ( node_id = '<STR_LIT:2>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> self . put_node_instance ( node_id = '<STR_LIT:2>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> self . put_node_instance ( node_id = '<STR_LIT:3>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> self . put_node_instance ( node_id = '<STR_LIT:3>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> self . put_node_instance ( node_id = '<STR_LIT:4>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> self . put_node_instance ( node_id = '<STR_LIT:4>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> all_instances = self . client . node_instances . list ( ) <EOL> dep1_node_instances = self . client . node_instances . list ( '<STR_LIT>' , [ '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:3>' , '<STR_LIT:4>' ] ) <EOL> self . assertEqual ( <NUM_LIT:8> , len ( all_instances ) ) <EOL> self . assertEquals ( <NUM_LIT:4> , len ( dep1_node_instances ) ) <EOL> def test_list_node_instances ( self ) : <EOL> self . put_node_instance ( node_id = '<STR_LIT:1>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> self . put_node_instance ( node_id = '<STR_LIT:1>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> self . put_node_instance ( node_id = '<STR_LIT:2>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> self . put_node_instance ( node_id = '<STR_LIT:2>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> self . put_node_instance ( node_id = '<STR_LIT:3>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> self . put_node_instance ( node_id = '<STR_LIT:3>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> self . put_node_instance ( node_id = '<STR_LIT:4>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> self . put_node_instance ( node_id = '<STR_LIT:4>' , instance_id = '<STR_LIT>' , <EOL> deployment_id = '<STR_LIT>' ) <EOL> all_instances = self . client . node_instances . list ( ) <EOL> dep1_instances = self . client . node_instances . list ( '<STR_LIT>' ) <EOL> dep2_instances = self . client . node_instances . list ( '<STR_LIT>' ) <EOL> dep1_n1_instances = self . client . node_instances . list ( '<STR_LIT>' , '<STR_LIT:1>' ) <EOL> dep1_n2_instances = self . client . node_instances . list ( '<STR_LIT>' , '<STR_LIT:2>' ) <EOL> dep2_n3_instances = self . client . node_instances . list ( '<STR_LIT>' , '<STR_LIT:3>' ) <EOL> dep2_n4_instances = self . client . node_instances . list ( '<STR_LIT>' , '<STR_LIT:4>' ) <EOL> self . assertEqual ( <NUM_LIT:8> , len ( all_instances ) ) <EOL> def assert_dep ( expected_len , dep , instances ) : <EOL> self . assertEqual ( expected_len , len ( instances ) ) <EOL> for instance in instances : <EOL> self . assertEqual ( instance . deployment_id , dep ) <EOL> assert_dep ( <NUM_LIT:4> , '<STR_LIT>' , dep1_instances ) <EOL> assert_dep ( <NUM_LIT:4> , '<STR_LIT>' , dep2_instances ) <EOL> def assert_dep_and_node ( expected_len , dep , node_id , instances ) : <EOL> self . assertEqual ( expected_len , len ( instances ) ) <EOL> for instance in instances : <EOL> self . assertEqual ( instance . deployment_id , dep ) <EOL> self . assertEqual ( instance . node_id , node_id ) <EOL> assert_dep_and_node ( <NUM_LIT:2> , '<STR_LIT>' , '<STR_LIT:1>' , dep1_n1_instances ) <EOL> assert_dep_and_node ( <NUM_LIT:2> , '<STR_LIT>' , '<STR_LIT:2>' , dep1_n2_instances ) <EOL> assert_dep_and_node ( <NUM_LIT:2> , '<STR_LIT>' , '<STR_LIT:3>' , dep2_n3_instances ) <EOL> assert_dep_and_node ( <NUM_LIT:2> , '<STR_LIT>' , '<STR_LIT:4>' , dep2_n4_instances ) <EOL> def test_patch_before_put ( self ) : <EOL> response = self . patch ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT:value>' } , <EOL> '<STR_LIT:version>' : <NUM_LIT:0> } ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> def put_node_instance ( self , <EOL> instance_id , <EOL> deployment_id , <EOL> runtime_properties = None , <EOL> node_id = None ) : <EOL> runtime_properties = runtime_properties or { } <EOL> from manager_rest . models import DeploymentNodeInstance <EOL> node = DeploymentNodeInstance ( id = instance_id , <EOL> node_id = node_id , <EOL> deployment_id = deployment_id , <EOL> runtime_properties = runtime_properties , <EOL> state = None , <EOL> version = None , <EOL> relationships = None , <EOL> host_id = None ) <EOL> storage_manager . _get_instance ( ) . put_node_instance ( node ) </s>
