From 4173f444667646a3442cfdc4b604012c86b04a65 Mon Sep 17 00:00:00 2001
From: Spyros Trigazis <spyridon.trigazis@cern.ch>
Date: Thu, 14 May 2020 13:48:32 +0300
Subject: [PATCH] [cern] Cherry-pick merge-labels

Signed-off-by: Spyros Trigazis <spyridon.trigazis@cern.ch>
---
 .gitlab-ci.yml                  |  52 ++++++++++
 0001-cern-Labels-override.patch | 172 ++++++++++++++++++++++++++++++++
 python-magnumclient.spec        |   8 +-
 3 files changed, 231 insertions(+), 1 deletion(-)
 create mode 100644 .gitlab-ci.yml
 create mode 100644 0001-cern-Labels-override.patch

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..b958e73
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,52 @@
+stages:
+  - build
+  - deploy
+
+before_script:
+  - export KOJI_TARGET=openstackclients7-train
+  - export SPEC=python-magnumclient.spec
+  - export USE_SOURCE_TARBALL=1
+  - export DIST='.el7.cern'
+  - export PKG=$(rpm -q --specfile python-magnumclient.spec --queryformat "%{name}-%{version}-%{release}\n"  | head -n1)
+
+kojicheck:
+  stage: build
+  image: gitlab-registry.cern.ch/cloud/ciadm
+  except:
+    - cern-train
+    - cern-train-qa
+    - master
+  script:
+    - curl https://gitlab.cern.ch/cloud-infrastructure/cloud-dev/raw/master/gitlab/kojicheck.sh | bash
+
+kojiscratch:
+  stage: build
+  image: gitlab-registry.cern.ch/cloud/ciadm
+  except:
+    - cern-train
+    - cern-train-qa
+    - master
+  script:
+    - export SCRATCH=1
+    - curl https://gitlab.cern.ch/cloud-infrastructure/cloud-dev/raw/master/gitlab/kojibuild.sh | bash
+
+deploy qa:
+  stage: deploy
+  image: gitlab-registry.cern.ch/cloud/ciadm
+  environment: qa
+  only:
+    - cern-train-qa
+  script:
+    - curl https://gitlab.cern.ch/cloud-infrastructure/cloud-dev/raw/master/gitlab/kojibuild.sh | bash
+    - echo $SVCBUILD_PASSWORD | kinit svcbuild@CERN.CH
+    - koji tag ${KOJI_TARGET}-qa $PKG
+
+deploy production:
+  stage: deploy
+  image: gitlab-registry.cern.ch/cloud/ciadm
+  environment: production
+  only:
+    - cern-train
+  script:
+    - echo $SVCBUILD_PASSWORD | kinit svcbuild@CERN.CH
+    - koji tag ${KOJI_TARGET}-stable $PKG
diff --git a/0001-cern-Labels-override.patch b/0001-cern-Labels-override.patch
new file mode 100644
index 0000000..0840bcb
--- /dev/null
+++ b/0001-cern-Labels-override.patch
@@ -0,0 +1,172 @@
+From 514ed7e02a9fe05d29c691b6c47d1e3d2615310a Mon Sep 17 00:00:00 2001
+From: Theodoros Tsioutsias <theodoros.tsioutsias@cern.ch>
+Date: Wed, 15 Apr 2020 14:59:07 +0000
+Subject: [PATCH] [cern] Labels override
+
+upstream https://review.opendev.org/#/c/720222/
+
+This adds a boolean flag called --merge-labels at the create CLIs
+for clusters and nodegroups. The show output for clusters and
+nodegroups is modified to contain also new fields called
+"labels_overridden", "labels_added", "labels_skipped". The new labels
+contain the differences of the object's labels with its parent's.
+
+story: 2007515
+task: 39692
+Depends-On: I1054c54da96005a49e874de6f4cf60b5db57fc02
+Change-Id: Ie68bb85f4b8bbacc5b71b523d8639cf30e6e1992
+---
+ magnumclient/osc/v1/clusters.py         | 17 ++++++++++++++++-
+ magnumclient/osc/v1/nodegroups.py       | 17 ++++++++++++++++-
+ magnumclient/tests/osc/unit/v1/fakes.py |  6 ++++++
+ magnumclient/v1/clusters.py             |  1 +
+ magnumclient/v1/nodegroups.py           |  2 +-
+ 5 files changed, 40 insertions(+), 3 deletions(-)
+
+diff --git a/magnumclient/osc/v1/clusters.py b/magnumclient/osc/v1/clusters.py
+index 3cf77d4..3ab06e9 100644
+--- a/magnumclient/osc/v1/clusters.py
++++ b/magnumclient/osc/v1/clusters.py
+@@ -34,6 +34,9 @@ CLUSTER_ATTRIBUTES = [
+     'updated_at',
+     'coe_version',
+     'labels',
++    'labels_overridden',
++    'labels_skipped',
++    'labels_added',
+     'faults',
+     'keypair',
+     'api_address',
+@@ -47,7 +50,7 @@ CLUSTER_ATTRIBUTES = [
+     'master_flavor_id',
+     'flavor_id',
+     'health_status_reason',
+-    'project_id'
++    'project_id',
+ ]
+ 
+ 
+@@ -141,6 +144,13 @@ class CreateCluster(command.Command):
+             action='append_const',
+             const=False,
+             help=_('Disables floating ip creation on the new Cluster'))
++        parser.add_argument(
++            '--merge-labels',
++            dest='merge_labels',
++            action='store_true',
++            default=False,
++            help=_('The labels provided will be merged with the labels '
++                   'configured in the specified cluster template.'))
+ 
+         return parser
+ 
+@@ -185,6 +195,11 @@ class CreateCluster(command.Command):
+         if parsed_args.fixed_subnet is not None:
+             args["fixed_subnet"] = parsed_args.fixed_subnet
+ 
++        if parsed_args.merge_labels:
++            # We are only sending this if it's True. This
++            # way we avoid breaking older APIs.
++            args["merge_labels"] = parsed_args.merge_labels
++
+         cluster = mag_client.clusters.create(**args)
+         print("Request to create cluster %s accepted"
+               % cluster.uuid)
+diff --git a/magnumclient/osc/v1/nodegroups.py b/magnumclient/osc/v1/nodegroups.py
+index 04967bf..afb5870 100644
+--- a/magnumclient/osc/v1/nodegroups.py
++++ b/magnumclient/osc/v1/nodegroups.py
+@@ -27,6 +27,9 @@ NODEGROUP_ATTRIBUTES = [
+     'project_id',
+     'docker_volume_size',
+     'labels',
++    'labels_overridden',
++    'labels_skipped',
++    'labels_added',
+     'flavor_id',
+     'image_id',
+     'node_addresses',
+@@ -37,7 +40,7 @@ NODEGROUP_ATTRIBUTES = [
+     'is_default',
+     'stack_id',
+     'status',
+-    'status_reason'
++    'status_reason',
+ ]
+ 
+ 
+@@ -100,6 +103,13 @@ class CreateNodeGroup(command.Command):
+             metavar='<flavor>',
+             help=_('The nova flavor name or UUID to use when launching the '
+                    'nodes in this NodeGroup.'))
++        parser.add_argument(
++            '--merge-labels',
++            dest='merge_labels',
++            action='store_true',
++            default=False,
++            help=_('The labels provided will be merged with the labels '
++                   'configured in the specified cluster.'))
+ 
+         return parser
+ 
+@@ -127,6 +137,11 @@ class CreateNodeGroup(command.Command):
+         if parsed_args.image is not None:
+             args['image_id'] = parsed_args.image
+ 
++        if parsed_args.merge_labels:
++            # We are only sending this if it's True. This
++            # way we avoid breaking older APIs.
++            args["merge_labels"] = parsed_args.merge_labels
++
+         cluster_id = parsed_args.cluster
+         nodegroup = mag_client.nodegroups.create(cluster_id, **args)
+         print("Request to create nodegroup %s accepted"
+diff --git a/magnumclient/tests/osc/unit/v1/fakes.py b/magnumclient/tests/osc/unit/v1/fakes.py
+index 2a25df5..4181010 100644
+--- a/magnumclient/tests/osc/unit/v1/fakes.py
++++ b/magnumclient/tests/osc/unit/v1/fakes.py
+@@ -237,6 +237,9 @@ class FakeCluster(object):
+             'stack_id': 'c4554582-77bd-4734-8f1a-72c3c40e5fb4',
+             'status_reason': None,
+             'labels': {},
++            'labels_overridden': {},
++            'labels_added': {},
++            'labels_skipped': {},
+             'created_at': '2017-03-16T18:40:39+00:00',
+             'updated_at': '2017-03-16T18:40:45+00:00',
+             'coe_version': None,
+@@ -324,6 +327,9 @@ class FakeNodeGroup(object):
+             'docker_volume_size': None,
+             'node_addresses': [],
+             'labels': {},
++            'labels_overridden': {},
++            'labels_added': {},
++            'labels_skipped': {},
+             'node_count': 1,
+             'name': 'fake-nodegroup',
+             'flavor_id': 'm1.medium',
+diff --git a/magnumclient/v1/clusters.py b/magnumclient/v1/clusters.py
+index 989de85..6aabc4b 100644
+--- a/magnumclient/v1/clusters.py
++++ b/magnumclient/v1/clusters.py
+@@ -26,6 +26,7 @@ CREATION_ATTRIBUTES.append('flavor_id')
+ CREATION_ATTRIBUTES.append('fixed_network')
+ CREATION_ATTRIBUTES.append('fixed_subnet')
+ CREATION_ATTRIBUTES.append('floating_ip_enabled')
++CREATION_ATTRIBUTES.append('merge_labels')
+ 
+ 
+ class Cluster(baseunit.BaseTemplate):
+diff --git a/magnumclient/v1/nodegroups.py b/magnumclient/v1/nodegroups.py
+index cd79934..111d8fb 100644
+--- a/magnumclient/v1/nodegroups.py
++++ b/magnumclient/v1/nodegroups.py
+@@ -20,7 +20,7 @@ from magnumclient.v1 import baseunit
+ 
+ CREATION_ATTRIBUTES = ['docker_volume_size', 'labels', 'flavor_id', 'image_id',
+                        'project_id', 'node_count', 'name', 'role',
+-                       'min_node_count', 'max_node_count']
++                       'min_node_count', 'max_node_count', 'merge_labels']
+ 
+ 
+ class NodeGroup(baseunit.BaseTemplate):
diff --git a/python-magnumclient.spec b/python-magnumclient.spec
index c61bc4a..fbf6192 100644
--- a/python-magnumclient.spec
+++ b/python-magnumclient.spec
@@ -23,12 +23,15 @@ command-line tool (magnum).
 
 Name:           python-%{pname}
 Version:        2.16.0
-Release:        1%{?dist}
+Release:        1.1%{?dist}
 Summary:        Client library for Magnum API
 
 License:        ASL 2.0
 URL:            https://launchpad.net/python-magnumclient
 Source0:        https://tarballs.openstack.org/%{sname}/%{sname}-%{upstream_version}.tar.gz
+
+Patch0: 0001-cern-Labels-override.patch
+
 BuildArch:      noarch
 
 %description
@@ -165,6 +168,9 @@ rm -rf doc/build/html/.{doctrees,buildinfo}
 %{pyver_sitelib}/%{pname}/tests
 
 %changelog
+* Thu May 14 2020 Spyros Trigazis <spyrdion.trigazis@cern.ch> 2.16.0-1.1
+- OS-11427 cherry-pick merge-labels https://review.opendev.org/#/c/720222/
+
 * Wed Jan 15 2020 Spyros Trigazis <spyrdion.trigazis@cern.ch> 2.16.0-1
 - Update to 2.16.0
 
-- 
GitLab