| Dominik Fleischmann | ca6eb95 | 2019-11-27 16:38:18 +0100 | [diff] [blame] | 1 | # Copyright 2019 Canonical Ltd. |
| 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 | |
| Adam Israel | 6d84dbd | 2019-03-08 18:33:35 -0500 | [diff] [blame] | 15 | """ |
| 16 | Test N2VC's ssh key generation |
| 17 | """ |
| 18 | import n2vc |
| Adam Israel | 6d84dbd | 2019-03-08 18:33:35 -0500 | [diff] [blame] | 19 | import pytest |
| 20 | from . import base |
| Adam Israel | 6d84dbd | 2019-03-08 18:33:35 -0500 | [diff] [blame] | 21 | import uuid |
| 22 | |
| 23 | |
| 24 | @pytest.mark.asyncio |
| 25 | async def test_model_create(): |
| 26 | """Test the creation of a new model.""" |
| 27 | client = base.get_n2vc() |
| 28 | |
| 29 | model_name = "test-{}".format( |
| 30 | uuid.uuid4().hex[-4:], |
| 31 | ) |
| 32 | |
| 33 | pytest.assume(await client.CreateNetworkService(model_name)) |
| 34 | pytest.assume(await client.DestroyNetworkService(model_name)) |
| 35 | pytest.assume(await client.logout()) |
| 36 | |
| 37 | |
| 38 | @pytest.mark.asyncio |
| 39 | async def test_destroy_non_existing_network_service(): |
| 40 | """Destroy a model that doesn't exist.""" |
| 41 | |
| 42 | client = base.get_n2vc() |
| 43 | |
| 44 | model_name = "test-{}".format( |
| 45 | uuid.uuid4().hex[-4:], |
| 46 | ) |
| 47 | |
| 48 | with pytest.raises(n2vc.vnf.NetworkServiceDoesNotExist): |
| 49 | pytest.assume(await client.DestroyNetworkService(model_name)) |
| 50 | |
| 51 | pytest.assume(await client.logout()) |
| 52 | |
| 53 | |
| 54 | @pytest.mark.asyncio |
| 55 | async def test_model_create_duplicate(): |
| 56 | """Create a new model, and try to create the same model.""" |
| 57 | client = base.get_n2vc() |
| 58 | |
| 59 | model_name = "test-{}".format( |
| 60 | uuid.uuid4().hex[-4:], |
| 61 | ) |
| 62 | |
| 63 | # Try to recreate bug 628 |
| 64 | for x in range(0, 1000): |
| 65 | model = await client.get_model(model_name) |
| 66 | pytest.assume(model) |
| 67 | |
| 68 | pytest.assume(await client.DestroyNetworkService(model_name)) |
| 69 | pytest.assume(await client.logout()) |