Remove regression tag from disabled daily tests
[osm/tests.git] / robot-systest / deprecated / lib / custom_lib.py
1 # -*- coding: utf-8 -*-
2
3 ##
4 # Copyright 2019 Tech Mahindra Limited
5 #
6 # All Rights Reserved.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
18 # under the License.
19 ##
20
21 ## Change log:
22 # Jayant Madavi, Mrityunjay Yadav : MY00514913@techmahindra.com
23 ##̥
24
25
26 import random
27 from haikunator import Haikunator
28 import yaml
29 from os.path import basename
30 import hashlib
31
32 from robot.api import logger
33 from robot.api.deco import keyword
34
35
36 def generate_name():
37 haikunator = Haikunator()
38 name = haikunator.haikunate(delimiter='_', token_length=2)
39 return name
40
41
42 def get_random_item_from_list(l):
43 assert isinstance(l, list), "List should be provided"
44 return random.choice(l)
45
46
47 def get_scaled_vnf(nsr):
48 nsr = yaml.load(nsr)
49 if 'scaling-group' in nsr['_admin']:
50 return nsr['_admin']['scaling-group'][0]['nb-scale-op']
51 else:
52 return 0
53
54
55 @keyword('Get File Name From Path')
56 def get_filename(path):
57 filename = basename(path)
58 return filename, filename.split('.')[0]
59
60
61 @keyword('Generate MD5')
62 def generate_md5(fpath):
63 hash_md5 = hashlib.md5()
64 with open(fpath, "rb") as f:
65 for chunk in iter(lambda: f.read(1024), b""):
66 hash_md5.update(chunk)
67 return hash_md5.hexdigest()