Browse Source

Merge the user given tags when update package

Change-Id: I1b4a556f619c346da49c0ddf5085b2aa12e7752e
zhurong 1 month ago
parent
commit
e5c89bb4a7
2 changed files with 54 additions and 1 deletions
  1. 5
    1
      murano/api/v1/catalog.py
  2. 49
    0
      murano/tests/unit/api/v1/test_catalog.py

+ 5
- 1
murano/api/v1/catalog.py View File

@@ -262,7 +262,11 @@ class Controller(object):
262 262
                 # extend dictionary for update db
263 263
                 for k, v in PKG_PARAMS_MAP.items():
264 264
                     if hasattr(pkg_to_upload, k):
265
-                        package_meta[v] = getattr(pkg_to_upload, k)
265
+                        if k == "tags" and package_meta.get(k):
266
+                            package_meta[v] = list(set(
267
+                                package_meta[v] + getattr(pkg_to_upload, k)))
268
+                        else:
269
+                            package_meta[v] = getattr(pkg_to_upload, k)
266 270
                 if len(package_meta['name']) > 80:
267 271
                     msg = _('Package name should be 80 characters maximum')
268 272
                     LOG.error(msg)

+ 49
- 0
murano/tests/unit/api/v1/test_catalog.py View File

@@ -1183,6 +1183,55 @@ This is a fake zip archive
1183 1183
             res = req.get_response(self.api)
1184 1184
             self.assertEqual(200, res.status_code)
1185 1185
 
1186
+    def test_upload_pkg_with_tag(self):
1187
+        """Check upload package with tags successfully"""
1188
+
1189
+        self._set_policy_rules({'upload_package': '@'})
1190
+        self.expect_policy_check('upload_package')
1191
+        file_obj_str = cStringIO("This is some dummy data")
1192
+        file_obj = mock.MagicMock(cgi.FieldStorage)
1193
+        file_obj.file = file_obj_str
1194
+        package_from_dir, _ = self._test_package()
1195
+
1196
+        body_fmt = '''\
1197
+
1198
+--BOUNDARY
1199
+Content-Disposition: form-data; name="__metadata__"
1200
+
1201
+{0}
1202
+--BOUNDARY
1203
+Content-Disposition: form-data; name="ziparchive"; filename="file.zip"
1204
+
1205
+This is a fake zip archive
1206
+--BOUNDARY--'''
1207
+
1208
+        def format_body(content):
1209
+            content = jsonutils.dumps(content)
1210
+            body = body_fmt.format(content)
1211
+            if six.PY3:
1212
+                body = body.encode('utf-8')
1213
+            return body
1214
+
1215
+        with mock.patch('murano.packages.load_utils.load_from_file') as lff:
1216
+            ctxmgr = mock.Mock()
1217
+            ctxmgr.__enter__ = mock.Mock(return_value=package_from_dir)
1218
+            ctxmgr.__exit__ = mock.Mock(return_value=False)
1219
+            lff.return_value = ctxmgr
1220
+
1221
+            # Uploading a package with foo_tag
1222
+            req = self._post(
1223
+                '/catalog/packages',
1224
+                format_body({'tags': ['foo_tag']}),
1225
+                content_type='multipart/form-data; ; boundary=BOUNDARY',
1226
+            )
1227
+            res = req.get_response(self.api)
1228
+
1229
+            processed_result = jsonutils.loads(res.body)
1230
+            # check user set foo_tag in result
1231
+            self.assertIn('foo_tag', processed_result["tags"])
1232
+            # check tag Linux from package in result
1233
+            self.assertIn('Linux', processed_result["tags"])
1234
+
1186 1235
     def test_add_category(self):
1187 1236
         """Check that category added successfully"""
1188 1237
 

Loading…
Cancel
Save