Пример #1
0
def interactive_update_lifcycle_policy(app_name):
    # Get current application settings
    api_model = elasticbeanstalk.describe_application(app_name)

    # Convert into yaml format from raw API
    lifecycle_config = LifecycleConfiguration(api_model)
    usr_model = lifecycle_config.convert_api_to_usr_model()

    # Save yaml file into temp file
    file_location = fileoperations.save_app_file(usr_model)
    fileoperations.open_file_for_editing(file_location)

    # Update and delete file
    try:
        usr_model = fileoperations.get_application_from_file(app_name)
        config_changes = lifecycle_config.collect_changes(usr_model)
        fileoperations.delete_app_file(app_name)
    except InvalidSyntaxError:
        io.log_error(strings['lifecycle.invalidsyntax'])
        fileoperations.delete_app_file(app_name)
        return

    if not config_changes:
        # no changes made, exit
        io.log_warning(strings['lifecycle.updatenochanges'])
        return

    elasticbeanstalk.update_application_resource_lifecycle(app_name, config_changes)
    io.echo(strings['lifecycle.success'])
def interactive_update_lifcycle_policy(app_name):
    api_model = elasticbeanstalk.describe_application(app_name)

    lifecycle_config = LifecycleConfiguration(api_model)
    usr_model = lifecycle_config.convert_api_to_usr_model()

    file_location = fileoperations.save_app_file(usr_model)
    fileoperations.open_file_for_editing(file_location)

    try:
        usr_model = fileoperations.get_application_from_file(app_name)
        config_changes = lifecycle_config.collect_changes(usr_model)
        fileoperations.delete_app_file(app_name)
    except InvalidSyntaxError:
        io.log_error(strings['lifecycle.invalidsyntax'])
        fileoperations.delete_app_file(app_name)
        return

    if not config_changes:
        io.log_warning(strings['lifecycle.updatenochanges'])
        return

    elasticbeanstalk.update_application_resource_lifecycle(
        app_name, config_changes)
    io.echo(strings['lifecycle.success'])
Пример #3
0
def interactive_update_lifcycle_policy(app_name):
    # Get current application settings
    api_model = elasticbeanstalk.describe_application(app_name)

    # Convert into yaml format from raw API
    lifecycle_config = LifecycleConfiguration(api_model)
    usr_model = lifecycle_config.convert_api_to_usr_model()

    # Save yaml file into temp file
    file_location = fileoperations.save_app_file(usr_model)
    fileoperations.open_file_for_editing(file_location)

    # Update and delete file
    try:
        usr_model = fileoperations.get_application_from_file(app_name)
        config_changes = lifecycle_config.collect_changes(usr_model)
        fileoperations.delete_app_file(app_name)
    except InvalidSyntaxError:
        io.log_error(strings['lifecycle.invalidsyntax'])
        fileoperations.delete_app_file(app_name)
        return

    if not config_changes:
        # no changes made, exit
        io.log_warning(strings['lifecycle.updatenochanges'])
        return

    elasticbeanstalk.update_application_resource_lifecycle(
        app_name, config_changes)
    io.echo(strings['lifecycle.success'])
 def test_convert_api_to_usr_model_with_service_role(self):
     lifecycle_config = LifecycleConfiguration(self.api_model)
     actual_usr_model = lifecycle_config.convert_api_to_usr_model()
     self.assertEqual(
         self.usr_model, actual_usr_model,
         "Expected changes to be: {0}\n But was: {1}".format(
             self.usr_model, actual_usr_model))
     self.mock_get_role.assert_not_called()
 def test_collect_changes_with_service_role(self):
     lifecycle_config = LifecycleConfiguration(self.api_model)
     changes = lifecycle_config.collect_changes(self.usr_model)
     expected_changed = self.usr_model['Configurations']
     self.assertEqual(
         expected_changed, changes,
         "Expected changes to be: {0}\n But was: {1}".format(
             expected_changed, changes))
     self.mock_get_role.assert_called_with(self.service_role.split('/')[-1])
    def test_collect_changes_no_service_role(self):
        no_service_role_model = copy.deepcopy(self.usr_model)
        del no_service_role_model['Configurations']['ServiceRole']
        expected_changes = no_service_role_model['Configurations']

        lifecycle_config = LifecycleConfiguration(self.api_model)
        changes = lifecycle_config.collect_changes(no_service_role_model)
        self.assertEqual(
            expected_changes, changes,
            "Expected changes to be: {0}\n But was: {1}".format(
                expected_changes, changes))
        self.mock_get_role.assert_not_called()
    def test_convert_api_to_usr_model_no_service_role(self):
        self.mock_get_role.return_value = self.get_role_response
        no_service_role_model = copy.deepcopy(self.api_model)
        del no_service_role_model['ResourceLifecycleConfig']['ServiceRole']

        lifecycle_config = LifecycleConfiguration(no_service_role_model)
        actual_usr_model = lifecycle_config.convert_api_to_usr_model()

        self.assertEqual(
            self.usr_model, actual_usr_model,
            "Expected changes to be: {0}\n But was: {1}".format(
                self.usr_model, actual_usr_model))
        self.mock_get_role.assert_called_with(
            lifecycleconfiguration.DEFAULT_LIFECYCLE_SERVICE_ROLE)
    def test_collect_changes_service_role_not_found(self):
        self.mock_get_role.side_effect = NotFoundError("Could not find role")
        lifecycle_config = LifecycleConfiguration(self.api_model)
        self.assertRaises(InvalidOptionsError,
                          lifecycle_config.collect_changes, self.usr_model)

        self.mock_get_role.assert_called_with(self.service_role.split('/')[-1])
    def test_convert_api_to_usr_model_default_role_does_not_exist(self):
        self.mock_get_role.side_effect = NotFoundError("Could not find role")
        no_service_role_model = copy.deepcopy(self.api_model)
        del no_service_role_model['ResourceLifecycleConfig']['ServiceRole']

        lifecycle_config = LifecycleConfiguration(no_service_role_model)
        actual_usr_model = lifecycle_config.convert_api_to_usr_model()
        expected_usr_model = copy.deepcopy(self.usr_model)
        expected_usr_model['Configurations'][
            u'ServiceRole'] = lifecycleconfiguration.DEFAULT_ARN_STRING

        self.assertEqual(
            expected_usr_model, actual_usr_model,
            "Expected changes to be: {0}\n But was: {1}".format(
                expected_usr_model, actual_usr_model))
        self.mock_get_role.assert_called_with(
            lifecycleconfiguration.DEFAULT_LIFECYCLE_SERVICE_ROLE)