[1/1] start-sru-cycle: New option 'usemasterbug'

Message ID 20180712045951.6390-1-khalid.elmously@canonical.com
State New
Headers show
Series
  • [1/1] start-sru-cycle: New option 'usemasterbug'
Related show

Commit Message

Khalid Elmously July 12, 2018, 4:59 a.m.
New option '--usemasterbug' to use pre-existing master bug instead of creating a new one.

Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
---
 ktl/tracking_bug.py    |  4 ++++
 stable/start-sru-cycle | 14 +++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

Comments

Stefan Bader July 12, 2018, 6:35 a.m. | #1
On 12.07.2018 06:59, Khalid Elmously wrote:
> New option '--usemasterbug' to use pre-existing master bug instead of creating a new one.
> 
> Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
> ---
>  ktl/tracking_bug.py    |  4 ++++
>  stable/start-sru-cycle | 14 +++++++++++++-
>  2 files changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/ktl/tracking_bug.py b/ktl/tracking_bug.py
> index 8956fa90..efea3678 100644
> --- a/ktl/tracking_bug.py
> +++ b/ktl/tracking_bug.py
> @@ -357,6 +357,10 @@ class TrackingBug:
>          s.reset_tasks(bug)
>          return bug
>  
> +    def get_bug(self, bug_id):
> +        bug = self.lp.get_bug(bug_id)
> +        return bug
> +
>      def open(self, package, version, new_abi, master_bug, series_specified, private=False):
>          center(self.__class__.__name__ + '.open')
>          cdebug('    package: %s' % package)
> diff --git a/stable/start-sru-cycle b/stable/start-sru-cycle
> index 60525c20..9ebb4562 100755
> --- a/stable/start-sru-cycle
> +++ b/stable/start-sru-cycle
> @@ -129,8 +129,19 @@ class Crankers():
>                  print('    ' + master_package)
>  
>                  print('        %s:%s' % (series, master_package))
> -                if not s.args.dryrun:
> +
> +                have_master_bug = False
> +
> +                if s.args.usemasterbug:
> +                    master_bug = s.tb.get_bug(s.args.usemasterbug[0])
> +                    print("Using pre-existing master-bug: %s" %(master_bug.id))
> +                    have_master_bug = True

If I read this right, then --dry-run would be ignored when --master-bug is
given. Can't you just keep the initial check for dry run and under that either
assign master_bug from the argument or open one. Then have_master_bug is not
needed either.

-Stefan

> +
> +                elif not s.args.dryrun:
>                      master_bug = s.tb.open(master_package, '<version to be filled>', True, None, series)
> +                    have_master_bug = True
> +
> +                if have_master_bug:
>                      for task in master_bug.tasks:
>                          # Move the primary package to Confirmed, link-to-tracker and
>                          # shanky will keep on top of the others and move them as needed.
> @@ -196,6 +207,7 @@ Examples:
>      parser.add_argument('--source', action='append', default=[], metavar='source', help='Only create tracking bugs for the specified source package(s). Requiers exactly one series argument to be given. This option can be used multiple times.')
>      parser.add_argument('--staging', action='store_true', default=False, help='Use the staging LP server to create the bug. This is just for testing and will go away when the staging database is reset.')
>      parser.add_argument('--dry-run', '--dryrun', action='store_true', default=False, help='Make no permanent changes.', dest='dryrun')
> +    parser.add_argument('--usemasterbug', type=int, nargs=1, help='Use pre-existing master-bug instead of creating a new one')
>  
>      args = parser.parse_args()
>  
>
Khalid Elmously July 12, 2018, 2:19 p.m. | #2
On 2018-07-12 08:35:57 , Stefan Bader wrote:
> On 12.07.2018 06:59, Khalid Elmously wrote:
> > New option '--usemasterbug' to use pre-existing master bug instead of creating a new one.
> > 
> > Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
> > ---
> >  ktl/tracking_bug.py    |  4 ++++
> >  stable/start-sru-cycle | 14 +++++++++++++-
> >  2 files changed, 17 insertions(+), 1 deletion(-)
> > 
> > diff --git a/ktl/tracking_bug.py b/ktl/tracking_bug.py
> > index 8956fa90..efea3678 100644
> > --- a/ktl/tracking_bug.py
> > +++ b/ktl/tracking_bug.py
> > @@ -357,6 +357,10 @@ class TrackingBug:
> >          s.reset_tasks(bug)
> >          return bug
> >  
> > +    def get_bug(self, bug_id):
> > +        bug = self.lp.get_bug(bug_id)
> > +        return bug
> > +
> >      def open(self, package, version, new_abi, master_bug, series_specified, private=False):
> >          center(self.__class__.__name__ + '.open')
> >          cdebug('    package: %s' % package)
> > diff --git a/stable/start-sru-cycle b/stable/start-sru-cycle
> > index 60525c20..9ebb4562 100755
> > --- a/stable/start-sru-cycle
> > +++ b/stable/start-sru-cycle
> > @@ -129,8 +129,19 @@ class Crankers():
> >                  print('    ' + master_package)
> >  
> >                  print('        %s:%s' % (series, master_package))
> > -                if not s.args.dryrun:
> > +
> > +                have_master_bug = False
> > +
> > +                if s.args.usemasterbug:
> > +                    master_bug = s.tb.get_bug(s.args.usemasterbug[0])
> > +                    print("Using pre-existing master-bug: %s" %(master_bug.id))
> > +                    have_master_bug = True
> 
> If I read this right, then --dry-run would be ignored when --master-bug is
> given. Can't you just keep the initial check for dry run and under that either
> assign master_bug from the argument or open one. Then have_master_bug is not
> needed either.
> 
> -Stefan

Yes your approach sounds better - I should have done that to begin with.

(Note though that with this patch '--dry-run' is NOT ignored. No bugs are created if --dry-run is supplied. The only new operation that happens when --dry-run is given is the master_bug lookup from launchpad, but as that is a read-only operation, I didn't see why it cares about --dry-run)

A v2 will be forthcoming. Thanks
Khaled

> 
> > +
> > +                elif not s.args.dryrun:
> >                      master_bug = s.tb.open(master_package, '<version to be filled>', True, None, series)
> > +                    have_master_bug = True
> > +
> > +                if have_master_bug:
> >                      for task in master_bug.tasks:
> >                          # Move the primary package to Confirmed, link-to-tracker and
> >                          # shanky will keep on top of the others and move them as needed.
> > @@ -196,6 +207,7 @@ Examples:
> >      parser.add_argument('--source', action='append', default=[], metavar='source', help='Only create tracking bugs for the specified source package(s). Requiers exactly one series argument to be given. This option can be used multiple times.')
> >      parser.add_argument('--staging', action='store_true', default=False, help='Use the staging LP server to create the bug. This is just for testing and will go away when the staging database is reset.')
> >      parser.add_argument('--dry-run', '--dryrun', action='store_true', default=False, help='Make no permanent changes.', dest='dryrun')
> > +    parser.add_argument('--usemasterbug', type=int, nargs=1, help='Use pre-existing master-bug instead of creating a new one')
> >  
> >      args = parser.parse_args()
> >  
> > 
> 
>

Patch

diff --git a/ktl/tracking_bug.py b/ktl/tracking_bug.py
index 8956fa90..efea3678 100644
--- a/ktl/tracking_bug.py
+++ b/ktl/tracking_bug.py
@@ -357,6 +357,10 @@  class TrackingBug:
         s.reset_tasks(bug)
         return bug
 
+    def get_bug(self, bug_id):
+        bug = self.lp.get_bug(bug_id)
+        return bug
+
     def open(self, package, version, new_abi, master_bug, series_specified, private=False):
         center(self.__class__.__name__ + '.open')
         cdebug('    package: %s' % package)
diff --git a/stable/start-sru-cycle b/stable/start-sru-cycle
index 60525c20..9ebb4562 100755
--- a/stable/start-sru-cycle
+++ b/stable/start-sru-cycle
@@ -129,8 +129,19 @@  class Crankers():
                 print('    ' + master_package)
 
                 print('        %s:%s' % (series, master_package))
-                if not s.args.dryrun:
+
+                have_master_bug = False
+
+                if s.args.usemasterbug:
+                    master_bug = s.tb.get_bug(s.args.usemasterbug[0])
+                    print("Using pre-existing master-bug: %s" %(master_bug.id))
+                    have_master_bug = True
+
+                elif not s.args.dryrun:
                     master_bug = s.tb.open(master_package, '<version to be filled>', True, None, series)
+                    have_master_bug = True
+
+                if have_master_bug:
                     for task in master_bug.tasks:
                         # Move the primary package to Confirmed, link-to-tracker and
                         # shanky will keep on top of the others and move them as needed.
@@ -196,6 +207,7 @@  Examples:
     parser.add_argument('--source', action='append', default=[], metavar='source', help='Only create tracking bugs for the specified source package(s). Requiers exactly one series argument to be given. This option can be used multiple times.')
     parser.add_argument('--staging', action='store_true', default=False, help='Use the staging LP server to create the bug. This is just for testing and will go away when the staging database is reset.')
     parser.add_argument('--dry-run', '--dryrun', action='store_true', default=False, help='Make no permanent changes.', dest='dryrun')
+    parser.add_argument('--usemasterbug', type=int, nargs=1, help='Use pre-existing master-bug instead of creating a new one')
 
     args = parser.parse_args()