Merge ~freyes/ubuntu/+source/magnum:bug/2038109-ussuri into ~ubuntu-openstack-dev/ubuntu/+source/magnum:stable/ussuri
- Git
- lp:~freyes/ubuntu/+source/magnum
- bug/2038109-ussuri
- Merge into stable/ussuri
Proposed by
Felipe Reyes
| Status: | Merged |
|---|---|
| Merged at revision: | ed5bcb88f8b7256af29f083cb093942e5eb71187 |
| Proposed branch: | ~freyes/ubuntu/+source/magnum:bug/2038109-ussuri |
| Merge into: | ~ubuntu-openstack-dev/ubuntu/+source/magnum:stable/ussuri |
| Diff against target: |
301 lines (+275/-0) 4 files modified
debian/changelog (+7/-0) debian/patches/lp2038109-1.patch (+93/-0) debian/patches/lp2038109-2.patch (+173/-0) debian/patches/series (+2/-0) |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Ubuntu OpenStack uploaders | Pending | ||
|
Review via email:
|
|||
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
| 1 | diff --git a/debian/changelog b/debian/changelog |
| 2 | index fb910d1..916df90 100644 |
| 3 | --- a/debian/changelog |
| 4 | +++ b/debian/changelog |
| 5 | @@ -1,3 +1,10 @@ |
| 6 | +magnum (10.1.0-0ubuntu1.1) UNRELEASED; urgency=medium |
| 7 | + |
| 8 | + * d/p/lp2038109-1.patch: Add validator for fixed_network (LP: #2038109). |
| 9 | + * d/d/lp2038109-2.patch: Add validator for fixed_subnet (LP: #2038109). |
| 10 | + |
| 11 | + -- Felipe Reyes <felipe.reyes@canonical.com> Mon, 05 Aug 2024 10:57:30 -0400 |
| 12 | + |
| 13 | magnum (10.1.0-0ubuntu1) focal; urgency=medium |
| 14 | |
| 15 | [ Corey bryant ] |
| 16 | diff --git a/debian/patches/lp2038109-1.patch b/debian/patches/lp2038109-1.patch |
| 17 | new file mode 100644 |
| 18 | index 0000000..c49b2ed |
| 19 | --- /dev/null |
| 20 | +++ b/debian/patches/lp2038109-1.patch |
| 21 | @@ -0,0 +1,93 @@ |
| 22 | +From 753baadbb8b5b4c3032d4618166b1c899a50fb07 Mon Sep 17 00:00:00 2001 |
| 23 | +From: Felipe Reyes <felipe.reyes@canonical.com> |
| 24 | +Date: Thu, 5 Oct 2023 18:39:39 -0300 |
| 25 | +Subject: [PATCH] Add validator for fixed_network. |
| 26 | + |
| 27 | +The validate_fixed_network() validator looks for an available network |
| 28 | +matching the id or name, if no networks match a FixedNetworkNotFound |
| 29 | +exception is raised, if more than one networks match then the Conflict |
| 30 | +exception is raised. |
| 31 | + |
| 32 | +Partial-Bug: #2038109 |
| 33 | +Change-Id: I7fb0122889feb4f8fa039be5752e8ac3fbc23b94 |
| 34 | +--- |
| 35 | + magnum/api/attr_validator.py | 20 +++++++++-- |
| 36 | + magnum/tests/unit/api/test_attr_validator.py | 38 ++++++++++++++++++++ |
| 37 | + 2 files changed, 55 insertions(+), 3 deletions(-) |
| 38 | + |
| 39 | +--- a/magnum/api/attr_validator.py |
| 40 | ++++ b/magnum/api/attr_validator.py |
| 41 | +@@ -100,9 +100,23 @@ |
| 42 | + def validate_fixed_network(cli, fixed_network): |
| 43 | + """Validate fixed network""" |
| 44 | + |
| 45 | +- # TODO(houming):this method implement will be added after this |
| 46 | +- # first pathch for Cluster's OpenStack resources validation is merged. |
| 47 | +- pass |
| 48 | ++ count = 0 |
| 49 | ++ network_id = None |
| 50 | ++ networks = cli.neutron().list_networks() |
| 51 | ++ for net in networks.get('networks'): |
| 52 | ++ if fixed_network in [net.get('name'), net.get('id')]: |
| 53 | ++ count += 1 |
| 54 | ++ network_id = net.get('id') |
| 55 | ++ |
| 56 | ++ if count == 0: |
| 57 | ++ # Unable to find the configured fixed_network. |
| 58 | ++ raise exception.FixedNetworkNotFound(network=fixed_network) |
| 59 | ++ elif count > 1: |
| 60 | ++ msg = _("Multiple networks exist with same name '%s'. " |
| 61 | ++ "Please use the network ID instead.") |
| 62 | ++ raise exception.Conflict(msg % fixed_network) |
| 63 | ++ |
| 64 | ++ return network_id |
| 65 | + |
| 66 | + |
| 67 | + def validate_labels(labels): |
| 68 | +--- a/magnum/tests/unit/api/test_attr_validator.py |
| 69 | ++++ b/magnum/tests/unit/api/test_attr_validator.py |
| 70 | +@@ -94,6 +94,44 @@ |
| 71 | + attr_validator.validate_external_network, |
| 72 | + mock_os_cli, 'test_ext_net') |
| 73 | + |
| 74 | ++ def test_validate_fixed_network_with_valid_network(self): |
| 75 | ++ mock_networks = {'networks': [{'name': 'test_net', |
| 76 | ++ 'id': 'test_net_id'}]} |
| 77 | ++ mock_neutron = mock.MagicMock() |
| 78 | ++ mock_neutron.list_networks.return_value = mock_networks |
| 79 | ++ mock_os_cli = mock.MagicMock() |
| 80 | ++ mock_os_cli.neutron.return_value = mock_neutron |
| 81 | ++ self.assertEqual('test_net_id', |
| 82 | ++ attr_validator.validate_fixed_network(mock_os_cli, |
| 83 | ++ 'test_net')) |
| 84 | ++ self.assertTrue(mock_neutron.list_networks.called) |
| 85 | ++ |
| 86 | ++ def test_validate_fixed_network_with_multiple_valid_network(self): |
| 87 | ++ mock_networks = { |
| 88 | ++ 'networks': [{'name': 'test_net', |
| 89 | ++ 'id': 'test_net_id1'}, |
| 90 | ++ {'name': 'test_net', |
| 91 | ++ 'id': 'test_net_id2'}], |
| 92 | ++ } |
| 93 | ++ mock_neutron = mock.MagicMock() |
| 94 | ++ mock_neutron.list_networks.return_value = mock_networks |
| 95 | ++ mock_os_cli = mock.MagicMock() |
| 96 | ++ mock_os_cli.neutron.return_value = mock_neutron |
| 97 | ++ self.assertRaises(exception.Conflict, |
| 98 | ++ attr_validator.validate_fixed_network, |
| 99 | ++ mock_os_cli, 'test_net') |
| 100 | ++ |
| 101 | ++ def test_validate_fixed_network_with_invalid_network(self): |
| 102 | ++ mock_networks = {'networks': [{'name': 'test_net_not_equal', |
| 103 | ++ 'id': 'test_net_id_not_equal'}]} |
| 104 | ++ mock_neutron = mock.MagicMock() |
| 105 | ++ mock_neutron.list_networks.return_value = mock_networks |
| 106 | ++ mock_os_cli = mock.MagicMock() |
| 107 | ++ mock_os_cli.neutron.return_value = mock_neutron |
| 108 | ++ self.assertRaises(exception.FixedNetworkNotFound, |
| 109 | ++ attr_validator.validate_fixed_network, |
| 110 | ++ mock_os_cli, 'test_net') |
| 111 | ++ |
| 112 | + def test_validate_keypair_with_no_keypair(self): |
| 113 | + mock_keypair = mock.MagicMock() |
| 114 | + mock_keypair.id = None |
| 115 | diff --git a/debian/patches/lp2038109-2.patch b/debian/patches/lp2038109-2.patch |
| 116 | new file mode 100644 |
| 117 | index 0000000..e863cce |
| 118 | --- /dev/null |
| 119 | +++ b/debian/patches/lp2038109-2.patch |
| 120 | @@ -0,0 +1,173 @@ |
| 121 | +From a8bce0bfee81218cd1c0ddcf3e2b86b96659933e Mon Sep 17 00:00:00 2001 |
| 122 | +From: Felipe Reyes <felipe.reyes@canonical.com> |
| 123 | +Date: Thu, 5 Oct 2023 18:45:55 -0300 |
| 124 | +Subject: [PATCH] Add validator for fixed_subnet |
| 125 | + |
| 126 | +Validate the existance of the subnet referenced by fixed_subnet. It's |
| 127 | +not checked if the subnet is associated to the fixed_network. |
| 128 | + |
| 129 | +Closes-Bug: #2038109 |
| 130 | +Change-Id: Ia75f0ae525b768ad5b965d22b522cca6f80dcab2 |
| 131 | +--- |
| 132 | + magnum/api/attr_validator.py | 35 +++++++-- |
| 133 | + magnum/tests/unit/api/test_attr_validator.py | 81 ++++++++++++++++++++ |
| 134 | + 2 files changed, 110 insertions(+), 6 deletions(-) |
| 135 | + |
| 136 | +--- a/magnum/api/attr_validator.py |
| 137 | ++++ b/magnum/api/attr_validator.py |
| 138 | +@@ -119,6 +119,28 @@ |
| 139 | + return network_id |
| 140 | + |
| 141 | + |
| 142 | ++def validate_fixed_subnet(cli, fixed_subnet): |
| 143 | ++ """Validate fixed subnet""" |
| 144 | ++ |
| 145 | ++ count = 0 |
| 146 | ++ subnet_id = None |
| 147 | ++ subnets = cli.neutron().list_subnets() |
| 148 | ++ for subnet in subnets.get('subnets'): |
| 149 | ++ if fixed_subnet in [subnet.get('name'), subnet.get('id')]: |
| 150 | ++ count += 1 |
| 151 | ++ subnet_id = subnet.get('id') |
| 152 | ++ |
| 153 | ++ if count == 0: |
| 154 | ++ # Unable to find the configured fixed_subnet. |
| 155 | ++ raise exception.FixedSubnetNotFound(subnet=fixed_subnet) |
| 156 | ++ elif count > 1: |
| 157 | ++ msg = _("Multiple subnets exist with same name '%s'. " |
| 158 | ++ "Please use the subnet ID instead.") |
| 159 | ++ raise exception.Conflict(msg % fixed_subnet) |
| 160 | ++ else: |
| 161 | ++ return subnet_id |
| 162 | ++ |
| 163 | ++ |
| 164 | + def validate_labels(labels): |
| 165 | + """"Validate labels""" |
| 166 | + |
| 167 | +@@ -207,15 +229,15 @@ |
| 168 | + |
| 169 | + for attr, validate_method in validators.items(): |
| 170 | + if cluster and attr in cluster and cluster[attr]: |
| 171 | +- if attr != 'labels': |
| 172 | +- validate_method(cli, cluster[attr]) |
| 173 | +- else: |
| 174 | ++ if attr == 'labels': |
| 175 | + validate_method(cluster[attr]) |
| 176 | +- elif attr in cluster_template and cluster_template[attr] is not None: |
| 177 | +- if attr != 'labels': |
| 178 | +- validate_method(cli, cluster_template[attr]) |
| 179 | + else: |
| 180 | ++ validate_method(cli, cluster[attr]) |
| 181 | ++ elif attr in cluster_template and cluster_template[attr] is not None: |
| 182 | ++ if attr == 'labels': |
| 183 | + validate_method(cluster_template[attr]) |
| 184 | ++ else: |
| 185 | ++ validate_method(cli, cluster_template[attr]) |
| 186 | + |
| 187 | + if cluster: |
| 188 | + validate_keypair(cli, cluster['keypair']) |
| 189 | +@@ -261,6 +283,7 @@ |
| 190 | + 'master_flavor_id': validate_flavor, |
| 191 | + 'external_network_id': validate_external_network, |
| 192 | + 'fixed_network': validate_fixed_network, |
| 193 | ++ 'fixed_subnet': validate_fixed_subnet, |
| 194 | + 'labels': validate_labels} |
| 195 | + |
| 196 | + labels_validators = {'mesos_slave_isolation': validate_labels_isolation, |
| 197 | +--- a/magnum/tests/unit/api/test_attr_validator.py |
| 198 | ++++ b/magnum/tests/unit/api/test_attr_validator.py |
| 199 | +@@ -132,6 +132,46 @@ |
| 200 | + attr_validator.validate_fixed_network, |
| 201 | + mock_os_cli, 'test_net') |
| 202 | + |
| 203 | ++ def test_validate_fixed_subnet_with_valid_subnet(self): |
| 204 | ++ mock_neutron = mock.MagicMock() |
| 205 | ++ mock_subnets = {'subnets': [{'name': 'test_subnet', |
| 206 | ++ 'id': 'test_subnet_id', |
| 207 | ++ 'network_id': 'test_net_id'}]} |
| 208 | ++ mock_neutron.list_subnets.return_value = mock_subnets |
| 209 | ++ mock_os_cli = mock.MagicMock() |
| 210 | ++ mock_os_cli.neutron.return_value = mock_neutron |
| 211 | ++ self.assertEqual('test_subnet_id', |
| 212 | ++ attr_validator.validate_fixed_subnet(mock_os_cli, |
| 213 | ++ 'test_subnet')) |
| 214 | ++ mock_neutron.list_subnets.assert_called_with() |
| 215 | ++ |
| 216 | ++ def test_validate_fixed_subnet_with_invalid_subnet(self): |
| 217 | ++ mock_neutron = mock.MagicMock() |
| 218 | ++ mock_subnets = {'subnets': [{'name': 'test_subnet', |
| 219 | ++ 'id': 'test_subnet_id', |
| 220 | ++ 'network_id': 'test_net_id'}]} |
| 221 | ++ mock_neutron.list_subnets.return_value = mock_subnets |
| 222 | ++ mock_os_cli = mock.MagicMock() |
| 223 | ++ mock_os_cli.neutron.return_value = mock_neutron |
| 224 | ++ self.assertRaises(exception.FixedSubnetNotFound, |
| 225 | ++ attr_validator.validate_fixed_subnet, |
| 226 | ++ mock_os_cli, 'test_subnet_not_found') |
| 227 | ++ |
| 228 | ++ def test_validate_fixed_subnet_with_multiple_valid_subnet(self): |
| 229 | ++ mock_neutron = mock.MagicMock() |
| 230 | ++ mock_subnets = {'subnets': [{'name': 'test_subnet', |
| 231 | ++ 'id': 'test_subnet_id', |
| 232 | ++ 'network_id': 'test_net_id'}, |
| 233 | ++ {'name': 'test_subnet', |
| 234 | ++ 'id': 'test_subnet_id2', |
| 235 | ++ 'network_id': 'test_net_id2'}]} |
| 236 | ++ mock_neutron.list_subnets.return_value = mock_subnets |
| 237 | ++ mock_os_cli = mock.MagicMock() |
| 238 | ++ mock_os_cli.neutron.return_value = mock_neutron |
| 239 | ++ self.assertRaises(exception.Conflict, |
| 240 | ++ attr_validator.validate_fixed_subnet, |
| 241 | ++ mock_os_cli, 'test_subnet') |
| 242 | ++ |
| 243 | + def test_validate_keypair_with_no_keypair(self): |
| 244 | + mock_keypair = mock.MagicMock() |
| 245 | + mock_keypair.id = None |
| 246 | +@@ -360,6 +400,47 @@ |
| 247 | + mock_cluster_template) |
| 248 | + |
| 249 | + @mock.patch('magnum.common.clients.OpenStackClients') |
| 250 | ++ def test_validate_os_resources_with_valid_fixed_subnet(self, |
| 251 | ++ os_clients_klass): |
| 252 | ++ mock_cluster_template = {'fixed_network': 'test_net', |
| 253 | ++ 'fixed_subnet': 'test_subnet'} |
| 254 | ++ mock_context = mock.MagicMock() |
| 255 | ++ mock_os_cli = mock.MagicMock() |
| 256 | ++ os_clients_klass.return_value = mock_os_cli |
| 257 | ++ mock_neutron = mock.MagicMock() |
| 258 | ++ mock_networks = {'networks': [{'name': 'test_net', |
| 259 | ++ 'id': 'test_net_id'}]} |
| 260 | ++ mock_neutron.list_networks.return_value = mock_networks |
| 261 | ++ mock_subnets = {'subnets': [{'name': 'test_subnet', |
| 262 | ++ 'id': 'test_subnet_id', |
| 263 | ++ 'network_id': 'test_net_id'}]} |
| 264 | ++ mock_neutron.list_subnets.return_value = mock_subnets |
| 265 | ++ mock_os_cli.neutron.return_value = mock_neutron |
| 266 | ++ attr_validator.validate_os_resources(mock_context, |
| 267 | ++ mock_cluster_template) |
| 268 | ++ |
| 269 | ++ @mock.patch('magnum.common.clients.OpenStackClients') |
| 270 | ++ def test_validate_os_resources_with_invalid_fixed_subnet(self, |
| 271 | ++ os_clients_klass): |
| 272 | ++ mock_cluster_template = {'fixed_network': 'test_net', |
| 273 | ++ 'fixed_subnet': 'test_subnet2'} |
| 274 | ++ mock_context = mock.MagicMock() |
| 275 | ++ mock_os_cli = mock.MagicMock() |
| 276 | ++ os_clients_klass.return_value = mock_os_cli |
| 277 | ++ mock_neutron = mock.MagicMock() |
| 278 | ++ mock_networks = {'networks': [{'name': 'test_net', |
| 279 | ++ 'id': 'test_net_id'}]} |
| 280 | ++ mock_neutron.list_networks.return_value = mock_networks |
| 281 | ++ mock_subnets = {'subnets': [{'name': 'test_subnet', |
| 282 | ++ 'id': 'test_subnet_id', |
| 283 | ++ 'network_id': 'test_net_id'}]} |
| 284 | ++ mock_neutron.list_subnets.return_value = mock_subnets |
| 285 | ++ mock_os_cli.neutron.return_value = mock_neutron |
| 286 | ++ self.assertRaises(exception.FixedSubnetNotFound, |
| 287 | ++ attr_validator.validate_os_resources, mock_context, |
| 288 | ++ mock_cluster_template) |
| 289 | ++ |
| 290 | ++ @mock.patch('magnum.common.clients.OpenStackClients') |
| 291 | + def test_validate_os_resources_with_cluster(self, mock_os_cli): |
| 292 | + mock_cluster_template = {} |
| 293 | + mock_cluster = { |
| 294 | diff --git a/debian/patches/series b/debian/patches/series |
| 295 | index 25c0f24..34e1237 100644 |
| 296 | --- a/debian/patches/series |
| 297 | +++ b/debian/patches/series |
| 298 | @@ -1 +1,3 @@ |
| 299 | install-missing-files.patch |
| 300 | +lp2038109-1.patch |
| 301 | +lp2038109-2.patch |
