예제 #1
0
    def test_get_environment_from_file__yaml_parse_errors(self, codecs_mock):
        open('.elasticbeanstalk/my-environment.env.yml', 'w').close()

        codecs_mock.side_effect = fileoperations.ScannerError
        with self.assertRaises(fileoperations.InvalidSyntaxError):
            fileoperations.get_environment_from_file('my-environment')

        codecs_mock.side_effect = fileoperations.ParserError
        with self.assertRaises(fileoperations.InvalidSyntaxError):
            fileoperations.get_environment_from_file('my-environment')
예제 #2
0
    def test_get_environment_from_file__gets_environment(self):
        with open('.elasticbeanstalk/my-environment.env.yml', 'w') as file:
            file.write('{"EnvironmentName": "my-environment"}')

        self.assertEqual(
            {'EnvironmentName': 'my-environment'},
            fileoperations.get_environment_from_file('my-environment'))
예제 #3
0
def update_environment_configuration(app_name, env_name, nohang, timeout=None):
    # get environment setting
    api_model = elasticbeanstalk.describe_configuration_settings(
        app_name, env_name)

    # Convert the raw api return to yaml format
    env_settings = EnvironmentSettings(api_model)
    usr_model = env_settings.convert_api_to_usr_model()

    # Save the yaml in a temp file
    file_location = fileoperations.save_env_file(usr_model)
    fileoperations.open_file_for_editing(file_location)

    platform_arn = None

    # Update and delete file
    try:
        usr_model = fileoperations.get_environment_from_file(env_name)
        changes, remove = env_settings.collect_changes(usr_model)
        if api_model['PlatformArn'] != usr_model['PlatformArn']:
            platform_arn = usr_model['PlatformArn']
        fileoperations.delete_env_file(env_name)
    except InvalidSyntaxError:
        io.log_error(prompts['update.invalidsyntax'])
        return

    if not changes and not remove and not platform_arn:
        # no changes made, exit
        io.log_warning('No changes made. Exiting.')
        return

    if fileoperations.env_yaml_exists():
        io.echo(strings['config.envyamlexists'])

    commonops.update_environment(env_name,
                                 changes,
                                 nohang,
                                 remove=remove,
                                 timeout=timeout,
                                 solution_stack_name=None,
                                 platform_arn=platform_arn)
예제 #4
0
def update_environment_configuration(app_name, env_name, nohang,
                                     timeout=None):
    # get environment setting
    api_model = elasticbeanstalk.describe_configuration_settings(
        app_name, env_name
    )

    # Convert the raw api return to yaml format
    env_settings = EnvironmentSettings(api_model)
    usr_model = env_settings.convert_api_to_usr_model()

    # Save the yaml in a temp file
    file_location = fileoperations.save_env_file(usr_model)
    fileoperations.open_file_for_editing(file_location)

    platform_arn = None

    # Update and delete file
    try:
        usr_model = fileoperations.get_environment_from_file(env_name)
        changes, remove = env_settings.collect_changes(usr_model)
        if api_model['PlatformArn'] != usr_model['PlatformArn']:
            platform_arn = usr_model['PlatformArn']
        fileoperations.delete_env_file(env_name)
    except InvalidSyntaxError:
        io.log_error(prompts['update.invalidsyntax'])
        return

    if not changes and not remove and not platform_arn:
        # no changes made, exit
        io.log_warning('No changes made. Exiting.')
        return

    if fileoperations.env_yaml_exists():
        io.echo(strings['config.envyamlexists'])

    commonops.update_environment(env_name, changes, nohang,
                                 remove=remove, timeout=timeout,
                                 solution_stack_name=None,
                                 platform_arn=platform_arn)
예제 #5
0
 def test_get_environment_from_file__env_yml_file_does_not_exist(self):
     self.assertIsNone(
         fileoperations.get_environment_from_file('my-application'))