Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shell scripts to export/import alerts and alert profiles #112

Closed
wants to merge 3 commits into from
Closed

Add shell scripts to export/import alerts and alert profiles #112

wants to merge 3 commits into from

Conversation

branic
Copy link

@branic branic commented Mar 1, 2017

These two scripts are used to export/import various ManageIQ objects. They are wrapper scripts for rake scripts that actually perform the export/import.

These scripts are from the CFME RH Consulting Scripts and are used by Red Hat consultants to enable storing customizations in Git and maintaining customizations between environments (e.g. dev/qa/prod) for an SDLC lifecycle.

PR 14126 in manageiq is tied to this PR and provides the rake scripts that these bash scripts call.

@branic branic changed the title Add shell scripts to export/import miq objects [WIP] Add shell scripts to export/import miq objects Mar 11, 2017
@miq-bot miq-bot added the wip label Mar 11, 2017
@branic branic changed the title [WIP] Add shell scripts to export/import miq objects Add shell scripts to export/import alerts and alert profiles Mar 11, 2017
@miq-bot miq-bot removed the wip label Mar 11, 2017
@Fryguy
Copy link
Member

Fryguy commented Mar 15, 2017

@carbonin Please review.

@Fryguy
Copy link
Member

Fryguy commented Mar 15, 2017

@branic I'm trying to understand the purpose of these shell scripts over just calling the rake task itself. Is it just for a pretty interface or is there some deeper reason?

Copy link
Member

@carbonin carbonin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to leave it at this as a first pass.

Also, agree with @Fryguy. It seems like it would be easier to just have people call the rake tasks directly.

Then we have less code to maintain (whenever anyone adds a new export task, they would also need to know to update these scripts) and the functionality can be rolled into automated testing (which we don't do here).

}

usage () {
progname=`basename $0`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be indented.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

return 1
}

parse_arguments () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would rather not have a function for this.

  1. I usually expect option parsing to be in the main script and
  2. I know it works, but it feels odd to be setting remaining_args in a function and then using it after.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move this out of the function into the main-line code.

KEEP_SPACES="true"
shift # past the argument
;;
--)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case for having this? It feels unnecessary as we already stop parsing when we see the first thing that isn't -s|--keep-spaces.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for backwards compatibility. In previous versions of the rake tasks the files created had spaces in the file names.

I would be comfortable removing this option in ManageIQ as the namespaces of the rake tasks will be different (since the rhconsulting namespace needs to be changed).

break # stop parsing arguments
;;
*)
# unknown option
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the comments in this case block feel unnecessary to me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

esac
done

# if there are any required arguments check for them here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this comment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.


# if there are any required arguments check for them here

# pass the shifted arguments back to the caller
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not needed if this logic is not in a separate function. Setting remaining_args becomes less confusing if it is done right before it is used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

}

parse_action () {
AVAILABLE_PARSERS=`compgen -A function | grep '^op_'`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is just an opportunity for weird bugs. I would rather be a bit more verbose and just validate against a known set of options.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll specify a fixed list for this.


obj_type="$1"
op_func="op_${obj_type}"
contains $op_func $AVAILABLE_PARSERS; VALID_OP=$?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can avoid all of this logic if we just make the object type a proper argument to the script something like --object-type|-o

Then if we don't match we can just fail there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object type is a positional argument to the script and is required. I can make it so that it has to be passed in the option format instead of a positional argument, but there still needs to be some way to check that the type of object the user wants to export is valid (i.e. alerts is a valid export object type, but alert isn't) which is what this line is doing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the object type argument is changed to the option format then the directory argument should also be changed to the option format so there are no positional arguments, just option arguments.

@branic
Copy link
Author

branic commented Mar 17, 2017

@Fryguy, @carbonin

The shell scripts do make for a prettier interface, but are meant to make it easier for a system administrator to use. Many system administrators aren't familiar with running rake tasks, but are familiar with running shell scripts.

In addition to the above they also provide an easier way to pass in arguments for the rake tasks from the command line.

@miq-bot
Copy link
Member

miq-bot commented Mar 20, 2017

Checked commits https://github.com/branic/manageiq-appliance/compare/7511ba25341c52641b57dc5fe2b913761c75f3f8~...b889874c74dcb2a822b314b2cf0a869388a4b5a6 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
0 files checked, 0 offenses detected
Everything looks good. 👍

@miq-bot miq-bot closed this Dec 11, 2017
@miq-bot
Copy link
Member

miq-bot commented Dec 11, 2017

This pull request has been automatically closed because it has not been updated for at least 6 months.

Feel free to reopen this pull request if these changes are still valid.

Thank you for all your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants