<s> """<STR_LIT>""" <EOL> from copy import deepcopy <EOL> from subprocess import check_call <EOL> from twisted . internet import reactor <EOL> from twisted . python . filepath import FilePath <EOL> from yaml import safe_dump <EOL> from ... common import loop_until <EOL> from ... control . _config import FlockerConfiguration <EOL> from ... control . httpapi import container_configuration_response <EOL> from . . testtools import require_flocker_cli , require_cluster <EOL> from ... testtools import AsyncTestCase , random_name , flaky <EOL> class FlockerDeployTests ( AsyncTestCase ) : <EOL> """<STR_LIT>""" <EOL> def flocker_deploy ( self , cluster , deployment_config , application_config ) : <EOL> """<STR_LIT>""" <EOL> applications_to_parse = deepcopy ( application_config ) <EOL> expected_deployment = dict ( ) <EOL> applications_map = FlockerConfiguration ( <EOL> applications_to_parse ) . applications ( ) <EOL> for node in deployment_config [ '<STR_LIT>' ] : <EOL> node_applications = [ ] <EOL> for node_app in deployment_config [ '<STR_LIT>' ] [ node ] : <EOL> if node_app in applications_map : <EOL> node_applications . append ( applications_map [ node_app ] ) <EOL> expected_deployment [ node ] = set ( node_applications ) <EOL> temp = FilePath ( self . mktemp ( ) ) <EOL> temp . makedirs ( ) <EOL> deployment = temp . child ( b"<STR_LIT>" ) <EOL> deployment . setContent ( safe_dump ( deployment_config ) ) <EOL> application = temp . child ( b"<STR_LIT>" ) <EOL> application . setContent ( safe_dump ( application_config ) ) <EOL> check_call ( [ b"<STR_LIT>" , <EOL> b"<STR_LIT>" , <EOL> cluster . certificates_path . path , <EOL> cluster . control_node . public_address , <EOL> deployment . path , application . path ] ) <EOL> da = self . assert_expected_deployment ( cluster , expected_deployment ) <EOL> return da <EOL> def assert_expected_deployment ( self , cluster , expected_deployment ) : <EOL> """<STR_LIT>""" <EOL> ip_to_uuid = { <EOL> node . reported_hostname : node . uuid for node in cluster . nodes <EOL> } <EOL> def got_results ( existing_containers ) : <EOL> expected = [ ] <EOL> for reported_hostname , apps in expected_deployment . items ( ) : <EOL> node_uuid = ip_to_uuid [ reported_hostname ] <EOL> expected += [ container_configuration_response ( app , node_uuid ) <EOL> for app in apps ] <EOL> for app in expected : <EOL> app [ u"<STR_LIT>" ] = True <EOL> return sorted ( existing_containers ) == sorted ( expected ) <EOL> def configuration_matches_state ( ) : <EOL> d = cluster . current_containers ( ) <EOL> d . addCallback ( got_results ) <EOL> return d <EOL> return loop_until ( reactor , configuration_matches_state ) <EOL> @ flaky ( [ u'<STR_LIT>' ] ) <EOL> @ require_flocker_cli <EOL> @ require_cluster ( <NUM_LIT:1> , require_container_agent = True ) <EOL> def test_deploy ( self , cluster ) : <EOL> """<STR_LIT>""" <EOL> [ node_1 ] = cluster . nodes <EOL> name = random_name ( self ) <EOL> minimal_deployment = { <EOL> u"<STR_LIT:version>" : <NUM_LIT:1> , <EOL> u"<STR_LIT>" : { <EOL> node_1 . reported_hostname : [ name ] , <EOL> } , <EOL> } <EOL> minimal_application = { <EOL> u"<STR_LIT:version>" : <NUM_LIT:1> , <EOL> u"<STR_LIT>" : { <EOL> name : { <EOL> u"<STR_LIT:image>" : u"<STR_LIT>" , <EOL> } , <EOL> } , <EOL> } <EOL> d = self . flocker_deploy ( <EOL> cluster , minimal_deployment , minimal_application ) <EOL> d . addCallback ( lambda _ : <EOL> self . addCleanup ( cluster . remove_container , name ) ) <EOL> return d </s>
