#443 Allow creating a compose with scratch module build only
Merged 3 years ago by lsedlar. Opened 3 years ago by hlin.
hlin/odcs master  into  master

file modified
+3 -1
@@ -231,7 +231,7 @@ 

  create_module_parser.add_argument(

      "modules",

      metavar="modules",

-     nargs="+",

+     nargs="*",

      help="List of modules in N:S, N:S:V or N:S:V:C format.",

  )

  _add_arguments(
@@ -410,6 +410,8 @@ 

          )

          result = client.request_compose(source, **request_args)

      elif args.command == "create-module":

+         if not args.modules and not args.scratch_module:

+             create_module_parser.error("Please give a module or --scratch-module")

          source = odcs.client.odcs.ComposeSourceModule(

              args.modules,

              args.sigkey,

file modified
+10 -6
@@ -321,11 +321,19 @@ 

          source_type = PUNGI_SOURCE_TYPE_NAMES[source_type]

  

          source = []

-         if "source" in source_data:

+         if "source" in source_data and source_data["source"] != "":

              # Use list(set()) here to remove duplicate sources.

              source = list(set(source_data["source"].split(" ")))

  

-         if not source and source_type != PungiSourceType.BUILD:

+         scratch_modules = None

+         if "scratch_modules" in source_data:

+             scratch_modules = " ".join(source_data["scratch_modules"])

+ 

+         if (

+             not source

+             and source_type != PungiSourceType.BUILD

+             and not (source_type == PungiSourceType.MODULE and scratch_modules)

+         ):

              err = "No source provided for %s" % source_type

              log.error(err)

              raise ValueError(err)
@@ -448,10 +456,6 @@ 

          elif module_defaults_url and module_defaults_commit:

              module_defaults = "%s %s" % (module_defaults_url, module_defaults_commit)

  

-         scratch_modules = None

-         if "scratch_modules" in source_data:

-             scratch_modules = " ".join(source_data["scratch_modules"])

- 

          scratch_build_tasks = None

          if "scratch_build_tasks" in source_data:

              scratch_build_tasks = " ".join(source_data["scratch_build_tasks"])

@@ -1298,6 +1298,38 @@ 

              )

              data = json.loads(rv.get_data(as_text=True))

              self.assertEqual(

+                 data["source"],

+                 "testmodule:master",

+             )

+             self.assertEqual(

+                 data["scratch_modules"],

+                 "foo:bar:20200806:abcdefgh fooo:bar:20200810:abcdefgh",

+             )

+ 

+     def test_submit_build_only_scratch_modules(self):

+         with self.test_request_context(user="dev"):

+             flask.g.oidc_scopes = [

+                 "{0}{1}".format(conf.oidc_base_namespace, "new-compose")

+             ]

+ 

+             rv = self.client.post(

+                 "/api/1/composes/",

+                 data=json.dumps(

+                     {

+                         "source": {

+                             "type": "module",

+                             "source": "",

+                             "scratch_modules": [

+                                 "foo:bar:20200806:abcdefgh",

+                                 "fooo:bar:20200810:abcdefgh",

+                             ],

+                         }

+                     }

+                 ),

+             )

+             data = json.loads(rv.get_data(as_text=True))

+             self.assertEqual(data["source"], "")

+             self.assertEqual(

                  data["scratch_modules"],

                  "foo:bar:20200806:abcdefgh fooo:bar:20200810:abcdefgh",

              )

JIRA: RHELCMP-2166
Signed-off-by: Haibo Lin hlin@redhat.com

rebased onto af047b1e530a3dd50cab56bcc7fb042aee17514c

3 years ago

rebased onto 1d5de721365dd7509c97f7c01c03115b7c70c597

3 years ago

Would parser.error be nicer here?

Interesting, this seems to be a subject of test fail.

Otherwise, it looks good to me.

It depends on version of black. The latest version in PyPI apparently changed in this regard.

rebased onto 8edac6f6ab657b46620ba0d26bdf2076e3685a67

3 years ago

1 new commit added

  • Make black 20.8b1 happy
3 years ago

Looks good to me. @hlin, can you please resolve the merge conflict?

rebased onto d3993aa

3 years ago

Pull-Request has been merged by lsedlar

3 years ago