Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import unittest |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 16 | import functools |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 17 | from mock import patch, Mock |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 18 | import requests_mock |
| 19 | |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 20 | import os |
| 21 | import sys |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 22 | |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 23 | test_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 24 | |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 25 | |
| 26 | def match_none(req): |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 27 | return req.text is None |
| 28 | |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 29 | |
| 30 | def match_json(desired, req): |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 31 | if desired != req.json(): |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 32 | raise Exception("Got request %s, but body is not matching" % req.url) |
| 33 | return False |
| 34 | return True |
| 35 | |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 36 | |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 37 | class TestSyncOnosApp(unittest.TestCase): |
| 38 | |
| 39 | def setUp(self): |
| 40 | global DeferredException |
| 41 | |
| 42 | self.sys_path_save = sys.path |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 43 | |
| 44 | # Setting up the config module |
| 45 | from xosconfig import Config |
| 46 | config = os.path.join(test_path, "../test_config.yaml") |
| 47 | Config.clear() |
| 48 | Config.init(config, "synchronizer-config-schema.yaml") |
| 49 | # END Setting up the config module |
| 50 | |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 51 | from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 52 | mock_modelaccessor_config(test_path, [("onos-service", "onos.xproto"), ]) |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 53 | |
| 54 | import xossynchronizer.modelaccessor |
| 55 | import mock_modelaccessor |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 56 | reload(mock_modelaccessor) # in case nose2 loaded it in a previous test |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 57 | reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 58 | |
| 59 | from sync_onos_app import SyncONOSApp, DeferredException, model_accessor |
| 60 | |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 61 | self.model_accessor = model_accessor |
| 62 | |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 63 | # import all class names to globals |
| 64 | for (k, v) in model_accessor.all_model_classes.items(): |
| 65 | globals()[k] = v |
| 66 | |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 67 | self.sync_step = SyncONOSApp |
| 68 | |
| 69 | onos = ONOSService() |
| 70 | onos.rest_hostname = "onos-url" |
| 71 | onos.rest_port = "8181" |
| 72 | onos.rest_username = "karaf" |
| 73 | onos.rest_password = "karaf" |
| 74 | |
| 75 | self.onos_app = Mock(spec=[ |
| 76 | 'id', |
| 77 | 'name', |
| 78 | 'app_id', |
| 79 | 'dependencies', |
| 80 | 'owner', |
| 81 | 'url', |
| 82 | 'backend_code', |
| 83 | 'version', |
| 84 | 'tologdict' |
| 85 | ]) |
| 86 | self.onos_app.id = 1 |
| 87 | self.onos_app.name = "vrouter" |
| 88 | self.onos_app.app_id = "org.onosproject.vrouter" |
| 89 | self.onos_app.dependencies = "" |
| 90 | self.onos_app.owner.leaf_model = onos |
| 91 | self.onos_app.url = None |
| 92 | self.onos_app.class_names = "ONOSApp" |
| 93 | self.onos_app.tologdict.return_value = "" |
| 94 | |
| 95 | self.si = Mock() |
| 96 | self.si.id = 1 |
| 97 | self.si.leaf_model = self.onos_app |
| 98 | |
| 99 | self.vrouter_app_response = { |
| 100 | "name": "org.onosproject.vrouter", |
| 101 | "version": "1.13.1", |
| 102 | } |
| 103 | |
| 104 | self.onos_app_attribute = Mock(spec=[ |
| 105 | 'id', |
| 106 | 'service_instance', |
| 107 | 'name', |
| 108 | 'value' |
| 109 | ]) |
| 110 | self.onos_app_attribute.id = 1 |
| 111 | self.onos_app_attribute.service_instance = self.si |
| 112 | self.onos_app_attribute.name = "/onos/v1/network/configuration/apps/org.opencord.olt" |
| 113 | self.onos_app_attribute.value = { |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 114 | "kafka": { |
| 115 | "bootstrapServers": "cord-kafka-kafka.default.svc.cluster.local:9092" |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | |
| 119 | def tearDown(self): |
| 120 | self.onos = None |
| 121 | sys.path = self.sys_path_save |
| 122 | |
| 123 | @requests_mock.Mocker() |
| 124 | def test_defer_app_sync(self, m): |
| 125 | self.onos_app.dependencies = "org.onosproject.segmentrouting, org.onosproject.openflow" |
| 126 | |
| 127 | segment_routing = Mock() |
| 128 | segment_routing.app_id = "org.onosproject.segmentrouting" |
| 129 | segment_routing.backend_code = 1 |
| 130 | |
| 131 | openflow = Mock() |
| 132 | openflow.app_id = "org.onosproject.openflow" |
| 133 | openflow.backend_code = 0 |
| 134 | |
| 135 | with patch.object(ONOSApp.objects, "get_items") as app_get, \ |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 136 | patch.object(ServiceInstance.objects, "get_items") as mock_si, \ |
| 137 | self.assertRaises(DeferredException) as e: |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 138 | |
| 139 | app_get.return_value = [segment_routing, openflow] |
| 140 | mock_si.return_value = [self.si] |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 141 | self.sync_step(model_accessor=self.model_accessor).sync_record(self.onos_app) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 142 | |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 143 | self.assertEqual( |
| 144 | e.exception.message, |
| 145 | 'Deferring installation of ONOSApp with id 1 as dependencies are not met') |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 146 | self.assertFalse(m.called) |
| 147 | |
| 148 | @requests_mock.Mocker() |
Scott Baker | 9ee45e1 | 2018-08-21 16:58:39 -0700 | [diff] [blame] | 149 | def test_dependencies_none(self, m): |
| 150 | """ App should sync if dependencies is set to None """ |
| 151 | |
| 152 | self.onos_app.dependencies = None |
| 153 | |
| 154 | m.post("http://onos-url:8181/onos/v1/applications/org.onosproject.vrouter/active", |
| 155 | status_code=200, |
| 156 | additional_matcher=match_none) |
| 157 | |
| 158 | m.get("http://onos-url:8181/onos/v1/applications/org.onosproject.vrouter", |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 159 | status_code=200, |
| 160 | json=self.vrouter_app_response) |
Scott Baker | 9ee45e1 | 2018-08-21 16:58:39 -0700 | [diff] [blame] | 161 | |
| 162 | self.si.serviceinstanceattribute_dict = {} |
| 163 | |
| 164 | with patch.object(ServiceInstance.objects, "get_items") as mock_si: |
| 165 | mock_si.return_value = [self.si] |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 166 | self.sync_step(model_accessor=self.model_accessor).sync_record(self.onos_app) |
Scott Baker | 9ee45e1 | 2018-08-21 16:58:39 -0700 | [diff] [blame] | 167 | |
| 168 | self.assertTrue(m.called) |
| 169 | self.assertEqual(m.call_count, 2) |
| 170 | self.assertEqual(self.onos_app.version, self.vrouter_app_response["version"]) |
| 171 | |
| 172 | @requests_mock.Mocker() |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 173 | def test_app_sync_local_app_no_config(self, m): |
| 174 | """ |
| 175 | Activate an application that is already installed in ONOS |
| 176 | """ |
| 177 | |
| 178 | m.post("http://onos-url:8181/onos/v1/applications/org.onosproject.vrouter/active", |
| 179 | status_code=200, |
| 180 | additional_matcher=match_none) |
| 181 | |
| 182 | m.get("http://onos-url:8181/onos/v1/applications/org.onosproject.vrouter", |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 183 | status_code=200, |
| 184 | json=self.vrouter_app_response) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 185 | |
| 186 | self.si.serviceinstanceattribute_dict = {} |
| 187 | |
| 188 | with patch.object(ServiceInstance.objects, "get_items") as mock_si: |
| 189 | mock_si.return_value = [self.si] |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 190 | self.sync_step(model_accessor=self.model_accessor).sync_record(self.onos_app) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 191 | |
| 192 | self.assertTrue(m.called) |
| 193 | self.assertEqual(m.call_count, 2) |
| 194 | self.assertEqual(self.onos_app.version, self.vrouter_app_response["version"]) |
| 195 | |
| 196 | @requests_mock.Mocker() |
| 197 | def test_app_sync_local_app_with_config(self, m): |
| 198 | |
| 199 | m.post("http://onos-url:8181/onos/v1/applications/org.onosproject.vrouter/active", |
| 200 | status_code=200, |
| 201 | additional_matcher=match_none) |
| 202 | |
| 203 | m.get("http://onos-url:8181/onos/v1/applications/org.onosproject.vrouter", |
| 204 | status_code=200, |
| 205 | json=self.vrouter_app_response) |
| 206 | |
| 207 | with patch.object(ServiceInstance.objects, "get_items") as mock_si: |
| 208 | mock_si.return_value = [self.si] |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 209 | self.sync_step(model_accessor=self.model_accessor).sync_record(self.onos_app) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 210 | self.assertTrue(m.called) |
| 211 | self.assertEqual(m.call_count, 2) |
| 212 | self.assertEqual(self.onos_app.version, self.vrouter_app_response["version"]) |
| 213 | |
| 214 | @requests_mock.Mocker() |
| 215 | def test_app_install_remote_app_no_config(self, m): |
| 216 | """ |
| 217 | Install an application that has to be downloaded from a remote source |
| 218 | """ |
| 219 | |
| 220 | self.onos_app.url = 'http://onf.org/maven/...' |
| 221 | self.onos_app.version = "1.13.1" |
Matteo Scandolo | 3b67257 | 2018-06-25 14:28:36 -0700 | [diff] [blame] | 222 | self.onos_app.app_id = "org.onosproject.vrouter" |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 223 | |
| 224 | expected = { |
| 225 | 'activate': True, |
| 226 | 'url': self.onos_app.url |
| 227 | } |
| 228 | |
| 229 | m.post("/onos/v1/applications", |
| 230 | status_code=200, |
| 231 | additional_matcher=functools.partial(match_json, expected), |
| 232 | json=self.vrouter_app_response) |
| 233 | |
Matteo Scandolo | 3b67257 | 2018-06-25 14:28:36 -0700 | [diff] [blame] | 234 | m.get("http://onos-url:8181/onos/v1/applications/org.onosproject.vrouter", [ |
| 235 | {'status_code': 404, 'text': "foo"}, |
| 236 | {'status_code': 200, 'json': self.vrouter_app_response} |
| 237 | ]) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 238 | |
| 239 | self.si.serviceinstanceattribute_dict = {} |
| 240 | |
| 241 | with patch.object(ServiceInstance.objects, "get_items") as mock_si: |
| 242 | mock_si.return_value = [self.si] |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 243 | self.sync_step(model_accessor=self.model_accessor).sync_record(self.onos_app) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 244 | self.assertTrue(m.called) |
Matteo Scandolo | 3b67257 | 2018-06-25 14:28:36 -0700 | [diff] [blame] | 245 | self.assertEqual(m.call_count, 3) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 246 | self.assertEqual(self.onos_app.app_id, self.vrouter_app_response["name"]) |
| 247 | |
| 248 | @requests_mock.Mocker() |
| 249 | def test_update_remote_app(self, m): |
| 250 | self.onos_app.url = 'http://onf.org/maven/...' |
| 251 | self.onos_app.version = "1.14.1" |
| 252 | |
| 253 | expected = { |
| 254 | 'activate': True, |
| 255 | 'url': self.onos_app.url |
| 256 | } |
| 257 | |
| 258 | self.vrouter_app_response_updated = self.vrouter_app_response.copy() |
| 259 | self.vrouter_app_response_updated["version"] = "1.14.1" |
| 260 | |
| 261 | m.post("/onos/v1/applications", |
| 262 | status_code=200, |
| 263 | additional_matcher=functools.partial(match_json, expected), |
| 264 | json=self.vrouter_app_response) |
| 265 | |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 266 | m.get("http://onos-url:8181/onos/v1/applications/org.onosproject.vrouter", |
| 267 | [ |
| 268 | {"json": self.vrouter_app_response, "status_code": 200}, |
| 269 | {"json": self.vrouter_app_response_updated, "status_code": 200} |
| 270 | ] |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 271 | ) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 272 | |
| 273 | m.delete("http://onos-url:8181/onos/v1/applications/org.onosproject.vrouter", |
| 274 | status_code=204) |
| 275 | |
| 276 | self.si.serviceinstanceattribute_dict = {} |
| 277 | |
| 278 | with patch.object(ServiceInstance.objects, "get_items") as mock_si: |
| 279 | mock_si.return_value = [self.si] |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 280 | self.sync_step(model_accessor=self.model_accessor).sync_record(self.onos_app) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 281 | self.assertTrue(m.called) |
| 282 | self.assertEqual(m.call_count, 4) |
| 283 | self.assertEqual(self.onos_app.app_id, self.vrouter_app_response_updated["name"]) |
| 284 | |
| 285 | @requests_mock.Mocker() |
| 286 | def test_app_sync_remote_app_no_config_fail_version(self, m): |
| 287 | """ |
| 288 | Activate an application that has to be downloaded from a remote source |
| 289 | """ |
| 290 | |
| 291 | self.onos_app.url = 'http://onf.org/maven/...' |
| 292 | self.onos_app.version = "1.14.2" |
Matteo Scandolo | 3b67257 | 2018-06-25 14:28:36 -0700 | [diff] [blame] | 293 | self.onos_app.app_id = "org.onosproject.vrouter" |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 294 | |
| 295 | expected = { |
| 296 | 'activate': True, |
| 297 | 'url': self.onos_app.url |
| 298 | } |
| 299 | |
| 300 | m.post("/onos/v1/applications", |
| 301 | status_code=200, |
| 302 | additional_matcher=functools.partial(match_json, expected), |
| 303 | json=self.vrouter_app_response) |
| 304 | |
Matteo Scandolo | 3b67257 | 2018-06-25 14:28:36 -0700 | [diff] [blame] | 305 | m.get("http://onos-url:8181/onos/v1/applications/org.onosproject.vrouter", [ |
| 306 | {'status_code': 404, 'text': "foo"}, |
| 307 | {'status_code': 200, 'json': self.vrouter_app_response} |
| 308 | ]) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 309 | |
| 310 | self.si.serviceinstanceattribute_dict = {} |
| 311 | |
| 312 | with patch.object(ServiceInstance.objects, "get_items") as mock_si, \ |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 313 | self.assertRaises(Exception) as e: |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 314 | mock_si.return_value = [self.si] |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 315 | self.sync_step(model_accessor=self.model_accessor).sync_record(self.onos_app) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 316 | |
| 317 | self.assertTrue(m.called) |
Matteo Scandolo | 3b67257 | 2018-06-25 14:28:36 -0700 | [diff] [blame] | 318 | self.assertEqual(m.call_count, 3) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 319 | self.assertEqual(self.onos_app.app_id, self.vrouter_app_response["name"]) |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 320 | self.assertEqual( |
| 321 | e.exception.message, |
| 322 | "The version of org.onosproject.vrouter you installed (1.13.1) is not the same you requested (1.14.2)") |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 323 | |
| 324 | @requests_mock.Mocker() |
Matteo Scandolo | 3b67257 | 2018-06-25 14:28:36 -0700 | [diff] [blame] | 325 | def test_handle_409(self, m): |
| 326 | """ |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 327 | A 409 "Application Already installed" response is not an error. This should not happen as we check |
| 328 | if the app is installed. |
Matteo Scandolo | 3b67257 | 2018-06-25 14:28:36 -0700 | [diff] [blame] | 329 | """ |
| 330 | |
| 331 | self.onos_app.url = 'http://onf.org/maven/...' |
| 332 | self.onos_app.version = "1.14.2" |
| 333 | self.onos_app.app_id = "org.onosproject.vrouter" |
| 334 | |
| 335 | m.post("/onos/v1/applications", |
| 336 | status_code=409) |
| 337 | |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 338 | step = self.sync_step(model_accessor=self.model_accessor) |
Matteo Scandolo | 3b67257 | 2018-06-25 14:28:36 -0700 | [diff] [blame] | 339 | with patch.object(step, "check_app_installed") as mock_check_installed: |
| 340 | mock_check_installed.return_value = False |
| 341 | |
| 342 | step.sync_record(self.onos_app) |
| 343 | |
| 344 | self.assertTrue(m.called) |
| 345 | self.assertEqual(m.call_count, 1) |
| 346 | |
| 347 | @requests_mock.Mocker() |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 348 | def test_config_delete(self, m): |
| 349 | m.delete("http://onos-url:8181%s" % self.onos_app_attribute.name, |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 350 | status_code=204) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 351 | |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 352 | self.sync_step(model_accessor=self.model_accessor).delete_record(self.onos_app_attribute) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 353 | self.assertTrue(m.called) |
| 354 | self.assertEqual(m.call_count, 1) |
| 355 | |
| 356 | @requests_mock.Mocker() |
| 357 | def test_app_deactivate(self, m): |
| 358 | m.delete("http://onos-url:8181/onos/v1/applications/org.onosproject.vrouter/active", |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 359 | status_code=204) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 360 | |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 361 | self.sync_step(model_accessor=self.model_accessor).delete_record(self.onos_app) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 362 | self.assertTrue(m.called) |
| 363 | self.assertEqual(m.call_count, 1) |
| 364 | |
| 365 | @requests_mock.Mocker() |
| 366 | def test_app_uninstall(self, m): |
| 367 | self.onos_app.url = 'http://onf.org/maven/...' |
| 368 | self.onos_app.version = "1.14.2" |
| 369 | self.onos_app.backend_code = 1 |
| 370 | |
| 371 | m.delete("http://onos-url:8181/onos/v1/applications/org.onosproject.vrouter", |
| 372 | status_code=204) |
| 373 | |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 374 | self.sync_step(model_accessor=self.model_accessor).delete_record(self.onos_app) |
Matteo Scandolo | 0b986e2 | 2018-06-04 14:07:33 -0700 | [diff] [blame] | 375 | self.assertTrue(m.called) |
| 376 | self.assertEqual(m.call_count, 1) |
| 377 | |
Scott Baker | 7848fa5 | 2019-04-01 17:54:36 -0700 | [diff] [blame] | 378 | |
Scott Baker | 806d4b7 | 2019-02-26 19:01:59 -0800 | [diff] [blame] | 379 | if __name__ == '__main__': |
| 380 | unittest.main() |