def test_make_up_command_files(self, fake_sync, fake_write_commands_to_file): assembled_spec = { 'apps': {'app1': get_app_dusty_schema({'repo': '/gc/app1', 'mount': '/gc/app1', 'commands': { 'once': ['app1 once 1', 'app1 once 2 &'], 'always': ['app1 always 1', 'app1 always 2'] }, 'depends': {'libs': ['lib1', 'lib2']}, 'scripts': [ {'name': 'script1', 'description': '', 'command': ['script1 1', 'script1 2']}, {'name': 'script2', 'description': '', 'command': ['script2 1', 'script2 2']}]}, name='app1')}, 'libs': {'lib1': get_lib_dusty_schema({'install': ['lib1 command 1', 'lib1 command 2'], 'repo': '/gc/lib1', 'mount': '/gc/lib1'}, name='lib1'), 'lib2': get_lib_dusty_schema({'install': ['lib2 command 1', 'lib2 command 2'], 'repo': '/gc/lib2', 'mount': '/gc/lib2'}, name='lib2')} } port_spec = {'hosts_file': []} command_file.make_up_command_files(assembled_spec, port_spec) commands1 = ['set -e', 'cd /gc/lib1', 'lib1 command 1', 'lib1 command 2', 'cd /gc/lib2', 'lib2 command 1', 'lib2 command 2', 'cd /gc/app1', 'export PATH=$PATH:/gc/app1', 'dusty_once_fn () {', 'app1 once 1', 'app1 once 2 &', '}', 'if [ ! -f {} ]; then'.format(constants.FIRST_RUN_FILE_PATH), 'touch {}'.format(constants.FIRST_RUN_FILE_PATH) ] + command_file._tee_output_commands('dusty_once_fn') + [ 'fi', 'dusty_always_fn () {', 'app1 always 1', 'app1 always 2', '}', 'dusty_always_fn'] call1 = call(commands1, 'app1', '{}/app1/dusty_command_file_app1.sh'.format(constants.COMMAND_FILES_DIR)) commands2 = ['cd /gc/app1', 'script1 1', 'script1 2 $@'] call2 = call(commands2, 'app1', '{}/app1/dusty_command_file_app1_script_script1.sh'.format(constants.COMMAND_FILES_DIR)) commands3 = ['cd /gc/app1', 'script2 1', 'script2 2 $@'] call3 = call(commands3, 'app1', '{}/app1/dusty_command_file_app1_script_script2.sh'.format(constants.COMMAND_FILES_DIR)) fake_write_commands_to_file.assert_has_calls([call1, call2, call3]) fake_sync.assert_has_calls([call('{}'.format(constants.COMMAND_FILES_DIR), '{}'.format(constants.VM_COMMAND_FILES_DIR))])
def test_make_up_command_files_no_mount(self, fake_sync, fake_write_commands_to_file): assembled_spec = { 'apps': {'app1': get_app_dusty_schema({ 'commands': { 'once': ['app1 once 1', 'app1 once 2 &'], 'always': ['app1 always 1', 'app1 always 2'] }}, name='app1')}} port_spec = {'hosts_file': []} command_file.make_up_command_files(assembled_spec, port_spec) commands1 = ['set -e', 'dusty_once_fn () {', 'app1 once 1', 'app1 once 2 &', '}', 'if [ ! -f {} ]; then'.format(constants.FIRST_RUN_FILE_PATH), 'touch {}'.format(constants.FIRST_RUN_FILE_PATH) ] + command_file._tee_output_commands('dusty_once_fn') + [ 'fi', 'dusty_always_fn () {', 'app1 always 1', 'app1 always 2', '}', 'dusty_always_fn'] call1 = call(commands1, 'app1', '{}/app1/dusty_command_file_app1.sh'.format(constants.COMMAND_FILES_DIR)) fake_write_commands_to_file.assert_has_calls([call1]) fake_sync.assert_has_calls([call('{}'.format(constants.COMMAND_FILES_DIR), '{}'.format(constants.VM_COMMAND_FILES_DIR))])
def test_make_up_command_files_no_mount(self, fake_sync, fake_write_commands_to_file): assembled_spec = { 'apps': {'app1': get_app_dusty_schema({ 'commands': { 'once': ['app1 once 1', 'app1 once 2 &'], 'always': ['app1 always 1', 'app1 always 2'] }})}} port_spec = {'hosts_file': []} command_file.make_up_command_files(assembled_spec, port_spec) commands1 = ['set -e', 'dusty_once_fn () {', 'app1 once 1', 'app1 once 2 &', '}', 'if [ ! -f {} ]; then'.format(constants.FIRST_RUN_FILE_PATH), 'touch {}'.format(constants.FIRST_RUN_FILE_PATH) ] + command_file._tee_output_commands('dusty_once_fn') + [ 'fi', 'dusty_always_fn () {', 'app1 always 1', 'app1 always 2', '}', 'dusty_always_fn'] call1 = call(commands1, 'app1', '{}/app1/dusty_command_file_app1.sh'.format(constants.COMMAND_FILES_DIR)) fake_write_commands_to_file.assert_has_calls([call1]) fake_sync.assert_has_calls([call('{}'.format(constants.COMMAND_FILES_DIR), '{}'.format(constants.VM_COMMAND_FILES_DIR))])
def test_make_up_command_files(self, fake_sync, fake_write_commands_to_file): assembled_spec = { 'apps': {'app1': get_app_dusty_schema({'repo': '/gc/app1', 'mount': '/gc/app1', 'commands': { 'once': ['app1 once 1', 'app1 once 2 &'], 'always': ['app1 always 1', 'app1 always 2'] }, 'depends': {'libs': ['lib1', 'lib2']}, 'scripts': [ {'name': 'script1', 'description': '', 'command': ['script1 1', 'script1 2']}, {'name': 'script2', 'description': '', 'command': ['script2 1', 'script2 2']}]})}, 'libs': {'lib1': get_lib_dusty_schema({'install': ['lib1 command 1', 'lib1 command 2'], 'repo': '/gc/lib1', 'mount': '/gc/lib1'}), 'lib2': get_lib_dusty_schema({'install': ['lib2 command 1', 'lib2 command 2'], 'repo': '/gc/lib2', 'mount': '/gc/lib2'})} } port_spec = {'hosts_file': []} command_file.make_up_command_files(assembled_spec, port_spec) commands1 = ['set -e', 'cd /gc/lib1', 'lib1 command 1', 'lib1 command 2', 'cd /gc/lib2', 'lib2 command 1', 'lib2 command 2', 'cd /gc/app1', 'export PATH=$PATH:/gc/app1', 'dusty_once_fn () {', 'app1 once 1', 'app1 once 2 &', '}', 'if [ ! -f {} ]; then'.format(constants.FIRST_RUN_FILE_PATH), 'touch {}'.format(constants.FIRST_RUN_FILE_PATH) ] + command_file._tee_output_commands('dusty_once_fn') + [ 'fi', 'dusty_always_fn () {', 'app1 always 1', 'app1 always 2', '}', 'dusty_always_fn'] call1 = call(commands1, 'app1', '{}/app1/dusty_command_file_app1.sh'.format(constants.COMMAND_FILES_DIR)) commands2 = ['cd /gc/app1', 'script1 1', 'script1 2 $@'] call2 = call(commands2, 'app1', '{}/app1/dusty_command_file_app1_script_script1.sh'.format(constants.COMMAND_FILES_DIR)) commands3 = ['cd /gc/app1', 'script2 1', 'script2 2 $@'] call3 = call(commands3, 'app1', '{}/app1/dusty_command_file_app1_script_script2.sh'.format(constants.COMMAND_FILES_DIR)) fake_write_commands_to_file.assert_has_calls([call1, call2, call3]) fake_sync.assert_has_calls([call('{}'.format(constants.COMMAND_FILES_DIR), '{}'.format(constants.VM_COMMAND_FILES_DIR))])