<s> import functools <EOL> from mock import patch <EOL> from nailgun import consts <EOL> from nailgun . objects . task import Task <EOL> from nailgun . test . base import fake_tasks <EOL> from nailgun . test . performance . base import BaseIntegrationLoadTestCase <EOL> from nailgun . utils import reverse <EOL> class IntegrationClusterTests ( BaseIntegrationLoadTestCase ) : <EOL> MAX_EXEC_TIME = <NUM_LIT> <EOL> MAX_TOTAL_EXEC_TIME = <NUM_LIT> <EOL> def setUp ( self ) : <EOL> super ( IntegrationClusterTests , self ) . setUp ( ) <EOL> self . env . create_nodes ( self . NODES_NUM , api = True ) <EOL> self . cluster = self . env . create_cluster ( api = True ) <EOL> controllers = <NUM_LIT:3> <EOL> created_controllers = <NUM_LIT:0> <EOL> nodes = [ ] <EOL> self . nodes_ids = [ ] <EOL> for node in self . env . nodes : <EOL> if created_controllers < controllers : <EOL> nodes . append ( { '<STR_LIT:id>' : node . id , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : self . cluster [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : True } ) <EOL> created_controllers += <NUM_LIT:1> <EOL> else : <EOL> nodes . append ( { '<STR_LIT:id>' : node . id , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : self . cluster [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : True } ) <EOL> self . nodes_ids . append ( str ( node . id ) ) <EOL> self . put_handler ( '<STR_LIT>' , nodes ) <EOL> @ fake_tasks ( fake_rpc = False , mock_rpc = False ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_deploy ( self , mock_rpc ) : <EOL> self . provision ( self . cluster [ '<STR_LIT:id>' ] , self . nodes_ids ) <EOL> self . deployment ( self . cluster [ '<STR_LIT:id>' ] , self . nodes_ids ) <EOL> @ fake_tasks ( ) <EOL> def test_put_cluster_changes ( self ) : <EOL> func = functools . partial ( <EOL> self . put_handler , <EOL> '<STR_LIT>' , <EOL> [ ] , <EOL> handler_kwargs = { '<STR_LIT>' : self . cluster [ '<STR_LIT:id>' ] } <EOL> ) <EOL> self . check_time_exec ( func , <NUM_LIT:4> ) <EOL> @ fake_tasks ( ) <EOL> def test_put_cluster_changes_after_reset ( self ) : <EOL> self . deployment ( self . cluster [ '<STR_LIT:id>' ] , self . nodes_ids ) <EOL> func = functools . partial ( <EOL> self . put_handler , <EOL> '<STR_LIT>' , <EOL> [ ] , <EOL> handler_kwargs = { '<STR_LIT>' : self . cluster [ '<STR_LIT:id>' ] } ) <EOL> self . check_time_exec ( func , <NUM_LIT:10> ) <EOL> func = functools . partial ( <EOL> self . put_handler , <EOL> '<STR_LIT>' , <EOL> [ ] , <EOL> handler_kwargs = { '<STR_LIT>' : self . cluster [ '<STR_LIT:id>' ] } <EOL> ) <EOL> self . check_time_exec ( func , <NUM_LIT:10> ) <EOL> @ fake_tasks ( fake_rpc = False , mock_rpc = False ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_double_deploy ( self , mock_rpc ) : <EOL> self . provision ( self . cluster [ '<STR_LIT:id>' ] , self . nodes_ids ) <EOL> self . deployment ( self . cluster [ '<STR_LIT:id>' ] , self . nodes_ids ) <EOL> new_nodes = self . env . create_nodes ( self . NODES_NUM , api = True ) <EOL> ids = [ str ( node [ '<STR_LIT:id>' ] ) for node in new_nodes ] <EOL> self . provision ( self . cluster [ '<STR_LIT:id>' ] , ids ) <EOL> self . deployment ( self . cluster [ '<STR_LIT:id>' ] , ids ) <EOL> @ fake_tasks ( ) <EOL> def test_rerun_stopped_deploy ( self ) : <EOL> cluster = self . cluster <EOL> @ fake_tasks ( override_state = { '<STR_LIT>' : <NUM_LIT:50> , '<STR_LIT:status>' : '<STR_LIT>' } ) <EOL> def first_deploy ( test ) : <EOL> test . app . put ( <EOL> reverse ( <EOL> '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : test . cluster [ '<STR_LIT:id>' ] } ) , <EOL> headers = test . default_headers ) <EOL> first_deploy ( self ) <EOL> stop_response = self . app . put ( <EOL> reverse ( <EOL> '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : cluster [ '<STR_LIT:id>' ] } ) , <EOL> headers = self . default_headers ) <EOL> task = Task . get_by_uuid ( stop_response . json_body [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( task . status , consts . TASK_STATUSES . ready ) <EOL> second_deploy_response = self . app . put ( <EOL> reverse ( <EOL> '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : cluster [ '<STR_LIT:id>' ] } ) , <EOL> headers = self . default_headers ) <EOL> task = Task . get_by_uuid ( second_deploy_response . json_body [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( task . status , consts . TASK_STATUSES . ready ) </s>
