Newer
Older
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from grpc import RpcError, StatusCode
from .conftest import create_qos_profile_from_json
from common.proto.context_pb2 import Empty, Uuid, QoSProfileId
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from common.tools.grpc.Tools import grpc_message_to_json_string
from qos_profile.client.QoSProfileClient import QoSProfileClient
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
qos_profile_data = {
"qos_profile_id": "f00406f5-8e36-4abc-a0ec-b871c7f062b7",
"name": "QCI_1_voice",
"description": "QoS profile for video streaming",
"status": "ACTIVE",
"targetMinUpstreamRate": {
"value": 10,
"unit": "bps"
},
"maxUpstreamRate": {
"value": 10,
"unit": "bps"
},
"maxUpstreamBurstRate": {
"value": 10,
"unit": "bps"
},
"targetMinDownstreamRate": {
"value": 10,
"unit": "bps"
},
"maxDownstreamRate": {
"value": 10,
"unit": "bps"
},
"maxDownstreamBurstRate": {
"value": 10,
"unit": "bps"
},
"minDuration": {
"value": 12,
"unit": "Minutes"
},
"maxDuration": {
"value": 12,
"unit": "Minutes"
},
"priority": 20,
"packetDelayBudget": {
"value": 12,
"unit": "Minutes"
},
"jitter": {
"value": 12,
"unit": "Minutes"
},
"packetErrorLossRate": 3
}
def test_create_qos_profile(qos_profile_client: QoSProfileClient):
qos_profile = create_qos_profile_from_json(qos_profile_data)
qos_profile_created = qos_profile_client.CreateQoSProfile(qos_profile)
LOGGER.info('qos_profile_data = {:s}'.format(grpc_message_to_json_string(qos_profile_created)))
assert qos_profile == qos_profile_created
def test_failed_create_qos_profile(qos_profile_client: QoSProfileClient):
qos_profile = create_qos_profile_from_json(qos_profile_data)
with pytest.raises(RpcError) as exc:
qos_profile_created = qos_profile_client.CreateQoSProfile(qos_profile)
assert exc.value.code() == StatusCode.ALREADY_EXISTS
def test_get_qos_profile(qos_profile_client: QoSProfileClient):
qos_profile = create_qos_profile_from_json(qos_profile_data)
qos_profile_got = qos_profile_client.GetQoSProfile(qos_profile.qos_profile_id)
LOGGER.info('qos_profile_data = {:s}'.format(grpc_message_to_json_string(qos_profile_got)))
assert qos_profile == qos_profile_got
def test_get_qos_profiles(qos_profile_client: QoSProfileClient):
qos_profile = create_qos_profile_from_json(qos_profile_data)
qos_profiles_got = list(qos_profile_client.GetQoSProfiles(Empty()))
Shayan Hajipour
committed
the_qos_profile = [q for q in qos_profiles_got if q.qos_profile_id == qos_profile.qos_profile_id]
LOGGER.info('qos_profile_data = {:s}'.format(grpc_message_to_json_string(qos_profiles_got)))
Shayan Hajipour
committed
assert len(the_qos_profile) == 1
assert qos_profile == the_qos_profile[0]
def test_update_qos_profile(qos_profile_client: QoSProfileClient):
qos_profile = create_qos_profile_from_json(qos_profile_data)
qos_profile.packetErrorLossRate = 5
qos_profile_updated = qos_profile_client.UpdateQoSProfile(qos_profile)
LOGGER.info('qos_profile_data = {:s}'.format(grpc_message_to_json_string(qos_profile_updated)))
assert qos_profile_updated.packetErrorLossRate == 5
def test_failed_delete_qos_profiles(qos_profile_client: QoSProfileClient):
qos_profile = create_qos_profile_from_json(qos_profile_data)
with pytest.raises(RpcError) as exc:
qos_profiles_deleted = qos_profile_client.DeleteQoSProfile(QoSProfileId(qos_profile_id=Uuid(uuid='f8b1c625-ac01-405c-b1f7-b5ee06e16282')))
assert exc.value.code() == StatusCode.NOT_FOUND
def test_delete_qos_profiles(qos_profile_client: QoSProfileClient):
qos_profile = create_qos_profile_from_json(qos_profile_data)
qos_profiles_deleted = qos_profile_client.DeleteQoSProfile(qos_profile.qos_profile_id)
assert qos_profiles_deleted == Empty()