Merge lp:~gandelman-a/nova/lp839796 into lp:~hudson-openstack/nova/trunk

Proposed by Adam Gandelman
Status: Needs review
Proposed branch: lp:~gandelman-a/nova/lp839796
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 23 lines (+13/-0)
1 file modified
nova/flags.py (+13/-0)
To merge this branch: bzr merge lp:~gandelman-a/nova/lp839796
Reviewer Review Type Date Requested Status
Nova Core security contacts Pending
Review via email: mp+76498@code.launchpad.net

Description of the change

It seems the original 'flagfile' specified in ARGV gets recursively loaded when glfags parses argv for the first time. We can do it once before and tack on any optional flagfiles only when they exist.

One drawback to note is that optional_flagfiles does not load recursivey from nested flagfiles like '--flagfiles'

To post a comment you must log in.

Unmerged revisions

1611. By Adam Gandelman

nova/flags.py: Use '--optional_flagfile' to specificy a flagfile that will be used
only if it exists.

Pre-parse flagfiles from FlagValues.__call_ prior to the base class, so we can check
existence of any optional_flagfiles. If the file exists, append it to argv as a
regular '--flagfile' before gflags.FlagVlues does its parsing/loading. The
original '--optional_flagfile' is then later ignored as an unknown argument
its not declared anywhere.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/flags.py'
2--- nova/flags.py 2011-09-21 20:59:40 +0000
3+++ nova/flags.py 2011-09-21 23:47:23 +0000
4@@ -70,6 +70,19 @@
5 sneaky_unparsed_args['value'] = unparsed_args
6 return optlist, unparsed_args
7
8+ # preparse flagfiles for --optional_flagfile and pass
9+ # as another --flagfile in argv only if it exists. the
10+ # original '--optional_flagfile' argument is later ignored
11+ # (LP: #839796)
12+ preparse = gflags.FlagValues.ReadFlagsFromFiles(self,
13+ argv[1:],
14+ force_gnu=False)
15+ for f in preparse:
16+ if f.startswith("--optional_flagfile") and f.count("="):
17+ flagfile = f.split("=")[1]
18+ if os.path.isfile(flagfile):
19+ argv.append("--flagfile=%s" % flagfile)
20+
21 try:
22 setattr(getopt, orig_name, _sneaky)
23 args = gflags.FlagValues.__call__(self, argv)